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

Changeset 284136 in webkit


Ignore:
Timestamp:
Oct 13, 2021, 5:18:01 PM (5 years ago)
Author:
Simon Fraser
Message:

Use a ScrollAnimation for rubber-banding
​https://bugs.webkit.org/show_bug.cgi?id=231695

Reviewed by Tim Horton.

The animation that runs when rubber-banding (when you momentum-scroll into an edge,
or stretch and release) was code in updateRubberBandAnimatingState(). Repackage
that code as a ScrollAnimation subclass, which allows it to share code with other
types of scroll animation.

ScrollAnimationRubberBand needs to do non-clamped scrolls, so add a way for ScrollAnimations
to state that they allow this.

Standardize the capitalization of RubberBand.

  • SourcesCocoa.txt:
  • WebCore.xcodeproj/project.pbxproj:
  • page/scrolling/ScrollingTreeScrollingNode.cpp:

(WebCore::ScrollingTreeScrollingNode::scrollTo):

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

(WebCore::ScrollingTreeScrollingNodeDelegateMac::willDoProgrammaticScroll):
(WebCore::ScrollingTreeScrollingNodeDelegateMac::didStopRubberBandAnimation):
(WebCore::ScrollingTreeScrollingNodeDelegateMac::didStopRubberbandSnapAnimation): Deleted.

  • platform/ScrollAnimation.cpp:

(WebCore::operator<<):

  • platform/ScrollAnimation.h:

(WebCore::ScrollAnimation::clamping const):

  • platform/ScrollingEffectsController.cpp:

(WebCore::ScrollingEffectsController::startMomentumScrollWithInitialVelocity): Need to be sure
to stop() any existing animation.
(WebCore::ScrollingEffectsController::scrollAnimationDidUpdate):
(WebCore::ScrollingEffectsController::scrollAnimationWillStart):
(WebCore::ScrollingEffectsController::scrollAnimationDidEnd):

  • platform/ScrollingEffectsController.h:

(WebCore::ScrollingEffectsControllerClient::willStartRubberBandAnimation):
(WebCore::ScrollingEffectsControllerClient::didStopRubberBandAnimation):
(WebCore::ScrollingEffectsControllerClient::willStartRubberBandSnapAnimation): Deleted.
(WebCore::ScrollingEffectsControllerClient::didStopRubberbandSnapAnimation): Deleted.

  • platform/mac/ScrollAnimationRubberBand.h: Added.
  • platform/mac/ScrollAnimationRubberBand.mm: Added.

(elasticDeltaForTimeDelta):
(WebCore::roundTowardZero):
(WebCore::roundToDevicePixelTowardZero):
(WebCore::ScrollAnimationRubberBand::ScrollAnimationRubberBand):
(WebCore::ScrollAnimationRubberBand::startRubberBandAnimation):
(WebCore::ScrollAnimationRubberBand::retargetActiveAnimation):
(WebCore::ScrollAnimationRubberBand::updateScrollExtents):
(WebCore::ScrollAnimationRubberBand::serviceAnimation):

  • platform/mac/ScrollingEffectsController.mm:

(WebCore::ScrollingEffectsController::handleWheelEvent):
(WebCore::ScrollingEffectsController::updateRubberBandAnimatingState):
(WebCore::ScrollingEffectsController::stopRubberBanding):
(WebCore::ScrollingEffectsController::startRubberBandAnimation):
(WebCore::ScrollingEffectsController::stopRubberBandAnimation):
(WebCore::ScrollingEffectsController::willStartRubberBandAnimation):
(WebCore::ScrollingEffectsController::didStopRubberBandAnimation):
(WebCore::ScrollingEffectsController::startRubberBandAnimationIfNecessary):
(WebCore::elasticDeltaForTimeDelta): Deleted.
(WebCore::roundTowardZero): Deleted.
(WebCore::roundToDevicePixelTowardZero): Deleted.
(WebCore::ScrollingEffectsController::stopRubberbanding): Deleted.
(WebCore::ScrollingEffectsController::startRubberbandAnimation): Deleted.
(WebCore::ScrollingEffectsController::stopRubberbandAnimation): Deleted.
(WebCore::ScrollingEffectsController::startRubberbandAnimationIfNecessary): Deleted.

