Title: [90838] trunk/Source/WebKit2
Revision
90838
Author
[email protected]
Date
2011-07-12 12:16:24 -0700 (Tue, 12 Jul 2011)

Log Message

[Qt][WK2] Add a basic Pinch gesture recognizer for WebKit2
https://bugs.webkit.org/show_bug.cgi?id=64373

Reviewed by Andreas Kling.

This patch adds QtPinchGestureRecognizer to recognize pinch gesture out of
the events not handled by the WebProcess.

TouchViewInterface::pinchGestureRequestScale() has a basic default implementation
so the feature can be tested manually.

* UIProcess/qt/QtGestureRecognizer.cpp:
QtGestureRecognizer is the private base class for both gesture recognizer
in order to be able to share some code.
(WebKit::QtGestureRecognizer::QtGestureRecognizer):
(WebKit::QtGestureRecognizer::reset):
* UIProcess/qt/QtGestureRecognizer.h:
* UIProcess/qt/QtPanGestureRecognizer.cpp:
(WebKit::QtPanGestureRecognizer::QtPanGestureRecognizer):
(WebKit::QtPanGestureRecognizer::reset):
* UIProcess/qt/QtPanGestureRecognizer.h:
* UIProcess/qt/QtPinchGestureRecognizer.cpp: Added.
(WebKit::findTouchPointIndex):
(WebKit::computeTouchCenter):
(WebKit::QtPinchGestureRecognizer::QtPinchGestureRecognizer):
(WebKit::QtPinchGestureRecognizer::recognize):
(WebKit::QtPinchGestureRecognizer::reset):
(WebKit::QtPinchGestureRecognizer::initializeGesture):
* UIProcess/qt/QtPinchGestureRecognizer.h: Copied from Source/WebKit2/UIProcess/qt/QtPanGestureRecognizer.h.
(WebKit::QtPinchGestureRecognizer::TouchPointInformation::TouchPointInformation):
(WebKit::QtPinchGestureRecognizer::TouchPointInformation::isValid):
* UIProcess/qt/TouchViewInterface.cpp:
(WebKit::TouchViewInterface::TouchViewInterface):
(WebKit::TouchViewInterface::pinchGestureStarted):
(WebKit::TouchViewInterface::pinchGestureRequestScale):
The scale factor reported by the recognizer to the TouchViewInterface is the total scale since the start
of the gesture in order to avoid numerical instabilities.
(WebKit::TouchViewInterface::pinchGestureEnded):
* UIProcess/qt/TouchViewInterface.h:
* UIProcess/qt/qtouchwebpageproxy.cpp:
(QTouchWebPageProxy::QTouchWebPageProxy):
(QTouchWebPageProxy::processDidCrash):
(QTouchWebPageProxy::doneWithTouchEvent):
* UIProcess/qt/qtouchwebpageproxy.h:
* WebKit2.pro:

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (90837 => 90838)


