Changeset 99065 in webkit


Ignore:
Timestamp:
Nov 2, 2011, 9:14:20 AM (14 years ago)
Author:
kenneth@webkit.org
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:
Location:
trunk/Source/WebKit2
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r99058 r99065  
     12011-11-02  Kenneth Rohde Christiansen  <kenneth@webkit.org>
     2
     3        [Qt] Handle interruption of page interaction better
     4        https://bugs.webkit.org/show_bug.cgi?id=71366
     5
     6        Reviewed by Simon Hausmann.
     7
     8        Touching the screen when a kinetic scrolling animation is running or
     9        it is bouncing back because it was out of bounds, the animation is
     10        immediately stopped and the content is immediately put into valid
     11        bounds.
     12
     13        Touching the screen when the contents is bouncing back from a pinch
     14        zoom which was out of bounds, we do not stop the animation, but
     15        instead ignored the touch events while the animation lasts.
     16
     17        In the future we want to queue the events instead.
     18
     19        This also fixes some issues which was present before: As the bounce
     20        back animation from pinch zoom centers the content using the contents
     21        point which was in the center of the viewport, this animation could
     22        not be used when stopping a pan animation, as it wouldn't position the
     23        content at the place it was when the pan animation was interrupted.
     24
     25        * UIProcess/qt/QtPanGestureRecognizer.cpp:
     26        (WebKit::QtPanGestureRecognizer::recognize):
     27        * UIProcess/qt/QtPinchGestureRecognizer.cpp:
     28        (WebKit::QtPinchGestureRecognizer::recognize):
     29        * UIProcess/qt/QtViewportInteractionEngine.cpp:
     30        (WebKit::QtViewportInteractionEngine::animateContentIntoBoundariesIfNeeded):
     31        (WebKit::QtViewportInteractionEngine::reset):
     32        (WebKit::QtViewportInteractionEngine::setConstraints):
     33        (WebKit::QtViewportInteractionEngine::panAnimationActive):
     34        (WebKit::QtViewportInteractionEngine::panGestureStarted):
     35        (WebKit::QtViewportInteractionEngine::panGestureCancelled):
     36        (WebKit::QtViewportInteractionEngine::pinchAnimationActive):
     37        * UIProcess/qt/QtViewportInteractionEngine.h:
     38
    1392011-11-02  Zalan Bujtas  <zbujtas@gmail.com>
    240
  • trunk/Source/WebKit2/UIProcess/qt/QtPanGestureRecognizer.cpp

    r98460 r99065  
    4040bool QtPanGestureRecognizer::recognize(const QTouchEvent* event, qint64 eventTimestampMillis)
    4141{
    42     // Pan gesture always starts on TouchBegin unless the engine is suspended.
     42    // Pan gesture always starts on TouchBegin unless the engine is suspended, or
     43    // we ignored the event.
    4344    if (m_state == NoGesture && event->type() != QEvent::TouchBegin)
    4445        return false;
     
    5758    case QEvent::TouchBegin:
    5859        ASSERT(m_state == NoGesture);
     60        // The pan gesture might still be animating kinetic scrolling/bounce back effect.
     61        if (m_viewportInteractionEngine->panAnimationActive())
     62            m_viewportInteractionEngine->panGestureCancelled();
     63
     64        // We do not stop bounce back effects for pinch zoom, but instead ignore the touch event.
     65        // FIXME: We should queue the events instead and repost then when done with the animation.
     66        if (m_viewportInteractionEngine->pinchAnimationActive())
     67            return false;
     68
    5969        m_state = GestureRecognitionStarted;
    6070        m_firstPosition = touchPoint.screenPos();
    61         m_viewportInteractionEngine->stopAnimations();
    6271        return false;
    6372    case QEvent::TouchUpdate: {
  • trunk/Source/WebKit2/UIProcess/qt/QtPinchGestureRecognizer.cpp

    r98474 r99065  
    6565        return false;
    6666    }
     67
     68    // The pan gesture might still be animating kinetic scrolling/bounce back effect.
     69    if (m_viewportInteractionEngine->panAnimationActive())
     70        m_viewportInteractionEngine->panGestureCancelled();
     71
     72    // We do not stop bounce back effects for pinch zoom, but instead ignore the touch event.
     73    // FIXME: We should queue the events instead and repost then when done with the animation.
     74    if (m_viewportInteractionEngine->pinchAnimationActive())
     75        return false;
    6776
    6877    switch (event->type()) {
  • trunk/Source/WebKit2/UIProcess/qt/QtViewportInteractionEngine.cpp

    r98965 r99065  
    196196}
    197197
    198 void QtViewportInteractionEngine::stopAnimations()
    199 {
    200     m_scaleAnimation->stop();
    201     scroller()->stop();
    202 
    203     // If the animations were stopped we need to scale and reposition the content into valid boundaries immediately.
    204     m_userInteractionFlags |= UserHasStoppedAnimations;
    205     animateContentIntoBoundariesIfNeeded();
    206     m_userInteractionFlags &= ~UserHasStoppedAnimations;
    207 }
    208 
    209198QRectF QtViewportInteractionEngine::computePosRangeForItemScale(qreal itemScale) const
    210199{
     
    220209void QtViewportInteractionEngine::animateContentIntoBoundariesIfNeeded()
    221210{
    222     m_scaleAnimation->stop();
     211    if (panAnimationActive() || pinchAnimationActive())
     212        return;
    223213
    224214    qreal currentCSSScale = cssScaleFromItem(m_content->scale());
    225215    bool userHasScaledContent = m_userInteractionFlags & UserHasScaledContent;
    226     bool userHasStoppedAnimations = m_userInteractionFlags & UserHasStoppedAnimations;
    227216
    228217    if (!userHasScaledContent)
     
    243232    endPosition.setY(qBound(minValue.y(), endPosition.y(), maxValue.y()));
    244233
    245     QRectF startVisibleContentRect(m_viewport->mapRectToItem(m_content, viewportRect));
     234    QRectF startVisibleContentRect = m_content->mapRectFromItem(m_viewport, viewportRect);
    246235    QRectF endVisibleContentRect(endPosition, viewportRect.size() / endItemScale);
    247236
     
    249238        return;
    250239
    251     if (userHasScaledContent && !userHasStoppedAnimations) {
     240    if (userHasScaledContent) {
    252241        m_scaleAnimation->setDuration(kScaleAnimationDurationMillis);
    253242        m_scaleAnimation->setEasingCurve(QEasingCurve::OutCubic);
     
    264253    m_userInteractionFlags = UserHasNotInteractedWithContent;
    265254
    266     stopAnimations();
     255    scroller()->stop();
     256    m_scaleAnimation->stop();
    267257
    268258    QScrollerProperties properties = scroller()->scrollerProperties();
     
    291281    ViewportUpdateGuard guard(this);
    292282    m_constraints = constraints;
     283
    293284    animateContentIntoBoundariesIfNeeded();
    294285}
    295286
     287bool QtViewportInteractionEngine::panAnimationActive() const
     288{
     289    QScroller* scroller = const_cast<QtViewportInteractionEngine*>(this)->scroller();
     290
     291    return scroller->state() != QScroller::Inactive;
     292}
     293
    296294void QtViewportInteractionEngine::panGestureStarted(const QPointF& touchPoint, qint64 eventTimestampMillis)
    297295{
     296    Q_ASSERT(!panGestureActive);
     297
    298298    // FIXME: suspend the Web engine (stop animated GIF, etc).
    299299    m_userInteractionFlags |= UserHasMovedContent;
     
    309309void QtViewportInteractionEngine::panGestureCancelled()
    310310{
    311     ViewportUpdateGuard guard(this);
    312     stopAnimations();
     311    // Stopping the scroller immediately stops kinetic scrolling and if the view is out of bounds it
     312    // is moved inside valid bounds immediately as well. This is the behavior that we want.
     313    scroller()->stop();
    313314}
    314315
     
    317318    ViewportUpdateGuard guard(this);
    318319    scroller()->handleInput(QScroller::InputRelease, m_viewport->mapFromItem(m_content, touchPoint), eventTimestampMillis);
     320}
     321
     322bool QtViewportInteractionEngine::pinchAnimationActive() const
     323{
     324    return m_scaleAnimation->state() == QAbstractAnimation::Running;
    319325}
    320326
  • trunk/Source/WebKit2/UIProcess/qt/QtViewportInteractionEngine.h

    r98965 r99065  
    6767    void setConstraints(const Constraints&);
    6868
     69    bool panAnimationActive() const;
    6970    void panGestureStarted(const QPointF& touchPoint, qint64 eventTimestampMillis);
    7071    void panGestureRequestUpdate(const QPointF& touchPoint, qint64 eventTimestampMillis);
     
    7273    void panGestureEnded(const QPointF& touchPoint, qint64 eventTimestampMillis);
    7374
     75    bool pinchAnimationActive() const;
    7476    void pinchGestureStarted(const QPointF& pinchCenterInContentCoordinates);
    7577    void pinchGestureRequestUpdate(const QPointF& pinchCenterInContentCoordinates, qreal totalScaleFactor);
    7678    void pinchGestureEnded();
    77     void stopAnimations();
    7879
    7980Q_SIGNALS:
     
    113114        UserHasMovedContent = 1,
    114115        UserHasScaledContent = 2,
    115         UserHasStoppedAnimations = 4
    116116    };
    117117    Q_DECLARE_FLAGS(UserInteractionFlags, UserInteractionFlag);
Note: See TracChangeset for help on using the changeset viewer.