Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / content / browser / renderer_host / input / synthetic_gesture_target_base.cc
index 5f2bb2d..987dff4 100644 (file)
@@ -14,6 +14,7 @@
 
 using blink::WebInputEvent;
 using blink::WebTouchEvent;
+using blink::WebTouchPoint;
 using blink::WebMouseEvent;
 using blink::WebMouseWheelEvent;
 
@@ -50,25 +51,31 @@ void SyntheticGestureTargetBase::DispatchInputEventToPlatform(
   latency_info.AddLatencyNumber(ui::INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0);
 
   if (WebInputEvent::isTouchEventType(event.type)) {
-    DCHECK(SupportsSyntheticGestureSourceType(
-            SyntheticGestureParams::TOUCH_INPUT));
-
     const WebTouchEvent& web_touch =
         static_cast<const WebTouchEvent&>(event);
+
+    // Check that all touch pointers are within the content bounds.
+    if (web_touch.type == WebInputEvent::TouchStart) {
+      for (unsigned i = 0; i < web_touch.touchesLength; i++)
+        CHECK(web_touch.touches[i].state != WebTouchPoint::StatePressed ||
+              PointIsWithinContents(web_touch.touches[i].position.x,
+                                    web_touch.touches[i].position.y))
+            << "Touch coordinates are not within content bounds on TouchStart.";
+    }
+
     DispatchWebTouchEventToPlatform(web_touch, latency_info);
   } else if (event.type == WebInputEvent::MouseWheel) {
-    DCHECK(SupportsSyntheticGestureSourceType(
-            SyntheticGestureParams::MOUSE_INPUT));
-
     const WebMouseWheelEvent& web_wheel =
         static_cast<const WebMouseWheelEvent&>(event);
+    CHECK(PointIsWithinContents(web_wheel.x, web_wheel.y))
+        << "Mouse wheel position is not within content bounds.";
     DispatchWebMouseWheelEventToPlatform(web_wheel, latency_info);
   } else if (WebInputEvent::isMouseEventType(event.type)) {
-    DCHECK(SupportsSyntheticGestureSourceType(
-            SyntheticGestureParams::MOUSE_INPUT));
-
     const WebMouseEvent& web_mouse =
         static_cast<const WebMouseEvent&>(event);
+    CHECK(event.type != WebInputEvent::MouseDown ||
+          PointIsWithinContents(web_mouse.x, web_mouse.y))
+        << "Mouse pointer is not within content bounds on MouseDown.";
     DispatchWebMouseEventToPlatform(web_mouse, latency_info);
   } else {
     NOTREACHED();
@@ -78,7 +85,10 @@ void SyntheticGestureTargetBase::DispatchInputEventToPlatform(
 void SyntheticGestureTargetBase::DispatchWebTouchEventToPlatform(
       const blink::WebTouchEvent& web_touch,
       const ui::LatencyInfo& latency_info) {
-  host_->ForwardTouchEventWithLatencyInfo(web_touch, latency_info);
+  // We assume that platforms supporting touch have their own implementation of
+  // SyntheticGestureTarget to route the events through their respective input
+  // stack.
+  CHECK(false) << "Touch events not supported for this browser.";
 }
 
 void SyntheticGestureTargetBase::DispatchWebMouseWheelEventToPlatform(
@@ -102,12 +112,6 @@ SyntheticGestureTargetBase::GetDefaultSyntheticGestureSourceType() const {
   return SyntheticGestureParams::MOUSE_INPUT;
 }
 
-bool SyntheticGestureTargetBase::SupportsSyntheticGestureSourceType(
-    SyntheticGestureParams::GestureSourceType gesture_source_type) const {
-  return gesture_source_type == SyntheticGestureParams::MOUSE_INPUT ||
-      gesture_source_type == SyntheticGestureParams::TOUCH_INPUT;
-}
-
 base::TimeDelta SyntheticGestureTargetBase::PointerAssumedStoppedTime()
     const {
   return base::TimeDelta::FromMilliseconds(kPointerAssumedStoppedTimeMs);
@@ -117,4 +121,10 @@ int SyntheticGestureTargetBase::GetTouchSlopInDips() const {
   return kTouchSlopInDips;
 }
 
+bool SyntheticGestureTargetBase::PointIsWithinContents(int x, int y) const {
+  gfx::Rect bounds = host_->GetView()->GetViewBounds();
+  bounds -= bounds.OffsetFromOrigin();  // Translate the bounds to (0,0).
+  return bounds.Contains(x, y);
+}
+
 }  // namespace content