--- trunk/Source/WebKit2/ChangeLog	2011-07-12 18:55:41 UTC (rev 90837)
+++ trunk/Source/WebKit2/ChangeLog	2011-07-12 19:16:24 UTC (rev 90838)
@@ -1,3 +1,51 @@
+2011-07-12  Benjamin Poulain  <[email protected]>
+
+        [Qt][WK2] Add a basic Pinch gesture recognizer for WebKit2
+        https://bugs.webkit.org/show_bug.cgi?id=64373
+
+        Reviewed by Andreas Kling.
+
+        This patch adds QtPinchGestureRecognizer to recognize pinch gesture out of
+        the events not handled by the WebProcess.
+
+        TouchViewInterface::pinchGestureRequestScale() has a basic default implementation
+        so the feature can be tested manually.
+
+        * UIProcess/qt/QtGestureRecognizer.cpp:
+        QtGestureRecognizer is the private base class for both gesture recognizer
+        in order to be able to share some code.
+        (WebKit::QtGestureRecognizer::QtGestureRecognizer):
+        (WebKit::QtGestureRecognizer::reset):
+        * UIProcess/qt/QtGestureRecognizer.h:
+        * UIProcess/qt/QtPanGestureRecognizer.cpp:
+        (WebKit::QtPanGestureRecognizer::QtPanGestureRecognizer):
+        (WebKit::QtPanGestureRecognizer::reset):
+        * UIProcess/qt/QtPanGestureRecognizer.h:
+        * UIProcess/qt/QtPinchGestureRecognizer.cpp: Added.
+        (WebKit::findTouchPointIndex):
+        (WebKit::computeTouchCenter):
+        (WebKit::QtPinchGestureRecognizer::QtPinchGestureRecognizer):
+        (WebKit::QtPinchGestureRecognizer::recognize):
+        (WebKit::QtPinchGestureRecognizer::reset):
+        (WebKit::QtPinchGestureRecognizer::initializeGesture):
+        * UIProcess/qt/QtPinchGestureRecognizer.h: Copied from Source/WebKit2/UIProcess/qt/QtPanGestureRecognizer.h.
+        (WebKit::QtPinchGestureRecognizer::TouchPointInformation::TouchPointInformation):
+        (WebKit::QtPinchGestureRecognizer::TouchPointInformation::isValid):
+        * UIProcess/qt/TouchViewInterface.cpp:
+        (WebKit::TouchViewInterface::TouchViewInterface):
+        (WebKit::TouchViewInterface::pinchGestureStarted):
+        (WebKit::TouchViewInterface::pinchGestureRequestScale):
+        The scale factor reported by the recognizer to the TouchViewInterface is the total scale since the start
+        of the gesture in order to avoid numerical instabilities.
+        (WebKit::TouchViewInterface::pinchGestureEnded):
+        * UIProcess/qt/TouchViewInterface.h:
+        * UIProcess/qt/qtouchwebpageproxy.cpp:
+        (QTouchWebPageProxy::QTouchWebPageProxy):
+        (QTouchWebPageProxy::processDidCrash):
+        (QTouchWebPageProxy::doneWithTouchEvent):
+        * UIProcess/qt/qtouchwebpageproxy.h:
+        * WebKit2.pro:
+
 2011-07-12  Andreas Kling  <[email protected]>
 
         [Qt][WK2] Navigation actions should react to web process availability.

Added: trunk/Source/WebKit2/UIProcess/qt/QtGestureRecognizer.cpp (0 => 90838)


--- trunk/Source/WebKit2/UIProcess/qt/QtGestureRecognizer.cpp	                        (rev 0)
+++ trunk/Source/WebKit2/UIProcess/qt/QtGestureRecognizer.cpp	2011-07-12 19:16:24 UTC (rev 90838)
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2011 Benjamin Poulain <[email protected]>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "QtGestureRecognizer.h"
+
+namespace WebKit {
+
+QtGestureRecognizer::QtGestureRecognizer(TouchViewInterface* touchViewInterface)
+    : m_touchViewInterface(touchViewInterface)
+    , m_state(NoGesture)
+{
+    ASSERT(touchViewInterface);
+}
+
+void QtGestureRecognizer::reset()
+{
+    m_state = NoGesture;
+}
+
+}

Added: trunk/Source/WebKit2/UIProcess/qt/QtGestureRecognizer.h (0 => 90838)


--- trunk/Source/WebKit2/UIProcess/qt/QtGestureRecognizer.h	                        (rev 0)
+++ trunk/Source/WebKit2/UIProcess/qt/QtGestureRecognizer.h	2011-07-12 19:16:24 UTC (rev 90838)
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2011 Benjamin Poulain <[email protected]>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef QtGestureRecognizer_h
+#define QtGestureRecognizer_h
+
+namespace WebKit {
+
+class TouchViewInterface;
+
+class QtGestureRecognizer {
+protected:
+    QtGestureRecognizer(TouchViewInterface*);
+    void reset();
+
+    TouchViewInterface* const m_touchViewInterface;
+    enum State {
+        NoGesture,
+        GestureRecognitionStarted,
+        GestureRecognized
+    } m_state;
+};
+
+}
+
+#endif /* QtGestureRecognizer_h */

Modified: trunk/Source/WebKit2/UIProcess/qt/QtPanGestureRecognizer.cpp (90837 => 90838)


