[Qt][WK2] Refactor GestureRecognizers to use QtWebPageEventHandler
authorjesus@webkit.org <jesus@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 25 Nov 2011 19:57:28 +0000 (19:57 +0000)
committerjesus@webkit.org <jesus@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 25 Nov 2011 19:57:28 +0000 (19:57 +0000)
https://bugs.webkit.org/show_bug.cgi?id=73096

Reviewed by Kenneth Rohde Christiansen.

Move all the interaction engine usage to QtWebPageEventHandler,
making all GestureRecognizers (Tap, Pinch and Pan) use it directly.

* UIProcess/qt/QtGestureRecognizer.cpp:
(WebKit::QtGestureRecognizer::QtGestureRecognizer):
* UIProcess/qt/QtGestureRecognizer.h:
* UIProcess/qt/QtPanGestureRecognizer.cpp:
(WebKit::QtPanGestureRecognizer::QtPanGestureRecognizer):
(WebKit::QtPanGestureRecognizer::recognize):
* UIProcess/qt/QtPanGestureRecognizer.h:
* UIProcess/qt/QtPinchGestureRecognizer.cpp:
(WebKit::QtPinchGestureRecognizer::QtPinchGestureRecognizer):
(WebKit::QtPinchGestureRecognizer::recognize):
* UIProcess/qt/QtPinchGestureRecognizer.h:
* UIProcess/qt/QtTapGestureRecognizer.cpp:
(WebKit::QtTapGestureRecognizer::QtTapGestureRecognizer):
(WebKit::QtTapGestureRecognizer::recognize):
(WebKit::QtTapGestureRecognizer::tapTimeout):
* UIProcess/qt/QtTapGestureRecognizer.h:
* UIProcess/qt/QtWebPageEventHandler.cpp:
(QtWebPageEventHandler::QtWebPageEventHandler):
(QtWebPageEventHandler::setViewportInteractionEngine):
* UIProcess/qt/QtWebPageEventHandler.h:
(QtWebPageEventHandler::interactionEngine):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@101179 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/qt/QtGestureRecognizer.cpp
Source/WebKit2/UIProcess/qt/QtGestureRecognizer.h
Source/WebKit2/UIProcess/qt/QtPanGestureRecognizer.cpp
Source/WebKit2/UIProcess/qt/QtPanGestureRecognizer.h
Source/WebKit2/UIProcess/qt/QtPinchGestureRecognizer.cpp
Source/WebKit2/UIProcess/qt/QtPinchGestureRecognizer.h
Source/WebKit2/UIProcess/qt/QtTapGestureRecognizer.cpp
Source/WebKit2/UIProcess/qt/QtTapGestureRecognizer.h
Source/WebKit2/UIProcess/qt/QtWebPageEventHandler.cpp
Source/WebKit2/UIProcess/qt/QtWebPageEventHandler.h

index 729a9ee..dc51b97 100644 (file)
@@ -1,3 +1,35 @@
+2011-11-25  Jesus Sanchez-Palencia  <jesus.palencia@openbossa.org>
+
+        [Qt][WK2] Refactor GestureRecognizers to use QtWebPageEventHandler
+        https://bugs.webkit.org/show_bug.cgi?id=73096
+
+        Reviewed by Kenneth Rohde Christiansen.
+
+        Move all the interaction engine usage to QtWebPageEventHandler,
+        making all GestureRecognizers (Tap, Pinch and Pan) use it directly.
+
+        * UIProcess/qt/QtGestureRecognizer.cpp:
+        (WebKit::QtGestureRecognizer::QtGestureRecognizer):
+        * UIProcess/qt/QtGestureRecognizer.h:
+        * UIProcess/qt/QtPanGestureRecognizer.cpp:
+        (WebKit::QtPanGestureRecognizer::QtPanGestureRecognizer):
+        (WebKit::QtPanGestureRecognizer::recognize):
+        * UIProcess/qt/QtPanGestureRecognizer.h:
+        * UIProcess/qt/QtPinchGestureRecognizer.cpp:
+        (WebKit::QtPinchGestureRecognizer::QtPinchGestureRecognizer):
+        (WebKit::QtPinchGestureRecognizer::recognize):
+        * UIProcess/qt/QtPinchGestureRecognizer.h:
+        * UIProcess/qt/QtTapGestureRecognizer.cpp:
+        (WebKit::QtTapGestureRecognizer::QtTapGestureRecognizer):
+        (WebKit::QtTapGestureRecognizer::recognize):
+        (WebKit::QtTapGestureRecognizer::tapTimeout):
+        * UIProcess/qt/QtTapGestureRecognizer.h:
+        * UIProcess/qt/QtWebPageEventHandler.cpp:
+        (QtWebPageEventHandler::QtWebPageEventHandler):
+        (QtWebPageEventHandler::setViewportInteractionEngine):
+        * UIProcess/qt/QtWebPageEventHandler.h:
+        (QtWebPageEventHandler::interactionEngine):
+
 2011-11-25  Caio Marcelo de Oliveira Filho  <caio.oliveira@openbossa.org>
 
         [Qt] Remove unneeded declaration from QQuickWebPagePrivate
