| 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_base.h" | 5 #include "content/browser/renderer_host/input/synthetic_gesture_target_base.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_base.h" | 8 #include "content/browser/renderer_host/render_widget_host_view_base.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_messages.h" | 10 #include "content/common/input_messages.h" |
| 11 #include "third_party/WebKit/public/platform/WebInputEvent.h" | 11 #include "third_party/WebKit/public/platform/WebInputEvent.h" |
| 12 #include "ui/events/blink/web_input_event_traits.h" | 12 #include "ui/events/blink/web_input_event_traits.h" |
| 13 #include "ui/events/event.h" | 13 #include "ui/events/event.h" |
| 14 #include "ui/events/latency_info.h" | 14 #include "ui/events/latency_info.h" |
| 15 | 15 |
| 16 using blink::WebInputEvent; | 16 using blink::WebInputEvent; |
| 17 using blink::WebTouchEvent; | 17 using blink::WebTouchEvent; |
| 18 using blink::WebTouchPoint; | 18 using blink::WebTouchPoint; |
| 19 using blink::WebMouseEvent; | 19 using blink::WebMouseEvent; |
| 20 using blink::WebMouseWheelEvent; | 20 using blink::WebMouseWheelEvent; |
| 21 using blink::WebGestureEvent; |
| 21 | 22 |
| 22 namespace content { | 23 namespace content { |
| 23 namespace { | 24 namespace { |
| 24 | 25 |
| 25 // This value was determined experimentally. It was sufficient to not cause a | 26 // This value was determined experimentally. It was sufficient to not cause a |
| 26 // fling on Android and Aura. | 27 // fling on Android and Aura. |
| 27 const int kPointerAssumedStoppedTimeMs = 100; | 28 const int kPointerAssumedStoppedTimeMs = 100; |
| 28 | 29 |
| 29 // SyntheticGestureTargetBase passes input events straight on to the renderer | 30 // SyntheticGestureTargetBase passes input events straight on to the renderer |
| 30 // without going through a gesture recognition framework. There is thus no touch | 31 // without going through a gesture recognition framework. There is thus no touch |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 CHECK(PointIsWithinContents(web_wheel.x, web_wheel.y)) | 69 CHECK(PointIsWithinContents(web_wheel.x, web_wheel.y)) |
| 69 << "Mouse wheel position is not within content bounds."; | 70 << "Mouse wheel position is not within content bounds."; |
| 70 DispatchWebMouseWheelEventToPlatform(web_wheel, latency_info); | 71 DispatchWebMouseWheelEventToPlatform(web_wheel, latency_info); |
| 71 } else if (WebInputEvent::isMouseEventType(event.type())) { | 72 } else if (WebInputEvent::isMouseEventType(event.type())) { |
| 72 const WebMouseEvent& web_mouse = | 73 const WebMouseEvent& web_mouse = |
| 73 static_cast<const WebMouseEvent&>(event); | 74 static_cast<const WebMouseEvent&>(event); |
| 74 CHECK(event.type() != WebInputEvent::MouseDown || | 75 CHECK(event.type() != WebInputEvent::MouseDown || |
| 75 PointIsWithinContents(web_mouse.x, web_mouse.y)) | 76 PointIsWithinContents(web_mouse.x, web_mouse.y)) |
| 76 << "Mouse pointer is not within content bounds on MouseDown."; | 77 << "Mouse pointer is not within content bounds on MouseDown."; |
| 77 DispatchWebMouseEventToPlatform(web_mouse, latency_info); | 78 DispatchWebMouseEventToPlatform(web_mouse, latency_info); |
| 79 } else if (event.type() == WebInputEvent::GestureFlingStart) { |
| 80 const WebGestureEvent& gesture_event = |
| 81 static_cast<const WebGestureEvent&>(event); |
| 82 CHECK(gesture_event.sourceDevice == blink::WebGestureDeviceTouchpad) |
| 83 << "The gesture event source must be touchpad."; |
| 84 DispatchTouchpadGestureFlingStartToPlatform(gesture_event, latency_info); |
| 78 } else { | 85 } else { |
| 79 NOTREACHED(); | 86 NOTREACHED(); |
| 80 } | 87 } |
| 81 } | 88 } |
| 82 | 89 |
| 83 void SyntheticGestureTargetBase::DispatchWebTouchEventToPlatform( | 90 void SyntheticGestureTargetBase::DispatchWebTouchEventToPlatform( |
| 84 const blink::WebTouchEvent& web_touch, | 91 const blink::WebTouchEvent& web_touch, |
| 85 const ui::LatencyInfo& latency_info) { | 92 const ui::LatencyInfo& latency_info) { |
| 86 // We assume that platforms supporting touch have their own implementation of | 93 // We assume that platforms supporting touch have their own implementation of |
| 87 // SyntheticGestureTarget to route the events through their respective input | 94 // SyntheticGestureTarget to route the events through their respective input |
| 88 // stack. | 95 // stack. |
| 89 CHECK(false) << "Touch events not supported for this browser."; | 96 CHECK(false) << "Touch events not supported for this browser."; |
| 90 } | 97 } |
| 91 | 98 |
| 92 void SyntheticGestureTargetBase::DispatchWebMouseWheelEventToPlatform( | 99 void SyntheticGestureTargetBase::DispatchWebMouseWheelEventToPlatform( |
| 93 const blink::WebMouseWheelEvent& web_wheel, | 100 const blink::WebMouseWheelEvent& web_wheel, |
| 94 const ui::LatencyInfo& latency_info) { | 101 const ui::LatencyInfo& latency_info) { |
| 95 host_->ForwardWheelEventWithLatencyInfo(web_wheel, latency_info); | 102 host_->ForwardWheelEventWithLatencyInfo(web_wheel, latency_info); |
| 96 } | 103 } |
| 97 | 104 |
| 98 void SyntheticGestureTargetBase::DispatchWebMouseEventToPlatform( | 105 void SyntheticGestureTargetBase::DispatchWebMouseEventToPlatform( |
| 99 const blink::WebMouseEvent& web_mouse, | 106 const blink::WebMouseEvent& web_mouse, |
| 100 const ui::LatencyInfo& latency_info) { | 107 const ui::LatencyInfo& latency_info) { |
| 101 host_->ForwardMouseEventWithLatencyInfo(web_mouse, latency_info); | 108 host_->ForwardMouseEventWithLatencyInfo(web_mouse, latency_info); |
| 102 } | 109 } |
| 103 | 110 |
| 111 void SyntheticGestureTargetBase::DispatchTouchpadGestureFlingStartToPlatform( |
| 112 const blink::WebGestureEvent& web_gesture, |
| 113 const ui::LatencyInfo& latency_info) { |
| 114 DCHECK_EQ(web_gesture.type(), WebInputEvent::GestureFlingStart); |
| 115 DCHECK_EQ(web_gesture.sourceDevice, blink::WebGestureDeviceTouchpad); |
| 116 host_->ForwardGestureEventWithLatencyInfo(web_gesture, latency_info); |
| 117 } |
| 118 |
| 104 void SyntheticGestureTargetBase::SetNeedsFlush() { | 119 void SyntheticGestureTargetBase::SetNeedsFlush() { |
| 105 host_->SetNeedsFlush(); | 120 host_->SetNeedsFlush(); |
| 106 } | 121 } |
| 107 | 122 |
| 108 SyntheticGestureParams::GestureSourceType | 123 SyntheticGestureParams::GestureSourceType |
| 109 SyntheticGestureTargetBase::GetDefaultSyntheticGestureSourceType() const { | 124 SyntheticGestureTargetBase::GetDefaultSyntheticGestureSourceType() const { |
| 110 return SyntheticGestureParams::MOUSE_INPUT; | 125 return SyntheticGestureParams::MOUSE_INPUT; |
| 111 } | 126 } |
| 112 | 127 |
| 113 base::TimeDelta SyntheticGestureTargetBase::PointerAssumedStoppedTime() | 128 base::TimeDelta SyntheticGestureTargetBase::PointerAssumedStoppedTime() |
| (...skipping 12 matching lines...) Expand all Loading... |
| 126 return 0.0f; | 141 return 0.0f; |
| 127 } | 142 } |
| 128 | 143 |
| 129 bool SyntheticGestureTargetBase::PointIsWithinContents(int x, int y) const { | 144 bool SyntheticGestureTargetBase::PointIsWithinContents(int x, int y) const { |
| 130 gfx::Rect bounds = host_->GetView()->GetViewBounds(); | 145 gfx::Rect bounds = host_->GetView()->GetViewBounds(); |
| 131 bounds -= bounds.OffsetFromOrigin(); // Translate the bounds to (0,0). | 146 bounds -= bounds.OffsetFromOrigin(); // Translate the bounds to (0,0). |
| 132 return bounds.Contains(x, y); | 147 return bounds.Contains(x, y); |
| 133 } | 148 } |
| 134 | 149 |
| 135 } // namespace content | 150 } // namespace content |
| OLD | NEW |