--- trunk/Source/WebKit2/UIProcess/qt/QtPanGestureRecognizer.cpp	2011-07-12 18:55:41 UTC (rev 90837)
+++ trunk/Source/WebKit2/UIProcess/qt/QtPanGestureRecognizer.cpp	2011-07-12 19:16:24 UTC (rev 90838)
@@ -31,7 +31,7 @@
 namespace WebKit {
 
 QtPanGestureRecognizer::QtPanGestureRecognizer(TouchViewInterface* touchViewInterface)
-    : m_touchViewInterface(touchViewInterface)
+    : QtGestureRecognizer(touchViewInterface)
 {
     reset();
 }
@@ -94,7 +94,7 @@
 
 void QtPanGestureRecognizer::reset()
 {
-    m_state = NoGesture;
+    QtGestureRecognizer::reset();
     m_firstPosition = QPointF();
 }
 

Modified: trunk/Source/WebKit2/UIProcess/qt/QtPanGestureRecognizer.h (90837 => 90838)


--- trunk/Source/WebKit2/UIProcess/qt/QtPanGestureRecognizer.h	2011-07-12 18:55:41 UTC (rev 90837)
+++ trunk/Source/WebKit2/UIProcess/qt/QtPanGestureRecognizer.h	2011-07-12 19:16:24 UTC (rev 90838)
@@ -26,6 +26,8 @@
 #ifndef QtPanGestureRecognizer_h
 #define QtPanGestureRecognizer_h
 
+#include "QtGestureRecognizer.h"
+
 #include <QPointF>
 #include <QtCore/QtGlobal>
 
@@ -35,22 +37,15 @@
 
 namespace WebKit {
 
-class TouchViewInterface;
 const qreal panningInitialTriggerDistanceThreshold = 5.;
 
-class QtPanGestureRecognizer {
+class QtPanGestureRecognizer : private QtGestureRecognizer {
 public:
     QtPanGestureRecognizer(TouchViewInterface*);
     bool recognize(const QTouchEvent*);
     void reset();
 
 private:
-    TouchViewInterface* const m_touchViewInterface;
-    enum {
-        NoGesture,
-        GestureRecognitionStarted,
-        GestureRecognized
-    } m_state;
     QPointF m_firstPosition;
 };
 

Added: trunk/Source/WebKit2/UIProcess/qt/QtPinchGestureRecognizer.cpp (0 => 90838)


--- trunk/Source/WebKit2/UIProcess/qt/QtPinchGestureRecognizer.cpp	                        (rev 0)
+++ trunk/Source/WebKit2/UIProcess/qt/QtPinchGestureRecognizer.cpp	2011-07-12 19:16:24 UTC (rev 90838)
@@ -0,0 +1,154 @@
+/*
+ * Copyright (C) 2011 Benjamin Poulain <[email protected]>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "QtPinchGestureRecognizer.h"
+
+#include "TouchViewInterface.h"
+#include <QtCore/QLineF>
+
+namespace WebKit {
+
+const qreal pinchInitialTriggerDistanceThreshold = 5.;
+
+static inline int findTouchPointIndex(const QList<QTouchEvent::TouchPoint>& touchPoints, const QtPinchGestureRecognizer::TouchPointInformation& pointInformation)
+{
+    const int touchCount = touchPoints.size();
+    for (int i = 0; i < touchCount; ++i) {
+        const QTouchEvent::TouchPoint& touchPoint = touchPoints.at(i);
+        if (touchPoint.id() == pointInformation.id)
+            return i;
+    }
+    return -1;
+}
+
+static inline QPointF computeTouchCenter(const QTouchEvent::TouchPoint& point1, const QTouchEvent::TouchPoint& point2)
+{
+    return (point1.pos() + point2.pos()) / 2.0f;
+}
+
+QtPinchGestureRecognizer::QtPinchGestureRecognizer(TouchViewInterface* touchViewInterface)
+    : QtGestureRecognizer(touchViewInterface)
+{
+    reset();
+}
+
+bool QtPinchGestureRecognizer::recognize(const QTouchEvent* event)
+{
+    const QList<QTouchEvent::TouchPoint>& touchPoints = event->touchPoints();
+    if (touchPoints.size() < 2) {
+        if (m_state == GestureRecognized)
+            m_touchViewInterface->pinchGestureEnded();
+        reset();
+        return false;
+    }
+
+    switch (event->type()) {
+    case QEvent::TouchBegin:
+    case QEvent::TouchUpdate:
+        switch (m_state) {
+        case NoGesture:
+            initializeGesture(touchPoints);
+            return false;
+        case GestureRecognitionStarted:
+        case GestureRecognized:
+            ASSERT(m_point1.isValid());
+            ASSERT(m_point2.isValid());
+
+            const int point1Index = findTouchPointIndex(touchPoints, m_point1);
+            if (point1Index < 0) {
+                reset();
+                return false;
+            }
+            const int point2Index = findTouchPointIndex(touchPoints, m_point2);
+            if (point2Index < 0) {
+                reset();
+                return false;
+            }
+
+            const QTouchEvent::TouchPoint& point1 = touchPoints.at(point1Index);
+            const QTouchEvent::TouchPoint& point2 = touchPoints.at(point2Index);
+            if (m_state == GestureRecognitionStarted) {
+                // FIXME: The gesture should only start if the touch events were not accepted at the start of the touch sequence.
+                const qreal pinchDistance = qAbs(QLineF(point1.screenPos(), point2.screenPos()).length() - QLineF(m_point1.initialScreenPosition, m_point2.initialScreenPosition).length());
+                if (pinchDistance < pinchInitialTriggerDistanceThreshold)
+                    return false;
+                m_state = GestureRecognized;
+                m_touchViewInterface->pinchGestureStarted();
+
+                // We reset the initial position to the previous position in order to avoid the jump caused
+                // by skipping all the events between the beginning and when the threshold is hit.
+                m_point1.initialPosition = point1.lastPos();
+                m_point1.initialScreenPosition = point1.lastScreenPos();
+                m_point2.initialPosition = point2.lastPos();
+                m_point2.initialScreenPosition = point2.lastScreenPos();
+            }
+            ASSERT(m_state == GestureRecognized);
+            const qreal currentSpanDistance = QLineF(point1.screenPos(), point2.screenPos()).length();
+            const qreal initialSpanDistance = QLineF(m_point1.initialScreenPosition, m_point2.initialScreenPosition).length();
+            const qreal totalScaleFactor = currentSpanDistance / initialSpanDistance;
+            const QPointF touchCenterInPageViewCoordinate = computeTouchCenter(point1, point2);
+            m_touchViewInterface->pinchGestureRequestUpdate(touchCenterInPageViewCoordinate, totalScaleFactor);
+            return true;
+            break;
+        }
+        break;
+    case QEvent::TouchEnd:
+        if (m_state == GestureRecognized) {
+            m_touchViewInterface->pinchGestureEnded();
+            reset();
+            return true;
+        }
+        reset();
+        break;
+    default:
+        ASSERT_NOT_REACHED();
+    }
+
+    return false;
+}
+
+void QtPinchGestureRecognizer::reset()
+{
+    QtGestureRecognizer::reset();
+    m_point1 = TouchPointInformation();
+    m_point2 = TouchPointInformation();
+}
+
+void QtPinchGestureRecognizer::initializeGesture(const QList<QTouchEvent::TouchPoint>& touchPoints)
+{
+    ASSERT(!m_point1.isValid());
+    ASSERT(!m_point2.isValid());
+
+    m_state = GestureRecognitionStarted;
+
+    m_point1 = TouchPointInformation(touchPoints.at(0));
+    m_point2 = TouchPointInformation(touchPoints.at(1));
+
+    ASSERT(m_point1.isValid());
+    ASSERT(m_point2.isValid());
+}
+
+}

Added: trunk/Source/WebKit2/UIProcess/qt/QtPinchGestureRecognizer.h (0 => 90838)


--- trunk/Source/WebKit2/UIProcess/qt/QtPinchGestureRecognizer.h	                        (rev 0)
+++ trunk/Source/WebKit2/UIProcess/qt/QtPinchGestureRecognizer.h	2011-07-12 19:16:24 UTC (rev 90838)
@@ -0,0 +1,85 @@
+/*
+ * Copyright (C) 2011 Benjamin Poulain <[email protected]>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef QtPinchGestureRecognizer_h
+#define QtPinchGestureRecognizer_h
+
+#include "QtGestureRecognizer.h"
+
+#include <QTouchEvent>
+#include <QtCore/QList>
+#include <QtCore/QPointF>
+
+QT_BEGIN_NAMESPACE
+class QTouchEvent;
+QT_END_NAMESPACE
+
+namespace WebKit {
+
+class TouchViewInterface;
+
+class QtPinchGestureRecognizer : private QtGestureRecognizer {
+public:
+    struct TouchPointInformation {
+        inline TouchPointInformation();
+        inline TouchPointInformation(const QTouchEvent::TouchPoint&);
+        inline bool isValid() const;
+
+        int id;
+        QPointF initialScreenPosition;
+        QPointF initialPosition;
+    };
+
+    QtPinchGestureRecognizer(TouchViewInterface*);
+    bool recognize(const QTouchEvent*);
+    void reset();
+
+private:
+    void initializeGesture(const QList<QTouchEvent::TouchPoint>& touchPoints);
+
+    TouchPointInformation m_point1;
+    TouchPointInformation m_point2;
+};
+
+inline QtPinchGestureRecognizer::TouchPointInformation::TouchPointInformation()
+    : id(-1)
+{
+}
+
+inline QtPinchGestureRecognizer::TouchPointInformation::TouchPointInformation(const QTouchEvent::TouchPoint& touchPoint)
+    : id(touchPoint.id())
+    , initialScreenPosition(touchPoint.screenPos())
+    , initialPosition(touchPoint.pos())
+{
+}
+
+inline bool QtPinchGestureRecognizer::TouchPointInformation::isValid() const
+{
+    return id >= 0;
+}
+
+}
+
+#endif /* QtPinchGestureRecognizer_h */

Modified: trunk/Source/WebKit2/UIProcess/qt/TouchViewInterface.cpp (90837 => 90838)


--- trunk/Source/WebKit2/UIProcess/qt/TouchViewInterface.cpp	2011-07-12 18:55:41 UTC (rev 90837)
+++ trunk/Source/WebKit2/UIProcess/qt/TouchViewInterface.cpp	2011-07-12 19:16:24 UTC (rev 90838)
@@ -22,6 +22,7 @@
 #include "TouchViewInterface.h"
 
 #include "qtouchwebpage.h"
+#include "qtouchwebpage_p.h"
 #include "qtouchwebview.h"
 #include "qtouchwebview_p.h"
 
@@ -30,6 +31,7 @@
 TouchViewInterface::TouchViewInterface(QTouchWebView* viewportView, QTouchWebPage* pageView)
     : m_viewportView(viewportView)
     , m_pageView(pageView)
+    , m_pinchStartScale(1.f)
 {
     Q_ASSERT(m_viewportView);
     Q_ASSERT(m_pageView);
@@ -57,6 +59,31 @@
     // FIXME: resume the Web engine.
 }
 
+void TouchViewInterface::pinchGestureStarted()
+{
+    // FIXME: suspend the engine.
+    m_pageView->d->prepareScaleChange();
+    m_pinchStartScale = m_pageView->scale();
+}
+
+void TouchViewInterface::pinchGestureRequestUpdate(const QPointF& pinchCenterInPageViewCoordinate, qreal totalScaleFactor)
+{
+    // FIXME: it is a bit more complicated than that, changes of the center position should move the page even
+    // if the zoom factor does not change. Both the zoom and the panning should be handled through the physics
+    // engine.
+    const qreal scale = m_pinchStartScale * totalScaleFactor;
+    m_pageView->setTransformOriginPoint(pinchCenterInPageViewCoordinate);
+    m_pageView->setScale(scale);
+}
+
+void TouchViewInterface::pinchGestureEnded()
+{
+    // FIXME: commit scale with the scale value in the valid range in order to get new tiles.
+    // FIXME: animate the back zoom in the valid range.
+    // FIXME: resume the engine after the animation.
+    m_pageView->d->commitScaleChange();
+}
+
 void TouchViewInterface::setViewNeedsDisplay(const QRect& invalidatedRect)
 {
     m_pageView->update(invalidatedRect);

Modified: trunk/Source/WebKit2/UIProcess/qt/TouchViewInterface.h (90837 => 90838)


--- trunk/Source/WebKit2/UIProcess/qt/TouchViewInterface.h	2011-07-12 18:55:41 UTC (rev 90837)
+++ trunk/Source/WebKit2/UIProcess/qt/TouchViewInterface.h	2011-07-12 19:16:24 UTC (rev 90838)
@@ -23,6 +23,7 @@
 
 #include "ViewInterface.h"
 
+class QPointF;
 class QTouchWebPage;
 class QTouchWebView;
 
@@ -38,6 +39,10 @@
     void panGestureEnded();
     void panGestureCancelled();
 
+    void pinchGestureStarted();
+    void pinchGestureRequestUpdate(const QPointF&, qreal);
+    void pinchGestureEnded();
+
 private:
     /* Implementation of ViewInterface */
     virtual void setViewNeedsDisplay(const QRect&);
@@ -70,6 +75,8 @@
 private:
     QTouchWebView* const m_viewportView;
     QTouchWebPage* const m_pageView;
+
+    qreal m_pinchStartScale;
 };
 
 }

Modified: trunk/Source/WebKit2/UIProcess/qt/qtouchwebpageproxy.cpp (90837 => 90838)


--- trunk/Source/WebKit2/UIProcess/qt/qtouchwebpageproxy.cpp	2011-07-12 18:55:41 UTC (rev 90837)
+++ trunk/Source/WebKit2/UIProcess/qt/qtouchwebpageproxy.cpp	2011-07-12 19:16:24 UTC (rev 90838)
@@ -30,6 +30,7 @@
 QTouchWebPageProxy::QTouchWebPageProxy(TouchViewInterface* viewInterface, QWKContext* context, WKPageGroupRef pageGroupRef)
     : QtWebPageProxy(viewInterface, context, pageGroupRef)
     , m_panGestureRecognizer(viewInterface)
+    , m_pinchGestureRecognizer(viewInterface)
 {
     init();
     // FIXME: add proper handling of viewport.
@@ -45,6 +46,7 @@
 {
     QtWebPageProxy::processDidCrash();
     m_panGestureRecognizer.reset();
+    m_pinchGestureRecognizer.reset();
 }
 
 void QTouchWebPageProxy::paintContent(QPainter* painter, const QRect& area)
@@ -61,10 +63,13 @@
 #if ENABLE(TOUCH_EVENTS)
 void QTouchWebPageProxy::doneWithTouchEvent(const NativeWebTouchEvent& event, bool wasEventHandled)
 {
-    if (wasEventHandled)
+    if (wasEventHandled) {
         m_panGestureRecognizer.reset();
-    else
+        m_pinchGestureRecognizer.reset();
+    } else {
         m_panGestureRecognizer.recognize(event.nativeEvent());
+        m_pinchGestureRecognizer.recognize(event.nativeEvent());
+    }
 }
 #endif
 

Modified: trunk/Source/WebKit2/UIProcess/qt/qtouchwebpageproxy.h (90837 => 90838)


--- trunk/Source/WebKit2/UIProcess/qt/qtouchwebpageproxy.h	2011-07-12 18:55:41 UTC (rev 90837)
+++ trunk/Source/WebKit2/UIProcess/qt/qtouchwebpageproxy.h	2011-07-12 19:16:24 UTC (rev 90838)
@@ -24,6 +24,7 @@
 
 #include "DrawingAreaProxy.h"
 #include "QtPanGestureRecognizer.h"
+#include "QtPinchGestureRecognizer.h"
 #include "QtWebPageProxy.h"
 #include "TiledDrawingAreaProxy.h"
 #include "TouchViewInterface.h"
@@ -61,6 +62,7 @@
     void touchEvent(QTouchEvent*);
 
     QtPanGestureRecognizer m_panGestureRecognizer;
+    QtPinchGestureRecognizer m_pinchGestureRecognizer;
     WebCore::ViewportArguments m_viewportArguments;
 };
 

Modified: trunk/Source/WebKit2/WebKit2.pro (90837 => 90838)


--- trunk/Source/WebKit2/WebKit2.pro	2011-07-12 18:55:41 UTC (rev 90837)
+++ trunk/Source/WebKit2/WebKit2.pro	2011-07-12 19:16:24 UTC (rev 90838)
@@ -236,7 +236,9 @@
     UIProcess/WebUIClient.h \
     UIProcess/qt/ClientImpl.h \
     UIProcess/qt/TouchViewInterface.h \
+    UIProcess/qt/QtGestureRecognizer.h \
     UIProcess/qt/QtPanGestureRecognizer.h \
+    UIProcess/qt/QtPinchGestureRecognizer.h \
     UIProcess/qt/qdesktopwebpageproxy.h \
     UIProcess/qt/qtouchwebpageproxy.h \
     UIProcess/qt/QtWebPageProxy.h \
@@ -465,7 +467,9 @@
     UIProcess/WebUIClient.cpp \
     UIProcess/qt/ClientImpl.cpp \
     UIProcess/qt/TouchViewInterface.cpp \
+    UIProcess/qt/QtGestureRecognizer.cpp \
     UIProcess/qt/QtPanGestureRecognizer.cpp \
+    UIProcess/qt/QtPinchGestureRecognizer.cpp \
     UIProcess/qt/qdesktopwebpageproxy.cpp \
     UIProcess/qt/qtouchwebpageproxy.cpp \
     UIProcess/qt/QtWebPageProxy.cpp \
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to