| 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" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 | 49 |
| 50 ui::LatencyInfo latency_info; | 50 ui::LatencyInfo latency_info; |
| 51 latency_info.AddLatencyNumber(ui::INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0); | 51 latency_info.AddLatencyNumber(ui::INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0); |
| 52 | 52 |
| 53 if (WebInputEvent::isTouchEventType(event.type)) { | 53 if (WebInputEvent::isTouchEventType(event.type)) { |
| 54 const WebTouchEvent& web_touch = | 54 const WebTouchEvent& web_touch = |
| 55 static_cast<const WebTouchEvent&>(event); | 55 static_cast<const WebTouchEvent&>(event); |
| 56 | 56 |
| 57 // Check that all touch pointers are within the content bounds. | 57 // Check that all touch pointers are within the content bounds. |
| 58 for (unsigned i = 0; i < web_touch.touchesLength; i++) | 58 for (unsigned i = 0; i < web_touch.touchesLength; i++) |
| 59 // Touch coordinates are not within content bounds on TouchStart. |
| 59 CHECK(web_touch.touches[i].state != WebTouchPoint::StatePressed || | 60 CHECK(web_touch.touches[i].state != WebTouchPoint::StatePressed || |
| 60 PointIsWithinContents(web_touch.touches[i].position.x, | 61 PointIsWithinContents(web_touch.touches[i].position.x, |
| 61 web_touch.touches[i].position.y)) | 62 web_touch.touches[i].position.y)); |
| 62 << "Touch coordinates are not within content bounds on TouchStart."; | |
| 63 | 63 |
| 64 DispatchWebTouchEventToPlatform(web_touch, latency_info); | 64 DispatchWebTouchEventToPlatform(web_touch, latency_info); |
| 65 } else if (event.type == WebInputEvent::MouseWheel) { | 65 } else if (event.type == WebInputEvent::MouseWheel) { |
| 66 const WebMouseWheelEvent& web_wheel = | 66 const WebMouseWheelEvent& web_wheel = |
| 67 static_cast<const WebMouseWheelEvent&>(event); | 67 static_cast<const WebMouseWheelEvent&>(event); |
| 68 CHECK(PointIsWithinContents(web_wheel.x, web_wheel.y)) | 68 // Mouse wheel position is not within content bounds. |
| 69 << "Mouse wheel position is not within content bounds."; | 69 CHECK(PointIsWithinContents(web_wheel.x, web_wheel.y)); |
| 70 DispatchWebMouseWheelEventToPlatform(web_wheel, latency_info); | 70 DispatchWebMouseWheelEventToPlatform(web_wheel, latency_info); |
| 71 } else if (WebInputEvent::isMouseEventType(event.type)) { | 71 } else if (WebInputEvent::isMouseEventType(event.type)) { |
| 72 const WebMouseEvent& web_mouse = | 72 const WebMouseEvent& web_mouse = |
| 73 static_cast<const WebMouseEvent&>(event); | 73 static_cast<const WebMouseEvent&>(event); |
| 74 // Mouse pointer is not within content bounds on MouseDown. |
| 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 DispatchWebMouseEventToPlatform(web_mouse, latency_info); | 77 DispatchWebMouseEventToPlatform(web_mouse, latency_info); |
| 78 } else { | 78 } else { |
| 79 NOTREACHED(); | 79 NOTREACHED(); |
| 80 } | 80 } |
| 81 } | 81 } |
| 82 | 82 |
| 83 void SyntheticGestureTargetBase::DispatchWebTouchEventToPlatform( | 83 void SyntheticGestureTargetBase::DispatchWebTouchEventToPlatform( |
| 84 const blink::WebTouchEvent& web_touch, | 84 const blink::WebTouchEvent& web_touch, |
| 85 const ui::LatencyInfo& latency_info) { | 85 const ui::LatencyInfo& latency_info) { |
| 86 // We assume that platforms supporting touch have their own implementation of | 86 // We assume that platforms supporting touch have their own implementation of |
| 87 // SyntheticGestureTarget to route the events through their respective input | 87 // SyntheticGestureTarget to route the events through their respective input |
| 88 // stack. | 88 // stack. |
| 89 CHECK(false) << "Touch events not supported for this browser."; | 89 // Touch events not supported for this browser. |
| 90 CHECK(false); |
| 90 } | 91 } |
| 91 | 92 |
| 92 void SyntheticGestureTargetBase::DispatchWebMouseWheelEventToPlatform( | 93 void SyntheticGestureTargetBase::DispatchWebMouseWheelEventToPlatform( |
| 93 const blink::WebMouseWheelEvent& web_wheel, | 94 const blink::WebMouseWheelEvent& web_wheel, |
| 94 const ui::LatencyInfo& latency_info) { | 95 const ui::LatencyInfo& latency_info) { |
| 95 host_->ForwardWheelEventWithLatencyInfo(web_wheel, latency_info); | 96 host_->ForwardWheelEventWithLatencyInfo(web_wheel, latency_info); |
| 96 } | 97 } |
| 97 | 98 |
| 98 void SyntheticGestureTargetBase::DispatchWebMouseEventToPlatform( | 99 void SyntheticGestureTargetBase::DispatchWebMouseEventToPlatform( |
| 99 const blink::WebMouseEvent& web_mouse, | 100 const blink::WebMouseEvent& web_mouse, |
| (...skipping 26 matching lines...) Expand all Loading... |
| 126 return 0.0f; | 127 return 0.0f; |
| 127 } | 128 } |
| 128 | 129 |
| 129 bool SyntheticGestureTargetBase::PointIsWithinContents(int x, int y) const { | 130 bool SyntheticGestureTargetBase::PointIsWithinContents(int x, int y) const { |
| 130 gfx::Rect bounds = host_->GetView()->GetViewBounds(); | 131 gfx::Rect bounds = host_->GetView()->GetViewBounds(); |
| 131 bounds -= bounds.OffsetFromOrigin(); // Translate the bounds to (0,0). | 132 bounds -= bounds.OffsetFromOrigin(); // Translate the bounds to (0,0). |
| 132 return bounds.Contains(x, y); | 133 return bounds.Contains(x, y); |
| 133 } | 134 } |
| 134 | 135 |
| 135 } // namespace content | 136 } // namespace content |
| OLD | NEW |