Title: [124455] trunk/Source/WebKit2
Revision
124455
Author
[email protected]
Date
2012-08-02 07:42:30 -0700 (Thu, 02 Aug 2012)

Log Message

[Qt][WK2] Click, mouse and links rely on touch mocking.
https://bugs.webkit.org/show_bug.cgi?id=83091

Reviewed by Simon Hausmann.

Send the incoming mouse events directly to the gesture recognizers to make
the WebView behave consistent with other Flickables.
This patch unifies the code paths for input events and makes it possible
to enable mouse events on the flickable web view again, thus makes the
mobile-version of QQuickWebView usable on desktop.

* UIProcess/API/qt/qquickwebview.cpp:
(QQuickWebViewPrivate::handleMouseEvent):
(QQuickWebViewFlickablePrivate::QQuickWebViewFlickablePrivate):
(QQuickWebViewFlickablePrivate::handleMouseEvent):
(QQuickWebView::mousePressEvent):
(QQuickWebView::mouseMoveEvent):
(QQuickWebView::mouseReleaseEvent):
(QQuickWebView::mouseDoubleClickEvent):
* UIProcess/API/qt/qquickwebview_p_p.h:
(QQuickWebViewPrivate):
(QQuickWebViewFlickablePrivate):
* UIProcess/qt/QtPanGestureRecognizer.cpp:
(WebKit::QtPanGestureRecognizer::update):
* UIProcess/qt/QtWebPageEventHandler.cpp:
(WebKit::QtWebPageEventHandler::QtWebPageEventHandler):
(WebKit::QtWebPageEventHandler::handleInputEvent):
(WebKit):
(WebKit::QtWebPageEventHandler::doneWithTouchEvent):
* UIProcess/qt/QtWebPageEventHandler.h:
(QtWebPageEventHandler):

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (124454 => 124455)


--- trunk/Source/WebKit2/ChangeLog	2012-08-02 14:21:10 UTC (rev 124454)
+++ trunk/Source/WebKit2/ChangeLog	2012-08-02 14:42:30 UTC (rev 124455)
@@ -1,3 +1,37 @@
+2012-08-02  Andras Becsi  <[email protected]>
+
+        [Qt][WK2] Click, mouse and links rely on touch mocking.
+        https://bugs.webkit.org/show_bug.cgi?id=83091
+
+        Reviewed by Simon Hausmann.
+
+        Send the incoming mouse events directly to the gesture recognizers to make
+        the WebView behave consistent with other Flickables.
+        This patch unifies the code paths for input events and makes it possible
+        to enable mouse events on the flickable web view again, thus makes the
+        mobile-version of QQuickWebView usable on desktop.
+
+        * UIProcess/API/qt/qquickwebview.cpp:
+        (QQuickWebViewPrivate::handleMouseEvent):
+        (QQuickWebViewFlickablePrivate::QQuickWebViewFlickablePrivate):
+        (QQuickWebViewFlickablePrivate::handleMouseEvent):
+        (QQuickWebView::mousePressEvent):
+        (QQuickWebView::mouseMoveEvent):
+        (QQuickWebView::mouseReleaseEvent):
+        (QQuickWebView::mouseDoubleClickEvent):
+        * UIProcess/API/qt/qquickwebview_p_p.h:
+        (QQuickWebViewPrivate):
+        (QQuickWebViewFlickablePrivate):
+        * UIProcess/qt/QtPanGestureRecognizer.cpp:
+        (WebKit::QtPanGestureRecognizer::update):
+        * UIProcess/qt/QtWebPageEventHandler.cpp:
+        (WebKit::QtWebPageEventHandler::QtWebPageEventHandler):
+        (WebKit::QtWebPageEventHandler::handleInputEvent):
+        (WebKit):
+        (WebKit::QtWebPageEventHandler::doneWithTouchEvent):
+        * UIProcess/qt/QtWebPageEventHandler.h:
+        (QtWebPageEventHandler):
+
 2012-08-01  Brady Eidson  <[email protected]>
 
         Small part of "Out-of-process plug-ins should support asynchronous initialization."

Modified: trunk/Source/WebKit2/UIProcess/API/qt/qquickwebview.cpp (124454 => 124455)


--- trunk/Source/WebKit2/UIProcess/API/qt/qquickwebview.cpp	2012-08-02 14:21:10 UTC (rev 124454)
+++ trunk/Source/WebKit2/UIProcess/API/qt/qquickwebview.cpp	2012-08-02 14:42:30 UTC (rev 124455)
@@ -408,6 +408,27 @@
     emit q->loadingChanged(&loadRequest);
 }
 
