1 // Copyright 2013 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/input/synthetic_gesture_target_aura.h"
7 #include "content/browser/renderer_host/render_widget_host_impl.h"
8 #include "content/browser/renderer_host/render_widget_host_view_aura.h"
9 #include "content/browser/renderer_host/ui_events_helper.h"
10 #include "ui/aura/window.h"
11 #include "ui/aura/window_tree_host.h"
12 #include "ui/events/event_processor.h"
13 #include "ui/events/event_utils.h"
14 #include "ui/events/gesture_detection/gesture_configuration.h"
16 using blink::WebTouchEvent
;
17 using blink::WebMouseWheelEvent
;
21 SyntheticGestureTargetAura::SyntheticGestureTargetAura(
22 RenderWidgetHostImpl
* host
)
23 : SyntheticGestureTargetBase(host
) {
26 void SyntheticGestureTargetAura::DispatchWebTouchEventToPlatform(
27 const WebTouchEvent
& web_touch
,
28 const ui::LatencyInfo
& latency_info
) {
29 TouchEventWithLatencyInfo
touch_with_latency(web_touch
, latency_info
);
30 ScopedVector
<ui::TouchEvent
> events
;
31 bool conversion_success
= MakeUITouchEventsFromWebTouchEvents(
32 touch_with_latency
, &events
, LOCAL_COORDINATES
);
33 DCHECK(conversion_success
);
35 aura::Window
* window
= GetWindow();
36 aura::WindowTreeHost
* host
= window
->GetHost();
37 for (ScopedVector
<ui::TouchEvent
>::iterator iter
= events
.begin(),
38 end
= events
.end(); iter
!= end
; ++iter
) {
39 (*iter
)->ConvertLocationToTarget(window
, host
->window());
40 ui::EventDispatchDetails details
=
41 host
->event_processor()->OnEventFromSource(*iter
);
42 if (details
.dispatcher_destroyed
)
47 void SyntheticGestureTargetAura::DispatchWebMouseWheelEventToPlatform(
48 const blink::WebMouseWheelEvent
& web_wheel
,
49 const ui::LatencyInfo
&) {
50 gfx::Point
location(web_wheel
.x
, web_wheel
.y
);
51 ui::MouseEvent
mouse_event(ui::ET_MOUSEWHEEL
, location
, location
,
52 ui::EventTimeForNow(), ui::EF_NONE
, ui::EF_NONE
);
53 ui::MouseWheelEvent
wheel_event(
54 mouse_event
, web_wheel
.deltaX
, web_wheel
.deltaY
);
56 aura::Window
* window
= GetWindow();
57 wheel_event
.ConvertLocationToTarget(window
, window
->GetRootWindow());
58 ui::EventDispatchDetails details
=
59 window
->GetHost()->event_processor()->OnEventFromSource(&wheel_event
);
60 if (details
.dispatcher_destroyed
)
67 WebMouseEventTypeToEventType(blink::WebInputEvent::Type web_type
) {
69 case blink::WebInputEvent::MouseDown
:
70 return ui::ET_MOUSE_PRESSED
;
72 case blink::WebInputEvent::MouseUp
:
73 return ui::ET_MOUSE_RELEASED
;
75 case blink::WebInputEvent::MouseMove
:
76 return ui::ET_MOUSE_MOVED
;
78 case blink::WebInputEvent::MouseEnter
:
79 return ui::ET_MOUSE_ENTERED
;
81 case blink::WebInputEvent::MouseLeave
:
82 return ui::ET_MOUSE_EXITED
;
84 case blink::WebInputEvent::ContextMenu
:
85 NOTREACHED() << "WebInputEvent::ContextMenu not supported by"
86 "SyntheticGestureTargetAura";
92 return ui::ET_UNKNOWN
;
95 int WebMouseEventButtonToFlags(blink::WebMouseEvent::Button button
) {
97 case blink::WebMouseEvent::ButtonLeft
:
98 return ui::EF_LEFT_MOUSE_BUTTON
;
100 case blink::WebMouseEvent::ButtonMiddle
:
101 return ui::EF_MIDDLE_MOUSE_BUTTON
;
103 case blink::WebMouseEvent::ButtonRight
:
104 return ui::EF_RIGHT_MOUSE_BUTTON
;
115 void SyntheticGestureTargetAura::DispatchWebMouseEventToPlatform(
116 const blink::WebMouseEvent
& web_mouse
,
117 const ui::LatencyInfo
& latency_info
) {
118 gfx::Point
location(web_mouse
.x
, web_mouse
.y
);
119 ui::EventType event_type
= WebMouseEventTypeToEventType(web_mouse
.type
);
120 int flags
= WebMouseEventButtonToFlags(web_mouse
.button
);
121 ui::MouseEvent
mouse_event(event_type
, location
, location
,
122 ui::EventTimeForNow(), flags
, flags
);
124 aura::Window
* window
= GetWindow();
125 mouse_event
.ConvertLocationToTarget(window
, window
->GetRootWindow());
126 ui::EventDispatchDetails details
=
127 window
->GetHost()->event_processor()->OnEventFromSource(&mouse_event
);
128 if (details
.dispatcher_destroyed
)
132 SyntheticGestureParams::GestureSourceType
133 SyntheticGestureTargetAura::GetDefaultSyntheticGestureSourceType() const {
134 return SyntheticGestureParams::TOUCH_INPUT
;
137 float SyntheticGestureTargetAura::GetTouchSlopInDips() const {
138 // - 1 because Aura considers a pointer to be moving if it has moved at least
139 // 'max_touch_move_in_pixels_for_click' pixels.
140 return ui::GestureConfiguration::GetInstance()
141 ->max_touch_move_in_pixels_for_click() -
145 float SyntheticGestureTargetAura::GetMinScalingSpanInDips() const {
146 return ui::GestureConfiguration::GetInstance()
147 ->min_distance_for_pinch_scroll_in_pixels();
150 aura::Window
* SyntheticGestureTargetAura::GetWindow() const {
151 aura::Window
* window
= render_widget_host()->GetView()->GetNativeView();
156 } // namespace content