Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / web / WebInputEventConversion.cpp
index 2b383ce..5ff894f 100644 (file)
@@ -29,7 +29,7 @@
  */
 
 #include "config.h"
-#include "WebInputEventConversion.h"
+#include "web/WebInputEventConversion.h"
 
 #include "core/dom/Touch.h"
 #include "core/dom/TouchList.h"
 #include "core/events/MouseEvent.h"
 #include "core/events/TouchEvent.h"
 #include "core/events/WheelEvent.h"
+#include "core/frame/FrameHost.h"
+#include "core/frame/FrameView.h"
+#include "core/frame/PinchViewport.h"
+#include "core/page/Page.h"
 #include "core/rendering/RenderObject.h"
 #include "platform/KeyboardCodes.h"
 #include "platform/Widget.h"
@@ -72,16 +76,29 @@ static IntSize widgetInputEventsOffset(const Widget* widget)
     return rootView->inputEventsOffsetForEmulation();
 }
 
+static IntPoint pinchViewportOffset(const Widget* widget)
+{
+    // Event position needs to be adjusted by the pinch viewport's offset within the
+    // main frame before being passed into the widget's convertFromContainingWindow.
+    FrameView* rootView = toFrameView(widget->root());
+    if (!rootView)
+        return IntPoint();
+
+    return flooredIntPoint(rootView->page()->frameHost().pinchViewport().visibleRect().location());
+}
+
 // MakePlatformMouseEvent -----------------------------------------------------
 
 PlatformMouseEventBuilder::PlatformMouseEventBuilder(Widget* widget, const WebMouseEvent& e)
 {
     float scale = widgetInputEventsScaleFactor(widget);
     IntSize offset = widgetInputEventsOffset(widget);
+    IntPoint pinchViewport = pinchViewportOffset(widget);
 
     // FIXME: Widget is always toplevel, unless it's a popup. We may be able
     // to get rid of this once we abstract popups into a WebKit API.
-    m_position = widget->convertFromContainingWindow(IntPoint((e.x - offset.width()) / scale, (e.y - offset.height()) / scale));
+    m_position = widget->convertFromContainingWindow(
+        IntPoint((e.x - offset.width()) / scale + pinchViewport.x(), (e.y - offset.height()) / scale + pinchViewport.y()));
     m_globalPosition = IntPoint(e.globalX, e.globalY);
     m_movementDelta = IntPoint(e.movementX / scale, e.movementY / scale);
     m_button = static_cast<MouseButton>(e.button);
@@ -125,8 +142,10 @@ PlatformWheelEventBuilder::PlatformWheelEventBuilder(Widget* widget, const WebMo
 {
     float scale = widgetInputEventsScaleFactor(widget);
     IntSize offset = widgetInputEventsOffset(widget);
+    IntPoint pinchViewport = pinchViewportOffset(widget);
 
-    m_position = widget->convertFromContainingWindow(IntPoint((e.x - offset.width()) / scale, (e.y - offset.height()) / scale));
+    m_position = widget->convertFromContainingWindow(
+        IntPoint((e.x - offset.width()) / scale + pinchViewport.x(), (e.y - offset.height()) / scale + pinchViewport.y()));
     m_globalPosition = IntPoint(e.globalX, e.globalY);
     m_deltaX = e.deltaX;
     m_deltaY = e.deltaY;
@@ -166,6 +185,7 @@ PlatformGestureEventBuilder::PlatformGestureEventBuilder(Widget* widget, const W
 {
     float scale = widgetInputEventsScaleFactor(widget);
     IntSize offset = widgetInputEventsOffset(widget);
+    IntPoint pinchViewport = pinchViewportOffset(widget);
 
     switch (e.type) {
     case WebInputEvent::GestureScrollBegin:
@@ -243,7 +263,8 @@ PlatformGestureEventBuilder::PlatformGestureEventBuilder(Widget* widget, const W
     default:
         ASSERT_NOT_REACHED();
     }
-    m_position = widget->convertFromContainingWindow(IntPoint((e.x - offset.width()) / scale, (e.y - offset.height()) / scale));
+    m_position = widget->convertFromContainingWindow(
+        IntPoint((e.x - offset.width()) / scale + pinchViewport.x(), (e.y - offset.height()) / scale + pinchViewport.y()));
     m_globalPosition = IntPoint(e.globalX, e.globalY);
     m_timestamp = e.timeStampSeconds;
 
@@ -405,9 +426,12 @@ PlatformTouchPointBuilder::PlatformTouchPointBuilder(Widget* widget, const WebTo
 {
     float scale = widgetInputEventsScaleFactor(widget);
     IntSize offset = widgetInputEventsOffset(widget);
+    IntPoint pinchViewport = pinchViewportOffset(widget);
     m_id = point.id;
     m_state = toPlatformTouchPointState(point.state);
-    m_pos = widget->convertFromContainingWindow(IntPoint((point.position.x - offset.width()) / scale, (point.position.y - offset.height()) / scale));
+    m_pos = widget->convertFromContainingWindow(IntPoint(
+        (point.position.x - offset.width()) / scale + pinchViewport.x(),
+        (point.position.y - offset.height()) / scale + pinchViewport.y()));
     m_screenPos = IntPoint(point.screenPosition.x, point.screenPosition.y);
     m_radiusY = point.radiusY / scale;
     m_radiusX = point.radiusX / scale;
@@ -433,6 +457,8 @@ PlatformTouchEventBuilder::PlatformTouchEventBuilder(Widget* widget, const WebTo
 
     for (unsigned i = 0; i < event.touchesLength; ++i)
         m_touchPoints.append(PlatformTouchPointBuilder(widget, event.touches[i]));
+
+    m_cancelable = event.cancelable;
 }
 
 static int getWebInputModifiers(const UIEventWithKeyState& event)
@@ -736,6 +762,7 @@ WebTouchEventBuilder::WebTouchEventBuilder(const Widget* widget, const WebCore::
 
     modifiers = getWebInputModifiers(event);
     timeStampSeconds = event.timeStamp() / millisPerSecond;
+    cancelable = event.cancelable();
 
     addTouchPoints(widget, event.type(), event.touches(), touches, &touchesLength, renderObject);
     addTouchPoints(widget, event.type(), event.changedTouches(), changedTouches, &changedTouchesLength, renderObject);