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

Changeset 273733 in webkit


Ignore:
Timestamp:
Mar 2, 2021, 9:57:53 AM (6 years ago)
Author:
commit-queue@webkit.org
Message:

Eliminate ScrollAnimatorGeneric::m_smoothAnimation
https://bugs.webkit.org/show_bug.cgi?id=222588

Patch by Martin Robinson <mrobinson@igalia.com> on 2021-03-02
Reviewed by Simon Fraser.

No new tests. This change should not change behavior.

Eliminate the extra ScrollAnimationSmooth in ScrollAnimatorGeneric. The base
class already knows how to do scroll animations for programmatic scrolls,
so we can reuse that animation for doing ScrollAnimator::scroll(...). This
makes the code easier to understand and should simplify managing interactions
between the different animations in the future.

  • platform/ScrollAnimator.cpp:

(WebCore::ScrollAnimator::ScrollAnimator): Renamed m_animationProgrammaticScroll
to m_scrollAnimation. The more generic name reflects the fact that it is also
used for doing scrolling from UI interaction now.
(WebCore::ScrollAnimator::scroll): Use the ScrollAnimationSmooth member to do
animated scrolls when necessary.
(WebCore::ScrollAnimator::scrollToPositionWithoutAnimation): Make sure the animation
is up to date with the current position when scrolling without it. This is
how ScrollAnimatorGeneric treated its ScrollAnimationSmooth.
(WebCore::ScrollAnimator::scrollToPositionWithAnimation): Rename member.
(WebCore::ScrollAnimator::cancelAnimations): Ditto.
(WebCore::ScrollAnimator::willEndLiveResize): Ditto.
(WebCore::ScrollAnimator::didAddVerticalScrollbar): Ditto.
(WebCore::ScrollAnimator::didAddHorizontalScrollbar): Ditto.

  • platform/ScrollAnimator.h: Ditto.
  • platform/generic/ScrollAnimatorGeneric.cpp:

(WebCore::ScrollAnimatorGeneric::ScrollAnimatorGeneric): Eliminate ScrollAnimationSmooth.
(WebCore::ScrollAnimatorGeneric::scrollToPositionWithoutAnimation): Ditto.
(WebCore::ScrollAnimatorGeneric::didAddVerticalScrollbar): Ditto.
(WebCore::ScrollAnimatorGeneric::didAddHorizontalScrollbar): Ditto.
(WebCore::ScrollAnimatorGeneric::ensureSmoothScrollingAnimation): Deleted.
(WebCore::ScrollAnimatorGeneric::scroll): Deleted.
(WebCore::ScrollAnimatorGeneric::willEndLiveResize): Deleted.

  • platform/generic/ScrollAnimatorGeneric.h:
