⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 277350 in webkit


Ignore:
Timestamp:
May 11, 2021, 7:45:51 PM (5 years ago)
Author:
Simon Fraser
Message:

Display-frequency animations in ScrollController should be externally driven
https://bugs.webkit.org/show_bug.cgi?id=225663

Reviewed by Tim Horton.

Display-frequency animations (i.e. those driven by 1/60_s timers) should ultimately
be driven by Page::updateRendering(), since their output should be synchronized with
rendering updates.

As the first step, remove m_snapRubberbandTimer and m_scrollSnapTimer from
ScrollController and have it expose functions that tell its client to start and stop
the animation, and a per-frame callback. Give ScrollAnimator a 1/60_s timer
to drive this, temporarily.

  • page/scrolling/mac/ScrollingTreeScrollingNodeDelegateMac.h:
  • page/scrolling/mac/ScrollingTreeScrollingNodeDelegateMac.mm:

(WebCore::ScrollingTreeScrollingNodeDelegateMac::startAnimationCallback):
(WebCore::ScrollingTreeScrollingNodeDelegateMac::stopAnimationCallback):
(WebCore::ScrollingTreeScrollingNodeDelegateMac::scrollControllerAnimationTimerFired):

  • platform/ScrollAnimator.cpp:

(WebCore::ScrollAnimator::ScrollAnimator):
(WebCore::ScrollAnimator::startAnimationCallback):
(WebCore::ScrollAnimator::stopAnimationCallback):
(WebCore::ScrollAnimator::scrollControllerAnimationTimerFired):

  • platform/ScrollAnimator.h:
  • platform/ScrollController.cpp:

(WebCore::ScrollController::animationCallback):
(WebCore::ScrollController::startOrStopAnimationCallbacks):
(WebCore::ScrollController::setIsAnimatingRubberBand):
(WebCore::ScrollController::setIsAnimatingScrollSnap):
(WebCore::ScrollController::updateScrollSnapAnimatingState):
(WebCore::ScrollController::updateRubberBandAnimatingState):

  • platform/ScrollController.h:
  • platform/ScrollSnapAnimatorState.cpp:

(WebCore::ScrollSnapAnimatorState::currentAnimatedScrollOffset const):

  • platform/ScrollSnapAnimatorState.h:
  • platform/mac/ScrollController.mm:

(WebCore::ScrollController::stopAllTimers):
(WebCore::ScrollController::handleWheelEvent):
(WebCore::ScrollController::updateRubberBandAnimatingState):
(WebCore::ScrollController::isScrollSnapInProgress const):
(WebCore::ScrollController::stopRubberbanding):
(WebCore::ScrollController::startRubberbandAnimation):
(WebCore::ScrollController::stopSnapRubberbandAnimation):
(WebCore::ScrollController::snapRubberBand):
(WebCore::ScrollController::isRubberBandInProgressInternal const):
(WebCore::ScrollController::scheduleStatelessScrollSnap):
(WebCore::ScrollController::statelessSnapTransitionTimerFired):
(WebCore::ScrollController::processWheelEventForScrollSnap):
(WebCore::ScrollController::startScrollSnapAnimation):
(WebCore::ScrollController::stopScrollSnapAnimation):
(WebCore::ScrollController::updateScrollSnapAnimatingState):
(WebCore::ScrollController::snapRubberBandTimerFired): Deleted.
(WebCore::ScrollController::startSnapRubberbandTimer): Deleted.
(WebCore::ScrollController::stopSnapRubberbandTimer): Deleted.
(WebCore::ScrollController::startScrollSnapTimer): Deleted.
(WebCore::ScrollController::stopScrollSnapTimer): Deleted.
(WebCore::ScrollController::scrollSnapTimerFired): Deleted.

