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/gestures/gesture_configuration.h"
15 using blink::WebTouchEvent
;
16 using blink::WebMouseWheelEvent
;
20 SyntheticGestureTargetAura::SyntheticGestureTargetAura(
21 RenderWidgetHostImpl
* host
)
22 : SyntheticGestureTargetBase(host
) {
25 void SyntheticGestureTargetAura::DispatchWebTouchEventToPlatform(
26 const WebTouchEvent
& web_touch
,
27 const ui::LatencyInfo
& latency_info
) {
28 TouchEventWithLatencyInfo
touch_with_latency(web_touch
, latency_info
);
29 ScopedVector
<ui::TouchEvent
> events
;
30 bool conversion_success
= MakeUITouchEventsFromWebTouchEvents(
31 touch_with_latency
, &events
, LOCAL_COORDINATES
);
32 DCHECK(conversion_success
);
34 aura::Window
* window
= GetWindow();
35 aura::WindowTreeHost
* host
= window
->GetHost();
36 for (ScopedVector
<ui::TouchEvent
>::iterator iter
= events
.begin(),
37 end
= events
.end(); iter
!= end
; ++iter
) {
38 (*iter
)->ConvertLocationToTarget(window
, host
->window());
39 ui::EventDispatchDetails details
=
40 host
->event_processor()->OnEventFromSource(*iter
);
41 if (details
.dispatcher_destroyed
)
46 void SyntheticGestureTargetAura::DispatchWebMouseWheelEventToPlatform(
47 const blink::WebMouseWheelEvent
& web_wheel
,
48 const ui::LatencyInfo
&) {
49 gfx::Point
location(web_wheel
.x
, web_wheel
.y
);
50 ui::MouseEvent
mouse_event(
51 ui::ET_MOUSEWHEEL
, location
, location
, ui::EF_NONE
, ui::EF_NONE
);
52 ui::MouseWheelEvent
wheel_event(
53 mouse_event
, web_wheel
.deltaX
, web_wheel
.deltaY
);
55 aura::Window
* window
= GetWindow();
56 wheel_event
.ConvertLocationToTarget(window
, window
->GetRootWindow());
57 ui::EventDispatchDetails details
=
58 window
->GetHost()->event_processor()->OnEventFromSource(&wheel_event
);
59 if (details
.dispatcher_destroyed
)
66 WebMouseEventTypeToEventType(blink::WebInputEvent::Type web_type
) {
68 case blink::WebInputEvent::MouseDown
:
69 return ui::ET_MOUSE_PRESSED
;
71 case blink::WebInputEvent::MouseUp
:
72 return ui::ET_MOUSE_RELEASED
;
74 case blink::WebInputEvent::MouseMove
:
75 return ui::ET_MOUSE_MOVED
;
77 case blink::WebInputEvent::MouseEnter
:
78 return ui::ET_MOUSE_ENTERED
;
80 case blink::WebInputEvent::MouseLeave
:
81 return ui::ET_MOUSE_EXITED
;
83 case blink::WebInputEvent::ContextMenu
:
84 NOTREACHED() << "WebInputEvent::ContextMenu not supported by"
85 "SyntheticGestureTargetAura";
91 return ui::ET_UNKNOWN
;
94 int WebMouseEventButtonToFlags(blink::WebMouseEvent::Button button
) {
96 case blink::WebMouseEvent::ButtonLeft
:
97 return ui::EF_LEFT_MOUSE_BUTTON
;
99 case blink::WebMouseEvent::ButtonMiddle
:
100 return ui::EF_MIDDLE_MOUSE_BUTTON
;
102 case blink::WebMouseEvent::ButtonRight
:
103 return ui::EF_RIGHT_MOUSE_BUTTON
;
114 void SyntheticGestureTargetAura::DispatchWebMouseEventToPlatform(
115 const blink::WebMouseEvent
& web_mouse
,
116 const ui::LatencyInfo
& latency_info
) {
117 gfx::Point
location(web_mouse
.x
, web_mouse
.y
);
118 ui::EventType event_type
= WebMouseEventTypeToEventType(web_mouse
.type
);
119 int flags
= WebMouseEventButtonToFlags(web_mouse
.button
);
120 ui::MouseEvent
mouse_event(event_type
, location
, location
, flags
, flags
);
122 aura::Window
* window
= GetWindow();
123 mouse_event
.ConvertLocationToTarget(window
, window
->GetRootWindow());
124 ui::EventDispatchDetails details
=
125 window
->GetHost()->event_processor()->OnEventFromSource(&mouse_event
);
126 if (details
.dispatcher_destroyed
)
130 SyntheticGestureParams::GestureSourceType
131 SyntheticGestureTargetAura::GetDefaultSyntheticGestureSourceType() const {
132 return SyntheticGestureParams::TOUCH_INPUT
;
135 int SyntheticGestureTargetAura::GetTouchSlopInDips() const {
136 // - 1 because Aura considers a pointer to be moving if it has moved at least
137 // 'max_touch_move_in_pixels_for_click' pixels.
138 return ui::GestureConfiguration::max_touch_move_in_pixels_for_click() - 1;
141 aura::Window
* SyntheticGestureTargetAura::GetWindow() const {
142 aura::Window
* window
= render_widget_host()->GetView()->GetNativeView();
147 } // namespace content