index ef1d872..0c62452 100644 (file)
 #include "config.h"
 #include "QtGestureRecognizer.h"
 
+#include "QtWebPageEventHandler.h"
+
 namespace WebKit {
 
-QtGestureRecognizer::QtGestureRecognizer(QtViewportInteractionEngine* viewportInteractionEngine)
-    : m_viewportInteractionEngine(viewportInteractionEngine)
+QtGestureRecognizer::QtGestureRecognizer(QtWebPageEventHandler* eventHandler)
+    : m_eventHandler(eventHandler)
     , m_state(NoGesture)
 {
 }
@@ -39,9 +41,9 @@ void QtGestureRecognizer::reset()
     m_state = NoGesture;
 }
 
-void QtGestureRecognizer::setViewportInteractionEngine(QtViewportInteractionEngine* engine)
+QtViewportInteractionEngine* QtGestureRecognizer::interactionEngine()
 {
-    m_viewportInteractionEngine = engine;
+    return m_eventHandler->interactionEngine();
 }
 
 }
index 4cca6bc..4c191f6 100644 (file)
@@ -26,6 +26,8 @@
 #ifndef QtGestureRecognizer_h
 #define QtGestureRecognizer_h
 
+class QtWebPageEventHandler;
+
 namespace WebKit {
 
 class QtViewportInteractionEngine;
@@ -35,16 +37,17 @@ public:
     bool isRecognized() const { return m_state == GestureRecognized; }
 
 protected:
-    QtGestureRecognizer(QtViewportInteractionEngine*);
-    void setViewportInteractionEngine(QtViewportInteractionEngine*);
+    QtGestureRecognizer(QtWebPageEventHandler*);
     void reset();
 
-    QtViewportInteractionEngine* m_viewportInteractionEngine;
+    QtWebPageEventHandler* m_eventHandler;
     enum State {
         NoGesture,
         GestureRecognitionStarted,
         GestureRecognized
     } m_state;
+
+    QtViewportInteractionEngine* interactionEngine();
 };
 
 }
index abe2692..924a665 100644 (file)
 
 #include "QtPanGestureRecognizer.h"
 