Location:
trunk/Source/WebCore
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r277347 r277350  
     12021-05-11  Simon Fraser  <simon.fraser@apple.com>
     2
     3        Display-frequency animations in ScrollController should be externally driven
     4        https://bugs.webkit.org/show_bug.cgi?id=225663
     5
     6        Reviewed by Tim Horton.
     7
     8        Display-frequency animations (i.e. those driven by 1/60_s timers) should ultimately
     9        be driven by Page::updateRendering(), since their output should be synchronized with
     10        rendering updates.
     11
     12        As the first step, remove m_snapRubberbandTimer and m_scrollSnapTimer from
     13        ScrollController and have it expose functions that tell its client to start and stop
     14        the animation, and a per-frame callback. Give ScrollAnimator a 1/60_s timer
     15        to drive this, temporarily.
     16
     17        * page/scrolling/mac/ScrollingTreeScrollingNodeDelegateMac.h:
     18        * page/scrolling/mac/ScrollingTreeScrollingNodeDelegateMac.mm:
     19        (WebCore::ScrollingTreeScrollingNodeDelegateMac::startAnimationCallback):
     20        (WebCore::ScrollingTreeScrollingNodeDelegateMac::stopAnimationCallback):
     21        (WebCore::ScrollingTreeScrollingNodeDelegateMac::scrollControllerAnimationTimerFired):
     22        * platform/ScrollAnimator.cpp:
     23        (WebCore::ScrollAnimator::ScrollAnimator):
     24        (WebCore::ScrollAnimator::startAnimationCallback):
     25        (WebCore::ScrollAnimator::stopAnimationCallback):
     26        (WebCore::ScrollAnimator::scrollControllerAnimationTimerFired):
     27        * platform/ScrollAnimator.h:
     28        * platform/ScrollController.cpp:
     29        (WebCore::ScrollController::animationCallback):
     30        (WebCore::ScrollController::startOrStopAnimationCallbacks):
     31        (WebCore::ScrollController::setIsAnimatingRubberBand):
     32        (WebCore::ScrollController::setIsAnimatingScrollSnap):
     33        (WebCore::ScrollController::updateScrollSnapAnimatingState):
     34        (WebCore::ScrollController::updateRubberBandAnimatingState):
     35        * platform/ScrollController.h:
     36        * platform/ScrollSnapAnimatorState.cpp:
     37        (WebCore::ScrollSnapAnimatorState::currentAnimatedScrollOffset const):
     38        * platform/ScrollSnapAnimatorState.h:
     39        * platform/mac/ScrollController.mm:
     40        (WebCore::ScrollController::stopAllTimers):
     41        (WebCore::ScrollController::handleWheelEvent):
     42        (WebCore::ScrollController::updateRubberBandAnimatingState):
     43        (WebCore::ScrollController::isScrollSnapInProgress const):
     44        (WebCore::ScrollController::stopRubberbanding):
     45        (WebCore::ScrollController::startRubberbandAnimation):
     46        (WebCore::ScrollController::stopSnapRubberbandAnimation):
     47        (WebCore::ScrollController::snapRubberBand):
     48        (WebCore::ScrollController::isRubberBandInProgressInternal const):
     49        (WebCore::ScrollController::scheduleStatelessScrollSnap):
     50        (WebCore::ScrollController::statelessSnapTransitionTimerFired):
     51        (WebCore::ScrollController::processWheelEventForScrollSnap):
     52        (WebCore::ScrollController::startScrollSnapAnimation):
     53        (WebCore::ScrollController::stopScrollSnapAnimation):
     54        (WebCore::ScrollController::updateScrollSnapAnimatingState):
     55        (WebCore::ScrollController::snapRubberBandTimerFired): Deleted.
     56        (WebCore::ScrollController::startSnapRubberbandTimer): Deleted.
     57        (WebCore::ScrollController::stopSnapRubberbandTimer): Deleted.
     58        (WebCore::ScrollController::startScrollSnapTimer): Deleted.
     59        (WebCore::ScrollController::stopScrollSnapTimer): Deleted.
     60        (WebCore::ScrollController::scrollSnapTimerFired): Deleted.
     61
    1622021-05-11  Geoffrey Garen  <ggaren@apple.com>
    263
  • trunk/Source/WebCore/page/scrolling/mac/ScrollingTreeScrollingNodeDelegateMac.h

    r271937 r277350  
    3131
    3232#include "ScrollController.h"
     33#include <wtf/RunLoop.h>
    3334
    3435OBJC_CLASS NSScrollerImp;
     
    7475    // ScrollControllerClient.
    7576    std::unique_ptr<ScrollControllerTimer> createTimer(Function<void()>&&) final;
     77    void startAnimationCallback(ScrollController&) final;
     78    void stopAnimationCallback(ScrollController&) final;
     79
    7680    bool allowsHorizontalStretching(const PlatformWheelEvent&) const final;
    7781    bool allowsVerticalStretching(const PlatformWheelEvent&) const final;
     
    8993
    9094    bool scrollPositionIsNotRubberbandingEdge(const FloatPoint&) const;
     95    void scrollControllerAnimationTimerFired();
    9196
    9297#if ENABLE(CSS_SCROLL_SNAP)
     
    103108
    104109    ScrollController m_scrollController;
    105    
    106     bool m_inMomentumPhase { false };
    107110
    108111    RetainPtr<NSScrollerImp> m_verticalScrollerImp;
    109112    RetainPtr<NSScrollerImp> m_horizontalScrollerImp;
     113
     114    std::unique_ptr<RunLoop::Timer<ScrollingTreeScrollingNodeDelegateMac>> m_scrollControllerAnimationTimer;
     115
     116    bool m_inMomentumPhase { false };
    110117};
    111118
  • trunk/Source/WebCore/page/scrolling/mac/ScrollingTreeScrollingNodeDelegateMac.mm

    r277083 r277350  
    226226}
    227227
     228void ScrollingTreeScrollingNodeDelegateMac::startAnimationCallback(ScrollController&)
     229{
     230    if (!m_scrollControllerAnimationTimer)
     231        m_scrollControllerAnimationTimer = WTF::makeUnique<RunLoop::Timer<ScrollingTreeScrollingNodeDelegateMac>>(RunLoop::current(), this, &ScrollingTreeScrollingNodeDelegateMac::scrollControllerAnimationTimerFired);
     232
     233    if (m_scrollControllerAnimationTimer->isActive())
     234        return;
     235
     236    m_scrollControllerAnimationTimer->startRepeating(1_s / 60.);
     237}
     238
     239void ScrollingTreeScrollingNodeDelegateMac::stopAnimationCallback(ScrollController&)
     240{
     241    if (m_scrollControllerAnimationTimer)
     242        m_scrollControllerAnimationTimer->stop();
     243}
     244
     245void ScrollingTreeScrollingNodeDelegateMac::scrollControllerAnimationTimerFired()
     246{
     247    m_scrollController.animationCallback(MonotonicTime::now());
     248}
     249
    228250bool ScrollingTreeScrollingNodeDelegateMac::allowsHorizontalStretching(const PlatformWheelEvent& wheelEvent) const
    229251{
  • trunk/Source/WebCore/platform/ScrollAnimator.cpp

    r276353 r277350  
    5757#if ENABLE(CSS_SCROLL_SNAP) || ENABLE(RUBBER_BANDING)
    5858    , m_scrollController(*this)
     59    , m_scrollControllerAnimationTimer(*this, &ScrollAnimator::scrollControllerAnimationTimerFired)
    5960#endif
    6061    , m_scrollAnimation(makeUnique<ScrollAnimationSmooth>(
     
    334335    });
    335336}
     337
     338void ScrollAnimator::startAnimationCallback(ScrollController&)
     339{
     340    if (m_scrollControllerAnimationTimer.isActive())
     341        return;
     342       
     343    m_scrollControllerAnimationTimer.startRepeating(1_s / 60.);
     344}
     345
     346void ScrollAnimator::stopAnimationCallback(ScrollController&)
     347{
     348    m_scrollControllerAnimationTimer.stop();
     349}
     350
     351void ScrollAnimator::scrollControllerAnimationTimerFired()
     352{
     353    m_scrollController.animationCallback(MonotonicTime::now());
     354}
    336355#endif
    337356
  • trunk/Source/WebCore/platform/ScrollAnimator.h

    r276353 r277350  
    3535#include "PlatformWheelEvent.h"
    3636#include "ScrollTypes.h"
     37#include "Timer.h"
    3738#include "WheelEventTestMonitor.h"
    3839#include <wtf/FastMalloc.h>
     
    147148#if ENABLE(CSS_SCROLL_SNAP) || ENABLE(RUBBER_BANDING)
    148149    std::unique_ptr<ScrollControllerTimer> createTimer(Function<void()>&&) final;
     150
     151    void startAnimationCallback(ScrollController&) final;
     152    void stopAnimationCallback(ScrollController&) final;
     153
     154    void scrollControllerAnimationTimerFired();
    149155#endif
    150156
     
    181187#if ENABLE(CSS_SCROLL_SNAP) || ENABLE(RUBBER_BANDING)
    182188    ScrollController m_scrollController;
     189    Timer m_scrollControllerAnimationTimer;
    183190#endif
    184191    FloatPoint m_currentPosition;
  • trunk/Source/WebCore/platform/ScrollController.cpp

    r277083 r277350  
    3131#include "PlatformWheelEvent.h"
    3232#include "WheelEventTestMonitor.h"
     33#include <wtf/text/TextStream.h>
    3334
    3435#if ENABLE(CSS_SCROLL_SNAP)
     
    4445    : m_client(client)
    4546{
     47}
     48
     49void ScrollController::animationCallback(MonotonicTime currentTime)
     50{
     51    LOG_WITH_STREAM(Scrolling, stream << "ScrollController " << this << " animationCallback: isAnimatingRubberBand " << m_isAnimatingRubberBand << " isAnimatingScrollSnap " << m_isAnimatingScrollSnap);
     52
     53    updateScrollSnapAnimatingState(currentTime);
     54    updateRubberBandAnimatingState(currentTime);
     55}
     56
     57void ScrollController::startOrStopAnimationCallbacks()
     58{
     59    bool needsCallbacks = m_isAnimatingRubberBand || m_isAnimatingScrollSnap;
     60    if (needsCallbacks == m_isRunningAnimatingCallback)
     61        return;
     62
     63    if (needsCallbacks) {
     64        m_client.startAnimationCallback(*this);
     65        m_isRunningAnimatingCallback = true;
     66        return;
     67    }
     68
     69    m_client.stopAnimationCallback(*this);
     70    m_isRunningAnimatingCallback = false;
     71}
     72
     73void ScrollController::setIsAnimatingRubberBand(bool isAnimatingRubberBand)
     74{
     75    if (isAnimatingRubberBand == m_isAnimatingRubberBand)
     76        return;
     77       
     78    m_isAnimatingRubberBand = isAnimatingRubberBand;
     79    startOrStopAnimationCallbacks();
     80}
     81
     82void ScrollController::setIsAnimatingScrollSnap(bool isAnimatingScrollSnap)
     83{
     84    if (isAnimatingScrollSnap == m_isAnimatingScrollSnap)
     85        return;
     86       
     87    m_isAnimatingScrollSnap = isAnimatingScrollSnap;
     88    startOrStopAnimationCallbacks();
    4689}
    4790
     
    170213}
    171214
     215void ScrollController::updateScrollSnapAnimatingState(MonotonicTime)
     216{
     217
     218}
     219
     220void ScrollController::updateRubberBandAnimatingState(MonotonicTime)
     221{
     222
     223}
     224
    172225#endif // PLATFORM(MAC)
    173226
  • trunk/Source/WebCore/platform/ScrollController.h

    r275354 r277350  
    7171
    7272public:
     73    // Only used for non-animation timers.
    7374    virtual std::unique_ptr<ScrollControllerTimer> createTimer(Function<void()>&&) = 0;
     75
     76    virtual void startAnimationCallback(ScrollController&) = 0;
     77    virtual void stopAnimationCallback(ScrollController&) = 0;
    7478
    7579#if ENABLE(RUBBER_BANDING)
     
    131135    void stopAllTimers();
    132136    void scrollPositionChanged();
     137   
     138    // Should be called periodically by the client. Started by startAnimationCallback(), stopped by stopAnimationCallback().
     139    void animationCallback(MonotonicTime);
    133140
    134141#if ENABLE(CSS_SCROLL_SNAP)
     
    172179#endif
    173180
     181    void updateScrollSnapAnimatingState(MonotonicTime);
     182    void updateRubberBandAnimatingState(MonotonicTime);
     183   
     184    void setIsAnimatingRubberBand(bool);
     185    void setIsAnimatingScrollSnap(bool);
     186
    174187#if PLATFORM(MAC)
    175188#if ENABLE(CSS_SCROLL_SNAP)
    176     void scrollSnapTimerFired();
    177     void startScrollSnapTimer();
    178     void stopScrollSnapTimer();
     189    void startScrollSnapAnimation();
     190    void stopScrollSnapAnimation();
     191
    179192    bool shouldOverrideMomentumScrolling() const;
    180193    void statelessSnapTransitionTimerFired();
     
    185198
    186199#if ENABLE(RUBBER_BANDING)
    187     void startSnapRubberbandTimer();
    188     void stopSnapRubberbandTimer();
     200    void startRubberbandAnimation();
     201    void stopSnapRubberbandAnimation();
     202
    189203    void snapRubberBand();
    190     void snapRubberBandTimerFired();
    191204    bool shouldRubberBandInHorizontalDirection(const PlatformWheelEvent&) const;
    192205    bool shouldRubberBandInDirection(ScrollDirection) const;
     
    197210#endif
    198211
     212    void startOrStopAnimationCallbacks();
     213
    199214    ScrollControllerClient& m_client;
    200215#if ENABLE(CSS_SCROLL_SNAP)
     
    202217    bool m_activeScrollSnapIndexDidChange { false };
    203218#endif
     219
     220    bool m_isRunningAnimatingCallback { false };
     221    bool m_isAnimatingRubberBand { false };
     222    bool m_isAnimatingScrollSnap { false };
    204223
    205224#if PLATFORM(MAC)
     
    217236    FloatSize m_dragEndedScrollingVelocity;
    218237    std::unique_ptr<ScrollControllerTimer> m_statelessSnapTransitionTimer;
    219     std::unique_ptr<ScrollControllerTimer> m_scrollSnapTimer;
    220238#endif
    221239
     
    226244    FloatSize m_origVelocity;
    227245    RectEdges<bool> m_rubberBandingEdges;
    228     std::unique_ptr<ScrollControllerTimer> m_snapRubberbandTimer;
    229246#endif
    230247
  • trunk/Source/WebCore/platform/ScrollSnapAnimatorState.cpp

    r277083 r277350  
    8080}
    8181
    82 FloatPoint ScrollSnapAnimatorState::currentAnimatedScrollOffset(bool& isAnimationComplete) const
     82FloatPoint ScrollSnapAnimatorState::currentAnimatedScrollOffset(MonotonicTime currentTime, bool& isAnimationComplete) const
    8383{
    8484    if (!m_momentumCalculator) {
     
    8787    }
    8888
    89     Seconds elapsedTime = MonotonicTime::now() - m_startTime;
     89    Seconds elapsedTime = currentTime - m_startTime;
    9090    isAnimationComplete = elapsedTime >= m_momentumCalculator->animationDuration();
    9191    return m_momentumCalculator->scrollOffsetAfterElapsedTime(elapsedTime);
  • trunk/Source/WebCore/platform/ScrollSnapAnimatorState.h

    r277083 r277350  
    7676    }
    7777
    78     FloatPoint currentAnimatedScrollOffset(bool& isAnimationComplete) const;
     78    FloatPoint currentAnimatedScrollOffset(MonotonicTime, bool& isAnimationComplete) const;
    7979
    8080    // State transition helpers.
  • trunk/Source/WebCore/platform/mac/ScrollController.mm

    r272878 r277350  
    7878void ScrollController::stopAllTimers()
    7979{
    80 #if ENABLE(RUBBER_BANDING)
    81     if (m_snapRubberbandTimer)
    82         m_snapRubberbandTimer->stop();
    83 #endif
    84 
    8580#if ENABLE(CSS_SCROLL_SNAP)
    8681    if (m_statelessSnapTransitionTimer)
    8782        m_statelessSnapTransitionTimer->stop();
    88 
    89     if (m_scrollSnapTimer)
    90         m_scrollSnapTimer->stop();
    9183#endif
    9284
     
    123115        m_stretchScrollForce.setWidth(reboundDeltaForElasticDelta(stretchAmount.width()));
    124116        m_stretchScrollForce.setHeight(reboundDeltaForElasticDelta(stretchAmount.height()));
    125         m_overflowScrollDelta = FloatSize();
    126 
    127         stopSnapRubberbandTimer();
     117        m_overflowScrollDelta = { };
     118
     119        stopSnapRubberbandAnimation();
    128120        updateRubberBandingState();
    129121        return true;
     
    131123
    132124    if (wheelEvent.phase() == PlatformWheelEventPhase::Ended) {
     125        // FIXME: This triggers the rubberband timer even when we don't start rubberbanding.
    133126        snapRubberBand();
    134127        updateRubberBandingState();
     
    137130
    138131    bool isMomentumScrollEvent = (wheelEvent.momentumPhase() != PlatformWheelEventPhase::None);
    139     if (m_ignoreMomentumScrolls && (isMomentumScrollEvent || m_snapRubberbandTimer)) {
     132    if (m_ignoreMomentumScrolls && (isMomentumScrollEvent || m_isAnimatingRubberBand)) {
    140133        if (wheelEvent.momentumPhase() == PlatformWheelEventPhase::Ended) {
    141134            m_ignoreMomentumScrolls = false;
     
    153146
    154147    // Reset overflow values because we may decide to remove delta at various points and put it into overflow.
    155     m_overflowScrollDelta = FloatSize();
     148    m_overflowScrollDelta = { };
    156149
    157150    IntSize stretchAmount = m_client.stretchAmount();
     
    388381}
    389382
    390 void ScrollController::snapRubberBandTimerFired()
    391 {
     383void ScrollController::updateRubberBandAnimatingState(MonotonicTime currentTime)
     384{
     385    if (!m_isAnimatingRubberBand)
     386        return;
     387
    392388    if (isScrollSnapInProgress())
    393389        return;
    394390   
    395     LOG_WITH_STREAM(Scrolling, stream << "ScrollController::snapRubberBandTimerFired() - main thread " << isMainThread());
     391    LOG_WITH_STREAM(Scrolling, stream << "ScrollController::updateRubberBandAnimatingState() - main thread " << isMainThread());
    396392
    397393    if (!m_momentumScrollInProgress || m_ignoreMomentumScrolls) {
    398         auto timeDelta = MonotonicTime::now() - m_startTime;
     394        auto timeDelta = currentTime - m_startTime;
    399395
    400396        if (m_startStretch.isZero()) {
     
    435431        }
    436432    } else {
    437         m_startTime = MonotonicTime::now();
     433        m_startTime = currentTime;
    438434        m_startStretch = { };
    439435        if (!isRubberBandInProgressInternal())
    440             stopSnapRubberbandTimer();
     436            stopSnapRubberbandAnimation();
    441437    }
    442438
     
    472468
    473469#if ENABLE(CSS_SCROLL_SNAP)
    474     if (m_inScrollGesture || m_momentumScrollInProgress || m_scrollSnapTimer)
     470    if (m_inScrollGesture || m_momentumScrollInProgress || m_isAnimatingScrollSnap)
    475471        return true;
    476472#endif
     
    481477{
    482478#if ENABLE(RUBBER_BANDING)
    483     stopSnapRubberbandTimer();
     479    stopSnapRubberbandAnimation();
    484480    m_stretchScrollForce = { };
    485481    m_startTime = { };
     
    491487
    492488#if ENABLE(RUBBER_BANDING)
    493 void ScrollController::startSnapRubberbandTimer()
     489void ScrollController::startRubberbandAnimation()
    494490{
    495491    m_client.willStartRubberBandSnapAnimation();
    496492
    497     // Make a new one each time to ensure it fires on the current RunLoop.
    498     m_snapRubberbandTimer = m_client.createTimer([this] {
    499         snapRubberBandTimerFired();
    500     });
    501     m_snapRubberbandTimer->startRepeating(1_s / 60.);
     493    setIsAnimatingRubberBand(true);
    502494
    503495    m_client.deferWheelEventTestCompletionForReason(reinterpret_cast<WheelEventTestMonitor::ScrollableAreaIdentifier>(this), WheelEventTestMonitor::RubberbandInProgress);
    504496}
    505497
    506 void ScrollController::stopSnapRubberbandTimer()
     498void ScrollController::stopSnapRubberbandAnimation()
    507499{
    508500    m_client.didStopRubberbandSnapAnimation();
    509501
    510     if (m_snapRubberbandTimer) {
    511         m_snapRubberbandTimer->stop();
    512         m_snapRubberbandTimer = nullptr;
    513     }
     502    setIsAnimatingRubberBand(false);
    514503
    515504    m_client.removeWheelEventTestCompletionDeferralForReason(reinterpret_cast<WheelEventTestMonitor::ScrollableAreaIdentifier>(this), WheelEventTestMonitor::RubberbandInProgress);
     
    522511        m_momentumVelocity = { };
    523512
    524     if (m_snapRubberbandTimer)
     513    if (m_isAnimatingRubberBand)
    525514        return;
    526515
     
    529518    m_origVelocity = { };
    530519
    531     startSnapRubberbandTimer();
     520    startRubberbandAnimation();
    532521}
    533522
     
    548537bool ScrollController::isRubberBandInProgressInternal() const
    549538{
    550     if (!m_inScrollGesture && !m_momentumScrollInProgress && !m_snapRubberbandTimer)
     539    if (!m_inScrollGesture && !m_momentumScrollInProgress && !m_isAnimatingRubberBand)
    551540        return false;
    552541
     
    660649void ScrollController::scheduleStatelessScrollSnap()
    661650{
    662     stopScrollSnapTimer();
     651    stopScrollSnapAnimation();
    663652    if (m_statelessSnapTransitionTimer) {
    664653        m_statelessSnapTransitionTimer->stop();
     
    684673
    685674    m_scrollSnapState->transitionToSnapAnimationState(m_client.scrollExtent(), m_client.viewportSize(), m_client.pageScaleFactor(), m_client.scrollOffset());
    686     startScrollSnapTimer();
     675    startScrollSnapAnimation();
    687676}
    688677
     
    713702    case WheelEventStatus::UserScrollBegin:
    714703    case WheelEventStatus::UserScrolling:
    715         stopScrollSnapTimer();
     704        stopScrollSnapAnimation();
    716705        m_scrollSnapState->transitionToUserInteractionState();
    717706        m_dragEndedScrollingVelocity = -wheelEvent.scrollingVelocity();
     
    719708    case WheelEventStatus::UserScrollEnd:
    720709        m_scrollSnapState->transitionToSnapAnimationState(m_client.scrollExtent(), m_client.viewportSize(), m_client.pageScaleFactor(), m_client.scrollOffset());
    721         startScrollSnapTimer();
     710        startScrollSnapAnimation();
    722711        break;
    723712    case WheelEventStatus::MomentumScrollBegin:
     
    752741}
    753742
    754 void ScrollController::startScrollSnapTimer()
    755 {
    756     if (m_scrollSnapTimer)
    757         return;
    758 
    759     LOG_WITH_STREAM(ScrollSnap, stream << "ScrollController " << this << " startScrollSnapTimer (main thread " << isMainThread() << ")");
     743void ScrollController::startScrollSnapAnimation()
     744{
     745    if (m_isAnimatingScrollSnap)
     746        return;
     747
     748    LOG_WITH_STREAM(ScrollSnap, stream << "ScrollController " << this << " startScrollSnapAnimation (main thread " << isMainThread() << ")");
    760749
    761750    startDeferringWheelEventTestCompletionDueToScrollSnapping();
    762751    m_client.willStartScrollSnapAnimation();
    763     m_scrollSnapTimer = m_client.createTimer([this] {
    764         scrollSnapTimerFired();
    765     });
    766     m_scrollSnapTimer->startRepeating(1_s / 60.);
    767 }
    768 
    769 void ScrollController::stopScrollSnapTimer()
    770 {
    771     if (!m_scrollSnapTimer)
    772         return;
    773 
    774     LOG_WITH_STREAM(ScrollSnap, stream << "ScrollController " << this << " stopScrollSnapTimer (main thread " << isMainThread() << ")");
     752    setIsAnimatingScrollSnap(true);
     753}
     754
     755void ScrollController::stopScrollSnapAnimation()
     756{
     757    if (!m_isAnimatingScrollSnap)
     758        return;
     759
     760    LOG_WITH_STREAM(ScrollSnap, stream << "ScrollController " << this << " stopScrollSnapAnimation (main thread " << isMainThread() << ")");
    775761
    776762    stopDeferringWheelEventTestCompletionDueToScrollSnapping();
    777763    m_client.didStopScrollSnapAnimation();
    778764
    779     m_scrollSnapTimer->stop();
    780     m_scrollSnapTimer = nullptr;
    781 }
    782 
    783 void ScrollController::scrollSnapTimerFired()
    784 {
     765    setIsAnimatingScrollSnap(false);
     766}
     767
     768void ScrollController::updateScrollSnapAnimatingState(MonotonicTime currentTime)
     769{
     770    if (!m_isAnimatingScrollSnap)
     771        return;
     772
    785773    if (!usesScrollSnap()) {
    786774        ASSERT_NOT_REACHED();
     
    789777
    790778    bool isAnimationComplete;
    791     auto animationOffset = m_scrollSnapState->currentAnimatedScrollOffset(isAnimationComplete);
     779    auto animationOffset = m_scrollSnapState->currentAnimatedScrollOffset(currentTime, isAnimationComplete);
    792780    auto currentOffset = m_client.scrollOffset();
    793781
    794     LOG_WITH_STREAM(ScrollSnap, stream << "ScrollController " << this << " scrollSnapTimerFired - isAnimationComplete " << isAnimationComplete << " currentOffset " << currentOffset << " (main thread " << isMainThread() << ")");
     782    LOG_WITH_STREAM(ScrollSnap, stream << "ScrollController " << this << " updateScrollSnapAnimatingState - isAnimationComplete " << isAnimationComplete << " currentOffset " << currentOffset << " (main thread " << isMainThread() << ")");
    795783
    796784    m_client.immediateScrollByWithoutContentEdgeConstraints(FloatSize(animationOffset.x() - currentOffset.x(), animationOffset.y() - currentOffset.y()));
    797785    if (isAnimationComplete) {
    798786        m_scrollSnapState->transitionToDestinationReachedState();
    799         stopScrollSnapTimer();
     787        stopScrollSnapAnimation();
    800788    }
    801789}
Note: See TracChangeset for help on using the changeset viewer.