| 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/event_injector.h" |
| 15 #include "ui/aura/window.h" | 16 #include "ui/aura/window.h" |
| 16 #include "ui/aura/window_tree_host.h" | 17 #include "ui/aura/window_tree_host.h" |
| 17 #include "ui/events/event_sink.h" | 18 #include "ui/events/event_sink.h" |
| 18 #include "ui/events/event_utils.h" | 19 #include "ui/events/event_utils.h" |
| 19 #include "ui/events/gesture_detection/gesture_configuration.h" | 20 #include "ui/events/gesture_detection/gesture_configuration.h" |
| 20 | 21 |
| 21 using blink::WebTouchEvent; | 22 using blink::WebTouchEvent; |
| 22 using blink::WebMouseWheelEvent; | 23 using blink::WebMouseWheelEvent; |
| 23 | 24 |
| 24 namespace content { | 25 namespace content { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 39 touch_with_latency.event.touches[i].radius_x *= device_scale_factor_; | 40 touch_with_latency.event.touches[i].radius_x *= device_scale_factor_; |
| 40 touch_with_latency.event.touches[i].radius_y *= device_scale_factor_; | 41 touch_with_latency.event.touches[i].radius_y *= device_scale_factor_; |
| 41 } | 42 } |
| 42 std::vector<std::unique_ptr<ui::TouchEvent>> events; | 43 std::vector<std::unique_ptr<ui::TouchEvent>> events; |
| 43 bool conversion_success = MakeUITouchEventsFromWebTouchEvents( | 44 bool conversion_success = MakeUITouchEventsFromWebTouchEvents( |
| 44 touch_with_latency, &events, LOCAL_COORDINATES); | 45 touch_with_latency, &events, LOCAL_COORDINATES); |
| 45 DCHECK(conversion_success); | 46 DCHECK(conversion_success); |
| 46 | 47 |
| 47 aura::Window* window = GetWindow(); | 48 aura::Window* window = GetWindow(); |
| 48 aura::WindowTreeHost* host = window->GetHost(); | 49 aura::WindowTreeHost* host = window->GetHost(); |
| 50 aura::EventInjector injector; |
| 51 |
| 49 for (const auto& event : events) { | 52 for (const auto& event : events) { |
| 50 event->ConvertLocationToTarget(window, host->window()); | 53 event->ConvertLocationToTarget(window, host->window()); |
| 51 | |
| 52 // Apply the screen scale factor to the event location after it has been | 54 // Apply the screen scale factor to the event location after it has been |
| 53 // transformed to the target. | 55 // transformed to the target. |
| 54 gfx::PointF device_location = | 56 gfx::PointF device_location = |
| 55 gfx::ScalePoint(event->location_f(), device_scale_factor_); | 57 gfx::ScalePoint(event->location_f(), device_scale_factor_); |
| 56 gfx::PointF device_root_location = | 58 gfx::PointF device_root_location = |
| 57 gfx::ScalePoint(event->root_location_f(), device_scale_factor_); | 59 gfx::ScalePoint(event->root_location_f(), device_scale_factor_); |
| 58 event->set_location_f(device_location); | 60 event->set_location_f(device_location); |
| 59 event->set_root_location_f(device_root_location); | 61 event->set_root_location_f(device_root_location); |
| 60 ui::EventDispatchDetails details = | 62 ui::EventDispatchDetails details = injector.Inject(host, event.get()); |
| 61 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&) { |
| 70 ui::MouseWheelEvent wheel_event( | 71 ui::MouseWheelEvent wheel_event( |
| 71 gfx::Vector2d(web_wheel.delta_x, web_wheel.delta_y), gfx::Point(), | 72 gfx::Vector2d(web_wheel.delta_x, web_wheel.delta_y), gfx::Point(), |
| 72 gfx::Point(), ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE); | 73 gfx::Point(), ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE); |
| 73 gfx::PointF location(web_wheel.PositionInWidget().x * device_scale_factor_, | 74 gfx::PointF location(web_wheel.PositionInWidget().x * device_scale_factor_, |
| 74 web_wheel.PositionInWidget().y * device_scale_factor_); | 75 web_wheel.PositionInWidget().y * device_scale_factor_); |
| 75 wheel_event.set_location_f(location); | 76 wheel_event.set_location_f(location); |
| 76 wheel_event.set_root_location_f(location); | 77 wheel_event.set_root_location_f(location); |
| 77 | 78 |
| 78 aura::Window* window = GetWindow(); | 79 aura::Window* window = GetWindow(); |
| 79 wheel_event.ConvertLocationToTarget(window, window->GetRootWindow()); | 80 wheel_event.ConvertLocationToTarget(window, window->GetRootWindow()); |
| 81 aura::EventInjector injector; |
| 80 ui::EventDispatchDetails details = | 82 ui::EventDispatchDetails details = |
| 81 window->GetHost()->event_sink()->OnEventFromSource(&wheel_event); | 83 injector.Inject(window->GetHost(), &wheel_event); |
| 82 if (details.dispatcher_destroyed) | 84 if (details.dispatcher_destroyed) |
| 83 return; | 85 return; |
| 84 } | 86 } |
| 85 | 87 |
| 86 namespace { | 88 namespace { |
| 87 | 89 |
| 88 ui::EventType | 90 ui::EventType |
| 89 WebMouseEventTypeToEventType(blink::WebInputEvent::Type web_type) { | 91 WebMouseEventTypeToEventType(blink::WebInputEvent::Type web_type) { |
| 90 switch (web_type) { | 92 switch (web_type) { |
| 91 case blink::WebInputEvent::kMouseDown: | 93 case blink::WebInputEvent::kMouseDown: |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 ui::EventTimeForNow(), flags, flags, | 157 ui::EventTimeForNow(), flags, flags, |
| 156 pointer_details); | 158 pointer_details); |
| 157 gfx::PointF location( | 159 gfx::PointF location( |
| 158 web_mouse_event.PositionInWidget().x * device_scale_factor_, | 160 web_mouse_event.PositionInWidget().x * device_scale_factor_, |
| 159 web_mouse_event.PositionInWidget().y * device_scale_factor_); | 161 web_mouse_event.PositionInWidget().y * device_scale_factor_); |
| 160 mouse_event.set_location_f(location); | 162 mouse_event.set_location_f(location); |
| 161 mouse_event.set_root_location_f(location); | 163 mouse_event.set_root_location_f(location); |
| 162 | 164 |
| 163 aura::Window* window = GetWindow(); | 165 aura::Window* window = GetWindow(); |
| 164 mouse_event.ConvertLocationToTarget(window, window->GetRootWindow()); | 166 mouse_event.ConvertLocationToTarget(window, window->GetRootWindow()); |
| 167 aura::EventInjector injector; |
| 165 ui::EventDispatchDetails details = | 168 ui::EventDispatchDetails details = |
| 166 window->GetHost()->event_sink()->OnEventFromSource(&mouse_event); | 169 injector.Inject(window->GetHost(), &mouse_event); |
| 167 if (details.dispatcher_destroyed) | 170 if (details.dispatcher_destroyed) |
| 168 return; | 171 return; |
| 169 } | 172 } |
| 170 | 173 |
| 171 SyntheticGestureParams::GestureSourceType | 174 SyntheticGestureParams::GestureSourceType |
| 172 SyntheticGestureTargetAura::GetDefaultSyntheticGestureSourceType() const { | 175 SyntheticGestureTargetAura::GetDefaultSyntheticGestureSourceType() const { |
| 173 return SyntheticGestureParams::TOUCH_INPUT; | 176 return SyntheticGestureParams::TOUCH_INPUT; |
| 174 } | 177 } |
| 175 | 178 |
| 176 float SyntheticGestureTargetAura::GetTouchSlopInDips() const { | 179 float SyntheticGestureTargetAura::GetTouchSlopInDips() const { |
| 177 // - 1 because Aura considers a pointer to be moving if it has moved at least | 180 // - 1 because Aura considers a pointer to be moving if it has moved at least |
| 178 // 'max_touch_move_in_pixels_for_click' pixels. | 181 // 'max_touch_move_in_pixels_for_click' pixels. |
| 179 return ui::GestureConfiguration::GetInstance() | 182 return ui::GestureConfiguration::GetInstance() |
| 180 ->max_touch_move_in_pixels_for_click() - | 183 ->max_touch_move_in_pixels_for_click() - |
| 181 1; | 184 1; |
| 182 } | 185 } |
| 183 | 186 |
| 184 float SyntheticGestureTargetAura::GetMinScalingSpanInDips() const { | 187 float SyntheticGestureTargetAura::GetMinScalingSpanInDips() const { |
| 185 return ui::GestureConfiguration::GetInstance() | 188 return ui::GestureConfiguration::GetInstance() |
| 186 ->min_distance_for_pinch_scroll_in_pixels(); | 189 ->min_distance_for_pinch_scroll_in_pixels(); |
| 187 } | 190 } |
| 188 | 191 |
| 189 aura::Window* SyntheticGestureTargetAura::GetWindow() const { | 192 aura::Window* SyntheticGestureTargetAura::GetWindow() const { |
| 190 aura::Window* window = render_widget_host()->GetView()->GetNativeView(); | 193 aura::Window* window = render_widget_host()->GetView()->GetNativeView(); |
| 191 DCHECK(window); | 194 DCHECK(window); |
| 192 return window; | 195 return window; |
| 193 } | 196 } |
| 194 | 197 |
| 195 } // namespace content | 198 } // namespace content |
| OLD | NEW |