Title: [99425] trunk/Source/WebKit2
Revision
99425
Author
kenn...@webkit.org
Date
2011-11-07 08:24:50 -0800 (Mon, 07 Nov 2011)

Log Message

[Qt] Put handling of gestures and their interaction in one place
https://bugs.webkit.org/show_bug.cgi?id=71682

Reviewed by Simon Hausmann.

Before this patch, the interaction (ie. cancelling animations, events)
was handled in the respective recognizers which then knew about each
others.

* UIProcess/qt/QtGestureRecognizer.h:
(WebKit::QtGestureRecognizer::isRecognized):
* UIProcess/qt/QtPanGestureRecognizer.cpp:
(WebKit::QtPanGestureRecognizer::recognize):
* UIProcess/qt/QtPanGestureRecognizer.h:
* UIProcess/qt/QtPinchGestureRecognizer.cpp:
(WebKit::QtPinchGestureRecognizer::recognize):
* UIProcess/qt/QtPinchGestureRecognizer.h:
* UIProcess/qt/QtTouchWebPageProxy.cpp:
(QtTouchWebPageProxy::QtTouchWebPageProxy):
(QtTouchWebPageProxy::doneWithTouchEvent):
* UIProcess/qt/QtTouchWebPageProxy.h:
* UIProcess/qt/QtViewportInteractionEngine.cpp:
(WebKit::QtViewportInteractionEngine::pagePositionRequest):
(WebKit::QtViewportInteractionEngine::ensureContentWithinViewportBoundary):
(WebKit::QtViewportInteractionEngine::scrollAnimationActive):
(WebKit::QtViewportInteractionEngine::interruptScrollAnimation):
(WebKit::QtViewportInteractionEngine::panGestureActive):
(WebKit::QtViewportInteractionEngine::scaleAnimationActive):
(WebKit::QtViewportInteractionEngine::interruptScaleAnimation):
(WebKit::QtViewportInteractionEngine::pinchGestureActive):
* UIProcess/qt/QtViewportInteractionEngine.h:

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (99424 => 99425)


--- trunk/Source/WebKit2/ChangeLog	2011-11-07 15:58:00 UTC (rev 99424)
+++ trunk/Source/WebKit2/ChangeLog	2011-11-07 16:24:50 UTC (rev 99425)
@@ -1,3 +1,37 @@
+2011-11-07  Kenneth Rohde Christiansen  <kenn...@webkit.org>
+
+        [Qt] Put handling of gestures and their interaction in one place
+        https://bugs.webkit.org/show_bug.cgi?id=71682
+
+        Reviewed by Simon Hausmann.
+
+        Before this patch, the interaction (ie. cancelling animations, events)
+        was handled in the respective recognizers which then knew about each
+        others.
+
+        * UIProcess/qt/QtGestureRecognizer.h:
+        (WebKit::QtGestureRecognizer::isRecognized):
+        * UIProcess/qt/QtPanGestureRecognizer.cpp:
+        (WebKit::QtPanGestureRecognizer::recognize):
+        * UIProcess/qt/QtPanGestureRecognizer.h:
+        * UIProcess/qt/QtPinchGestureRecognizer.cpp:
+        (WebKit::QtPinchGestureRecognizer::recognize):
+        * UIProcess/qt/QtPinchGestureRecognizer.h:
+        * UIProcess/qt/QtTouchWebPageProxy.cpp:
+        (QtTouchWebPageProxy::QtTouchWebPageProxy):
+        (QtTouchWebPageProxy::doneWithTouchEvent):
+        * UIProcess/qt/QtTouchWebPageProxy.h:
+        * UIProcess/qt/QtViewportInteractionEngine.cpp:
+        (WebKit::QtViewportInteractionEngine::pagePositionRequest):
+        (WebKit::QtViewportInteractionEngine::ensureContentWithinViewportBoundary):
+        (WebKit::QtViewportInteractionEngine::scrollAnimationActive):
+        (WebKit::QtViewportInteractionEngine::interruptScrollAnimation):
+        (WebKit::QtViewportInteractionEngine::panGestureActive):
+        (WebKit::QtViewportInteractionEngine::scaleAnimationActive):
+        (WebKit::QtViewportInteractionEngine::interruptScaleAnimation):
+        (WebKit::QtViewportInteractionEngine::pinchGestureActive):
+        * UIProcess/qt/QtViewportInteractionEngine.h:
+
 2011-11-07  Simon Hausmann  <simon.hausm...@nokia.com>
 
         [Qt] Make it possible to include qdesktopwebview.h from apps

