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/web/WebInputEvent.h" | 11 #include "third_party/WebKit/public/web/WebInputEvent.h" |
12 #include "ui/events/event.h" | 12 #include "ui/events/event.h" |
13 #include "ui/events/latency_info.h" | 13 #include "ui/events/latency_info.h" |
14 | 14 |
15 using blink::WebInputEvent; | 15 using blink::WebInputEvent; |
16 using blink::WebTouchEvent; | 16 using blink::WebTouchEvent; |
| 17 using blink::WebTouchPoint; |
17 using blink::WebMouseEvent; | 18 using blink::WebMouseEvent; |
18 using blink::WebMouseWheelEvent; | 19 using blink::WebMouseWheelEvent; |
19 | 20 |
20 namespace content { | 21 namespace content { |
21 namespace { | 22 namespace { |
22 | 23 |
23 // This value was determined experimentally. It was sufficient to not cause a | 24 // This value was determined experimentally. It was sufficient to not cause a |
24 // fling on Android and Aura. | 25 // fling on Android and Aura. |
25 const int kPointerAssumedStoppedTimeMs = 100; | 26 const int kPointerAssumedStoppedTimeMs = 100; |
26 | 27 |
(...skipping 18 matching lines...) Expand all Loading... |
45 TRACE_EVENT1("input", | 46 TRACE_EVENT1("input", |
46 "SyntheticGestureTarget::DispatchInputEventToPlatform", | 47 "SyntheticGestureTarget::DispatchInputEventToPlatform", |
47 "type", WebInputEventTraits::GetName(event.type)); | 48 "type", WebInputEventTraits::GetName(event.type)); |
48 | 49 |
49 ui::LatencyInfo latency_info; | 50 ui::LatencyInfo latency_info; |
50 latency_info.AddLatencyNumber(ui::INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0); | 51 latency_info.AddLatencyNumber(ui::INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0); |
51 | 52 |
52 if (WebInputEvent::isTouchEventType(event.type)) { | 53 if (WebInputEvent::isTouchEventType(event.type)) { |
53 const WebTouchEvent& web_touch = | 54 const WebTouchEvent& web_touch = |
54 static_cast<const WebTouchEvent&>(event); | 55 static_cast<const WebTouchEvent&>(event); |
| 56 |
| 57 // Check that all touch pointers are within the content bounds. |
| 58 if (web_touch.type == WebInputEvent::TouchStart) { |
| 59 for (unsigned i = 0; i < web_touch.touchesLength; i++) |
| 60 CHECK(web_touch.touches[i].state != WebTouchPoint::StatePressed || |
| 61 PointIsWithinContents(web_touch.touches[i].position.x, |
| 62 web_touch.touches[i].position.y)) |
| 63 << "Touch coordinates are not within content bounds on TouchStart."; |
| 64 } |
| 65 |
55 DispatchWebTouchEventToPlatform(web_touch, latency_info); | 66 DispatchWebTouchEventToPlatform(web_touch, latency_info); |
56 } else if (event.type == WebInputEvent::MouseWheel) { | 67 } else if (event.type == WebInputEvent::MouseWheel) { |
57 const WebMouseWheelEvent& web_wheel = | 68 const WebMouseWheelEvent& web_wheel = |
58 static_cast<const WebMouseWheelEvent&>(event); | 69 static_cast<const WebMouseWheelEvent&>(event); |
| 70 CHECK(PointIsWithinContents(web_wheel.x, web_wheel.y)) |
| 71 << "Mouse wheel position is not within content bounds."; |
59 DispatchWebMouseWheelEventToPlatform(web_wheel, latency_info); | 72 DispatchWebMouseWheelEventToPlatform(web_wheel, latency_info); |
60 } else if (WebInputEvent::isMouseEventType(event.type)) { | 73 } else if (WebInputEvent::isMouseEventType(event.type)) { |
61 const WebMouseEvent& web_mouse = | 74 const WebMouseEvent& web_mouse = |
62 static_cast<const WebMouseEvent&>(event); | 75 static_cast<const WebMouseEvent&>(event); |
| 76 CHECK(event.type != WebInputEvent::MouseDown || |
| 77 PointIsWithinContents(web_mouse.x, web_mouse.y)) |
| 78 << "Mouse pointer is not within content bounds on MouseDown."; |
63 DispatchWebMouseEventToPlatform(web_mouse, latency_info); | 79 DispatchWebMouseEventToPlatform(web_mouse, latency_info); |
64 } else { | 80 } else { |
65 NOTREACHED(); | 81 NOTREACHED(); |
66 } | 82 } |
67 } | 83 } |
68 | 84 |
69 void SyntheticGestureTargetBase::DispatchWebTouchEventToPlatform( | 85 void SyntheticGestureTargetBase::DispatchWebTouchEventToPlatform( |
70 const blink::WebTouchEvent& web_touch, | 86 const blink::WebTouchEvent& web_touch, |
71 const ui::LatencyInfo& latency_info) { | 87 const ui::LatencyInfo& latency_info) { |
72 // We assume that platforms supporting touch have their own implementation of | 88 // We assume that platforms supporting touch have their own implementation of |
73 // SyntheticGestureTarget to route the events through their respective input | 89 // SyntheticGestureTarget to route the events through their respective input |
74 // stack. | 90 // stack. |
75 CHECK(false); | 91 CHECK(false) << "Touch events not supported for this browser."; |
76 } | 92 } |
77 | 93 |
78 void SyntheticGestureTargetBase::DispatchWebMouseWheelEventToPlatform( | 94 void SyntheticGestureTargetBase::DispatchWebMouseWheelEventToPlatform( |
79 const blink::WebMouseWheelEvent& web_wheel, | 95 const blink::WebMouseWheelEvent& web_wheel, |
80 const ui::LatencyInfo& latency_info) { | 96 const ui::LatencyInfo& latency_info) { |
81 host_->ForwardWheelEventWithLatencyInfo(web_wheel, latency_info); | 97 host_->ForwardWheelEventWithLatencyInfo(web_wheel, latency_info); |
82 } | 98 } |
83 | 99 |
84 void SyntheticGestureTargetBase::DispatchWebMouseEventToPlatform( | 100 void SyntheticGestureTargetBase::DispatchWebMouseEventToPlatform( |
85 const blink::WebMouseEvent& web_mouse, | 101 const blink::WebMouseEvent& web_mouse, |
(...skipping 12 matching lines...) Expand all Loading... |
98 | 114 |
99 base::TimeDelta SyntheticGestureTargetBase::PointerAssumedStoppedTime() | 115 base::TimeDelta SyntheticGestureTargetBase::PointerAssumedStoppedTime() |
100 const { | 116 const { |
101 return base::TimeDelta::FromMilliseconds(kPointerAssumedStoppedTimeMs); | 117 return base::TimeDelta::FromMilliseconds(kPointerAssumedStoppedTimeMs); |
102 } | 118 } |
103 | 119 |
104 int SyntheticGestureTargetBase::GetTouchSlopInDips() const { | 120 int SyntheticGestureTargetBase::GetTouchSlopInDips() const { |
105 return kTouchSlopInDips; | 121 return kTouchSlopInDips; |
106 } | 122 } |
107 | 123 |
| 124 bool SyntheticGestureTargetBase::PointIsWithinContents(int x, int y) const { |
| 125 gfx::Rect bounds = host_->GetView()->GetViewBounds(); |
| 126 bounds -= bounds.OffsetFromOrigin(); // Translate the bounds to (0,0). |
| 127 return bounds.Contains(x, y); |
| 128 } |
| 129 |
108 } // namespace content | 130 } // namespace content |
OLD | NEW |