Title: [276299] trunk/Source/WebCore
Revision
276299
Author
[email protected]
Date
2021-04-20 03:54:38 -0700 (Tue, 20 Apr 2021)

Log Message

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

Reviewed by Žan Doberšek.

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.

Changes since first version: Now only update the current position of the animation
if it is not active. This is the behavior that was used in ScrollAnimatorGeneric
and is the correct behavior when using ScrollAnimationSmooth.

* 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:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (276298 => 276299)


--- trunk/Source/WebCore/ChangeLog	2021-04-20 10:25:08 UTC (rev 276298)
+++ trunk/Source/WebCore/ChangeLog	2021-04-20 10:54:38 UTC (rev 276299)
@@ -1,3 +1,47 @@
+2021-04-20  Martin Robinson  <[email protected]>
+
+        Re-land: Eliminate ScrollAnimatorGeneric::m_smoothAnimation
+        https://bugs.webkit.org/show_bug.cgi?id=222588
+
+        Reviewed by Žan Doberšek.
+
+        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.
+
+        Changes since first version: Now only update the current position of the animation
+        if it is not active. This is the behavior that was used in ScrollAnimatorGeneric
+        and is the correct behavior when using ScrollAnimationSmooth.
+
+        * 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:
+
 2021-04-20  Chris Lord  <[email protected]>
 
         Don't use the full CSS parser for CSSFontFaceSet

Modified: trunk/Source/WebCore/platform/ScrollAnimator.cpp (276298 => 276299)


--- trunk/Source/WebCore/platform/ScrollAnimator.cpp	2021-04-20 10:25:08 UTC (rev 276298)
+++ trunk/Source/WebCore/platform/ScrollAnimator.cpp	2021-04-20 10:54:38 UTC (rev 276299)
@@ -57,7 +57,7 @@
 #if ENABLE(CSS_SCROLL_SNAP) || ENABLE(RUBBER_BANDING)
     , m_scrollController(*this)
 #endif
