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