+void QQuickWebViewPrivate::handleMouseEvent(QMouseEvent* event)
+{
+    switch (event->type()) {
+    case QEvent::MouseButtonPress:
+    case QEvent::MouseButtonDblClick:
+        // If a MouseButtonDblClick was received then we got a MouseButtonPress before
+        // handleMousePressEvent will take care of double clicks.
+        pageView->eventHandler()->handleMousePressEvent(event);
+        break;
+    case QEvent::MouseMove:
+        pageView->eventHandler()->handleMouseMoveEvent(event);
+        break;
+    case QEvent::MouseButtonRelease:
+        pageView->eventHandler()->handleMouseReleaseEvent(event);
+        break;
+    default:
+        ASSERT_NOT_REACHED();
+        break;
+    }
+}
+
 void QQuickWebViewPrivate::setNeedsDisplay()
 {
     Q_Q(QQuickWebView);
@@ -815,12 +836,6 @@
 QQuickWebViewFlickablePrivate::QQuickWebViewFlickablePrivate(QQuickWebView* viewport)
     : QQuickWebViewPrivate(viewport)
 {
-    // Disable mouse events on the flickable web view so we do not
-    // select text during pan gestures on platforms which send both
-    // touch and mouse events simultaneously.
-    // FIXME: Temporary workaround code which should be removed when
-    // bug http://codereview.qt-project.org/21896 is fixed.
-    viewport->setAcceptedMouseButtons(Qt::NoButton);
     viewport->setAcceptHoverEvents(false);
 }
 
@@ -872,6 +887,15 @@
     m_viewportHandler->pageContentsSizeChanged(newSize, q->boundingRect().size().toSize());
 }
 
