OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/browser/renderer_host/input/synthetic_gesture_target_aura.h" | 5 #include "content/browser/renderer_host/input/synthetic_gesture_target_aura.h" |
6 | 6 |
7 #include "content/browser/renderer_host/render_widget_host_impl.h" | 7 #include "content/browser/renderer_host/render_widget_host_impl.h" |
8 #include "content/browser/renderer_host/render_widget_host_view_aura.h" | 8 #include "content/browser/renderer_host/render_widget_host_view_aura.h" |
9 #include "content/browser/renderer_host/ui_events_helper.h" | 9 #include "content/browser/renderer_host/ui_events_helper.h" |
10 #include "content/common/input/input_event.h" | 10 #include "content/common/input/input_event.h" |
11 #include "ui/aura/client/screen_position_client.h" | 11 #include "ui/aura/client/screen_position_client.h" |
12 #include "ui/aura/root_window.h" | 12 #include "ui/aura/root_window.h" |
13 #include "ui/aura/window.h" | 13 #include "ui/aura/window.h" |
14 #include "ui/events/gestures/gesture_configuration.h" | 14 #include "ui/events/gestures/gesture_configuration.h" |
15 | 15 |
16 using blink::WebTouchEvent; | 16 using blink::WebTouchEvent; |
17 using blink::WebMouseWheelEvent; | 17 using blink::WebMouseWheelEvent; |
18 | 18 |
19 namespace content { | 19 namespace content { |
20 | 20 |
21 SyntheticGestureTargetAura::SyntheticGestureTargetAura( | 21 SyntheticGestureTargetAura::SyntheticGestureTargetAura( |
22 RenderWidgetHostImpl* host) | 22 RenderWidgetHostImpl* host) |
23 : SyntheticGestureTargetBase(host) { | 23 : SyntheticGestureTargetBase(host) { |
24 } | 24 } |
25 | 25 |
26 void SyntheticGestureTargetAura::DispatchWebTouchEventToPlatform( | 26 void SyntheticGestureTargetAura::DispatchWebTouchEventToPlatform( |
27 const WebTouchEvent& web_touch, | 27 const WebTouchEvent& web_touch, |
28 const ui::LatencyInfo& latency_info) { | 28 const ui::LatencyInfo& latency_info) { |
29 aura::Window* window = render_widget_host()->GetView()->GetNativeView(); | 29 aura::Window* window = GetWindow(); |
30 aura::Window* root_window = window->GetRootWindow(); | |
31 aura::client::ScreenPositionClient* position_client = | 30 aura::client::ScreenPositionClient* position_client = |
32 aura::client::GetScreenPositionClient(root_window); | 31 GetScreenPositionClient(); |
33 DCHECK(position_client); | |
34 | 32 |
35 TouchEventWithLatencyInfo touch_with_latency(web_touch, latency_info); | 33 TouchEventWithLatencyInfo touch_with_latency(web_touch, latency_info); |
36 | 34 |
37 // SyntheticGesture may skip calculating screenPosition, so we will fill it | 35 // SyntheticGesture may skip calculating screenPosition, so we will fill it |
38 // in here. "screenPosition" is converted from "position". | 36 // in here. "screenPosition" is converted from "position". |
39 const size_t num_touches = touch_with_latency.event.touchesLength; | 37 const size_t num_touches = touch_with_latency.event.touchesLength; |
40 for (size_t i = 0; i < num_touches; ++ i) { | 38 for (size_t i = 0; i < num_touches; ++ i) { |
41 blink::WebTouchPoint* point = &touch_with_latency.event.touches[i]; | 39 blink::WebTouchPoint* point = &touch_with_latency.event.touches[i]; |
42 gfx::Point position(point->position.x, point->position.y); | 40 gfx::Point position(point->position.x, point->position.y); |
43 position_client->ConvertPointToScreen(window, &position); | 41 position_client->ConvertPointToScreen(window, &position); |
(...skipping 10 matching lines...) Expand all Loading... |
54 GetRootWindowHostDelegate(); | 52 GetRootWindowHostDelegate(); |
55 for (ScopedVector<ui::TouchEvent>::iterator iter = events.begin(), | 53 for (ScopedVector<ui::TouchEvent>::iterator iter = events.begin(), |
56 end = events.end(); iter != end; ++iter) { | 54 end = events.end(); iter != end; ++iter) { |
57 root_window_host_delegate->OnHostTouchEvent(*iter); | 55 root_window_host_delegate->OnHostTouchEvent(*iter); |
58 } | 56 } |
59 } | 57 } |
60 | 58 |
61 void SyntheticGestureTargetAura::DispatchWebMouseWheelEventToPlatform( | 59 void SyntheticGestureTargetAura::DispatchWebMouseWheelEventToPlatform( |
62 const blink::WebMouseWheelEvent& web_wheel, | 60 const blink::WebMouseWheelEvent& web_wheel, |
63 const ui::LatencyInfo&) { | 61 const ui::LatencyInfo&) { |
| 62 aura::Window* window = GetWindow(); |
| 63 aura::client::ScreenPositionClient* position_client = |
| 64 GetScreenPositionClient(); |
64 gfx::Point location(web_wheel.x, web_wheel.y); | 65 gfx::Point location(web_wheel.x, web_wheel.y); |
| 66 position_client->ConvertPointToScreen(window, &location); |
| 67 |
65 ui::MouseEvent mouse_event( | 68 ui::MouseEvent mouse_event( |
66 ui::ET_MOUSEWHEEL, location, location, ui::EF_NONE, ui::EF_NONE); | 69 ui::ET_MOUSEWHEEL, location, location, ui::EF_NONE, ui::EF_NONE); |
67 ui::MouseWheelEvent wheel_event( | 70 ui::MouseWheelEvent wheel_event( |
68 mouse_event, web_wheel.deltaX, web_wheel.deltaY); | 71 mouse_event, web_wheel.deltaX, web_wheel.deltaY); |
69 | 72 |
70 GetRootWindowHostDelegate()->OnHostMouseEvent(&wheel_event); | 73 GetRootWindowHostDelegate()->OnHostMouseEvent(&wheel_event); |
71 } | 74 } |
72 | 75 |
73 namespace { | 76 namespace { |
74 | 77 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 } | 120 } |
118 | 121 |
119 return 0; | 122 return 0; |
120 } | 123 } |
121 | 124 |
122 } // namespace | 125 } // namespace |
123 | 126 |
124 void SyntheticGestureTargetAura::DispatchWebMouseEventToPlatform( | 127 void SyntheticGestureTargetAura::DispatchWebMouseEventToPlatform( |
125 const blink::WebMouseEvent& web_mouse, | 128 const blink::WebMouseEvent& web_mouse, |
126 const ui::LatencyInfo& latency_info) { | 129 const ui::LatencyInfo& latency_info) { |
| 130 aura::Window* window = GetWindow(); |
| 131 aura::client::ScreenPositionClient* position_client = |
| 132 GetScreenPositionClient(); |
127 gfx::Point location(web_mouse.x, web_mouse.y); | 133 gfx::Point location(web_mouse.x, web_mouse.y); |
| 134 position_client->ConvertPointToScreen(window, &location); |
| 135 |
128 ui::EventType event_type = WebMouseEventTypeToEventType(web_mouse.type); | 136 ui::EventType event_type = WebMouseEventTypeToEventType(web_mouse.type); |
129 int flags = WebMouseEventButtonToFlags(web_mouse.button); | 137 int flags = WebMouseEventButtonToFlags(web_mouse.button); |
130 // TODO: last argument (changed_button_flags) likely isn't right. | 138 ui::MouseEvent mouse_event(event_type, location, location, flags, flags); |
131 ui::MouseEvent mouse_event(event_type, location, location, flags, 0); | |
132 | 139 |
133 GetRootWindowHostDelegate()->OnHostMouseEvent(&mouse_event); | 140 GetRootWindowHostDelegate()->OnHostMouseEvent(&mouse_event); |
134 } | 141 } |
135 | 142 |
136 SyntheticGestureParams::GestureSourceType | 143 SyntheticGestureParams::GestureSourceType |
137 SyntheticGestureTargetAura::GetDefaultSyntheticGestureSourceType() const { | 144 SyntheticGestureTargetAura::GetDefaultSyntheticGestureSourceType() const { |
138 return SyntheticGestureParams::MOUSE_INPUT; | 145 return SyntheticGestureParams::MOUSE_INPUT; |
139 } | 146 } |
140 | 147 |
141 bool SyntheticGestureTargetAura::SupportsSyntheticGestureSourceType( | 148 bool SyntheticGestureTargetAura::SupportsSyntheticGestureSourceType( |
142 SyntheticGestureParams::GestureSourceType gesture_source_type) const { | 149 SyntheticGestureParams::GestureSourceType gesture_source_type) const { |
143 return gesture_source_type == SyntheticGestureParams::TOUCH_INPUT || | 150 return gesture_source_type == SyntheticGestureParams::TOUCH_INPUT || |
144 gesture_source_type == SyntheticGestureParams::MOUSE_INPUT; | 151 gesture_source_type == SyntheticGestureParams::MOUSE_INPUT; |
145 } | 152 } |
146 | 153 |
147 int SyntheticGestureTargetAura::GetTouchSlopInDips() const { | 154 int SyntheticGestureTargetAura::GetTouchSlopInDips() const { |
148 // - 1 because Aura considers a pointer to be moving if it has moved at least | 155 // - 1 because Aura considers a pointer to be moving if it has moved at least |
149 // 'max_touch_move_in_pixels_for_click' pixels. | 156 // 'max_touch_move_in_pixels_for_click' pixels. |
150 return ui::GestureConfiguration::max_touch_move_in_pixels_for_click() - 1; | 157 return ui::GestureConfiguration::max_touch_move_in_pixels_for_click() - 1; |
151 } | 158 } |
152 | 159 |
| 160 aura::Window* SyntheticGestureTargetAura::GetWindow() const { |
| 161 aura::Window* window = render_widget_host()->GetView()->GetNativeView(); |
| 162 DCHECK(window); |
| 163 return window; |
| 164 } |
| 165 |
153 aura::RootWindowHostDelegate* | 166 aura::RootWindowHostDelegate* |
154 SyntheticGestureTargetAura::GetRootWindowHostDelegate() const { | 167 SyntheticGestureTargetAura::GetRootWindowHostDelegate() const { |
155 aura::Window* window = render_widget_host()->GetView()->GetNativeView(); | 168 aura::Window* root_window = GetWindow()->GetRootWindow(); |
156 aura::Window* root_window = window->GetRootWindow(); | |
157 aura::RootWindowHostDelegate* root_window_host_delegate = | 169 aura::RootWindowHostDelegate* root_window_host_delegate = |
158 root_window->GetDispatcher()->AsRootWindowHostDelegate(); | 170 root_window->GetDispatcher()->AsRootWindowHostDelegate(); |
159 DCHECK(root_window_host_delegate); | 171 DCHECK(root_window_host_delegate); |
160 return root_window_host_delegate; | 172 return root_window_host_delegate; |
161 } | 173 } |
162 | 174 |
| 175 aura::client::ScreenPositionClient* |
| 176 SyntheticGestureTargetAura::GetScreenPositionClient() const { |
| 177 aura::Window* root_window = GetWindow()->GetRootWindow(); |
| 178 aura::client::ScreenPositionClient* position_client = |
| 179 aura::client::GetScreenPositionClient(root_window); |
| 180 DCHECK(position_client); |
| 181 return position_client; |
| 182 } |
163 | 183 |
164 } // namespace content | 184 } // namespace content |
OLD | NEW |