-    , m_animationProgrammaticScroll(makeUnique<ScrollAnimationSmooth>(
+    , m_scrollAnimation(makeUnique<ScrollAnimationSmooth>(
         [this]() -> ScrollExtents {
             return { m_scrollableArea.minimumScrollPosition(), m_scrollableArea.maximumScrollPosition(), m_scrollableArea.visibleSize() };
         },
@@ -106,6 +106,14 @@
     UNUSED_PARAM(behavior);
 #endif
 
+#if ENABLE(SMOOTH_SCROLLING) && !PLATFORM(IOS_FAMILY)
+    if (m_scrollableArea.scrollAnimatorEnabled()) {
+        if (!m_scrollAnimation->isActive())
+            m_scrollAnimation->setCurrentPosition(m_currentPosition);
+        return m_scrollAnimation->scroll(orientation, granularity, step, multiplier);
+    }
+#endif
+
     return scrollToPositionWithoutAnimation(currentPosition() + delta);
 }
 
@@ -124,6 +132,7 @@
     if (adjustedPosition == currentPosition && adjustedPosition == scrollableArea().scrollPosition() && !scrollableArea().scrollOriginChanged())
         return false;
 
+    m_scrollAnimation->setCurrentPosition(adjustedPosition);
     m_currentPosition = adjustedPosition;
     notifyPositionChanged(adjustedPosition - currentPosition);
     updateActiveScrollSnapIndexForOffset();
@@ -141,8 +150,8 @@
     if (!positionChanged && !scrollableArea().scrollOriginChanged())
         return false;
 
-    m_animationProgrammaticScroll->setCurrentPosition(m_currentPosition);
-    m_animationProgrammaticScroll->scroll(newPosition);
+    m_scrollAnimation->setCurrentPosition(m_currentPosition);
+    m_scrollAnimation->scroll(newPosition);
     scrollableArea().setScrollBehaviorStatus(ScrollBehaviorStatus::InNonNativeAnimation);
     return true;
 }
@@ -355,23 +364,23 @@
 void ScrollAnimator::cancelAnimations()
 {
 #if !USE(REQUEST_ANIMATION_FRAME_TIMER)
-    m_animationProgrammaticScroll->stop();
+    m_scrollAnimation->stop();
 #endif
 }
 
 void ScrollAnimator::willEndLiveResize()
 {
-    m_animationProgrammaticScroll->updateVisibleLengths();
+    m_scrollAnimation->updateVisibleLengths();
 }
 
 void ScrollAnimator::didAddVerticalScrollbar(Scrollbar*)
 {
-    m_animationProgrammaticScroll->updateVisibleLengths();
+    m_scrollAnimation->updateVisibleLengths();
 }
 
 void ScrollAnimator::didAddHorizontalScrollbar(Scrollbar*)
 {
-    m_animationProgrammaticScroll->updateVisibleLengths();
+    m_scrollAnimation->updateVisibleLengths();
 }
 
 FloatPoint ScrollAnimator::adjustScrollOffsetForSnappingIfNeeded(const FloatPoint& offset, ScrollSnapPointSelectionMethod method)

Modified: trunk/Source/WebCore/platform/ScrollAnimator.h (276298 => 276299)


--- trunk/Source/WebCore/platform/ScrollAnimator.h	2021-04-20 10:25:08 UTC (rev 276298)
+++ trunk/Source/WebCore/platform/ScrollAnimator.h	2021-04-20 10:54:38 UTC (rev 276299)
@@ -185,7 +185,7 @@
 #endif
     FloatPoint m_currentPosition;
 
-    std::unique_ptr<ScrollAnimation> m_animationProgrammaticScroll;
+    std::unique_ptr<ScrollAnimation> m_scrollAnimation;
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/platform/generic/ScrollAnimatorGeneric.cpp (276298 => 276299)


--- trunk/Source/WebCore/platform/generic/ScrollAnimatorGeneric.cpp	2021-04-20 10:25:08 UTC (rev 276298)
+++ trunk/Source/WebCore/platform/generic/ScrollAnimatorGeneric.cpp	2021-04-20 10:54:38 UTC (rev 276299)
@@ -55,70 +55,17 @@
             return { m_scrollableArea.minimumScrollPosition(), m_scrollableArea.maximumScrollPosition(), m_scrollableArea.visibleSize() };
         },
         [this](FloatPoint&& position) {
-#if ENABLE(SMOOTH_SCROLLING)
-            if (m_smoothAnimation)
-                m_smoothAnimation->setCurrentPosition(position);
-#endif
+            m_scrollAnimation->setCurrentPosition(position);
             updatePosition(WTFMove(position));
         });
-
-#if ENABLE(SMOOTH_SCROLLING)
-    if (scrollableArea.scrollAnimatorEnabled())
-        ensureSmoothScrollingAnimation();
-#endif
 }
 
 ScrollAnimatorGeneric::~ScrollAnimatorGeneric() = default;
 
-#if ENABLE(SMOOTH_SCROLLING)
-void ScrollAnimatorGeneric::ensureSmoothScrollingAnimation()
-{
-    if (m_smoothAnimation) {
-        if (!m_smoothAnimation->isActive())
-            m_smoothAnimation->setCurrentPosition(m_currentPosition);
-        return;
-    }
-
-    m_smoothAnimation = makeUnique<ScrollAnimationSmooth>(
-        [this]() -> ScrollExtents {
-            return { m_scrollableArea.minimumScrollPosition(), m_scrollableArea.maximumScrollPosition(), m_scrollableArea.visibleSize() };
-        },
-        m_currentPosition,
-        [this](FloatPoint&& position) {
-            updatePosition(WTFMove(position));
-        },
-        [this] {
-            m_scrollableArea.setScrollBehaviorStatus(ScrollBehaviorStatus::NotInAnimation);
-        });
-}
-#endif
-
-#if ENABLE(SMOOTH_SCROLLING)
-bool ScrollAnimatorGeneric::scroll(ScrollbarOrientation orientation, ScrollGranularity granularity, float step, float multiplier, ScrollBehavior behavior)
-{
-    if (!m_scrollableArea.scrollAnimatorEnabled())
-        return ScrollAnimator::scroll(orientation, granularity, step, multiplier, behavior);
-
-    // This method doesn't do directional snapping, but our base class does. It will call into
-    // ScrollAnimatorGeneric::scroll again with the snapped positions and ScrollBehavior::Default.
-    if (behavior == ScrollBehavior::DoDirectionalSnapping)
-        return ScrollAnimator::scroll(orientation, granularity, step, multiplier, behavior);
-
-    ensureSmoothScrollingAnimation();
-    return m_smoothAnimation->scroll(orientation, granularity, step, multiplier);
-}
-#endif
-
 bool ScrollAnimatorGeneric::scrollToPositionWithoutAnimation(const FloatPoint& position, ScrollClamping clamping)
 {
     m_kineticAnimation->stop();
     m_kineticAnimation->clearScrollHistory();
-
-#if ENABLE(SMOOTH_SCROLLING)
-    if (m_smoothAnimation)
-        m_smoothAnimation->setCurrentPosition(position);
-#endif
-
     return ScrollAnimator::scrollToPositionWithoutAnimation(position, clamping);
 }
 
