| 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/latency/latency_info.h" | 14 #include "ui/latency/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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 << "Mouse wheel position is not within content bounds."; | 71 << "Mouse wheel position is not within content bounds."; |
| 71 DispatchWebMouseWheelEventToPlatform(web_wheel, latency_info); | 72 DispatchWebMouseWheelEventToPlatform(web_wheel, latency_info); |
| 72 } else if (WebInputEvent::IsMouseEventType(event.GetType())) { | 73 } else if (WebInputEvent::IsMouseEventType(event.GetType())) { |
| 73 const WebMouseEvent& web_mouse = | 74 const WebMouseEvent& web_mouse = |
| 74 static_cast<const WebMouseEvent&>(event); | 75 static_cast<const WebMouseEvent&>(event); |
| 75 CHECK(event.GetType() != WebInputEvent::kMouseDown || | 76 CHECK(event.GetType() != WebInputEvent::kMouseDown || |
| 76 PointIsWithinContents(web_mouse.PositionInWidget().x, | 77 PointIsWithinContents(web_mouse.PositionInWidget().x, |
| 77 web_mouse.PositionInWidget().y)) | 78 web_mouse.PositionInWidget().y)) |
| 78 << "Mouse pointer is not within content bounds on MouseDown."; | 79 << "Mouse pointer is not within content bounds on MouseDown."; |
| 79 DispatchWebMouseEventToPlatform(web_mouse, latency_info); | 80 DispatchWebMouseEventToPlatform(web_mouse, latency_info); |
| 81 } else if (event.GetType() == WebInputEvent::kGestureFlingStart) { |
| 82 const WebGestureEvent& gesture_event = |
| 83 static_cast<const WebGestureEvent&>(event); |
| 84 CHECK(gesture_event.source_device == blink::kWebGestureDeviceTouchpad) |
| 85 << "The gesture event source must be touchpad."; |
| 86 DispatchTouchpadGestureFlingStartToPlatform(gesture_event, latency_info); |
| 80 } else { | 87 } else { |
| 81 NOTREACHED(); | 88 NOTREACHED(); |
| 82 } | 89 } |
| 83 } | 90 } |
| 84 | 91 |
| 85 void SyntheticGestureTargetBase::DispatchWebTouchEventToPlatform( | 92 void SyntheticGestureTargetBase::DispatchWebTouchEventToPlatform( |
| 86 const blink::WebTouchEvent& web_touch, | 93 const blink::WebTouchEvent& web_touch, |
| 87 const ui::LatencyInfo& latency_info) { | 94 const ui::LatencyInfo& latency_info) { |
| 88 // We assume that platforms supporting touch have their own implementation of | 95 // We assume that platforms supporting touch have their own implementation of |
| 89 // SyntheticGestureTarget to route the events through their respective input | 96 // SyntheticGestureTarget to route the events through their respective input |
| 90 // stack. | 97 // stack. |
| 91 CHECK(false) << "Touch events not supported for this browser."; | 98 CHECK(false) << "Touch events not supported for this browser."; |
| 92 } | 99 } |
| 93 | 100 |
| 94 void SyntheticGestureTargetBase::DispatchWebMouseWheelEventToPlatform( | 101 void SyntheticGestureTargetBase::DispatchWebMouseWheelEventToPlatform( |
| 95 const blink::WebMouseWheelEvent& web_wheel, | 102 const blink::WebMouseWheelEvent& web_wheel, |
| 96 const ui::LatencyInfo& latency_info) { | 103 const ui::LatencyInfo& latency_info) { |
| 97 host_->ForwardWheelEventWithLatencyInfo(web_wheel, latency_info); | 104 host_->ForwardWheelEventWithLatencyInfo(web_wheel, latency_info); |
| 98 } | 105 } |
| 99 | 106 |
| 100 void SyntheticGestureTargetBase::DispatchWebMouseEventToPlatform( | 107 void SyntheticGestureTargetBase::DispatchWebMouseEventToPlatform( |
| 101 const blink::WebMouseEvent& web_mouse, | 108 const blink::WebMouseEvent& web_mouse, |
| 102 const ui::LatencyInfo& latency_info) { | 109 const ui::LatencyInfo& latency_info) { |
| 103 host_->ForwardMouseEventWithLatencyInfo(web_mouse, latency_info); | 110 host_->ForwardMouseEventWithLatencyInfo(web_mouse, latency_info); |
| 104 } | 111 } |
| 105 | 112 |
| 113 void SyntheticGestureTargetBase::DispatchTouchpadGestureFlingStartToPlatform( |
| 114 const blink::WebGestureEvent& web_gesture, |
| 115 const ui::LatencyInfo& latency_info) { |
| 116 DCHECK_EQ(web_gesture.GetType(), WebInputEvent::kGestureFlingStart); |
| 117 DCHECK_EQ(web_gesture.source_device, blink::kWebGestureDeviceTouchpad); |
| 118 host_->ForwardGestureEventWithLatencyInfo(web_gesture, latency_info); |
| 119 } |
| 120 |
| 106 void SyntheticGestureTargetBase::SetNeedsFlush() { | 121 void SyntheticGestureTargetBase::SetNeedsFlush() { |
| 107 host_->SetNeedsFlush(); | 122 host_->SetNeedsFlush(); |
| 108 } | 123 } |
| 109 | 124 |
| 110 SyntheticGestureParams::GestureSourceType | 125 SyntheticGestureParams::GestureSourceType |
| 111 SyntheticGestureTargetBase::GetDefaultSyntheticGestureSourceType() const { | 126 SyntheticGestureTargetBase::GetDefaultSyntheticGestureSourceType() const { |
| 112 return SyntheticGestureParams::MOUSE_INPUT; | 127 return SyntheticGestureParams::MOUSE_INPUT; |
| 113 } | 128 } |
| 114 | 129 |
| 115 base::TimeDelta SyntheticGestureTargetBase::PointerAssumedStoppedTime() | 130 base::TimeDelta SyntheticGestureTargetBase::PointerAssumedStoppedTime() |
| (...skipping 12 matching lines...) Expand all Loading... |
| 128 return 0.0f; | 143 return 0.0f; |
| 129 } | 144 } |
| 130 | 145 |
| 131 bool SyntheticGestureTargetBase::PointIsWithinContents(int x, int y) const { | 146 bool SyntheticGestureTargetBase::PointIsWithinContents(int x, int y) const { |
| 132 gfx::Rect bounds = host_->GetView()->GetViewBounds(); | 147 gfx::Rect bounds = host_->GetView()->GetViewBounds(); |
| 133 bounds -= bounds.OffsetFromOrigin(); // Translate the bounds to (0,0). | 148 bounds -= bounds.OffsetFromOrigin(); // Translate the bounds to (0,0). |
| 134 return bounds.Contains(x, y); | 149 return bounds.Contains(x, y); |
| 135 } | 150 } |
| 136 | 151 |
| 137 } // namespace content | 152 } // namespace content |
| OLD | NEW |