Location:
trunk/Source/WebCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r273731 r273733  
     12021-03-02  Martin Robinson  <mrobinson@igalia.com>
     2
     3        Eliminate ScrollAnimatorGeneric::m_smoothAnimation
     4        https://bugs.webkit.org/show_bug.cgi?id=222588
     5
     6        Reviewed by Simon Fraser.
     7
     8        No new tests. This change should not change behavior.
     9
     10        Eliminate the extra ScrollAnimationSmooth in ScrollAnimatorGeneric. The base
     11        class already knows how to do scroll animations for programmatic scrolls,
     12        so we can reuse that animation for doing ScrollAnimator::scroll(...). This
     13        makes the code easier to understand and should simplify managing interactions
     14        between the different animations in the future.
     15
     16        * platform/ScrollAnimator.cpp:
     17        (WebCore::ScrollAnimator::ScrollAnimator): Renamed m_animationProgrammaticScroll
     18        to m_scrollAnimation. The more generic name reflects the fact that it is also
     19        used for doing scrolling from UI interaction now.
     20        (WebCore::ScrollAnimator::scroll): Use the ScrollAnimationSmooth member to do
     21        animated scrolls when necessary.
     22        (WebCore::ScrollAnimator::scrollToPositionWithoutAnimation): Make sure the animation
     23        is up to date with the current position when scrolling without it. This is
     24        how ScrollAnimatorGeneric treated its ScrollAnimationSmooth.
     25        (WebCore::ScrollAnimator::scrollToPositionWithAnimation): Rename member.
     26        (WebCore::ScrollAnimator::cancelAnimations): Ditto.
     27        (WebCore::ScrollAnimator::willEndLiveResize): Ditto.
     28        (WebCore::ScrollAnimator::didAddVerticalScrollbar): Ditto.
     29        (WebCore::ScrollAnimator::didAddHorizontalScrollbar): Ditto.
     30        * platform/ScrollAnimator.h: Ditto.
     31        * platform/generic/ScrollAnimatorGeneric.cpp:
     32        (WebCore::ScrollAnimatorGeneric::ScrollAnimatorGeneric): Eliminate ScrollAnimationSmooth.
     33        (WebCore::ScrollAnimatorGeneric::scrollToPositionWithoutAnimation): Ditto.
     34        (WebCore::ScrollAnimatorGeneric::didAddVerticalScrollbar): Ditto.
     35        (WebCore::ScrollAnimatorGeneric::didAddHorizontalScrollbar): Ditto.
     36        (WebCore::ScrollAnimatorGeneric::ensureSmoothScrollingAnimation): Deleted.
     37        (WebCore::ScrollAnimatorGeneric::scroll): Deleted.
     38        (WebCore::ScrollAnimatorGeneric::willEndLiveResize): Deleted.
     39        * platform/generic/ScrollAnimatorGeneric.h:
     40
    1412021-03-02  Xabier Rodriguez Calvar  <calvaris@igalia.com>
    242
  • trunk/Source/WebCore/platform/ScrollAnimator.cpp

    r273690 r273733  
    5858    , m_scrollController(*this)
    5959#endif
    60     , m_animationProgrammaticScroll(makeUnique<ScrollAnimationSmooth>(
     60    , m_scrollAnimation(makeUnique<ScrollAnimationSmooth>(
    6161        [this]() -> ScrollExtents {
    6262            return { m_scrollableArea.minimumScrollPosition(), m_scrollableArea.maximumScrollPosition(), m_scrollableArea.visibleSize() };
     
    100100#endif
    101101
     102#if ENABLE(SMOOTH_SCROLLING) && !PLATFORM(IOS_FAMILY)
     103    if (m_scrollableArea.scrollAnimatorEnabled()) {
     104        m_scrollAnimation->setCurrentPosition(m_currentPosition);
     105        return m_scrollAnimation->scroll(orientation, granularity, step, multiplier);
     106    }
     107#endif
     108
    102109    return scrollToPositionWithoutAnimation(positionFromStep(orientation, step, multiplier));
    103110}
     
    118125        return false;
    119126
     127    m_scrollAnimation->setCurrentPosition(adjustedPosition);
    120128    m_currentPosition = adjustedPosition;
    121129    notifyPositionChanged(adjustedPosition - currentPosition);
     
    135143        return false;
    136144
    137     m_animationProgrammaticScroll->setCurrentPosition(m_currentPosition);
    138     m_animationProgrammaticScroll->scroll(newPosition);
     145    m_scrollAnimation->setCurrentPosition(m_currentPosition);
     146    m_scrollAnimation->scroll(newPosition);
    139147    scrollableArea().setScrollBehaviorStatus(ScrollBehaviorStatus::InNonNativeAnimation);
    140148    return true;
     
    339347{
    340348#if !USE(REQUEST_ANIMATION_FRAME_TIMER)
    341     m_animationProgrammaticScroll->stop();
     349    m_scrollAnimation->stop();
    342350#endif
    343351}
     
    345353void ScrollAnimator::willEndLiveResize()
    346354{
    347     m_animationProgrammaticScroll->updateVisibleLengths();
     355    m_scrollAnimation->updateVisibleLengths();
    348356}
    349357
    350358void ScrollAnimator::didAddVerticalScrollbar(Scrollbar*)
    351359{
    352     m_animationProgrammaticScroll->updateVisibleLengths();
     360    m_scrollAnimation->updateVisibleLengths();
    353361}
    354362
    355363void ScrollAnimator::didAddHorizontalScrollbar(Scrollbar*)
    356364{
    357     m_animationProgrammaticScroll->updateVisibleLengths();
     365    m_scrollAnimation->updateVisibleLengths();
    358366}
    359367
  • trunk/Source/WebCore/platform/ScrollAnimator.h

    r273690 r273733  
    183183    FloatPoint m_currentPosition;
    184184
    185     std::unique_ptr<ScrollAnimation> m_animationProgrammaticScroll;
     185    std::unique_ptr<ScrollAnimation> m_scrollAnimation;
    186186};
    187187
  • trunk/Source/WebCore/platform/generic/ScrollAnimatorGeneric.cpp

    r273275 r273733  
    5656        },
    5757        [this](FloatPoint&& position) {
    58 #if ENABLE(SMOOTH_SCROLLING)
    59             if (m_smoothAnimation)
    60                 m_smoothAnimation->setCurrentPosition(position);
    61 #endif
     58            m_scrollAnimation->setCurrentPosition(position);
    6259            updatePosition(WTFMove(position));
    6360        });
    64 
    65 #if ENABLE(SMOOTH_SCROLLING)
    66     if (scrollableArea.scrollAnimatorEnabled())
    67         ensureSmoothScrollingAnimation();
    68 #endif
    6961}
    7062
    7163ScrollAnimatorGeneric::~ScrollAnimatorGeneric() = default;
    72 
    73 #if ENABLE(SMOOTH_SCROLLING)
    74 void ScrollAnimatorGeneric::ensureSmoothScrollingAnimation()
    75 {
    76     if (m_smoothAnimation) {
    77         if (!m_smoothAnimation->isActive())
    78             m_smoothAnimation->setCurrentPosition(m_currentPosition);
    79         return;
    80     }
    81 
    82     m_smoothAnimation = makeUnique<ScrollAnimationSmooth>(
    83         [this]() -> ScrollExtents {
    84             return { m_scrollableArea.minimumScrollPosition(), m_scrollableArea.maximumScrollPosition(), m_scrollableArea.visibleSize() };
    85         },
    86         m_currentPosition,
    87         [this](FloatPoint&& position) {
    88             updatePosition(WTFMove(position));
    89         },
    90         [this] {
    91             m_scrollableArea.setScrollBehaviorStatus(ScrollBehaviorStatus::NotInAnimation);
    92         });
    93 }
    94 #endif
    95 
    96 #if ENABLE(SMOOTH_SCROLLING)
    97 bool ScrollAnimatorGeneric::scroll(ScrollbarOrientation orientation, ScrollGranularity granularity, float step, float multiplier, ScrollBehavior behavior)
    98 {
    99     if (!m_scrollableArea.scrollAnimatorEnabled())
    100         return ScrollAnimator::scroll(orientation, granularity, step, multiplier, behavior);
    101 
    102     // This method doesn't do directional snapping, but our base class does. It will call into
    103     // ScrollAnimatorGeneric::scroll again with the snapped positions and ScrollBehavior::Default.
    104     if (behavior == ScrollBehavior::DoDirectionalSnapping)
    105         return ScrollAnimator::scroll(orientation, granularity, step, multiplier, behavior);
    106 
    107     ensureSmoothScrollingAnimation();
    108     return m_smoothAnimation->scroll(orientation, granularity, step, multiplier);
    109 }
    110 #endif
    11164
    11265bool ScrollAnimatorGeneric::scrollToPositionWithoutAnimation(const FloatPoint& position, ScrollClamping clamping)
     
    11467    m_kineticAnimation->stop();
    11568    m_kineticAnimation->clearScrollHistory();
    116 
    117 #if ENABLE(SMOOTH_SCROLLING)
    118     if (m_smoothAnimation)
    119         m_smoothAnimation->setCurrentPosition(position);
    120 #endif
    121 
    12269    return ScrollAnimator::scrollToPositionWithoutAnimation(position, clamping);
    12370}
     
    14491}
    14592
    146 void ScrollAnimatorGeneric::willEndLiveResize()
    147 {
    148 #if ENABLE(SMOOTH_SCROLLING)
    149     if (m_smoothAnimation)
    150         m_smoothAnimation->updateVisibleLengths();
    151 #endif
    152 }
    153 
    15493void ScrollAnimatorGeneric::updatePosition(FloatPoint&& position)
    15594{
     
    162101void ScrollAnimatorGeneric::didAddVerticalScrollbar(Scrollbar* scrollbar)
    163102{
    164 #if ENABLE(SMOOTH_SCROLLING)
    165     if (m_smoothAnimation)
    166         m_smoothAnimation->updateVisibleLengths();
    167 #endif
     103    ScrollAnimator::didAddVerticalScrollbar(scrollbar);
     104
    168105    if (!scrollbar->isOverlayScrollbar())
    169106        return;
     
    177114void ScrollAnimatorGeneric::didAddHorizontalScrollbar(Scrollbar* scrollbar)
    178115{
    179 #if ENABLE(SMOOTH_SCROLLING)
    180     if (m_smoothAnimation)
    181         m_smoothAnimation->updateVisibleLengths();
    182 #endif
     116    ScrollAnimator::didAddHorizontalScrollbar(scrollbar);
     117
    183118    if (!scrollbar->isOverlayScrollbar())
    184119        return;
  • trunk/Source/WebCore/platform/generic/ScrollAnimatorGeneric.h

    r273275 r273733  
    4545
    4646private:
    47 #if ENABLE(SMOOTH_SCROLLING)
    48     bool scroll(ScrollbarOrientation, ScrollGranularity, float step, float multiplier, ScrollBehavior) override;
    49 #endif
    5047    bool scrollToPositionWithoutAnimation(const FloatPoint&, ScrollClamping) override;
    51     void willEndLiveResize() override;
    5248
    5349    bool handleWheelEvent(const PlatformWheelEvent&) override;
     
    7369    void updateOverlayScrollbarsOpacity();
    7470
    75 #if ENABLE(SMOOTH_SCROLLING)
    76     void ensureSmoothScrollingAnimation();
    77 
    78     std::unique_ptr<ScrollAnimation> m_smoothAnimation;
    79 #endif
    8071    std::unique_ptr<ScrollAnimationKinetic> m_kineticAnimation;
    8172    Scrollbar* m_horizontalOverlayScrollbar { nullptr };
Note: See TracChangeset for help on using the changeset viewer.