Modified: trunk/Source/WebKit2/UIProcess/qt/QtGestureRecognizer.h (99424 => 99425)


--- trunk/Source/WebKit2/UIProcess/qt/QtGestureRecognizer.h	2011-11-07 15:58:00 UTC (rev 99424)
+++ trunk/Source/WebKit2/UIProcess/qt/QtGestureRecognizer.h	2011-11-07 16:24:50 UTC (rev 99425)
@@ -31,6 +31,9 @@
 class QtViewportInteractionEngine;
 
 class QtGestureRecognizer {
+public:
+    bool isRecognized() const { return m_state == GestureRecognized; }
+
 protected:
     QtGestureRecognizer(QtViewportInteractionEngine*);
     void reset();

Modified: trunk/Source/WebKit2/UIProcess/qt/QtPanGestureRecognizer.cpp (99424 => 99425)


--- trunk/Source/WebKit2/UIProcess/qt/QtPanGestureRecognizer.cpp	2011-11-07 15:58:00 UTC (rev 99424)
+++ trunk/Source/WebKit2/UIProcess/qt/QtPanGestureRecognizer.cpp	2011-11-07 16:24:50 UTC (rev 99425)
@@ -57,15 +57,6 @@
     switch (event->type()) {
     case QEvent::TouchBegin:
         ASSERT(m_state == NoGesture);
-        // The pan gesture might still be animating kinetic scrolling/bounce back effect.
-        if (m_viewportInteractionEngine->panAnimationActive())
-            m_viewportInteractionEngine->panGestureCancelled();
-
-        // We do not stop bounce back effects for pinch zoom, but instead ignore the touch event.
-        // FIXME: We should queue the events instead and repost then when done with the animation.
-        if (m_viewportInteractionEngine->pinchAnimationActive())
-            return false;
-
         m_state = GestureRecognitionStarted;
         m_firstPosition = touchPoint.screenPos();
         return false;

Modified: trunk/Source/WebKit2/UIProcess/qt/QtPanGestureRecognizer.h (99424 => 99425)


--- trunk/Source/WebKit2/UIProcess/qt/QtPanGestureRecognizer.h	2011-11-07 15:58:00 UTC (rev 99424)
+++ trunk/Source/WebKit2/UIProcess/qt/QtPanGestureRecognizer.h	2011-11-07 16:24:50 UTC (rev 99425)
@@ -39,7 +39,7 @@
 
 const qreal panningInitialTriggerDistanceThreshold = 5.;
 
-class QtPanGestureRecognizer : private QtGestureRecognizer {
+class QtPanGestureRecognizer : public QtGestureRecognizer {
 public:
     QtPanGestureRecognizer(QtViewportInteractionEngine*);
     bool recognize(const QTouchEvent*, qint64 eventTimestampMillis);

Modified: trunk/Source/WebKit2/UIProcess/qt/QtPinchGestureRecognizer.cpp (99424 => 99425)


--- trunk/Source/WebKit2/UIProcess/qt/QtPinchGestureRecognizer.cpp	2011-11-07 15:58:00 UTC (rev 99424)
+++ trunk/Source/WebKit2/UIProcess/qt/QtPinchGestureRecognizer.cpp	2011-11-07 16:24:50 UTC (rev 99425)
@@ -65,15 +65,6 @@
         return false;
     }
 
-    // The pan gesture might still be animating kinetic scrolling/bounce back effect.
-    if (m_viewportInteractionEngine->panAnimationActive())
-        m_viewportInteractionEngine->panGestureCancelled();
-
-    // We do not stop bounce back effects for pinch zoom, but instead ignore the touch event.
-    // FIXME: We should queue the events instead and repost then when done with the animation.
-    if (m_viewportInteractionEngine->pinchAnimationActive())
-        return false;
-
     switch (event->type()) {
     case QEvent::TouchBegin:
     case QEvent::TouchUpdate:

Modified: trunk/Source/WebKit2/UIProcess/qt/QtPinchGestureRecognizer.h (99424 => 99425)


--- trunk/Source/WebKit2/UIProcess/qt/QtPinchGestureRecognizer.h	2011-11-07 15:58:00 UTC (rev 99424)
+++ trunk/Source/WebKit2/UIProcess/qt/QtPinchGestureRecognizer.h	2011-11-07 16:24:50 UTC (rev 99425)
@@ -38,7 +38,7 @@
 
 namespace WebKit {
 
-class QtPinchGestureRecognizer : private QtGestureRecognizer {
+class QtPinchGestureRecognizer : public QtGestureRecognizer {
 public:
     struct TouchPointInformation {
         inline TouchPointInformation();

Modified: trunk/Source/WebKit2/UIProcess/qt/QtTouchWebPageProxy.cpp (99424 => 99425)


--- trunk/Source/WebKit2/UIProcess/qt/QtTouchWebPageProxy.cpp	2011-11-07 15:58:00 UTC (rev 99424)
+++ trunk/Source/WebKit2/UIProcess/qt/QtTouchWebPageProxy.cpp	2011-11-07 16:24:50 UTC (rev 99425)
@@ -22,6 +22,7 @@
 #include "QtTouchWebPageProxy.h"
 
 #include "DrawingAreaProxyImpl.h"
+#include "QtViewportInteractionEngine.h"
 #include <IntRect.h>
 #include <NativeWebTouchEvent.h>
 #include <WebEventFactoryQt.h>
@@ -31,6 +32,7 @@
 
 QtTouchWebPageProxy::QtTouchWebPageProxy(QtTouchViewInterface* viewInterface, QtViewportInteractionEngine* viewportInteractionEngine)
     : QtWebPageProxy(viewInterface, 0)
+    , m_interactionEngine(viewportInteractionEngine)
     , m_panGestureRecognizer(viewportInteractionEngine)
     , m_pinchGestureRecognizer(viewportInteractionEngine)
 {
@@ -67,12 +69,40 @@
     if (wasEventHandled || event.type() == WebEvent::TouchCancel) {
         m_panGestureRecognizer.reset();
         m_pinchGestureRecognizer.reset();
-    } else {
-        // Convert the event timestamp from second to millisecond.
-        qint64 eventTimestampMillis = static_cast<qint64>(event.timestamp() * 1000);
-        m_panGestureRecognizer.recognize(event.nativeEvent(), eventTimestampMillis);
-        m_pinchGestureRecognizer.recognize(event.nativeEvent());
+        return;
     }
+
+    const QTouchEvent* ev = event.nativeEvent();
+
+    switch (ev->type()) {
+    case QEvent::TouchBegin:
+        ASSERT(!m_interactionEngine->panGestureActive());
+        ASSERT(!m_interactionEngine->pinchGestureActive());
+
+        // The interaction engine might still be animating kinetic scrolling or a scale animation
+        // such as double-tap to zoom or the bounce back effect. A touch stops the kinetic scrolling
+        // where as it does not stop the scale animation.
+        if (m_interactionEngine->scrollAnimationActive())
+            m_interactionEngine->interruptScrollAnimation();
+        break;
+    case QEvent::TouchUpdate:
+        // The scale animation can only be interrupted by a pinch gesture, which will then take over.
+        if (m_interactionEngine->scaleAnimationActive() && m_pinchGestureRecognizer.isRecognized())
+            m_interactionEngine->interruptScaleAnimation();
+        break;
+    default:
+        break;
+    }
+
+    // If the scale animation is active we don't pass the event to the recognizers. In the future
+    // we would want to queue the event here and repost then when the animation ends.
+    if (m_interactionEngine->scaleAnimationActive())
+        return;
+
+    // Convert the event timestamp from second to millisecond.
+    qint64 eventTimestampMillis = static_cast<qint64>(event.timestamp() * 1000);
+    m_panGestureRecognizer.recognize(ev, eventTimestampMillis);
+    m_pinchGestureRecognizer.recognize(ev);
 }
 #endif
 

Modified: trunk/Source/WebKit2/UIProcess/qt/QtTouchWebPageProxy.h (99424 => 99425)


--- trunk/Source/WebKit2/UIProcess/qt/QtTouchWebPageProxy.h	2011-11-07 15:58:00 UTC (rev 99424)
+++ trunk/Source/WebKit2/UIProcess/qt/QtTouchWebPageProxy.h	2011-11-07 16:24:50 UTC (rev 99425)
@@ -61,6 +61,7 @@
 
     void touchEvent(QTouchEvent*);
 
+    QtViewportInteractionEngine* m_interactionEngine;
     QtPanGestureRecognizer m_panGestureRecognizer;
     QtPinchGestureRecognizer m_pinchGestureRecognizer;
 };

Modified: trunk/Source/WebKit2/UIProcess/qt/QtViewportInteractionEngine.cpp (99424 => 99425)


--- trunk/Source/WebKit2/UIProcess/qt/QtViewportInteractionEngine.cpp	2011-11-07 15:58:00 UTC (rev 99424)
+++ trunk/Source/WebKit2/UIProcess/qt/QtViewportInteractionEngine.cpp	2011-11-07 16:24:50 UTC (rev 99425)
@@ -204,7 +204,7 @@
 void QtViewportInteractionEngine::pagePositionRequest(const QPoint& pagePosition)
 {
     // FIXME: Assert when we are suspending properly.
-    if (panAnimationActive() || pinchAnimationActive() || m_pinchViewportUpdateDeferrer)
+    if (scrollAnimationActive() || scaleAnimationActive() || pinchGestureActive())
         return; // Ignore.
 
     qreal endItemScale = m_content->scale(); // Stay at same scale.
@@ -230,7 +230,7 @@
 
 void QtViewportInteractionEngine::ensureContentWithinViewportBoundary()
 {
-    if (panAnimationActive() || pinchAnimationActive())
+    if (scrollAnimationActive() || scaleAnimationActive())
         return;
 
     qreal currentCSSScale = cssScaleFromItem(m_content->scale());
@@ -302,13 +302,25 @@
     ensureContentWithinViewportBoundary();
 }
 
-bool QtViewportInteractionEngine::panAnimationActive() const
+bool QtViewportInteractionEngine::scrollAnimationActive() const
 {
     QScroller* scroller = const_cast<QtViewportInteractionEngine*>(this)->scroller();
+    return scroller->state() == QScroller::Scrolling;
+}
 
-    return scroller->state() != QScroller::Inactive;
+void QtViewportInteractionEngine::interruptScrollAnimation()
+{
+    // Stopping the scroller immediately stops kinetic scrolling and if the view is out of bounds it
+    // is moved inside valid bounds immediately as well. This is the behavior that we want.
+    scroller()->stop();
 }
 
+bool QtViewportInteractionEngine::panGestureActive() const
+{
+    QScroller* scroller = const_cast<QtViewportInteractionEngine*>(this)->scroller();
+    return scroller->state() == QScroller::Pressed || scroller->state() == QScroller::Dragging;
+}
+
 void QtViewportInteractionEngine::panGestureStarted(const QPointF& touchPoint, qint64 eventTimestampMillis)
 {
     // FIXME: suspend the Web engine (stop animated GIF, etc).
@@ -335,11 +347,22 @@
     scroller()->handleInput(QScroller::InputRelease, m_viewport->mapFromItem(m_content, touchPoint), eventTimestampMillis);
 }
 
-bool QtViewportInteractionEngine::pinchAnimationActive() const
+bool QtViewportInteractionEngine::scaleAnimationActive() const
 {
     return m_scaleAnimation->state() == QAbstractAnimation::Running;
 }
 
+void QtViewportInteractionEngine::interruptScaleAnimation()
+{
+    // This interrupts the scale animation exactly where it is, even if it is out of bounds.
+    m_scaleAnimation->stop();
+}
+
+bool QtViewportInteractionEngine::pinchGestureActive() const
+{
+    return !!m_pinchViewportUpdateDeferrer;
+}
+
 void QtViewportInteractionEngine::pinchGestureStarted(const QPointF& pinchCenterInContentCoordinates)
 {
     if (!m_constraints.isUserScalable)

Modified: trunk/Source/WebKit2/UIProcess/qt/QtViewportInteractionEngine.h (99424 => 99425)


--- trunk/Source/WebKit2/UIProcess/qt/QtViewportInteractionEngine.h	2011-11-07 15:58:00 UTC (rev 99424)
+++ trunk/Source/WebKit2/UIProcess/qt/QtViewportInteractionEngine.h	2011-11-07 16:24:50 UTC (rev 99425)
@@ -68,13 +68,19 @@
 
     void pagePositionRequest(const QPoint& pos);
 
-    bool panAnimationActive() const;
+    bool scrollAnimationActive() const;
+    void interruptScrollAnimation();
+
+    bool panGestureActive() const;
     void panGestureStarted(const QPointF& touchPoint, qint64 eventTimestampMillis);
     void panGestureRequestUpdate(const QPointF& touchPoint, qint64 eventTimestampMillis);
     void panGestureCancelled();
     void panGestureEnded(const QPointF& touchPoint, qint64 eventTimestampMillis);
 
-    bool pinchAnimationActive() const;
+    bool scaleAnimationActive() const;
+    void interruptScaleAnimation();
+
+    bool pinchGestureActive() const;
     void pinchGestureStarted(const QPointF& pinchCenterInContentCoordinates);
     void pinchGestureRequestUpdate(const QPointF& pinchCenterInContentCoordinates, qreal totalScaleFactor);
     void pinchGestureEnded();
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to