-#include "QtViewportInteractionEngine.h"
+#include "QtWebPageEventHandler.h"
 #include <QTouchEvent>
 
 namespace WebKit {
 
-QtPanGestureRecognizer::QtPanGestureRecognizer(QtViewportInteractionEngine* interactionEngine)
-    : QtGestureRecognizer(interactionEngine)
+QtPanGestureRecognizer::QtPanGestureRecognizer(QtWebPageEventHandler* eventHandler)
+    : QtGestureRecognizer(eventHandler)
 {
     reset();
 }
 
-void QtPanGestureRecognizer::setViewportInteractionEngine(QtViewportInteractionEngine* engine)
-{
-    QtGestureRecognizer::setViewportInteractionEngine(engine);
-    reset();
-}
-
 bool QtPanGestureRecognizer::recognize(const QTouchEvent* event, qint64 eventTimestampMillis)
 {
-    if (!m_viewportInteractionEngine)
+    if (interactionEngine())
         return false;
 
     // Pan gesture always starts on TouchBegin unless the engine is suspended, or
@@ -56,7 +50,7 @@ bool QtPanGestureRecognizer::recognize(const QTouchEvent* event, qint64 eventTim
     // Having multiple touch points cancel the panning gesture.
     if (event->touchPoints().size() > 1) {
         if (m_state == GestureRecognized)
-            m_viewportInteractionEngine->panGestureCancelled();
+            interactionEngine()->panGestureCancelled();
         reset();
         return false;
     }
@@ -79,16 +73,16 @@ bool QtPanGestureRecognizer::recognize(const QTouchEvent* event, qint64 eventTim
                 return false;
 
             m_state = GestureRecognized;
-            m_viewportInteractionEngine->panGestureStarted(touchPoint.pos(), eventTimestampMillis);
+            interactionEngine()->panGestureStarted(touchPoint.pos(), eventTimestampMillis);
         }
 
         ASSERT(m_state == GestureRecognized);
-        m_viewportInteractionEngine->panGestureRequestUpdate(touchPoint.pos(), eventTimestampMillis);
+        interactionEngine()->panGestureRequestUpdate(touchPoint.pos(), eventTimestampMillis);
         return true;
     }
     case QEvent::TouchEnd:
         if (m_state == GestureRecognized) {
-            m_viewportInteractionEngine->panGestureEnded(touchPoint.pos(), eventTimestampMillis);
+            interactionEngine()->panGestureEnded(touchPoint.pos(), eventTimestampMillis);
             reset();
             return true;
         }
index 514fea8..532507e 100644 (file)
@@ -41,8 +41,7 @@ const qreal panningInitialTriggerDistanceThreshold = 5.;
 
 class QtPanGestureRecognizer : public QtGestureRecognizer {
 public:
-    QtPanGestureRecognizer(QtViewportInteractionEngine*);
-    void setViewportInteractionEngine(QtViewportInteractionEngine*);
+    QtPanGestureRecognizer(QtWebPageEventHandler*);
     bool recognize(const QTouchEvent*, qint64 eventTimestampMillis);
     void reset();
 
index 72467b4..9167792 100644 (file)
@@ -26,7 +26,7 @@
 #include "config.h"
 #include "QtPinchGestureRecognizer.h"
 
-#include "QtViewportInteractionEngine.h"
+#include "QtWebPageEventHandler.h"
 #include <QtCore/QLineF>
 
 namespace WebKit {
@@ -49,21 +49,21 @@ static inline QPointF computePinchCenter(const QTouchEvent::TouchPoint& point1,
     return (point1.pos() + point2.pos()) / 2.0f;
 }
 
-QtPinchGestureRecognizer::QtPinchGestureRecognizer(QtViewportInteractionEngine* interactionEngine)
-    : QtGestureRecognizer(interactionEngine)
+QtPinchGestureRecognizer::QtPinchGestureRecognizer(QtWebPageEventHandler* eventHandler)
+    : QtGestureRecognizer(eventHandler)
 {
     reset();
 }
 
 bool QtPinchGestureRecognizer::recognize(const QTouchEvent* event)
 {
-    if (!m_viewportInteractionEngine)
+    if (!interactionEngine())
         return false;
 
     const QList<QTouchEvent::TouchPoint>& touchPoints = event->touchPoints();
     if (touchPoints.size() < 2) {
         if (m_state == GestureRecognized)
-            m_viewportInteractionEngine->pinchGestureEnded();
+            interactionEngine()->pinchGestureEnded();
         reset();
         return false;
     }
@@ -99,7 +99,7 @@ bool QtPinchGestureRecognizer::recognize(const QTouchEvent* event)
                 if (pinchDistance < pinchInitialTriggerDistanceThreshold)
                     return false;
                 m_state = GestureRecognized;
-                m_viewportInteractionEngine->pinchGestureStarted(computePinchCenter(point1, point2));
+                interactionEngine()->pinchGestureStarted(computePinchCenter(point1, point2));
 
                 // 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.
@@ -113,14 +113,14 @@ bool QtPinchGestureRecognizer::recognize(const QTouchEvent* event)
             const qreal initialSpanDistance = QLineF(m_point1.initialScreenPosition, m_point2.initialScreenPosition).length();
             const qreal totalScaleFactor = currentSpanDistance / initialSpanDistance;
             const QPointF touchCenterInPageViewCoordinates = computePinchCenter(point1, point2);
-            m_viewportInteractionEngine->pinchGestureRequestUpdate(touchCenterInPageViewCoordinates, totalScaleFactor);
+            interactionEngine()->pinchGestureRequestUpdate(touchCenterInPageViewCoordinates, totalScaleFactor);
             return true;
             break;
         }
         break;
     case QEvent::TouchEnd:
         if (m_state == GestureRecognized) {
-            m_viewportInteractionEngine->pinchGestureEnded();
+            interactionEngine()->pinchGestureEnded();
             reset();
             return true;
         }
@@ -133,12 +133,6 @@ bool QtPinchGestureRecognizer::recognize(const QTouchEvent* event)
     return false;
 }
 
-void QtPinchGestureRecognizer::setViewportInteractionEngine(QtViewportInteractionEngine* engine)
-{
-    QtGestureRecognizer::setViewportInteractionEngine(engine);
-    reset();
-}
-
 void QtPinchGestureRecognizer::reset()
 {
     QtGestureRecognizer::reset();
index 208c05a..7dd3d91 100644 (file)
@@ -50,8 +50,7 @@ public:
         QPointF initialPosition;
     };
 
-    QtPinchGestureRecognizer(QtViewportInteractionEngine*);
-    void setViewportInteractionEngine(QtViewportInteractionEngine*);
+    QtPinchGestureRecognizer(QtWebPageEventHandler*);
     bool recognize(const QTouchEvent*);
     void reset();
 
index 12a305e..2ed773c 100644 (file)
 #include "QtTapGestureRecognizer.h"
 
 #include "QtWebPageEventHandler.h"
-#include "QtViewportInteractionEngine.h"
 #include <QLineF>
 #include <QTouchEvent>
 
 namespace WebKit {
 
-QtTapGestureRecognizer::QtTapGestureRecognizer(QtViewportInteractionEngine* interactionEngine, QtWebPageEventHandler* eventHandler)
-    : QtGestureRecognizer(interactionEngine)
-    , m_eventHandler(eventHandler)
+QtTapGestureRecognizer::QtTapGestureRecognizer(QtWebPageEventHandler* eventHandler)
+    : QtGestureRecognizer(eventHandler)
     , m_tapState(NoTap)
 {
     reset();
 }
 
-void QtTapGestureRecognizer::setViewportInteractionEngine(QtViewportInteractionEngine* engine)
-{
-    QtGestureRecognizer::setViewportInteractionEngine(engine);
-    reset();
-}
-
 bool QtTapGestureRecognizer::recognize(const QTouchEvent* event, qint64 eventTimestampMillis)
 {
     if (event->touchPoints().size() != 1) {
index 4390fd3..a4ec41e 100644 (file)
@@ -49,8 +49,7 @@ namespace WebKit {
 
 class QtTapGestureRecognizer : public QObject, private QtGestureRecognizer {
 public:
-    QtTapGestureRecognizer(QtViewportInteractionEngine*, QtWebPageEventHandler*);
-    void setViewportInteractionEngine(QtViewportInteractionEngine*);
+    QtTapGestureRecognizer(QtWebPageEventHandler*);
     bool recognize(const QTouchEvent*, qint64 eventTimestampMillis);
     void reset();
 
@@ -60,7 +59,6 @@ protected:
     void tapAndHoldTimeout();
 
 private:
-    QtWebPageEventHandler* m_eventHandler;
     QBasicTimer m_doubleTapTimer;
     QBasicTimer m_tapAndHoldTimer;
     OwnPtr<QTouchEvent> m_touchBeginEventForTap;
index 97f747e..19d32f4 100644 (file)
@@ -80,9 +80,9 @@ WebCore::DragOperation QtWebPageEventHandler::dropActionToDragOperation(Qt::Drop
 QtWebPageEventHandler::QtWebPageEventHandler(WKPageRef pageRef, WebKit::QtViewportInteractionEngine* viewportInteractionEngine)
     : m_webPageProxy(toImpl(pageRef))
     , m_interactionEngine(viewportInteractionEngine)
-    , m_panGestureRecognizer(viewportInteractionEngine)
-    , m_pinchGestureRecognizer(viewportInteractionEngine)
-    , m_tapGestureRecognizer(viewportInteractionEngine, this)
+    , m_panGestureRecognizer(this)
+    , m_pinchGestureRecognizer(this)
+    , m_tapGestureRecognizer(this)
 {
 }
 
@@ -303,9 +303,6 @@ bool QtWebPageEventHandler::handleFocusOutEvent(QFocusEvent*)
 void QtWebPageEventHandler::setViewportInteractionEngine(QtViewportInteractionEngine* engine)
 {
     m_interactionEngine = engine;
-    m_panGestureRecognizer.setViewportInteractionEngine(engine);
-    m_pinchGestureRecognizer.setViewportInteractionEngine(engine);
-    m_tapGestureRecognizer.setViewportInteractionEngine(engine);
 }
 
 void QtWebPageEventHandler::touchEvent(QTouchEvent* event)
index 0a58ff7..8e80bc7 100644 (file)
@@ -24,6 +24,7 @@
 #include "QtPanGestureRecognizer.h"
 #include "QtPinchGestureRecognizer.h"
 #include "QtTapGestureRecognizer.h"
+#include "QtViewportInteractionEngine.h"
 #include "WebPageProxy.h"
 #include <QBasicTimer>
 #include <QKeyEvent>
@@ -54,6 +55,8 @@ public:
     void doneWithTouchEvent(const NativeWebTouchEvent&, bool wasEventHandled);
     void resetGestureRecognizers();
 
+    QtViewportInteractionEngine* interactionEngine() { return m_interactionEngine; }
+
 protected:
     WebPageProxy* m_webPageProxy;
     QtViewportInteractionEngine* m_interactionEngine;