+void QQuickWebViewFlickablePrivate::handleMouseEvent(QMouseEvent* event)
+{
+    if (!pageView->eventHandler())
+        return;
+
+    // FIXME: Update the axis locker for mouse events as well.
+    pageView->eventHandler()->handleInputEvent(event);
+}
+
 /*!
     \qmlsignal WebView::onNavigationRequested(WebNavigationRequest request)
 
@@ -1766,29 +1790,26 @@
 {
     Q_D(QQuickWebView);
     forceActiveFocus();
-    d->pageView->eventHandler()->handleMousePressEvent(event);
+    d->handleMouseEvent(event);
 }
 
 void QQuickWebView::mouseMoveEvent(QMouseEvent* event)
 {
     Q_D(QQuickWebView);
-    d->pageView->eventHandler()->handleMouseMoveEvent(event);
+    d->handleMouseEvent(event);
 }
 
 void QQuickWebView::mouseReleaseEvent(QMouseEvent* event)
 {
     Q_D(QQuickWebView);
-    d->pageView->eventHandler()->handleMouseReleaseEvent(event);
+    d->handleMouseEvent(event);
 }
 
 void QQuickWebView::mouseDoubleClickEvent(QMouseEvent* event)
 {
     Q_D(QQuickWebView);
-
     forceActiveFocus();
-    // If a MouseButtonDblClick was received then we got a MouseButtonPress before
-    // handleMousePressEvent will take care of double clicks.
-    d->pageView->eventHandler()->handleMousePressEvent(event);
+    d->handleMouseEvent(event);
 }
 
 void QQuickWebView::wheelEvent(QWheelEvent* event)

Modified: trunk/Source/WebKit2/UIProcess/API/qt/qquickwebview_p_p.h (124454 => 124455)


--- trunk/Source/WebKit2/UIProcess/API/qt/qquickwebview_p_p.h	2012-08-02 14:21:10 UTC (rev 124454)
+++ trunk/Source/WebKit2/UIProcess/API/qt/qquickwebview_p_p.h	2012-08-02 14:42:30 UTC (rev 124455)
@@ -83,6 +83,7 @@
     virtual void backForwardListDidChange();
     virtual void loadDidSucceed();
     virtual void loadDidFail(const WebKit::QtWebError& error);
+    virtual void handleMouseEvent(QMouseEvent*);
 
     virtual void didChangeViewportProperties(const WebCore::ViewportAttributes& attr) { }
 
@@ -228,6 +229,7 @@
 
     virtual void pageDidRequestScroll(const QPoint& pos);
     virtual void didChangeContentsSize(const QSize& newSize);
+    virtual void handleMouseEvent(QMouseEvent*);
 
 private:
     QScopedPointer<WebKit::QtViewportHandler> m_viewportHandler;

Modified: trunk/Source/WebKit2/UIProcess/qt/QtPanGestureRecognizer.cpp (124454 => 124455)


--- trunk/Source/WebKit2/UIProcess/qt/QtPanGestureRecognizer.cpp	2012-08-02 14:21:10 UTC (rev 124454)
+++ trunk/Source/WebKit2/UIProcess/qt/QtPanGestureRecognizer.cpp	2012-08-02 14:42:30 UTC (rev 124455)
@@ -47,13 +47,13 @@
     switch (m_state) {
     case NoGesture:
         m_state = GestureRecognitionStarted;
-        m_firstScreenPosition = touchPoint.scenePos();
+        m_firstScreenPosition = touchPoint.screenPos();
         viewportHandler()->cancelScrollAnimation();
         return false;
     case GestureRecognitionStarted: {
         // To start the gesture, the delta from start in screen coordinates
         // must be bigger than the trigger threshold.
-        QPointF totalOffsetFromStart(touchPoint.scenePos() - m_firstScreenPosition);
+        QPointF totalOffsetFromStart(touchPoint.screenPos() - m_firstScreenPosition);
         if (qAbs(totalOffsetFromStart.x()) < panningInitialTriggerDistanceThreshold && qAbs(totalOffsetFromStart.y()) < panningInitialTriggerDistanceThreshold)
             return false;
 

Modified: trunk/Source/WebKit2/UIProcess/qt/QtWebPageEventHandler.cpp (124454 => 124455)


--- trunk/Source/WebKit2/UIProcess/qt/QtWebPageEventHandler.cpp	2012-08-02 14:21:10 UTC (rev 124454)
+++ trunk/Source/WebKit2/UIProcess/qt/QtWebPageEventHandler.cpp	2012-08-02 14:42:30 UTC (rev 124455)
@@ -31,8 +31,10 @@
 #include <QCursor>
 #include <QDrag>
 #include <QGuiApplication>
+#include <QInputEvent>
 #include <QInputMethod>
 #include <QMimeData>
+#include <QMouseEvent>
 #include <QQuickWindow>
 #include <QStyleHints>
 #include <QTextFormat>
@@ -99,6 +101,7 @@
     , m_clickCount(0)
     , m_postponeTextInputStateChanged(false)
     , m_isTapHighlightActive(false)
+    , m_isMouseButtonPressed(false)
 {
     connect(qApp->inputMethod(), SIGNAL(visibleChanged()), this, SLOT(inputPanelVisibleChanged()));
 }
@@ -445,23 +448,17 @@
     updateTextInputState();
 }
 
-#if ENABLE(TOUCH_EVENTS)
-void QtWebPageEventHandler::doneWithTouchEvent(const NativeWebTouchEvent& event, bool wasEventHandled)
+void QtWebPageEventHandler::handleInputEvent(const QInputEvent* event)
 {
-    if (!m_viewportHandler)
-        return;
+    ASSERT(m_viewportHandler);
 
-    if (wasEventHandled || event.type() == WebEvent::TouchCancel) {
-        m_panGestureRecognizer.cancel();
-        m_pinchGestureRecognizer.cancel();
-        if (event.type() != WebEvent::TouchMove)
-            m_tapGestureRecognizer.cancel();
-        return;
-    }
+    bool isMouseEvent = false;
 
-    const QTouchEvent* ev = event.nativeEvent();
-
-    switch (ev->type()) {
+    switch (event->type()) {
+    case QEvent::MouseButtonPress:
+        isMouseEvent = true;
+        m_isMouseButtonPressed = true;
+        // Fall through.
     case QEvent::TouchBegin:
         ASSERT(!m_viewportHandler->panGestureActive());
         ASSERT(!m_viewportHandler->pinchGestureActive());
@@ -472,16 +469,27 @@
         // where as it does not stop the scale animation.
         // The gesture recognizer stops the kinetic scrolling animation if needed.
         break;
+    case QEvent::MouseMove:
+        if (!m_isMouseButtonPressed)
+            return;
+
+        isMouseEvent = true;
+        // Fall through.
     case QEvent::TouchUpdate:
         // The scale animation can only be interrupted by a pinch gesture, which will then take over.
         if (m_viewportHandler->scaleAnimationActive() && m_pinchGestureRecognizer.isRecognized())
             m_viewportHandler->interruptScaleAnimation();
         break;
+    case QEvent::MouseButtonRelease:
+        isMouseEvent = true;
+        m_isMouseButtonPressed = false;
+        // Fall through.
     case QEvent::TouchEnd:
         m_viewportHandler->touchEnd();
         break;
     default:
-        break;
+        ASSERT(event->type() == QEvent::MouseButtonDblClick);
+        return;
     }
 
     // If the scale animation is active we don't pass the event to the recognizers. In the future
@@ -489,15 +497,36 @@
     if (m_viewportHandler->scaleAnimationActive())
         return;
 
-    const QList<QTouchEvent::TouchPoint>& touchPoints = ev->touchPoints();
-    const int touchPointCount = touchPoints.size();
-    qint64 eventTimestampMillis = ev->timestamp();
     QList<QTouchEvent::TouchPoint> activeTouchPoints;
-    activeTouchPoints.reserve(touchPointCount);
+    QTouchEvent::TouchPoint currentTouchPoint;
+    qint64 eventTimestampMillis = event->timestamp();
+    int touchPointCount = 0;
 
-    for (int i = 0; i < touchPointCount; ++i) {
-        if (touchPoints[i].state() != Qt::TouchPointReleased)
-            activeTouchPoints << touchPoints[i];
+    if (!isMouseEvent) {
+        const QTouchEvent* touchEvent = static_cast<const QTouchEvent*>(event);
+        const QList<QTouchEvent::TouchPoint>& touchPoints = touchEvent->touchPoints();
+        currentTouchPoint = touchPoints.first();
+        touchPointCount = touchPoints.size();
+        activeTouchPoints.reserve(touchPointCount);
+
+        for (int i = 0; i < touchPointCount; ++i) {
+            if (touchPoints[i].state() != Qt::TouchPointReleased)
+                activeTouchPoints << touchPoints[i];
+        }
+    } else {
+        const QMouseEvent* mouseEvent = static_cast<const QMouseEvent*>(event);
+        touchPointCount = 1;
+
+        // Make a distinction between mouse events on the basis of pressed buttons.
+        currentTouchPoint.setId(mouseEvent->buttons());
+        currentTouchPoint.setScreenPos(mouseEvent->screenPos());
+        // For tap gesture hit testing the float touch rect is translated to
+        // an int rect representing the radius of the touch point (size/2),
+        // thus the touch rect has to have a size of at least 2.
+        currentTouchPoint.setRect(QRectF(mouseEvent->localPos(), QSizeF(2, 2)));
+
+        if (m_isMouseButtonPressed)
+            activeTouchPoints << currentTouchPoint;
     }
 
     const int activeTouchPointCount = activeTouchPoints.size();
@@ -506,11 +535,11 @@
         if (touchPointCount == 1) {
             // No active touch points, one finger released.
             if (m_panGestureRecognizer.isRecognized())
-                m_panGestureRecognizer.finish(touchPoints.first(), eventTimestampMillis);
+                m_panGestureRecognizer.finish(currentTouchPoint, eventTimestampMillis);
             else {
                 // The events did not result in a pan gesture.
                 m_panGestureRecognizer.cancel();
-                m_tapGestureRecognizer.finish(touchPoints.first());
+                m_tapGestureRecognizer.finish(currentTouchPoint);
             }
 
         } else
@@ -532,8 +561,28 @@
     if (m_panGestureRecognizer.isRecognized() || m_pinchGestureRecognizer.isRecognized() || m_webView->isMoving())
         m_tapGestureRecognizer.cancel();
     else if (touchPointCount == 1)
-        m_tapGestureRecognizer.update(touchPoints.first());
+        m_tapGestureRecognizer.update(currentTouchPoint);
+
 }
+
+#if ENABLE(TOUCH_EVENTS)
+void QtWebPageEventHandler::doneWithTouchEvent(const NativeWebTouchEvent& event, bool wasEventHandled)
+{
+    if (!m_viewportHandler)
+        return;
+
+    if (wasEventHandled || event.type() == WebEvent::TouchCancel) {
+        m_panGestureRecognizer.cancel();
+        m_pinchGestureRecognizer.cancel();
+        if (event.type() != WebEvent::TouchMove)
+            m_tapGestureRecognizer.cancel();
+        return;
+    }
+
+    const QTouchEvent* ev = event.nativeEvent();
+
+    handleInputEvent(ev);
+}
 #endif
 
 void QtWebPageEventHandler::didFindZoomableArea(const IntPoint& target, const IntRect& area)

Modified: trunk/Source/WebKit2/UIProcess/qt/QtWebPageEventHandler.h (124454 => 124455)


--- trunk/Source/WebKit2/UIProcess/qt/QtWebPageEventHandler.h	2012-08-02 14:21:10 UTC (rev 124454)
+++ trunk/Source/WebKit2/UIProcess/qt/QtWebPageEventHandler.h	2012-08-02 14:42:30 UTC (rev 124455)
@@ -88,6 +88,7 @@
 #if ENABLE(TOUCH_EVENTS)
     void doneWithTouchEvent(const NativeWebTouchEvent&, bool wasEventHandled);
 #endif
+    void handleInputEvent(const QInputEvent*);
     void resetGestureRecognizers();
 
     QtViewportHandler* viewportHandler() { return m_viewportHandler; }
@@ -115,6 +116,7 @@
     int m_clickCount;
     bool m_postponeTextInputStateChanged;
     bool m_isTapHighlightActive;
+    bool m_isMouseButtonPressed;
 };
 
 } // namespace WebKit
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to