- Revision
- 99065
- Author
- [email protected]
- Date
- 2011-11-02 09:14:20 -0700 (Wed, 02 Nov 2011)
Log Message
[Qt] Handle interruption of page interaction better
https://bugs.webkit.org/show_bug.cgi?id=71366
Reviewed by Simon Hausmann.
Touching the screen when a kinetic scrolling animation is running or
it is bouncing back because it was out of bounds, the animation is
immediately stopped and the content is immediately put into valid
bounds.
Touching the screen when the contents is bouncing back from a pinch
zoom which was out of bounds, we do not stop the animation, but
instead ignored the touch events while the animation lasts.
In the future we want to queue the events instead.
This also fixes some issues which was present before: As the bounce
back animation from pinch zoom centers the content using the contents
point which was in the center of the viewport, this animation could
not be used when stopping a pan animation, as it wouldn't position the
content at the place it was when the pan animation was interrupted.
* UIProcess/qt/QtPanGestureRecognizer.cpp:
(WebKit::QtPanGestureRecognizer::recognize):
* UIProcess/qt/QtPinchGestureRecognizer.cpp:
(WebKit::QtPinchGestureRecognizer::recognize):
* UIProcess/qt/QtViewportInteractionEngine.cpp:
(WebKit::QtViewportInteractionEngine::animateContentIntoBoundariesIfNeeded):
(WebKit::QtViewportInteractionEngine::reset):
(WebKit::QtViewportInteractionEngine::setConstraints):
(WebKit::QtViewportInteractionEngine::panAnimationActive):
(WebKit::QtViewportInteractionEngine::panGestureStarted):
(WebKit::QtViewportInteractionEngine::panGestureCancelled):
(WebKit::QtViewportInteractionEngine::pinchAnimationActive):
* UIProcess/qt/QtViewportInteractionEngine.h:
Modified Paths
Diff
Modified: trunk/Source/WebKit2/ChangeLog (99064 => 99065)
--- trunk/Source/WebKit2/ChangeLog 2011-11-02 16:11:11 UTC (rev 99064)
+++ trunk/Source/WebKit2/ChangeLog 2011-11-02 16:14:20 UTC (rev 99065)
@@ -1,3 +1,41 @@
+2011-11-02 Kenneth Rohde Christiansen <[email protected]>
+
+ [Qt] Handle interruption of page interaction better
+ https://bugs.webkit.org/show_bug.cgi?id=71366
+
+ Reviewed by Simon Hausmann.
+
+ Touching the screen when a kinetic scrolling animation is running or
+ it is bouncing back because it was out of bounds, the animation is
+ immediately stopped and the content is immediately put into valid
+ bounds.
+
+ Touching the screen when the contents is bouncing back from a pinch
+ zoom which was out of bounds, we do not stop the animation, but
+ instead ignored the touch events while the animation lasts.
+
+ In the future we want to queue the events instead.
+
+ This also fixes some issues which was present before: As the bounce
+ back animation from pinch zoom centers the content using the contents
+ point which was in the center of the viewport, this animation could
+ not be used when stopping a pan animation, as it wouldn't position the
+ content at the place it was when the pan animation was interrupted.
+
+ * UIProcess/qt/QtPanGestureRecognizer.cpp:
+ (WebKit::QtPanGestureRecognizer::recognize):
+ * UIProcess/qt/QtPinchGestureRecognizer.cpp:
+ (WebKit::QtPinchGestureRecognizer::recognize):
+ * UIProcess/qt/QtViewportInteractionEngine.cpp:
+ (WebKit::QtViewportInteractionEngine::animateContentIntoBoundariesIfNeeded):
+ (WebKit::QtViewportInteractionEngine::reset):
+ (WebKit::QtViewportInteractionEngine::setConstraints):
+ (WebKit::QtViewportInteractionEngine::panAnimationActive):
+ (WebKit::QtViewportInteractionEngine::panGestureStarted):
+ (WebKit::QtViewportInteractionEngine::panGestureCancelled):
+ (WebKit::QtViewportInteractionEngine::pinchAnimationActive):
+ * UIProcess/qt/QtViewportInteractionEngine.h:
+
2011-11-02 Zalan Bujtas <[email protected]>
[Qt][WK2] Move content to resize (setResizesToContentsUsingLayoutSize) from UI process to Web process
Modified: trunk/Source/WebKit2/UIProcess/qt/QtPanGestureRecognizer.cpp (99064 => 99065)
--- trunk/Source/WebKit2/UIProcess/qt/QtPanGestureRecognizer.cpp 2011-11-02 16:11:11 UTC (rev 99064)
+++ trunk/Source/WebKit2/UIProcess/qt/QtPanGestureRecognizer.cpp 2011-11-02 16:14:20 UTC (rev 99065)
@@ -39,7 +39,8 @@
bool QtPanGestureRecognizer::recognize(const QTouchEvent* event, qint64 eventTimestampMillis)
{
- // Pan gesture always starts on TouchBegin unless the engine is suspended.
+ // Pan gesture always starts on TouchBegin unless the engine is suspended, or
+ // we ignored the event.
if (m_state == NoGesture && event->type() != QEvent::TouchBegin)
return false;
@@ -56,9 +57,17 @@
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();
- m_viewportInteractionEngine->stopAnimations();
return false;
case QEvent::TouchUpdate: {
ASSERT(m_state != NoGesture);
Modified: trunk/Source/WebKit2/UIProcess/qt/QtPinchGestureRecognizer.cpp (99064 => 99065)
--- trunk/Source/WebKit2/UIProcess/qt/QtPinchGestureRecognizer.cpp 2011-11-02 16:11:11 UTC (rev 99064)
+++ trunk/Source/WebKit2/UIProcess/qt/QtPinchGestureRecognizer.cpp 2011-11-02 16:14:20 UTC (rev 99065)
@@ -65,6 +65,15 @@
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/QtViewportInteractionEngine.cpp (99064 => 99065)
--- trunk/Source/WebKit2/UIProcess/qt/QtViewportInteractionEngine.cpp 2011-11-02 16:11:11 UTC (rev 99064)
+++ trunk/Source/WebKit2/UIProcess/qt/QtViewportInteractionEngine.cpp 2011-11-02 16:14:20 UTC (rev 99065)
@@ -195,17 +195,6 @@
return QObject::event(event);
}
-void QtViewportInteractionEngine::stopAnimations()
-{
- m_scaleAnimation->stop();
- scroller()->stop();
-
- // If the animations were stopped we need to scale and reposition the content into valid boundaries immediately.
- m_userInteractionFlags |= UserHasStoppedAnimations;
- animateContentIntoBoundariesIfNeeded();
- m_userInteractionFlags &= ~UserHasStoppedAnimations;
-}
-
QRectF QtViewportInteractionEngine::computePosRangeForItemScale(qreal itemScale) const
{
const QSizeF contentItemSize = m_content->boundingRect().size() * itemScale;
@@ -219,11 +208,11 @@
void QtViewportInteractionEngine::animateContentIntoBoundariesIfNeeded()
{
- m_scaleAnimation->stop();
+ if (panAnimationActive() || pinchAnimationActive())
+ return;
qreal currentCSSScale = cssScaleFromItem(m_content->scale());
bool userHasScaledContent = m_userInteractionFlags & UserHasScaledContent;
- bool userHasStoppedAnimations = m_userInteractionFlags & UserHasStoppedAnimations;
if (!userHasScaledContent)
currentCSSScale = m_constraints.initialScale;
@@ -242,13 +231,13 @@
endPosition.setX(qBound(minValue.x(), endPosition.x(), maxValue.x()));
endPosition.setY(qBound(minValue.y(), endPosition.y(), maxValue.y()));
- QRectF startVisibleContentRect(m_viewport->mapRectToItem(m_content, viewportRect));
+ QRectF startVisibleContentRect = m_content->mapRectFromItem(m_viewport, viewportRect);
QRectF endVisibleContentRect(endPosition, viewportRect.size() / endItemScale);
if (endVisibleContentRect == startVisibleContentRect)
return;
- if (userHasScaledContent && !userHasStoppedAnimations) {
+ if (userHasScaledContent) {
m_scaleAnimation->setDuration(kScaleAnimationDurationMillis);
m_scaleAnimation->setEasingCurve(QEasingCurve::OutCubic);
m_scaleAnimation->setStartValue(startVisibleContentRect);
@@ -263,7 +252,8 @@
ViewportUpdateGuard guard(this);
m_userInteractionFlags = UserHasNotInteractedWithContent;
- stopAnimations();
+ scroller()->stop();
+ m_scaleAnimation->stop();
QScrollerProperties properties = scroller()->scrollerProperties();
@@ -290,11 +280,21 @@
ViewportUpdateGuard guard(this);
m_constraints = constraints;
+
animateContentIntoBoundariesIfNeeded();
}
+bool QtViewportInteractionEngine::panAnimationActive() const
+{
+ QScroller* scroller = const_cast<QtViewportInteractionEngine*>(this)->scroller();
+
+ return scroller->state() != QScroller::Inactive;
+}
+
void QtViewportInteractionEngine::panGestureStarted(const QPointF& touchPoint, qint64 eventTimestampMillis)
{
+ Q_ASSERT(!panGestureActive);
+
// FIXME: suspend the Web engine (stop animated GIF, etc).
m_userInteractionFlags |= UserHasMovedContent;
scroller()->handleInput(QScroller::InputPress, m_viewport->mapFromItem(m_content, touchPoint), eventTimestampMillis);
@@ -308,8 +308,9 @@
void QtViewportInteractionEngine::panGestureCancelled()
{
- ViewportUpdateGuard guard(this);
- stopAnimations();
+ // 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();
}
void QtViewportInteractionEngine::panGestureEnded(const QPointF& touchPoint, qint64 eventTimestampMillis)
@@ -318,6 +319,11 @@
scroller()->handleInput(QScroller::InputRelease, m_viewport->mapFromItem(m_content, touchPoint), eventTimestampMillis);
}
+bool QtViewportInteractionEngine::pinchAnimationActive() const
+{
+ return m_scaleAnimation->state() == QAbstractAnimation::Running;
+}
+
void QtViewportInteractionEngine::pinchGestureStarted(const QPointF& pinchCenterInContentCoordinates)
{
if (!m_constraints.isUserScalable)
Modified: trunk/Source/WebKit2/UIProcess/qt/QtViewportInteractionEngine.h (99064 => 99065)
--- trunk/Source/WebKit2/UIProcess/qt/QtViewportInteractionEngine.h 2011-11-02 16:11:11 UTC (rev 99064)
+++ trunk/Source/WebKit2/UIProcess/qt/QtViewportInteractionEngine.h 2011-11-02 16:14:20 UTC (rev 99065)
@@ -66,15 +66,16 @@
void reset();
void setConstraints(const Constraints&);
+ bool panAnimationActive() 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;
void pinchGestureStarted(const QPointF& pinchCenterInContentCoordinates);
void pinchGestureRequestUpdate(const QPointF& pinchCenterInContentCoordinates, qreal totalScaleFactor);
void pinchGestureEnded();
- void stopAnimations();
Q_SIGNALS:
void viewportUpdateRequested();
@@ -112,7 +113,6 @@
UserHasNotInteractedWithContent = 0,
UserHasMovedContent = 1,
UserHasScaledContent = 2,
- UserHasStoppedAnimations = 4
};
Q_DECLARE_FLAGS(UserInteractionFlags, UserInteractionFlag);
UserInteractionFlags m_userInteractionFlags;