@@ -143,14 +90,6 @@
     return ScrollAnimator::handleWheelEvent(event);
 }
 
-void ScrollAnimatorGeneric::willEndLiveResize()
-{
-#if ENABLE(SMOOTH_SCROLLING)
-    if (m_smoothAnimation)
-        m_smoothAnimation->updateVisibleLengths();
-#endif
-}
-
 void ScrollAnimatorGeneric::updatePosition(FloatPoint&& position)
 {
     FloatSize delta = position - m_currentPosition;
@@ -161,10 +100,8 @@
 
 void ScrollAnimatorGeneric::didAddVerticalScrollbar(Scrollbar* scrollbar)
 {
-#if ENABLE(SMOOTH_SCROLLING)
-    if (m_smoothAnimation)
-        m_smoothAnimation->updateVisibleLengths();
-#endif
+    ScrollAnimator::didAddVerticalScrollbar(scrollbar);
+
     if (!scrollbar->isOverlayScrollbar())
         return;
     m_verticalOverlayScrollbar = scrollbar;
@@ -176,10 +113,8 @@
 
 void ScrollAnimatorGeneric::didAddHorizontalScrollbar(Scrollbar* scrollbar)
 {
-#if ENABLE(SMOOTH_SCROLLING)
-    if (m_smoothAnimation)
-        m_smoothAnimation->updateVisibleLengths();
-#endif
+    ScrollAnimator::didAddHorizontalScrollbar(scrollbar);
+
     if (!scrollbar->isOverlayScrollbar())
         return;
     m_horizontalOverlayScrollbar = scrollbar;

Modified: trunk/Source/WebCore/platform/generic/ScrollAnimatorGeneric.h (276298 => 276299)


--- trunk/Source/WebCore/platform/generic/ScrollAnimatorGeneric.h	2021-04-20 10:25:08 UTC (rev 276298)
+++ trunk/Source/WebCore/platform/generic/ScrollAnimatorGeneric.h	2021-04-20 10:54:38 UTC (rev 276299)
@@ -44,11 +44,7 @@
     virtual ~ScrollAnimatorGeneric();
 
 private:
-#if ENABLE(SMOOTH_SCROLLING)
-    bool scroll(ScrollbarOrientation, ScrollGranularity, float step, float multiplier, ScrollBehavior) override;
-#endif
     bool scrollToPositionWithoutAnimation(const FloatPoint&, ScrollClamping) override;
-    void willEndLiveResize() override;
 
     bool handleWheelEvent(const PlatformWheelEvent&) override;
 
@@ -72,11 +68,6 @@
     void hideOverlayScrollbars();
     void updateOverlayScrollbarsOpacity();
 
-#if ENABLE(SMOOTH_SCROLLING)
-    void ensureSmoothScrollingAnimation();
-
-    std::unique_ptr<ScrollAnimation> m_smoothAnimation;
-#endif
     std::unique_ptr<ScrollAnimationKinetic> m_kineticAnimation;
     Scrollbar* m_horizontalOverlayScrollbar { nullptr };
     Scrollbar* m_verticalOverlayScrollbar { nullptr };
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to