1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/browser/renderer_host/ui_events_helper.h"
7 #include "content/browser/renderer_host/input/web_input_event_util.h"
8 #include "content/common/input/web_touch_event_traits.h"
9 #include "third_party/WebKit/public/web/WebInputEvent.h"
10 #include "ui/events/blink/blink_event_util.h"
11 #include "ui/events/event.h"
12 #include "ui/events/event_constants.h"
16 ui::EventType
WebTouchPointStateToEventType(
17 blink::WebTouchPoint::State state
) {
19 case blink::WebTouchPoint::StateReleased
:
20 return ui::ET_TOUCH_RELEASED
;
22 case blink::WebTouchPoint::StatePressed
:
23 return ui::ET_TOUCH_PRESSED
;
25 case blink::WebTouchPoint::StateMoved
:
26 return ui::ET_TOUCH_MOVED
;
28 case blink::WebTouchPoint::StateCancelled
:
29 return ui::ET_TOUCH_CANCELLED
;
32 return ui::ET_UNKNOWN
;
40 bool MakeUITouchEventsFromWebTouchEvents(
41 const TouchEventWithLatencyInfo
& touch_with_latency
,
42 ScopedVector
<ui::TouchEvent
>* list
,
43 TouchEventCoordinateSystem coordinate_system
) {
44 const blink::WebTouchEvent
& touch
= touch_with_latency
.event
;
45 ui::EventType type
= ui::ET_UNKNOWN
;
47 case blink::WebInputEvent::TouchStart
:
48 type
= ui::ET_TOUCH_PRESSED
;
50 case blink::WebInputEvent::TouchEnd
:
51 type
= ui::ET_TOUCH_RELEASED
;
53 case blink::WebInputEvent::TouchMove
:
54 type
= ui::ET_TOUCH_MOVED
;
56 case blink::WebInputEvent::TouchCancel
:
57 type
= ui::ET_TOUCH_CANCELLED
;
64 int flags
= WebEventModifiersToEventFlags(touch
.modifiers
);
65 base::TimeDelta timestamp
= base::TimeDelta::FromMicroseconds(
66 static_cast<int64
>(touch
.timeStampSeconds
* 1000000));
67 for (unsigned i
= 0; i
< touch
.touchesLength
; ++i
) {
68 const blink::WebTouchPoint
& point
= touch
.touches
[i
];
69 if (WebTouchPointStateToEventType(point
.state
) != type
)
71 // ui events start in the co-ordinate space of the EventDispatcher.
73 if (coordinate_system
== LOCAL_COORDINATES
)
74 location
= point
.position
;
76 location
= point
.screenPosition
;
77 ui::TouchEvent
* uievent
= new ui::TouchEvent(type
,
86 uievent
->set_latency(touch_with_latency
.latency
);
87 list
->push_back(uievent
);
92 blink::WebGestureEvent
MakeWebGestureEventFromUIEvent(
93 const ui::GestureEvent
& event
) {
94 return ui::CreateWebGestureEvent(event
.details(), event
.time_stamp(),
95 event
.location_f(), event
.root_location_f(),
99 } // namespace content