Location:
trunk/Source/WebCore
Files:
2 added
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r284135 r284136  
     12021-10-13  Simon Fraser  <simon.fraser@apple.com>
     2
     3        Use a ScrollAnimation for rubber-banding
     4        https://bugs.webkit.org/show_bug.cgi?id=231695
     5
     6        Reviewed by Tim Horton.
     7
     8        The animation that runs when rubber-banding (when you momentum-scroll into an edge,
     9        or stretch and release) was code in updateRubberBandAnimatingState(). Repackage
     10        that code as a ScrollAnimation subclass, which allows it to share code with other
     11        types of scroll animation.
     12
     13        ScrollAnimationRubberBand needs to do non-clamped scrolls, so add a way for ScrollAnimations
     14        to state that they allow this.
     15       
     16        Standardize the capitalization of RubberBand.
     17
     18        * SourcesCocoa.txt:
     19        * WebCore.xcodeproj/project.pbxproj:
     20        * page/scrolling/ScrollingTreeScrollingNode.cpp:
     21        (WebCore::ScrollingTreeScrollingNode::scrollTo):
     22        * page/scrolling/mac/ScrollingTreeScrollingNodeDelegateMac.h:
     23        * page/scrolling/mac/ScrollingTreeScrollingNodeDelegateMac.mm:
     24        (WebCore::ScrollingTreeScrollingNodeDelegateMac::willDoProgrammaticScroll):
     25        (WebCore::ScrollingTreeScrollingNodeDelegateMac::didStopRubberBandAnimation):
     26        (WebCore::ScrollingTreeScrollingNodeDelegateMac::didStopRubberbandSnapAnimation): Deleted.
     27        * platform/ScrollAnimation.cpp:
     28        (WebCore::operator<<):
     29        * platform/ScrollAnimation.h:
     30        (WebCore::ScrollAnimation::clamping const):
     31        * platform/ScrollingEffectsController.cpp:
     32        (WebCore::ScrollingEffectsController::startMomentumScrollWithInitialVelocity): Need to be sure
     33        to stop() any existing animation.
     34        (WebCore::ScrollingEffectsController::scrollAnimationDidUpdate):
     35        (WebCore::ScrollingEffectsController::scrollAnimationWillStart):
     36        (WebCore::ScrollingEffectsController::scrollAnimationDidEnd):
     37        * platform/ScrollingEffectsController.h:
     38        (WebCore::ScrollingEffectsControllerClient::willStartRubberBandAnimation):
     39        (WebCore::ScrollingEffectsControllerClient::didStopRubberBandAnimation):
     40        (WebCore::ScrollingEffectsControllerClient::willStartRubberBandSnapAnimation): Deleted.
     41        (WebCore::ScrollingEffectsControllerClient::didStopRubberbandSnapAnimation): Deleted.
     42        * platform/mac/ScrollAnimationRubberBand.h: Added.
     43        * platform/mac/ScrollAnimationRubberBand.mm: Added.
     44        (elasticDeltaForTimeDelta):
     45        (WebCore::roundTowardZero):
     46        (WebCore::roundToDevicePixelTowardZero):
     47        (WebCore::ScrollAnimationRubberBand::ScrollAnimationRubberBand):
     48        (WebCore::ScrollAnimationRubberBand::startRubberBandAnimation):
     49        (WebCore::ScrollAnimationRubberBand::retargetActiveAnimation):
     50        (WebCore::ScrollAnimationRubberBand::updateScrollExtents):
     51        (WebCore::ScrollAnimationRubberBand::serviceAnimation):
     52        * platform/mac/ScrollingEffectsController.mm:
     53        (WebCore::ScrollingEffectsController::handleWheelEvent):
     54        (WebCore::ScrollingEffectsController::updateRubberBandAnimatingState):
     55        (WebCore::ScrollingEffectsController::stopRubberBanding):
     56        (WebCore::ScrollingEffectsController::startRubberBandAnimation):
     57        (WebCore::ScrollingEffectsController::stopRubberBandAnimation):
     58        (WebCore::ScrollingEffectsController::willStartRubberBandAnimation):
     59        (WebCore::ScrollingEffectsController::didStopRubberBandAnimation):
     60        (WebCore::ScrollingEffectsController::startRubberBandAnimationIfNecessary):
     61        (WebCore::elasticDeltaForTimeDelta): Deleted.
     62        (WebCore::roundTowardZero): Deleted.
     63        (WebCore::roundToDevicePixelTowardZero): Deleted.
     64        (WebCore::ScrollingEffectsController::stopRubberbanding): Deleted.
     65        (WebCore::ScrollingEffectsController::startRubberbandAnimation): Deleted.
     66        (WebCore::ScrollingEffectsController::stopRubberbandAnimation): Deleted.
     67        (WebCore::ScrollingEffectsController::startRubberbandAnimationIfNecessary): Deleted.
     68
    1692021-10-13  Jean-Yves Avenard  <jya@apple.com>
    270
  • trunk/Source/WebCore/SourcesCocoa.txt

    r283703 r284136  
    492492platform/mac/SSLKeyGeneratorMac.mm
    493493platform/mac/ScrollAnimatorMac.mm @no-unify
    494 platform/mac/ScrollingEffectsController.mm
     494platform/mac/ScrollAnimationRubberBand.mm
    495495platform/mac/ScrollViewMac.mm
    496496platform/mac/ScrollbarsControllerMac.mm @no-unify
    497497platform/mac/ScrollbarThemeMac.mm @no-unify
     498platform/mac/ScrollingEffectsController.mm
    498499platform/mac/ScrollingMomentumCalculatorMac.mm
    499500platform/mac/SerializedPlatformDataCueMac.mm
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r284085 r284136  
    62156215                0F37F0832202AC8F00A89C0B /* ScrollingTreeScrollingNodeDelegateMac.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = ScrollingTreeScrollingNodeDelegateMac.mm; sourceTree = "<group>"; };
    62166216                0F37F0842202ACB700A89C0B /* ScrollingTreeScrollingNodeDelegateMac.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ScrollingTreeScrollingNodeDelegateMac.h; sourceTree = "<group>"; };
     6217                0F38186A2708D20100414F32 /* ScrollAnimationRubberBand.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = ScrollAnimationRubberBand.mm; sourceTree = "<group>"; };
     6218                0F38186C2708D20200414F32 /* ScrollAnimationRubberBand.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ScrollAnimationRubberBand.h; sourceTree = "<group>"; };
    62176219                0F3DD44D12F5EA1B000D9190 /* ShadowBlur.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ShadowBlur.cpp; sourceTree = "<group>"; };
    62186220                0F3DD44E12F5EA1B000D9190 /* ShadowBlur.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ShadowBlur.h; sourceTree = "<group>"; };
    … …  
    2235322355                                46DBB64E1AB8C96F00D9A813 /* PowerObserverMac.h */,
    2235422356                                0081FEFE16B0A2B6008AAA7A /* PublicSuffixMac.mm */,
     22357                                0F38186C2708D20200414F32 /* ScrollAnimationRubberBand.h */,
     22358                                0F38186A2708D20100414F32 /* ScrollAnimationRubberBand.mm */,
    2235522359                                BCAE1FA512939DB7004CB026 /* ScrollAnimatorMac.h */,
    2235622360                                BC51156D12B1749C00C96754 /* ScrollAnimatorMac.mm */,
  • trunk/Source/WebCore/page/scrolling/mac/ScrollingTreeScrollingNodeDelegateMac.h

    r283793 r284136  
    8888    bool shouldRubberBandOnSide(BoxSide) const final;
    8989    void immediateScrollBy(const FloatSize&, ScrollClamping = ScrollClamping::Clamped) final;
    90     void didStopRubberbandSnapAnimation() final;
     90    void didStopRubberBandAnimation() final;
    9191    void rubberBandingStateChanged(bool) final;
    9292    void adjustScrollPositionToBoundsIfNecessary() final;
  • trunk/Source/WebCore/page/scrolling/mac/ScrollingTreeScrollingNodeDelegateMac.mm

    r283983 r284136  
    132132    if (scrollPositionIsNotRubberbandingEdge(targetPosition)) {
    133133        LOG(Scrolling, "ScrollingTreeScrollingNodeDelegateMac::willDoProgrammaticScroll() - scrolling away from rubberbanding edge so stopping rubberbanding");
    134         m_scrollController.stopRubberbanding();
     134        m_scrollController.stopRubberBanding();
    135135    }
    136136}
    … …  
    340340}
    341341
    342 void ScrollingTreeScrollingNodeDelegateMac::didStopRubberbandSnapAnimation()
     342void ScrollingTreeScrollingNodeDelegateMac::didStopRubberBandAnimation()
    343343{
    344344    // Since the rubberband timer has stopped, totalContentsSizeForRubberBand can be synchronized with totalContentsSize.
  • trunk/Source/WebCore/platform/ScrollAnimation.cpp

    r283072 r284136  
    3737    case ScrollAnimation::Type::Kinetic: ts << "kinetic"; break;
    3838    case ScrollAnimation::Type::Momentum: ts << "momentum"; break;
     39    case ScrollAnimation::Type::RubberBand: ts << "rubber-band"; break;
    3940    }
    4041    return ts;
  • trunk/Source/WebCore/platform/ScrollAnimation.h

    r283851 r284136  
    5555        Kinetic,
    5656        Momentum,
     57        RubberBand,
    5758    };
    5859
    … …  
    6465   
    6566    Type type() const { return m_animationType; }
     67
     68    virtual ScrollClamping clamping() const { return ScrollClamping::Clamped; }
    6669
    6770    virtual bool retargetActiveAnimation(const FloatPoint& newDestinationOffset) = 0;
    … …  
    7679   
    7780    FloatPoint currentOffset() const { return m_currentOffset; }
    78    
     81
    7982    virtual void serviceAnimation(MonotonicTime) = 0;
    8083
  • trunk/Source/WebCore/platform/ScrollingEffectsController.cpp

    r283851 r284136  
    4242#endif
    4343
     44#if HAVE(RUBBER_BANDING)
     45#include "ScrollAnimationRubberBand.h"
     46#endif
     47
    4448namespace WebCore {
    4549
    … …  
    5963    }
    6064
    61     updateRubberBandAnimatingState(currentTime);
     65    updateRubberBandAnimatingState();
    6266    updateKeyboardScrollingAnimatingState(currentTime);
    6367   
    … …  
    126130{
    127131    if (m_currentAnimation) {
    128         if (is<ScrollAnimationMomentum>(m_currentAnimation.get()))
    129             m_currentAnimation->stop();
    130         else
     132        m_currentAnimation->stop();
     133        if (!is<ScrollAnimationMomentum>(m_currentAnimation.get()))
    131134            m_currentAnimation = nullptr;
    132135    }
    … …  
    430433}
    431434
    432 void ScrollingEffectsController::scrollAnimationDidUpdate(ScrollAnimation& animation, const FloatPoint& currentOffset)
    433 {
    434     auto scrollDelta = currentOffset - m_client.scrollOffset();
    435 
    436     LOG_WITH_STREAM(ScrollAnimations, stream << "ScrollingEffectsController " << this << " scrollAnimationDidUpdate " << animation << " (main thread " << isMainThread() << ") scrolling by " << scrollDelta);
     435void ScrollingEffectsController::scrollAnimationDidUpdate(ScrollAnimation& animation, const FloatPoint& scrollOffset)
     436{
     437    LOG_WITH_STREAM(ScrollAnimations, stream << "ScrollingEffectsController " << this << " scrollAnimationDidUpdate " << animation << " (main thread " << isMainThread() << ") scrolling to " << scrollOffset);
     438
     439    auto currentOffset = m_client.scrollOffset();
     440    auto scrollDelta = scrollOffset - currentOffset;
     441
     442    m_client.immediateScrollBy(scrollDelta, animation.clamping());
     443}
     444
     445void ScrollingEffectsController::scrollAnimationWillStart(ScrollAnimation& animation)
     446{
     447    LOG_WITH_STREAM(ScrollAnimations, stream << "ScrollingEffectsController " << this << " scrollAnimationWillStart " << animation);
     448
     449#if HAVE(RUBBER_BANDING)
     450    if (is<ScrollAnimationRubberBand>(animation))
     451        willStartRubberBandAnimation();
     452#else
    437453    UNUSED_PARAM(animation);
    438 
    439     m_client.immediateScrollBy(scrollDelta);
    440 }
    441 
    442 void ScrollingEffectsController::scrollAnimationWillStart(ScrollAnimation& animation)
    443 {
    444     LOG_WITH_STREAM(ScrollAnimations, stream << "ScrollingEffectsController " << this << " scrollAnimationWillStart " << animation);
    445     UNUSED_PARAM(animation);
     454#endif
    446455
    447456    startOrStopAnimationCallbacks();
    … …  
    451460{
    452461    LOG_WITH_STREAM(ScrollAnimations, stream << "ScrollingEffectsController " << this << " scrollAnimationDidEnd " << animation);
    453     UNUSED_PARAM(animation);
    454462
    455463    if (usesScrollSnap() && m_isAnimatingScrollSnap) {
    … …  
    457465        stopScrollSnapAnimation();
    458466    }
     467
     468#if HAVE(RUBBER_BANDING)
     469    if (is<ScrollAnimationRubberBand>(animation))
     470        didStopRubberBandAnimation();
     471#else
     472    UNUSED_PARAM(animation);
     473#endif
    459474
    460475    // FIXME: Need to track state better and only call this when the running animation is for CSS smooth scrolling. Calling should be harmless, though.
    … …  
    483498}
    484499
    485 void ScrollingEffectsController::updateRubberBandAnimatingState(MonotonicTime)
     500void ScrollingEffectsController::updateRubberBandAnimatingState()
    486501{
    487502}
  • trunk/Source/WebCore/platform/ScrollingEffectsController.h

    r283851 r284136  
    101101    virtual bool shouldRubberBandOnSide(BoxSide) const = 0;
    102102
    103     virtual void willStartRubberBandSnapAnimation() { }
    104     virtual void didStopRubberbandSnapAnimation() { }
     103    virtual void willStartRubberBandAnimation() { }
     104    virtual void didStopRubberBandAnimation() { }
    105105
    106106    virtual void rubberBandingStateChanged(bool) { }
    … …  
    175175    bool processWheelEventForScrollSnap(const PlatformWheelEvent&);
    176176
    177     void stopRubberbanding();
     177    void stopRubberBanding();
    178178    bool isRubberBandInProgress() const;
    179179    RectEdges<bool> rubberBandingEdges() const { return m_rubberBandingEdges; }
    … …  
    181181
    182182private:
    183     void updateRubberBandAnimatingState(MonotonicTime);
     183    void updateRubberBandAnimatingState();
    184184    void updateKeyboardScrollingAnimatingState(MonotonicTime);
    185185
    … …  
    201201    bool applyScrollDeltaWithStretching(const PlatformWheelEvent&, FloatSize, bool isHorizontallyStretched, bool isVerticallyStretched);
    202202
    203     void startRubberbandAnimationIfNecessary();
    204     void startRubberbandAnimation();
    205     void stopRubberbandAnimation();
     203    void startRubberBandAnimationIfNecessary();
     204
     205    void startRubberBandAnimation(const FloatPoint& targetOffset, const FloatSize& initialVelocity, const FloatSize& initialOverscroll);
     206    void stopRubberBandAnimation();
     207
     208    void willStartRubberBandAnimation();
     209    void didStopRubberBandAnimation();
    206210
    207211    bool shouldRubberBandOnSide(BoxSide) const;
    … …  
    255259
    256260#if HAVE(RUBBER_BANDING)
    257     // Rubber band state.
    258     MonotonicTime m_startTime;
    259     FloatSize m_startStretch;
    260     FloatSize m_origVelocity;
    261261    RectEdges<bool> m_rubberBandingEdges;
    262262#endif
  • trunk/Source/WebCore/platform/mac/ScrollingEffectsController.mm

    r283851 r284136  
    2929#import "Logging.h"
    3030#import "PlatformWheelEvent.h"
     31#import "ScrollAnimationRubberBand.h"
    3132#import "ScrollExtents.h"
    3233#import "WheelEventTestMonitor.h"
    … …  
    4445static const float rubberbandMinimumRequiredDeltaBeforeStretch = 10;
    4546
    46 static float elasticDeltaForTimeDelta(float initialPosition, float initialVelocity, Seconds elapsedTime)
    47 {
    48     return _NSElasticDeltaForTimeDelta(initialPosition, initialVelocity, elapsedTime.seconds());
    49 }
    50 
    5147static float elasticDeltaForReboundDelta(float delta)
    5248{
    … …  
    143139        m_unappliedOverscrollDelta = { };
    144140
    145         stopRubberbandAnimation();
     141        stopRubberBandAnimation();
    146142        updateRubberBandingState();
    147143        return true;
    … …  
    150146    if (wheelEvent.phase() == PlatformWheelEventPhase::Ended) {
    151147        // FIXME: This triggers the rubberband timer even when we don't start rubberbanding.
    152         startRubberbandAnimationIfNecessary();
     148        startRubberBandAnimationIfNecessary();
    153149        updateRubberBandingState();
    154150        return true;
    … …  
    214210                    m_ignoreMomentumScrolls = true;
    215211                    m_momentumScrollInProgress = false;
    216                     startRubberbandAnimationIfNecessary();
     212                    startRubberBandAnimationIfNecessary();
    217213                }
    218214            }
    … …  
    347343}
    348344
    349 static inline float roundTowardZero(float num)
    350 {
    351     return num > 0 ? ceilf(num - 0.5f) : floorf(num + 0.5f);
    352 }
    353 
    354 static inline float roundToDevicePixelTowardZero(float num)
    355 {
    356     float roundedNum = roundf(num);
    357     if (fabs(num - roundedNum) < 0.125)
    358         num = roundedNum;
    359 
    360     return roundTowardZero(num);
    361 }
    362 
    363 void ScrollingEffectsController::updateRubberBandAnimatingState(MonotonicTime currentTime)
     345void ScrollingEffectsController::updateRubberBandAnimatingState()
    364346{
    365347    if (!m_isAnimatingRubberBand)
    … …  
    369351        return;
    370352   
    371     if (!m_momentumScrollInProgress || m_ignoreMomentumScrolls) {
    372         auto timeDelta = currentTime - m_startTime;
    373 
    374         if (m_startStretch.isZero()) {
    375             m_startStretch = m_client.stretchAmount();
    376             if (m_startStretch.isZero()) {
    377                 stopRubberbanding();
    378                 return;
    379             }
    380 
    381             m_origVelocity = m_momentumVelocity;
    382 
    383             // Just like normal scrolling, prefer vertical rubberbanding
    384             if (fabsf(m_origVelocity.height()) >= fabsf(m_origVelocity.width()))
    385                 m_origVelocity.setWidth(0);
    386 
    387             // Don't rubber-band horizontally if it's not possible to scroll horizontally
    388             if (!m_client.allowsHorizontalScrolling())
    389                 m_origVelocity.setWidth(0);
    390 
    391             // Don't rubber-band vertically if it's not possible to scroll vertically
    392             if (!m_client.allowsVerticalScrolling())
    393                 m_origVelocity.setHeight(0);
    394 
    395             LOG_WITH_STREAM(ScrollAnimations, stream << "ScrollingEffectsController::updateRubberBandAnimatingState() - starting rubbberband with m_origVelocity" << m_origVelocity << " m_startStretch " << m_startStretch);
    396         }
    397 
    398         auto rubberBandDelta = FloatSize {
    399             roundToDevicePixelTowardZero(elasticDeltaForTimeDelta(m_startStretch.width(), -m_origVelocity.width(), timeDelta)),
    400             roundToDevicePixelTowardZero(elasticDeltaForTimeDelta(m_startStretch.height(), -m_origVelocity.height(), timeDelta))
    401         };
    402 
    403         if (fabs(rubberBandDelta.width()) >= 1 || fabs(rubberBandDelta.height()) >= 1) {
    404             auto stretchDelta = rubberBandDelta - FloatSize(m_client.stretchAmount());
    405 
    406             LOG_WITH_STREAM(ScrollAnimations, stream << "ScrollingEffectsController::updateRubberBandAnimatingState() - rubberBandDelta " << rubberBandDelta << " stretched " << m_client.stretchAmount() << " moving by " << stretchDelta);
    407 
    408             m_client.immediateScrollBy(stretchDelta, ScrollClamping::Unclamped);
    409 
    410             FloatSize newStretch = m_client.stretchAmount();
    411 
    412             m_stretchScrollForce.setWidth(reboundDeltaForElasticDelta(newStretch.width()));
    413             m_stretchScrollForce.setHeight(reboundDeltaForElasticDelta(newStretch.height()));
    414         } else {
    415             LOG_WITH_STREAM(ScrollAnimations, stream << "ScrollingEffectsController::updateRubberBandAnimatingState() - rubber band complete");
    416             m_client.adjustScrollPositionToBoundsIfNecessary();
    417             stopRubberbanding();
    418         }
    419     } else {
     353    if (m_momentumScrollInProgress && !m_ignoreMomentumScrolls) {
    420354        LOG_WITH_STREAM(ScrollAnimations, stream << "ScrollingEffectsController::updateRubberBandAnimatingState() - not animating, momentumScrollInProgress " << m_momentumScrollInProgress << " ignoreMomentumScrolls " << m_ignoreMomentumScrolls);
    421         m_startTime = currentTime;
    422         m_startStretch = { };
    423355        if (!isRubberBandInProgressInternal())
    424             stopRubberbandAnimation();
     356            stopRubberBandAnimation();
    425357    }
    426358
    … …  
    454386}
    455387
    456 void ScrollingEffectsController::stopRubberbanding()
    457 {
    458     stopRubberbandAnimation();
     388void ScrollingEffectsController::stopRubberBanding()
     389{
     390    stopRubberBandAnimation();
     391    updateRubberBandingState();
     392}
     393
     394void ScrollingEffectsController::startRubberBandAnimation(const FloatPoint& targetOffset, const FloatSize& initialVelocity, const FloatSize& initialOverscroll)
     395{
     396    if (m_currentAnimation)
     397        m_currentAnimation->stop();
     398
     399    m_currentAnimation = makeUnique<ScrollAnimationRubberBand>(*this);
     400    LOG_WITH_STREAM(ScrollAnimations, stream << "ScrollingEffectsController::startRubberBandAnimation() - starting rubbberband with targetOffset " << targetOffset << " initialVelocity " << initialVelocity << " initialOverscroll " << initialOverscroll);
     401    downcast<ScrollAnimationRubberBand>(*m_currentAnimation).startRubberBandAnimation(targetOffset, initialVelocity, initialOverscroll);
     402}
     403
     404void ScrollingEffectsController::stopRubberBandAnimation()
     405{
     406    if (m_isAnimatingRubberBand)
     407        stopAnimatedScroll();
     408
    459409    m_stretchScrollForce = { };
    460     m_startTime = { };
    461     m_startStretch = { };
    462     m_origVelocity = { };
    463     updateRubberBandingState();
    464 }
    465 
    466 void ScrollingEffectsController::startRubberbandAnimation()
    467 {
    468     m_client.willStartRubberBandSnapAnimation();
    469 
    470     setIsAnimatingRubberBand(true);
    471 
     410}
     411
     412void ScrollingEffectsController::willStartRubberBandAnimation()
     413{
     414    m_isAnimatingRubberBand = true;
     415    m_client.willStartRubberBandAnimation();
    472416    m_client.deferWheelEventTestCompletionForReason(reinterpret_cast<WheelEventTestMonitor::ScrollableAreaIdentifier>(this), WheelEventTestMonitor::RubberbandInProgress);
    473417}
    474418
    475 void ScrollingEffectsController::stopRubberbandAnimation()
    476 {
    477     m_client.didStopRubberbandSnapAnimation();
    478 
    479     setIsAnimatingRubberBand(false);
    480 
     419void ScrollingEffectsController::didStopRubberBandAnimation()
     420{
     421    m_isAnimatingRubberBand = false;
     422    m_client.didStopRubberBandAnimation();
    481423    m_client.removeWheelEventTestCompletionDeferralForReason(reinterpret_cast<WheelEventTestMonitor::ScrollableAreaIdentifier>(this), WheelEventTestMonitor::RubberbandInProgress);
    482424}
    483425
    484 void ScrollingEffectsController::startRubberbandAnimationIfNecessary()
     426void ScrollingEffectsController::startRubberBandAnimationIfNecessary()
    485427{
    486428    auto timeDelta = WallTime::now() - m_lastMomentumScrollTimestamp;
    … …  
    491433        return;
    492434
    493     m_startTime = MonotonicTime::now();
    494     m_startStretch = { };
    495     m_origVelocity = { };
    496 
    497     startRubberbandAnimation();
     435    auto extents = m_client.scrollExtents();
     436    auto targetOffset = m_client.scrollOffset();
     437    auto contrainedOffset = targetOffset.constrainedBetween(extents.minimumScrollOffset(), extents.maximumScrollOffset());
     438    bool willOverscroll = targetOffset != contrainedOffset;
     439
     440    auto stretchAmount = m_client.stretchAmount();
     441
     442    LOG_WITH_STREAM(ScrollAnimations, stream << "ScrollingEffectsController::startRubberBandAnimationIfNecessary() - rubberBandAnimationRunning " << m_isAnimatingRubberBand << " stretchAmount " << stretchAmount << " targetOffset " << targetOffset);
     443
     444    if (stretchAmount.isZero() && !willOverscroll)
     445        return;
     446
     447    auto initialVelocity = m_momentumVelocity;
     448
     449    // Just like normal scrolling, prefer vertical rubberbanding
     450    if (fabsf(initialVelocity.height()) >= fabsf(initialVelocity.width()))
     451        initialVelocity.setWidth(0);
     452
     453    // Don't rubber-band horizontally if it's not possible to scroll horizontally
     454    if (!m_client.allowsHorizontalScrolling())
     455        initialVelocity.setWidth(0);
     456
     457    // Don't rubber-band vertically if it's not possible to scroll vertically
     458    if (!m_client.allowsVerticalScrolling())
     459        initialVelocity.setHeight(0);
     460
     461    startRubberBandAnimation(contrainedOffset, initialVelocity, stretchAmount);
    498462}
    499463
Note: See TracChangeset for help on using the changeset viewer.