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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "content/browser/renderer_host/render_widget_host_impl.h" | 9 #include "content/browser/renderer_host/render_widget_host_impl.h" |
10 #include "content/browser/renderer_host/render_widget_host_view_aura.h" | 10 #include "content/browser/renderer_host/render_widget_host_view_aura.h" |
11 #include "content/browser/renderer_host/ui_events_helper.h" | 11 #include "content/browser/renderer_host/ui_events_helper.h" |
12 #include "ui/aura/window.h" | 12 #include "ui/aura/window.h" |
13 #include "ui/aura/window_tree_host.h" | 13 #include "ui/aura/window_tree_host.h" |
14 #include "ui/events/event_processor.h" | 14 #include "ui/events/event_processor.h" |
15 #include "ui/events/event_utils.h" | 15 #include "ui/events/event_utils.h" |
16 #include "ui/events/gesture_detection/gesture_configuration.h" | 16 #include "ui/events/gesture_detection/gesture_configuration.h" |
17 | 17 |
18 using blink::WebTouchEvent; | 18 using blink::WebTouchEvent; |
19 using blink::WebMouseWheelEvent; | 19 using blink::WebMouseWheelEvent; |
| 20 using blink::WebGestureEvent; |
20 | 21 |
21 namespace content { | 22 namespace content { |
22 | 23 |
23 SyntheticGestureTargetAura::SyntheticGestureTargetAura( | 24 SyntheticGestureTargetAura::SyntheticGestureTargetAura( |
24 RenderWidgetHostImpl* host) | 25 RenderWidgetHostImpl* host) |
25 : SyntheticGestureTargetBase(host) { | 26 : SyntheticGestureTargetBase(host) { |
26 ScreenInfo screen_info; | 27 ScreenInfo screen_info; |
27 host->GetScreenInfo(&screen_info); | 28 host->GetScreenInfo(&screen_info); |
28 device_scale_factor_ = screen_info.device_scale_factor; | 29 device_scale_factor_ = screen_info.device_scale_factor; |
29 } | 30 } |
(...skipping 28 matching lines...) Expand all Loading... |
58 ui::EventDispatchDetails details = | 59 ui::EventDispatchDetails details = |
59 host->event_processor()->OnEventFromSource(*iter); | 60 host->event_processor()->OnEventFromSource(*iter); |
60 if (details.dispatcher_destroyed) | 61 if (details.dispatcher_destroyed) |
61 break; | 62 break; |
62 } | 63 } |
63 } | 64 } |
64 | 65 |
65 void SyntheticGestureTargetAura::DispatchWebMouseWheelEventToPlatform( | 66 void SyntheticGestureTargetAura::DispatchWebMouseWheelEventToPlatform( |
66 const blink::WebMouseWheelEvent& web_wheel, | 67 const blink::WebMouseWheelEvent& web_wheel, |
67 const ui::LatencyInfo&) { | 68 const ui::LatencyInfo&) { |
| 69 base::TimeTicks timestamp = |
| 70 ui::EventTimeStampFromSeconds(web_wheel.timeStampSeconds()); |
68 ui::MouseWheelEvent wheel_event( | 71 ui::MouseWheelEvent wheel_event( |
69 gfx::Vector2d(web_wheel.deltaX, web_wheel.deltaY), gfx::Point(), | 72 gfx::Vector2d(web_wheel.deltaX, web_wheel.deltaY), gfx::Point(), |
70 gfx::Point(), ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE); | 73 gfx::Point(), timestamp, ui::EF_NONE, ui::EF_NONE); |
71 gfx::PointF location(web_wheel.x * device_scale_factor_, | 74 gfx::PointF location(web_wheel.x * device_scale_factor_, |
72 web_wheel.y * device_scale_factor_); | 75 web_wheel.y * device_scale_factor_); |
73 wheel_event.set_location_f(location); | 76 wheel_event.set_location_f(location); |
74 wheel_event.set_root_location_f(location); | 77 wheel_event.set_root_location_f(location); |
75 | 78 |
76 aura::Window* window = GetWindow(); | 79 aura::Window* window = GetWindow(); |
77 wheel_event.ConvertLocationToTarget(window, window->GetRootWindow()); | 80 wheel_event.ConvertLocationToTarget(window, window->GetRootWindow()); |
78 ui::EventDispatchDetails details = | 81 ui::EventDispatchDetails details = |
79 window->GetHost()->event_processor()->OnEventFromSource(&wheel_event); | 82 window->GetHost()->event_processor()->OnEventFromSource(&wheel_event); |
80 if (details.dispatcher_destroyed) | 83 if (details.dispatcher_destroyed) |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 mouse_event.set_pointer_details(pointer_details); | 158 mouse_event.set_pointer_details(pointer_details); |
156 | 159 |
157 aura::Window* window = GetWindow(); | 160 aura::Window* window = GetWindow(); |
158 mouse_event.ConvertLocationToTarget(window, window->GetRootWindow()); | 161 mouse_event.ConvertLocationToTarget(window, window->GetRootWindow()); |
159 ui::EventDispatchDetails details = | 162 ui::EventDispatchDetails details = |
160 window->GetHost()->event_processor()->OnEventFromSource(&mouse_event); | 163 window->GetHost()->event_processor()->OnEventFromSource(&mouse_event); |
161 if (details.dispatcher_destroyed) | 164 if (details.dispatcher_destroyed) |
162 return; | 165 return; |
163 } | 166 } |
164 | 167 |
| 168 // This function generates a synthetic ui event which aligns with ChromeOS |
| 169 // event stream for handling touchpad fling. |
| 170 void SyntheticGestureTargetAura::DispatchTouchpadGestureFlingStartToPlatform( |
| 171 const blink::WebGestureEvent& web_gesture, |
| 172 const ui::LatencyInfo& latency_info) { |
| 173 DCHECK_EQ(web_gesture.type(), blink::WebInputEvent::GestureFlingStart); |
| 174 |
| 175 float velocity_x = web_gesture.data.flingStart.velocityX; |
| 176 float velocity_y = web_gesture.data.flingStart.velocityY; |
| 177 DCHECK(velocity_x || velocity_y); |
| 178 |
| 179 base::TimeTicks timestamp = |
| 180 ui::EventTimeStampFromSeconds(web_gesture.timeStampSeconds()); |
| 181 ui::ScrollEvent fling_event(ui::ET_SCROLL_FLING_START, gfx::Point(), |
| 182 timestamp, ui::EF_NONE, velocity_x, velocity_y, |
| 183 velocity_x, velocity_y, |
| 184 2); // finger_count |
| 185 gfx::PointF location(web_gesture.x * device_scale_factor_, |
| 186 web_gesture.y * device_scale_factor_); |
| 187 fling_event.set_location_f(location); |
| 188 fling_event.set_root_location_f(location); |
| 189 |
| 190 aura::Window* window = GetWindow(); |
| 191 fling_event.ConvertLocationToTarget(window, window->GetRootWindow()); |
| 192 ui::EventDispatchDetails details = |
| 193 window->GetHost()->event_processor()->OnEventFromSource(&fling_event); |
| 194 if (details.dispatcher_destroyed) |
| 195 return; |
| 196 } |
| 197 |
165 SyntheticGestureParams::GestureSourceType | 198 SyntheticGestureParams::GestureSourceType |
166 SyntheticGestureTargetAura::GetDefaultSyntheticGestureSourceType() const { | 199 SyntheticGestureTargetAura::GetDefaultSyntheticGestureSourceType() const { |
167 return SyntheticGestureParams::TOUCH_INPUT; | 200 return SyntheticGestureParams::TOUCH_INPUT; |
168 } | 201 } |
169 | 202 |
170 float SyntheticGestureTargetAura::GetTouchSlopInDips() const { | 203 float SyntheticGestureTargetAura::GetTouchSlopInDips() const { |
171 // - 1 because Aura considers a pointer to be moving if it has moved at least | 204 // - 1 because Aura considers a pointer to be moving if it has moved at least |
172 // 'max_touch_move_in_pixels_for_click' pixels. | 205 // 'max_touch_move_in_pixels_for_click' pixels. |
173 return ui::GestureConfiguration::GetInstance() | 206 return ui::GestureConfiguration::GetInstance() |
174 ->max_touch_move_in_pixels_for_click() - | 207 ->max_touch_move_in_pixels_for_click() - |
175 1; | 208 1; |
176 } | 209 } |
177 | 210 |
178 float SyntheticGestureTargetAura::GetMinScalingSpanInDips() const { | 211 float SyntheticGestureTargetAura::GetMinScalingSpanInDips() const { |
179 return ui::GestureConfiguration::GetInstance() | 212 return ui::GestureConfiguration::GetInstance() |
180 ->min_distance_for_pinch_scroll_in_pixels(); | 213 ->min_distance_for_pinch_scroll_in_pixels(); |
181 } | 214 } |
182 | 215 |
183 aura::Window* SyntheticGestureTargetAura::GetWindow() const { | 216 aura::Window* SyntheticGestureTargetAura::GetWindow() const { |
184 aura::Window* window = render_widget_host()->GetView()->GetNativeView(); | 217 aura::Window* window = render_widget_host()->GetView()->GetNativeView(); |
185 DCHECK(window); | 218 DCHECK(window); |
186 return window; | 219 return window; |
187 } | 220 } |
188 | 221 |
189 } // namespace content | 222 } // namespace content |
OLD | NEW |