Title: [283548] trunk/Source/WebCore
Revision
283548
Author
[email protected]
Date
2021-10-05 06:57:34 -0700 (Tue, 05 Oct 2021)

Log Message

[GTK][WPE] REGRESSION: Async scrolling jumps to the top of the page until keyboard-initiated paging
https://bugs.webkit.org/show_bug.cgi?id=230953

Reviewed by Martin Robinson.

Update the non-Mac/iOS async scrolling path to work correctly after the
scrolling refactor. Trying to summarise, this implements
ScrollingEffectsController in ScrollingTreeScrollingNodeDelegateNicosia
and moves smooth and kinetic scrolling animations to
ScrollingEffectsController, to be shared by both sync and async paths.

No new tests, covered by existing tests (hopefully).

* PlatformPlayStation.cmake:
* SourcesGTK.txt:
* SourcesWPE.txt:
* page/scrolling/ScrollingTreeScrollingNode.h:
* page/scrolling/nicosia/ScrollingTreeFrameScrollingNodeNicosia.cpp:
(WebCore::ScrollingTreeFrameScrollingNodeNicosia::commitStateBeforeChildren):
(WebCore::ScrollingTreeFrameScrollingNodeNicosia::commitStateAfterChildren):
* page/scrolling/nicosia/ScrollingTreeOverflowScrollingNodeNicosia.cpp:
(WebCore::ScrollingTreeOverflowScrollingNodeNicosia::commitStateAfterChildren):
* page/scrolling/nicosia/ScrollingTreeScrollingNodeDelegateNicosia.cpp:
(WebCore::ScrollingTreeScrollingNodeDelegateNicosia::ScrollingTreeScrollingNodeDelegateNicosia):
(WebCore::ScrollingTreeScrollingNodeDelegateNicosia::updateFromStateNode):
(WebCore::ScrollingTreeScrollingNodeDelegateNicosia::updateVisibleLengths):
(WebCore::ScrollingTreeScrollingNodeDelegateNicosia::handleWheelEvent):
(WebCore::ScrollingTreeScrollingNodeDelegateNicosia::stopScrollAnimations):
(WebCore::ScrollingTreeScrollingNodeDelegateNicosia::animationTimerFired):
(WebCore::ScrollingTreeScrollingNodeDelegateNicosia::createTimer):
(WebCore::ScrollingTreeScrollingNodeDelegateNicosia::startAnimationCallback):
(WebCore::ScrollingTreeScrollingNodeDelegateNicosia::stopAnimationCallback):
(WebCore::ScrollingTreeScrollingNodeDelegateNicosia::allowsHorizontalScrolling const):
(WebCore::ScrollingTreeScrollingNodeDelegateNicosia::allowsVerticalScrolling const):
(WebCore::ScrollingTreeScrollingNodeDelegateNicosia::immediateScrollBy):
(WebCore::ScrollingTreeScrollingNodeDelegateNicosia::adjustScrollPositionToBoundsIfNecessary):
(WebCore::ScrollingTreeScrollingNodeDelegateNicosia::scrollOffset const):
(WebCore::ScrollingTreeScrollingNodeDelegateNicosia::willStartScrollSnapAnimation):
(WebCore::ScrollingTreeScrollingNodeDelegateNicosia::didStopScrollSnapAnimation):
(WebCore::ScrollingTreeScrollingNodeDelegateNicosia::pageScaleFactor const):
(WebCore::ScrollingTreeScrollingNodeDelegateNicosia::scrollExtents const):
(WebCore::ScrollingTreeScrollingNodeDelegateNicosia::resetCurrentPosition): Deleted.
(WebCore::ScrollingTreeScrollingNodeDelegateNicosia::ensureScrollAnimationKinetic): Deleted.
(WebCore::ScrollingTreeScrollingNodeDelegateNicosia::ensureScrollAnimationSmooth): Deleted.
(WebCore::ScrollingTreeScrollingNodeDelegateNicosia::pageScaleFactor): Deleted.
(WebCore::ScrollingTreeScrollingNodeDelegateNicosia::scrollAnimationDidUpdate): Deleted.
(WebCore::ScrollingTreeScrollingNodeDelegateNicosia::scrollAnimationDidEnd): Deleted.
(WebCore::ScrollingTreeScrollingNodeDelegateNicosia::scrollExtentsForAnimation): Deleted.
(WebCore::ScrollingTreeScrollingNodeDelegateNicosia::startTimerIfNecessary): Deleted.
* page/scrolling/nicosia/ScrollingTreeScrollingNodeDelegateNicosia.h:
* platform/ScrollAnimationKinetic.h:
* platform/ScrollAnimationSmooth.h:
* platform/ScrollAnimator.cpp:
(WebCore::ScrollAnimator::retargetRunningAnimation):
(WebCore::ScrollAnimator::handleWheelEvent):
(WebCore::ScrollAnimator::scrollAnimationEnabled const):
* platform/ScrollAnimator.h:
* platform/ScrollingEffectsController.cpp:
(WebCore::ScrollingEffectsController::retargetAnimatedScroll):
(WebCore::ScrollingEffectsController::processWheelEventForKineticScrolling):
(WebCore::ScrollingEffectsController::handleWheelEvent):
(WebCore::ScrollingEffectsController::regargetAnimatedScroll): Deleted.
* platform/ScrollingEffectsController.h:
(WebCore::ScrollingEffectsControllerClient::scrollAnimationEnabled const):
* platform/generic/ScrollAnimatorGeneric.cpp: Removed.
(WebCore::ScrollAnimator::create): Deleted.
(WebCore::ScrollAnimatorGeneric::ScrollAnimatorGeneric): Deleted.
(WebCore::ScrollAnimatorGeneric::handleWheelEvent): Deleted.
* platform/generic/ScrollAnimatorGeneric.h: Removed.
(): Deleted.

Modified Paths

Removed Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (283547 => 283548)


--- trunk/Source/WebCore/ChangeLog	2021-10-05 13:54:20 UTC (rev 283547)
+++ trunk/Source/WebCore/ChangeLog	2021-10-05 13:57:34 UTC (rev 283548)
@@ -1,3 +1,76 @@
+2021-10-05  Chris Lord  <[email protected]>
+
+        [GTK][WPE] REGRESSION: Async scrolling jumps to the top of the page until keyboard-initiated paging
+        https://bugs.webkit.org/show_bug.cgi?id=230953
+
+        Reviewed by Martin Robinson.
+
+        Update the non-Mac/iOS async scrolling path to work correctly after the
+        scrolling refactor. Trying to summarise, this implements
+        ScrollingEffectsController in ScrollingTreeScrollingNodeDelegateNicosia
+        and moves smooth and kinetic scrolling animations to
+        ScrollingEffectsController, to be shared by both sync and async paths.
+
+        No new tests, covered by existing tests (hopefully).
+
+        * PlatformPlayStation.cmake:
+        * SourcesGTK.txt:
+        * SourcesWPE.txt:
+        * page/scrolling/ScrollingTreeScrollingNode.h:
+        * page/scrolling/nicosia/ScrollingTreeFrameScrollingNodeNicosia.cpp:
+        (WebCore::ScrollingTreeFrameScrollingNodeNicosia::commitStateBeforeChildren):
+        (WebCore::ScrollingTreeFrameScrollingNodeNicosia::commitStateAfterChildren):
+        * page/scrolling/nicosia/ScrollingTreeOverflowScrollingNodeNicosia.cpp:
+        (WebCore::ScrollingTreeOverflowScrollingNodeNicosia::commitStateAfterChildren):
+        * page/scrolling/nicosia/ScrollingTreeScrollingNodeDelegateNicosia.cpp:
+        (WebCore::ScrollingTreeScrollingNodeDelegateNicosia::ScrollingTreeScrollingNodeDelegateNicosia):
+        (WebCore::ScrollingTreeScrollingNodeDelegateNicosia::updateFromStateNode):
+        (WebCore::ScrollingTreeScrollingNodeDelegateNicosia::updateVisibleLengths):
+        (WebCore::ScrollingTreeScrollingNodeDelegateNicosia::handleWheelEvent):
+        (WebCore::ScrollingTreeScrollingNodeDelegateNicosia::stopScrollAnimations):
+        (WebCore::ScrollingTreeScrollingNodeDelegateNicosia::animationTimerFired):
+        (WebCore::ScrollingTreeScrollingNodeDelegateNicosia::createTimer):
+        (WebCore::ScrollingTreeScrollingNodeDelegateNicosia::startAnimationCallback):
+        (WebCore::ScrollingTreeScrollingNodeDelegateNicosia::stopAnimationCallback):
+        (WebCore::ScrollingTreeScrollingNodeDelegateNicosia::allowsHorizontalScrolling const):
+        (WebCore::ScrollingTreeScrollingNodeDelegateNicosia::allowsVerticalScrolling const):
+        (WebCore::ScrollingTreeScrollingNodeDelegateNicosia::immediateScrollBy):
+        (WebCore::ScrollingTreeScrollingNodeDelegateNicosia::adjustScrollPositionToBoundsIfNecessary):
+        (WebCore::ScrollingTreeScrollingNodeDelegateNicosia::scrollOffset const):
+        (WebCore::ScrollingTreeScrollingNodeDelegateNicosia::willStartScrollSnapAnimation):
+        (WebCore::ScrollingTreeScrollingNodeDelegateNicosia::didStopScrollSnapAnimation):
+        (WebCore::ScrollingTreeScrollingNodeDelegateNicosia::pageScaleFactor const):
+        (WebCore::ScrollingTreeScrollingNodeDelegateNicosia::scrollExtents const):
+        (WebCore::ScrollingTreeScrollingNodeDelegateNicosia::resetCurrentPosition): Deleted.
+        (WebCore::ScrollingTreeScrollingNodeDelegateNicosia::ensureScrollAnimationKinetic): Deleted.
+        (WebCore::ScrollingTreeScrollingNodeDelegateNicosia::ensureScrollAnimationSmooth): Deleted.
+        (WebCore::ScrollingTreeScrollingNodeDelegateNicosia::pageScaleFactor): Deleted.
+        (WebCore::ScrollingTreeScrollingNodeDelegateNicosia::scrollAnimationDidUpdate): Deleted.
+        (WebCore::ScrollingTreeScrollingNodeDelegateNicosia::scrollAnimationDidEnd): Deleted.
+        (WebCore::ScrollingTreeScrollingNodeDelegateNicosia::scrollExtentsForAnimation): Deleted.
+        (WebCore::ScrollingTreeScrollingNodeDelegateNicosia::startTimerIfNecessary): Deleted.
+        * page/scrolling/nicosia/ScrollingTreeScrollingNodeDelegateNicosia.h:
+        * platform/ScrollAnimationKinetic.h:
+        * platform/ScrollAnimationSmooth.h:
+        * platform/ScrollAnimator.cpp:
+        (WebCore::ScrollAnimator::retargetRunningAnimation):
+        (WebCore::ScrollAnimator::handleWheelEvent):
+        (WebCore::ScrollAnimator::scrollAnimationEnabled const):
+        * platform/ScrollAnimator.h:
+        * platform/ScrollingEffectsController.cpp:
+        (WebCore::ScrollingEffectsController::retargetAnimatedScroll):
+        (WebCore::ScrollingEffectsController::processWheelEventForKineticScrolling):
+        (WebCore::ScrollingEffectsController::handleWheelEvent):
+        (WebCore::ScrollingEffectsController::regargetAnimatedScroll): Deleted.
+        * platform/ScrollingEffectsController.h:
+        (WebCore::ScrollingEffectsControllerClient::scrollAnimationEnabled const):
+        * platform/generic/ScrollAnimatorGeneric.cpp: Removed.
+        (WebCore::ScrollAnimator::create): Deleted.
+        (WebCore::ScrollAnimatorGeneric::ScrollAnimatorGeneric): Deleted.
+        (WebCore::ScrollAnimatorGeneric::handleWheelEvent): Deleted.
+        * platform/generic/ScrollAnimatorGeneric.h: Removed.
+        (): Deleted.
+
 2021-10-05  Antti Koivisto  <[email protected]>
 
         [LFC][Integration] Split BoxIterator into a base class and LeafBoxIterator

Modified: trunk/Source/WebCore/PlatformPlayStation.cmake (283547 => 283548)


--- trunk/Source/WebCore/PlatformPlayStation.cmake	2021-10-05 13:54:20 UTC (rev 283547)
+++ trunk/Source/WebCore/PlatformPlayStation.cmake	2021-10-05 13:57:34 UTC (rev 283548)
@@ -36,7 +36,6 @@
 
     platform/generic/KeyedDecoderGeneric.cpp
     platform/generic/KeyedEncoderGeneric.cpp
-    platform/generic/ScrollAnimatorGeneric.cpp
 
     platform/graphics/GLContext.cpp
     platform/graphics/PlatformDisplay.cpp

Modified: trunk/Source/WebCore/SourcesGTK.txt (283547 => 283548)


--- trunk/Source/WebCore/SourcesGTK.txt	2021-10-05 13:54:20 UTC (rev 283547)
+++ trunk/Source/WebCore/SourcesGTK.txt	2021-10-05 13:57:34 UTC (rev 283548)
@@ -79,7 +79,6 @@
 platform/gamepad/manette/ManetteGamepad.cpp
 platform/gamepad/manette/ManetteGamepadProvider.cpp
 
-platform/generic/ScrollAnimatorGeneric.cpp
 platform/generic/ScrollbarsControllerGeneric.cpp
 
 platform/graphics/ANGLEWebKitBridge.cpp

Modified: trunk/Source/WebCore/SourcesWPE.txt (283547 => 283548)


--- trunk/Source/WebCore/SourcesWPE.txt	2021-10-05 13:54:20 UTC (rev 283547)
+++ trunk/Source/WebCore/SourcesWPE.txt	2021-10-05 13:57:34 UTC (rev 283548)
@@ -63,7 +63,6 @@
 platform/adwaita/ScrollbarThemeAdwaita.cpp
 platform/adwaita/ThemeAdwaita.cpp
 
-platform/generic/ScrollAnimatorGeneric.cpp
 platform/generic/ScrollbarsControllerGeneric.cpp
 
 platform/graphics/ANGLEWebKitBridge.cpp

Modified: trunk/Source/WebCore/page/scrolling/ScrollingTreeScrollingNode.h (283547 => 283548)


--- trunk/Source/WebCore/page/scrolling/ScrollingTreeScrollingNode.h	2021-10-05 13:54:20 UTC (rev 283547)
+++ trunk/Source/WebCore/page/scrolling/ScrollingTreeScrollingNode.h	2021-10-05 13:57:34 UTC (rev 283548)
@@ -44,6 +44,9 @@
 #if PLATFORM(MAC)
     friend class ScrollingTreeScrollingNodeDelegateMac;
 #endif
+#if USE(NICOSIA)
+    friend class ScrollingTreeScrollingNodeDelegateNicosia;
+#endif
     friend class ScrollingTree;
 
 public:

Modified: trunk/Source/WebCore/page/scrolling/nicosia/ScrollingTreeFrameScrollingNodeNicosia.cpp (283547 => 283548)


--- trunk/Source/WebCore/page/scrolling/nicosia/ScrollingTreeFrameScrollingNodeNicosia.cpp	2021-10-05 13:54:20 UTC (rev 283547)
+++ trunk/Source/WebCore/page/scrolling/nicosia/ScrollingTreeFrameScrollingNodeNicosia.cpp	2021-10-05 13:57:34 UTC (rev 283548)
@@ -82,6 +82,8 @@
         auto* layer = static_cast<Nicosia::PlatformLayer*>(scrollingStateNode.footerLayer());
         m_footerLayer = downcast<Nicosia::CompositionLayer>(layer);
     }
+
+    m_delegate.updateFromStateNode(scrollingStateNode);
 }
 
 void ScrollingTreeFrameScrollingNodeNicosia::commitStateAfterChildren(const ScrollingStateNode& stateNode)
@@ -95,7 +97,6 @@
         stopScrollAnimations();
         const auto& requestedScrollData = scrollingStateNode.requestedScrollData();
         scrollTo(requestedScrollData.scrollPosition, requestedScrollData.scrollType, requestedScrollData.clamping);
-        m_delegate.resetCurrentPosition();
     }
 }
 

Modified: trunk/Source/WebCore/page/scrolling/nicosia/ScrollingTreeOverflowScrollingNodeNicosia.cpp (283547 => 283548)


--- trunk/Source/WebCore/page/scrolling/nicosia/ScrollingTreeOverflowScrollingNodeNicosia.cpp	2021-10-05 13:54:20 UTC (rev 283547)
+++ trunk/Source/WebCore/page/scrolling/nicosia/ScrollingTreeOverflowScrollingNodeNicosia.cpp	2021-10-05 13:57:34 UTC (rev 283548)
@@ -56,7 +56,6 @@
         stopScrollAnimations();
         const auto& requestedScrollData = overflowStateNode.requestedScrollData();
         scrollTo(requestedScrollData.scrollPosition, requestedScrollData.scrollType, requestedScrollData.clamping);
-        m_delegate.resetCurrentPosition();
     }
 }
 

Modified: trunk/Source/WebCore/page/scrolling/nicosia/ScrollingTreeScrollingNodeDelegateNicosia.cpp (283547 => 283548)


--- trunk/Source/WebCore/page/scrolling/nicosia/ScrollingTreeScrollingNodeDelegateNicosia.cpp	2021-10-05 13:54:20 UTC (rev 283547)
+++ trunk/Source/WebCore/page/scrolling/nicosia/ScrollingTreeScrollingNodeDelegateNicosia.cpp	2021-10-05 13:57:34 UTC (rev 283548)
@@ -42,20 +42,25 @@
 
 ScrollingTreeScrollingNodeDelegateNicosia::ScrollingTreeScrollingNodeDelegateNicosia(ScrollingTreeScrollingNode& scrollingNode, bool scrollAnimatorEnabled)
     : ScrollingTreeScrollingNodeDelegate(scrollingNode)
+    , m_scrollController(*this)
     , m_scrollAnimatorEnabled(scrollAnimatorEnabled)
-#if ENABLE(KINETIC_SCROLLING) || ENABLE(SMOOTH_SCROLLING)
-    , m_animationTimer(RunLoop::current(), this, &ScrollingTreeScrollingNodeDelegateNicosia::animationTimerFired)
-#endif
 {
-#if ENABLE(KINETIC_SCROLLING) || ENABLE(SMOOTH_SCROLLING)
-#if USE(GLIB_EVENT_LOOP)
-    m_animationTimer.setPriority(WTF::RunLoopSourcePriority::DisplayRefreshMonitorTimer);
-#endif
-#endif    
 }
 
 ScrollingTreeScrollingNodeDelegateNicosia::~ScrollingTreeScrollingNodeDelegateNicosia() = default;
 
+void ScrollingTreeScrollingNodeDelegateNicosia::updateFromStateNode(const ScrollingStateScrollingNode& scrollingStateNode)
+{
+    if (scrollingStateNode.hasChangedProperty(ScrollingStateNode::Property::SnapOffsetsInfo))
+        m_scrollController.setSnapOffsetsInfo(scrollingStateNode.snapOffsetsInfo().convertUnits<LayoutScrollSnapOffsetsInfo>());
+
+    if (scrollingStateNode.hasChangedProperty(ScrollingStateNode::Property::CurrentHorizontalSnapOffsetIndex))
+        m_scrollController.setActiveScrollSnapIndexForAxis(ScrollEventAxis::Horizontal, scrollingStateNode.currentHorizontalSnapPointIndex());
+
+    if (scrollingStateNode.hasChangedProperty(ScrollingStateNode::Property::CurrentVerticalSnapOffsetIndex))
+        m_scrollController.setActiveScrollSnapIndexForAxis(ScrollEventAxis::Vertical, scrollingStateNode.currentVerticalSnapPointIndex());
+}
+
 std::unique_ptr<Nicosia::SceneIntegration::UpdateScope> ScrollingTreeScrollingNodeDelegateNicosia::createUpdateScope()
 {
     auto* scrollLayer = static_cast<Nicosia::PlatformLayer*>(scrollingNode().scrollContainerLayer());
@@ -67,171 +72,109 @@
     return compositionLayer.createUpdateScope();
 }
 
-void ScrollingTreeScrollingNodeDelegateNicosia::resetCurrentPosition()
+void ScrollingTreeScrollingNodeDelegateNicosia::updateVisibleLengths()
 {
-#if ENABLE(SMOOTH_SCROLLING)
-    if (m_smoothAnimation)
-        m_smoothAnimation->stop();
-#endif
+    m_scrollController.contentsSizeChanged();
 }
 
-void ScrollingTreeScrollingNodeDelegateNicosia::updateVisibleLengths()
+WheelEventHandlingResult ScrollingTreeScrollingNodeDelegateNicosia::handleWheelEvent(const PlatformWheelEvent& wheelEvent, EventTargeting eventTargeting)
 {
-#if ENABLE(SMOOTH_SCROLLING)
-    if (m_smoothAnimation)
-        m_smoothAnimation->updateScrollExtents();
-#endif
+    if (!scrollingNode().canHandleWheelEvent(wheelEvent, eventTargeting)
+        || !m_scrollController.handleWheelEvent(wheelEvent))
+        return WheelEventHandlingResult::unhandled();
+
+    return WheelEventHandlingResult::handled();
 }
 
-#if ENABLE(KINETIC_SCROLLING)
-void ScrollingTreeScrollingNodeDelegateNicosia::ensureScrollAnimationKinetic()
+void ScrollingTreeScrollingNodeDelegateNicosia::stopScrollAnimations()
 {
-    if (m_kineticAnimation)
-        return;
+    m_scrollController.stopAnimatedScroll();
+}
 
-    m_kineticAnimation = makeUnique<ScrollAnimationKinetic>(*this);
-    startTimerIfNecessary();
+void ScrollingTreeScrollingNodeDelegateNicosia::animationTimerFired()
+{
+    m_scrollController.animationCallback(MonotonicTime::now());
 }
-#endif
 
-#if ENABLE(SMOOTH_SCROLLING)
-void ScrollingTreeScrollingNodeDelegateNicosia::ensureScrollAnimationSmooth()
+std::unique_ptr<ScrollingEffectsControllerTimer> ScrollingTreeScrollingNodeDelegateNicosia::createTimer(Function<void()>&& function)
 {
-    if (m_smoothAnimation)
-        return;
-
-    m_smoothAnimation = makeUnique<ScrollAnimationSmooth>(*this);
-    startTimerIfNecessary();
+    return WTF::makeUnique<ScrollingEffectsControllerTimer>(RunLoop::current(), [function = WTFMove(function), protectedNode = Ref { scrollingNode() }] {
+        Locker locker { protectedNode->scrollingTree().treeLock() };
+        function();
+    });
 }
-#endif
 
-WheelEventHandlingResult ScrollingTreeScrollingNodeDelegateNicosia::handleWheelEvent(const PlatformWheelEvent& wheelEvent, EventTargeting eventTargeting)
+void ScrollingTreeScrollingNodeDelegateNicosia::startAnimationCallback(ScrollingEffectsController&)
 {
-    if (!scrollingNode().canHandleWheelEvent(wheelEvent, eventTargeting))
-        return WheelEventHandlingResult::unhandled();
+    if (!m_animationTimer) {
+        m_animationTimer = WTF::makeUnique<RunLoop::Timer<ScrollingTreeScrollingNodeDelegateNicosia>>(RunLoop::current(), this, &ScrollingTreeScrollingNodeDelegateNicosia::animationTimerFired);
 
-    bool canHaveHorizontalScrollbar = scrollingNode().canHaveHorizontalScrollbar();
-    bool canHaveVerticalScrollbar = scrollingNode().canHaveVerticalScrollbar();
-#if ENABLE(KINETIC_SCROLLING)
-    ensureScrollAnimationKinetic();
-    m_kineticAnimation->appendToScrollHistory(wheelEvent);
-    m_kineticAnimation->stop();
-    if (wheelEvent.isEndOfNonMomentumScroll()) {
-        m_kineticAnimation->startAnimatedScrollWithInitialVelocity(currentScrollPosition(), m_kineticAnimation->computeVelocity(), canHaveHorizontalScrollbar, canHaveVerticalScrollbar);
-        m_kineticAnimation->clearScrollHistory();
-        return WheelEventHandlingResult::handled();
-    }
-    if (wheelEvent.isTransitioningToMomentumScroll()) {
-        m_kineticAnimation->startAnimatedScrollWithInitialVelocity(currentScrollPosition(), wheelEvent.swipeVelocity(), canHaveHorizontalScrollbar, canHaveVerticalScrollbar);
-        m_kineticAnimation->clearScrollHistory();
-        return WheelEventHandlingResult::handled();
-    }
+#if USE(GLIB_EVENT_LOOP)
+        m_animationTimer->setPriority(WTF::RunLoopSourcePriority::DisplayRefreshMonitorTimer);
 #endif
-
-    // FIXME: This needs to share code with ScrollAnimator::handleWheelEvent(), perhaps by moving code into ScrollingEffectsController::handleWheelEvent().
-    float deltaX = canHaveHorizontalScrollbar ? wheelEvent.deltaX() : 0;
-    float deltaY = canHaveVerticalScrollbar ? wheelEvent.deltaY() : 0;
-    if ((deltaX < 0 && currentScrollPosition().x() >= maximumScrollPosition().x())
-        || (deltaX > 0 && currentScrollPosition().x() <= minimumScrollPosition().x()))
-        deltaX = 0;
-    if ((deltaY < 0 && currentScrollPosition().y() >= maximumScrollPosition().y())
-        || (deltaY > 0 && currentScrollPosition().y() <= minimumScrollPosition().y()))
-        deltaY = 0;
-
-    if (!deltaX && !deltaY)
-        return WheelEventHandlingResult::unhandled();
-
-    if (wheelEvent.granularity() == ScrollByPageWheelEvent) {
-        if (deltaX) {
-            bool negative = deltaX < 0;
-            deltaX = Scrollbar::pageStepDelta(scrollableAreaSize().width());
-            if (negative)
-                deltaX = -deltaX;
-        }
-        if (deltaY) {
-            bool negative = deltaY < 0;
-            deltaY = Scrollbar::pageStepDelta(scrollableAreaSize().height());
-            if (negative)
-                deltaY = -deltaY;
-        }
     }
 
-    deltaX = -deltaX;
-    deltaY = -deltaY;
+    if (m_animationTimer->isActive())
+        return;
 
-    if (!scrollingNode().snapOffsetsInfo().isEmpty()) {
-        float scale = pageScaleFactor();
-        FloatPoint originalOffset = LayoutPoint(scrollingNode().currentScrollOffset().x() / scale, scrollingNode().currentScrollOffset().y() / scale);
-        auto newOffset = (scrollingNode().currentScrollOffset() + FloatSize(deltaX, deltaY));
-        newOffset.scale(1.0 / scale);
+    static constexpr double frameRate = 60;
+    static constexpr Seconds tickTime = 1_s / frameRate;
+    m_animationTimer->startRepeating(tickTime);
+}
 
-        auto offsetX = scrollingNode().snapOffsetsInfo().closestSnapOffset(ScrollEventAxis::Horizontal, scrollableAreaSize(), newOffset, deltaX, originalOffset.x()).first;
-        auto offsetY = scrollingNode().snapOffsetsInfo().closestSnapOffset(ScrollEventAxis::Vertical, scrollableAreaSize(), newOffset, deltaY, originalOffset.y()).first;
+void ScrollingTreeScrollingNodeDelegateNicosia::stopAnimationCallback(ScrollingEffectsController&)
+{
+    if (m_animationTimer)
+        m_animationTimer->stop();
+}
 
-        deltaX = (offsetX - originalOffset.x()) * scale;
-        deltaY = (offsetY - originalOffset.y()) * scale;
-    }
+bool ScrollingTreeScrollingNodeDelegateNicosia::allowsHorizontalScrolling() const
+{
+    return ScrollingTreeScrollingNodeDelegate::allowsHorizontalScrolling();
+}
 
-#if ENABLE(SMOOTH_SCROLLING)
-    if (m_scrollAnimatorEnabled && !wheelEvent.hasPreciseScrollingDeltas()) {
-        ensureScrollAnimationSmooth();
-        auto currentOffset = scrollingNode().currentScrollOffset();
-        auto destinationOffset = currentOffset + FloatSize { deltaX, deltaY };
-        m_smoothAnimation->startAnimatedScrollToDestination(currentOffset, destinationOffset);
-        return WheelEventHandlingResult::handled();
-    }
-#endif
+bool ScrollingTreeScrollingNodeDelegateNicosia::allowsVerticalScrolling() const
+{
+    return ScrollingTreeScrollingNodeDelegate::allowsVerticalScrolling();
+}
 
+void ScrollingTreeScrollingNodeDelegateNicosia::immediateScrollBy(const FloatSize& delta, ScrollClamping clamping)
+{
     auto updateScope = createUpdateScope();
-    scrollingNode().scrollBy({ deltaX, deltaY });
+    scrollingNode().scrollBy(delta, clamping);
+}
 
-    return WheelEventHandlingResult::handled();
+void ScrollingTreeScrollingNodeDelegateNicosia::adjustScrollPositionToBoundsIfNecessary()
+{
+    FloatPoint scrollPosition = currentScrollPosition();
+    FloatPoint constrainedPosition = scrollPosition.constrainedBetween(minimumScrollPosition(), maximumScrollPosition());
+    immediateScrollBy(constrainedPosition - scrollPosition);
 }
 
-void ScrollingTreeScrollingNodeDelegateNicosia::stopScrollAnimations()
+FloatPoint ScrollingTreeScrollingNodeDelegateNicosia::scrollOffset() const
 {
-#if ENABLE(KINETIC_SCROLLING)
-    if (m_kineticAnimation) {
-        m_kineticAnimation->stop();
-        m_kineticAnimation->clearScrollHistory();
-    }
-#endif
-#if ENABLE(SMOOTH_SCROLLING)
-    if (m_smoothAnimation)
-        m_smoothAnimation->stop();
-#endif
-#if ENABLE(KINETIC_SCROLLING) || ENABLE(SMOOTH_SCROLLING)
-    m_animationTimer.stop();
-#endif
+    return ScrollableArea::scrollOffsetFromPosition(currentScrollPosition(), scrollOrigin());
 }
 
-float ScrollingTreeScrollingNodeDelegateNicosia::pageScaleFactor()
+void ScrollingTreeScrollingNodeDelegateNicosia::willStartScrollSnapAnimation()
 {
-    // FIXME: What should this return for non-root frames, and overflow?
-    // Also, this should not have to access ScrollingTreeFrameScrollingNode.
-    return is<ScrollingTreeFrameScrollingNode>(scrollingNode()) ?
-        downcast<ScrollingTreeFrameScrollingNode>(scrollingNode()).frameScaleFactor() : 1.;
+    scrollingNode().setScrollSnapInProgress(true);
 }
 
-void ScrollingTreeScrollingNodeDelegateNicosia::scrollAnimationDidUpdate(ScrollAnimation& animation, const FloatPoint& offset)
+void ScrollingTreeScrollingNodeDelegateNicosia::didStopScrollSnapAnimation()
 {
-#if ENABLE(SMOOTH_SCROLLING)
-    if (&animation == m_kineticAnimation.get()) {
-        if (m_smoothAnimation)
-            m_smoothAnimation->stop();
-    }
-#endif
-    auto updateScope = createUpdateScope();
-
-    // FIXME: Need to convert an offset to a position.
-    scrollingNode().scrollTo(offset);
+    scrollingNode().setScrollSnapInProgress(false);
 }
 
-void ScrollingTreeScrollingNodeDelegateNicosia::scrollAnimationDidEnd(ScrollAnimation&)
+float ScrollingTreeScrollingNodeDelegateNicosia::pageScaleFactor() const
 {
+    // FIXME: What should this return for non-root frames, and overflow?
+    // Also, this should not have to access ScrollingTreeFrameScrollingNode.
+    return is<ScrollingTreeFrameScrollingNode>(scrollingNode()) ?
+        downcast<ScrollingTreeFrameScrollingNode>(scrollingNode()).frameScaleFactor() : 1.;
 }
 
-ScrollExtents ScrollingTreeScrollingNodeDelegateNicosia::scrollExtentsForAnimation(ScrollAnimation&)
+ScrollExtents ScrollingTreeScrollingNodeDelegateNicosia::scrollExtents() const
 {
     return {
         scrollingNode().totalContentsSize(),
@@ -239,35 +182,6 @@
     };
 }
 
-void ScrollingTreeScrollingNodeDelegateNicosia::startTimerIfNecessary()
-{
-#if ENABLE(KINETIC_SCROLLING) || ENABLE(SMOOTH_SCROLLING)
-    if (m_animationTimer.isActive())
-        return;
-
-    static constexpr double frameRate = 60;
-    static constexpr Seconds tickTime = 1_s / frameRate;
-    
-    m_animationTimer.startRepeating(tickTime);
-#endif
-}
-
-void ScrollingTreeScrollingNodeDelegateNicosia::animationTimerFired()
-{
-#if ENABLE(KINETIC_SCROLLING) || ENABLE(SMOOTH_SCROLLING)
-    auto now = MonotonicTime::now();
-#endif
-
-#if ENABLE(KINETIC_SCROLLING)
-    if (m_kineticAnimation)
-        m_kineticAnimation->serviceAnimation(now);
-#endif
-#if ENABLE(SMOOTH_SCROLLING)
-    if (m_smoothAnimation)
-        m_smoothAnimation->serviceAnimation(now);
-#endif    
-}
-
 } // namespace WebCore
 
 #endif // ENABLE(ASYNC_SCROLLING) && USE(NICOSIA)

Modified: trunk/Source/WebCore/page/scrolling/nicosia/ScrollingTreeScrollingNodeDelegateNicosia.h (283547 => 283548)


--- trunk/Source/WebCore/page/scrolling/nicosia/ScrollingTreeScrollingNodeDelegateNicosia.h	2021-10-05 13:54:20 UTC (rev 283547)
+++ trunk/Source/WebCore/page/scrolling/nicosia/ScrollingTreeScrollingNodeDelegateNicosia.h	2021-10-05 13:57:34 UTC (rev 283548)
@@ -32,68 +32,57 @@
 
 #include "NicosiaPlatformLayer.h"
 #include "ScrollAnimation.h"
+#include "ScrollingEffectsController.h"
 #include "ScrollingStateOverflowScrollingNode.h"
 #include "ThreadedScrollingTree.h"
-
-#if ENABLE(KINETIC_SCROLLING)
-#include "ScrollAnimationKinetic.h"
-#endif
-
-#if ENABLE(SMOOTH_SCROLLING)
-#include "ScrollAnimationSmooth.h"
-#endif
-
-#if ENABLE(KINETIC_SCROLLING) || ENABLE(SMOOTH_SCROLLING)
 #include <wtf/RunLoop.h>
-#endif
 
 namespace WebCore {
 
 // FIXME: This should not be a ScrollAnimationClient.
-class ScrollingTreeScrollingNodeDelegateNicosia : public ScrollingTreeScrollingNodeDelegate, public ScrollAnimationClient {
+class ScrollingTreeScrollingNodeDelegateNicosia : public ScrollingTreeScrollingNodeDelegate, public ScrollingEffectsControllerClient {
 public:
     explicit ScrollingTreeScrollingNodeDelegateNicosia(ScrollingTreeScrollingNode&, bool scrollAnimatorEnabled);
     virtual ~ScrollingTreeScrollingNodeDelegateNicosia();
 
+    void updateFromStateNode(const ScrollingStateScrollingNode&);
     std::unique_ptr<Nicosia::SceneIntegration::UpdateScope> createUpdateScope();
-    void resetCurrentPosition();
     void updateVisibleLengths();
     WheelEventHandlingResult handleWheelEvent(const PlatformWheelEvent&, EventTargeting);
     void stopScrollAnimations();
 
 private:
-    bool m_scrollAnimatorEnabled { false };
-    float pageScaleFactor();
+    void animationTimerFired();
 
-#if ENABLE(KINETIC_SCROLLING)
-    void ensureScrollAnimationKinetic();
-#endif
-#if ENABLE(SMOOTH_SCROLLING)
-    void ensureScrollAnimationSmooth();
-#endif
+    // ScrollingEffectsControllerClient.
+    std::unique_ptr<ScrollingEffectsControllerTimer> createTimer(Function<void()>&&) final;
 
-    void animationTimerFired();
-    void startTimerIfNecessary();
+    void startAnimationCallback(ScrollingEffectsController&) final;
+    void stopAnimationCallback(ScrollingEffectsController&) final;
 
-    // ScrollAnimationClient
-    void scrollAnimationDidUpdate(ScrollAnimation&, const FloatPoint& currentPosition) final;
-    void scrollAnimationDidEnd(ScrollAnimation&) final;
-    ScrollExtents scrollExtentsForAnimation(ScrollAnimation&) final;
+    bool allowsHorizontalScrolling() const final;
+    bool allowsVerticalScrolling() const final;
 
-    // FIXME: These animations should not live here. They need to be managed by ScrollingEffectsController,
-    // to be coordinated with other kinds of scroll animations, and be referenced by ScrollingEffectsController::m_currentAnimation.
-    
-#if ENABLE(KINETIC_SCROLLING)
-    std::unique_ptr<ScrollAnimationKinetic> m_kineticAnimation;
-#endif
-#if ENABLE(SMOOTH_SCROLLING)
-    std::unique_ptr<ScrollAnimationSmooth> m_smoothAnimation;
-#endif
+    void setScrollBehaviorStatus(ScrollBehaviorStatus status) final { m_scrollBehaviorStatus = status; }
+    ScrollBehaviorStatus scrollBehaviorStatus() const final { return m_scrollBehaviorStatus; }
 
-#if ENABLE(KINETIC_SCROLLING) || ENABLE(SMOOTH_SCROLLING)
-    // FIXME: When the above two animations are removed, this timer can be removed.
-    RunLoop::Timer<ScrollingTreeScrollingNodeDelegateNicosia> m_animationTimer;
-#endif
+    void immediateScrollBy(const FloatSize&, ScrollClamping = ScrollClamping::Clamped) final;
+
+    void adjustScrollPositionToBoundsIfNecessary() final;
+
+    FloatPoint scrollOffset() const final;
+    void willStartScrollSnapAnimation() final;
+    void didStopScrollSnapAnimation() final;
+    float pageScaleFactor() const final;
+    ScrollExtents scrollExtents() const final;
+
+    bool scrollAnimationEnabled() const final { return m_scrollAnimatorEnabled; }
+
+    ScrollingEffectsController m_scrollController;
+    std::unique_ptr<RunLoop::Timer<ScrollingTreeScrollingNodeDelegateNicosia>> m_animationTimer;
+    ScrollBehaviorStatus m_scrollBehaviorStatus { ScrollBehaviorStatus::NotInAnimation };
+
+    bool m_scrollAnimatorEnabled { false };
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/platform/ScrollAnimationKinetic.h (283547 => 283548)


--- trunk/Source/WebCore/platform/ScrollAnimationKinetic.h	2021-10-05 13:54:20 UTC (rev 283547)
+++ trunk/Source/WebCore/platform/ScrollAnimationKinetic.h	2021-10-05 13:57:34 UTC (rev 283548)
@@ -63,9 +63,6 @@
     bool startAnimatedScrollWithInitialVelocity(const FloatPoint& initialOffset, const FloatSize& velocity, bool mayHScroll, bool mayVScroll);
     bool retargetActiveAnimation(const FloatPoint& newOffset) final;
 
-    // FIXME: only public for ScrollingTreeScrollingNodeDelegateNicosia.
-    void serviceAnimation(MonotonicTime) final;
-
     void appendToScrollHistory(const PlatformWheelEvent&);
     void clearScrollHistory();
 
@@ -72,6 +69,8 @@
     FloatSize computeVelocity();
 
 private:
+    void serviceAnimation(MonotonicTime) final;
+
     std::optional<PerAxisData> m_horizontalData;
     std::optional<PerAxisData> m_verticalData;
 

Modified: trunk/Source/WebCore/platform/ScrollAnimationSmooth.h (283547 => 283548)


--- trunk/Source/WebCore/platform/ScrollAnimationSmooth.h	2021-10-05 13:54:20 UTC (rev 283547)
+++ trunk/Source/WebCore/platform/ScrollAnimationSmooth.h	2021-10-05 13:57:34 UTC (rev 283548)
@@ -41,16 +41,17 @@
     bool startAnimatedScrollToDestination(const FloatPoint& fromOffset, const FloatPoint& destinationOffset);
     bool retargetActiveAnimation(const FloatPoint& newOffset) final;
 
-    // FIXME: only public for ScrollingTreeScrollingNodeDelegateNicosia.
-    void updateScrollExtents() final;
-    void serviceAnimation(MonotonicTime) final;
+    const FloatPoint& destinationOffset() const { return m_destinationOffset; }
 
 private:
 
     bool startOrRetargetAnimation(const ScrollExtents&, const FloatPoint& destinationOffset);
-    
+
+    void updateScrollExtents() final;
+    void serviceAnimation(MonotonicTime) final;
+
     Seconds durationFromDistance(const FloatSize&) const;
-    
+
     bool animateScroll(MonotonicTime);
 
     Seconds m_duration;

Modified: trunk/Source/WebCore/platform/ScrollAnimator.cpp (283547 => 283548)


--- trunk/Source/WebCore/platform/ScrollAnimator.cpp	2021-10-05 13:54:20 UTC (rev 283547)
+++ trunk/Source/WebCore/platform/ScrollAnimator.cpp	2021-10-05 13:57:34 UTC (rev 283548)
@@ -43,7 +43,7 @@
 
 namespace WebCore {
 
-#if !ENABLE(SMOOTH_SCROLLING) && !PLATFORM(IOS_FAMILY) && !PLATFORM(MAC) && !PLATFORM(WPE)
+#if !PLATFORM(IOS_FAMILY) && !PLATFORM(MAC)
 std::unique_ptr<ScrollAnimator> ScrollAnimator::create(ScrollableArea& scrollableArea)
 {
     return makeUnique<ScrollAnimator>(scrollableArea);
@@ -127,7 +127,7 @@
 void ScrollAnimator::retargetRunningAnimation(const FloatPoint& newPosition)
 {
     ASSERT(scrollableArea().currentScrollBehaviorStatus() == ScrollBehaviorStatus::InNonNativeAnimation);
-    m_scrollController.regargetAnimatedScroll(offsetFromPosition(newPosition));
+    m_scrollController.retargetAnimatedScroll(offsetFromPosition(newPosition));
 }
 
 FloatPoint ScrollAnimator::offsetFromPosition(const FloatPoint& position) const
@@ -185,6 +185,8 @@
         return true;
 #endif
 
+#if PLATFORM(MAC)
+    // FIXME: We should be able to remove this code, but Mac's handleWheelEvent relies on this somehow.
     Scrollbar* horizontalScrollbar = m_scrollableArea.horizontalScrollbar();
     Scrollbar* verticalScrollbar = m_scrollableArea.verticalScrollbar();
 
@@ -228,6 +230,9 @@
         }
     }
     return handled;
+#else
+    return m_scrollController.handleWheelEvent(e);
+#endif
 }
 
 #if ENABLE(TOUCH_EVENTS)
@@ -406,6 +411,13 @@
 }
 #endif
 
+#if PLATFORM(GTK) || USE(NICOSIA)
+bool ScrollAnimator::scrollAnimationEnabled() const
+{
+    return m_scrollableArea.scrollAnimatorEnabled() && platformAllowsScrollAnimation();
+}
+#endif
+
 void ScrollAnimator::cancelAnimations()
 {
     m_scrollController.stopAnimatedScroll();

Modified: trunk/Source/WebCore/platform/ScrollAnimator.h (283547 => 283548)


--- trunk/Source/WebCore/platform/ScrollAnimator.h	2021-10-05 13:54:20 UTC (rev 283547)
+++ trunk/Source/WebCore/platform/ScrollAnimator.h	2021-10-05 13:57:34 UTC (rev 283548)
@@ -161,6 +161,10 @@
     void removeWheelEventTestCompletionDeferralForReason(WheelEventTestMonitor::ScrollableAreaIdentifier, WheelEventTestMonitor::DeferReason) const final;
 #endif
 
+#if PLATFORM(GTK) || USE(NICOSIA)
+    bool scrollAnimationEnabled() const final;
+#endif
+
     static FloatSize deltaFromStep(ScrollbarOrientation, float step, float multiplier);
 
 protected:

Modified: trunk/Source/WebCore/platform/ScrollingEffectsController.cpp (283547 => 283548)


--- trunk/Source/WebCore/platform/ScrollingEffectsController.cpp	2021-10-05 13:54:20 UTC (rev 283547)
+++ trunk/Source/WebCore/platform/ScrollingEffectsController.cpp	2021-10-05 13:57:34 UTC (rev 283548)
@@ -30,7 +30,6 @@
 #include "LayoutSize.h"
 #include "Logging.h"
 #include "PlatformWheelEvent.h"
-#include "ScrollAnimationKinetic.h"
 #include "ScrollAnimationMomentum.h"
 #include "ScrollAnimationSmooth.h"
 #include "ScrollableArea.h"
@@ -37,6 +36,10 @@
 #include "WheelEventTestMonitor.h"
 #include <wtf/text/TextStream.h>
 
+#if ENABLE(KINETIC_SCROLLING) && !PLATFORM(MAC)
+#include "ScrollAnimationKinetic.h"
+#endif
+
 namespace WebCore {
 
 ScrollingEffectsController::ScrollingEffectsController(ScrollingEffectsControllerClient& client)
@@ -99,12 +102,12 @@
     return downcast<ScrollAnimationSmooth>(*m_currentAnimation).startAnimatedScrollToDestination(startOffset, destinationOffset);
 }
 
-bool ScrollingEffectsController::regargetAnimatedScroll(FloatPoint newDestinationOffset)
+bool ScrollingEffectsController::retargetAnimatedScroll(FloatPoint newDestinationOffset)
 {
     if (!is<ScrollAnimationSmooth>(m_currentAnimation.get()))
         return false;
     
-    LOG_WITH_STREAM(ScrollAnimations, stream << "ScrollingEffectsController " << this << " regargetAnimatedScroll to " << newDestinationOffset);
+    LOG_WITH_STREAM(ScrollAnimations, stream << "ScrollingEffectsController " << this << " retargetAnimatedScroll to " << newDestinationOffset);
 
     ASSERT(m_currentAnimation->isActive());
     return downcast<ScrollAnimationSmooth>(*m_currentAnimation).retargetActiveAnimation(newDestinationOffset);
@@ -118,35 +121,6 @@
         m_currentAnimation->stop();
 }
 
-bool ScrollingEffectsController::processWheelEventForKineticScrolling(const PlatformWheelEvent& event)
-{
-#if ENABLE(KINETIC_SCROLLING)
-    if (m_currentAnimation && !is<ScrollAnimationKinetic>(m_currentAnimation.get())) {
-        m_currentAnimation->stop();
-        m_currentAnimation = nullptr;
-    }
-
-    if (!m_currentAnimation)
-        m_currentAnimation = makeUnique<ScrollAnimationKinetic>(*this);
-
-    auto& kineticAnimation = downcast<ScrollAnimationKinetic>(*m_currentAnimation);
-    kineticAnimation.appendToScrollHistory(event);
-
-    if (event.isEndOfNonMomentumScroll()) {
-        kineticAnimation.startAnimatedScrollWithInitialVelocity(m_client.scrollOffset(), kineticAnimation.computeVelocity(), m_client.allowsHorizontalScrolling(), m_client.allowsVerticalScrolling());
-        return true;
-    }
-    if (event.isTransitioningToMomentumScroll()) {
-        kineticAnimation.clearScrollHistory();
-        kineticAnimation.startAnimatedScrollWithInitialVelocity(m_client.scrollOffset(), event.swipeVelocity(), m_client.allowsHorizontalScrolling(), m_client.allowsVerticalScrolling());
-        return true;
-    }
-#else
-    UNUSED_PARAM(event);
-#endif
-    return false;
-}
-
 bool ScrollingEffectsController::startMomentumScrollWithInitialVelocity(const FloatPoint& initialOffset, const FloatSize& initialVelocity, const FloatSize& initialDelta, const Function<FloatPoint(const FloatPoint&)>& destinationModifier)
 {
     if (m_currentAnimation) {
@@ -249,6 +223,121 @@
     return m_scrollSnapState->adjustedScrollDestination(axis, destinationOffset, velocity, originalOffset, m_client.scrollExtents(), m_client.pageScaleFactor());
 }
 
+#if !PLATFORM(MAC)
+#if ENABLE(KINETIC_SCROLLING)
+bool ScrollingEffectsController::processWheelEventForKineticScrolling(const PlatformWheelEvent& event)
+{
+    if (is<ScrollAnimationKinetic>(m_currentAnimation.get()))
+        m_currentAnimation->stop();
+
+    if (!event.hasPreciseScrollingDeltas()) {
+        m_scrollHistory.clear();
+        return false;
+    }
+
+    m_scrollHistory.append(event);
+
+    if (!event.isEndOfNonMomentumScroll() && !event.isTransitioningToMomentumScroll())
+        return false;
+
+    if (m_currentAnimation && !is<ScrollAnimationKinetic>(m_currentAnimation.get())) {
+        m_currentAnimation->stop();
+        m_currentAnimation = nullptr;
+    }
+
+    if (!m_currentAnimation)
+        m_currentAnimation = makeUnique<ScrollAnimationKinetic>(*this);
+
+    auto& kineticAnimation = downcast<ScrollAnimationKinetic>(*m_currentAnimation);
+    while (!m_scrollHistory.isEmpty())
+        kineticAnimation.appendToScrollHistory(m_scrollHistory.takeFirst());
+
+    if (event.isEndOfNonMomentumScroll()) {
+        kineticAnimation.startAnimatedScrollWithInitialVelocity(m_client.scrollOffset(), kineticAnimation.computeVelocity(), m_client.allowsHorizontalScrolling(), m_client.allowsVerticalScrolling());
+        return true;
+    }
+    if (event.isTransitioningToMomentumScroll()) {
+        kineticAnimation.clearScrollHistory();
+        kineticAnimation.startAnimatedScrollWithInitialVelocity(m_client.scrollOffset(), event.swipeVelocity(), m_client.allowsHorizontalScrolling(), m_client.allowsVerticalScrolling());
+        return true;
+    }
+
+    ASSERT_NOT_REACHED();
+    return false;
+}
+#endif
+
+bool ScrollingEffectsController::handleWheelEvent(const PlatformWheelEvent& wheelEvent)
+{
+#if ENABLE(KINETIC_SCROLLING)
+    if (processWheelEventForKineticScrolling(wheelEvent))
+        return true;
+#endif
+
+    auto scrollOffset = m_client.scrollOffset();
+    float deltaX = m_client.allowsHorizontalScrolling() ? wheelEvent.deltaX() : 0;
+    float deltaY = m_client.allowsVerticalScrolling() ? wheelEvent.deltaY() : 0;
+    auto extents = m_client.scrollExtents();
+    auto minPosition = extents.minimumScrollOffset();
+    auto maxPosition = extents.maximumScrollOffset();
+
+    if ((deltaX < 0 && scrollOffset.x() >= maxPosition.x())
+        || (deltaX > 0 && scrollOffset.x() <= minPosition.x()))
+        deltaX = 0;
+    if ((deltaY < 0 && scrollOffset.y() >= maxPosition.y())
+        || (deltaY > 0 && scrollOffset.y() <= minPosition.y()))
+        deltaY = 0;
+
+    if (!deltaX && !deltaY)
+        return false;
+
+    if (wheelEvent.granularity() == ScrollByPageWheelEvent) {
+        if (deltaX) {
+            bool negative = deltaX < 0;
+            deltaX = Scrollbar::pageStepDelta(extents.contentsSize.width());
+            if (negative)
+                deltaX = -deltaX;
+        }
+        if (deltaY) {
+            bool negative = deltaY < 0;
+            deltaY = Scrollbar::pageStepDelta(extents.contentsSize.height());
+            if (negative)
+                deltaY = -deltaY;
+        }
+    }
+
+    deltaX = -deltaX;
+    deltaY = -deltaY;
+
+    if (snapOffsetsInfo() && !snapOffsetsInfo()->isEmpty()) {
+        float scale = m_client.pageScaleFactor();
+        auto originalOffset = LayoutPoint(scrollOffset.x() / scale, scrollOffset.y() / scale);
+        auto newOffset = LayoutPoint((scrollOffset.x() + deltaX) / scale, (scrollOffset.y() + deltaY) / scale);
+
+        auto offsetX = snapOffsetsInfo()->closestSnapOffset(ScrollEventAxis::Horizontal, LayoutSize(extents.contentsSize), newOffset, deltaX, originalOffset.x()).first;
+        auto offsetY = snapOffsetsInfo()->closestSnapOffset(ScrollEventAxis::Vertical, LayoutSize(extents.contentsSize), newOffset, deltaY, originalOffset.y()).first;
+
+        deltaX = (offsetX - originalOffset.x()) * scale;
+        deltaY = (offsetY - originalOffset.y()) * scale;
+    }
+
+#if ENABLE(SMOOTH_SCROLLING)
+    if (m_client.scrollAnimationEnabled() && !wheelEvent.hasPreciseScrollingDeltas()) {
+        if (is<ScrollAnimationSmooth>(m_currentAnimation.get())) {
+            auto lastDestinationOffset = downcast<ScrollAnimationSmooth>(*m_currentAnimation).destinationOffset();
+            retargetAnimatedScroll(lastDestinationOffset + FloatSize { deltaX, deltaY });
+        } else
+            startAnimatedScrollToDestination(scrollOffset, scrollOffset + FloatSize { deltaX, deltaY });
+        return true;
+    }
+#endif
+
+    m_client.immediateScrollBy({ deltaX, deltaY });
+
+    return true;
+}
+#endif
+
 void ScrollingEffectsController::updateActiveScrollSnapIndexForClientOffset()
 {
     if (!usesScrollSnap())

Modified: trunk/Source/WebCore/platform/ScrollingEffectsController.h (283547 => 283548)


--- trunk/Source/WebCore/platform/ScrollingEffectsController.h	2021-10-05 13:54:20 UTC (rev 283547)
+++ trunk/Source/WebCore/platform/ScrollingEffectsController.h	2021-10-05 13:57:34 UTC (rev 283548)
@@ -34,6 +34,7 @@
 #include "ScrollSnapOffsetsInfo.h"
 #include "ScrollTypes.h"
 #include "WheelEventTestMonitor.h"
+#include <wtf/Deque.h>
 #include <wtf/Noncopyable.h>
 #include <wtf/RunLoop.h>
 
@@ -116,6 +117,7 @@
     virtual void didStopScrollSnapAnimation() { }
     virtual float pageScaleFactor() const = 0;
     virtual ScrollExtents scrollExtents() const = 0;
+    virtual bool scrollAnimationEnabled() const { return true; }
 };
 
 class ScrollingEffectsController : public ScrollAnimationClient {
@@ -130,12 +132,9 @@
     void scrollPositionChanged();
 
     bool startAnimatedScrollToDestination(FloatPoint startOffset, FloatPoint destinationOffset);
-    bool regargetAnimatedScroll(FloatPoint newDestinationOffset);
+    bool retargetAnimatedScroll(FloatPoint newDestinationOffset);
     void stopAnimatedScroll();
 
-    // FIXME: Hack for ScrollAnimatorGeneric. Needs cleanup.
-    bool processWheelEventForKineticScrolling(const PlatformWheelEvent&);
-
     bool startMomentumScrollWithInitialVelocity(const FloatPoint& initialOffset, const FloatSize& initialVelocity, const FloatSize& initialDelta, const WTF::Function<FloatPoint(const FloatPoint&)>& destinationModifier);
 
     void beginKeyboardScrolling();
@@ -161,10 +160,10 @@
     // FIXME: This is never called. We never set m_activeScrollSnapIndexDidChange back to false.
     void setScrollSnapIndexDidChange(bool state) { m_activeScrollSnapIndexDidChange = state; }
 
-#if PLATFORM(MAC)
     // Returns true if handled.
     bool handleWheelEvent(const PlatformWheelEvent&);
 
+#if PLATFORM(MAC)
     static FloatSize wheelDeltaBiasingTowardsVertical(const PlatformWheelEvent&);
 
     bool isScrollSnapInProgress() const;
@@ -215,8 +214,15 @@
     void scrollAnimationDidUpdate(ScrollAnimation&, const FloatPoint& /* currentOffset */) final;
     void scrollAnimationWillStart(ScrollAnimation&) final;
     void scrollAnimationDidEnd(ScrollAnimation&) final;
-    ScrollExtents scrollExtentsForAnimation(ScrollAnimation&)  final;
+    ScrollExtents scrollExtentsForAnimation(ScrollAnimation&) final;
 
+#if ENABLE(KINETIC_SCROLLING) && !PLATFORM(MAC)
+    // Returns true if handled.
+    bool processWheelEventForKineticScrolling(const PlatformWheelEvent&);
+
+    Deque<PlatformWheelEvent> m_scrollHistory;
+#endif
+
     ScrollingEffectsControllerClient& m_client;
 
     std::unique_ptr<ScrollAnimation> m_currentAnimation;

Deleted: trunk/Source/WebCore/platform/generic/ScrollAnimatorGeneric.cpp (283547 => 283548)


--- trunk/Source/WebCore/platform/generic/ScrollAnimatorGeneric.cpp	2021-10-05 13:54:20 UTC (rev 283547)
+++ trunk/Source/WebCore/platform/generic/ScrollAnimatorGeneric.cpp	2021-10-05 13:57:34 UTC (rev 283548)
@@ -1,59 +0,0 @@
-/*
- * Copyright (c) 2016 Igalia S.L.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- *     * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *     * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- *     * Neither the name of Google Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "config.h"
-#include "ScrollAnimatorGeneric.h"
-
-#include "ScrollableArea.h"
-
-namespace WebCore {
-
-std::unique_ptr<ScrollAnimator> ScrollAnimator::create(ScrollableArea& scrollableArea)
-{
-    return makeUnique<ScrollAnimatorGeneric>(scrollableArea);
-}
-
-ScrollAnimatorGeneric::ScrollAnimatorGeneric(ScrollableArea& scrollableArea)
-    : ScrollAnimator(scrollableArea)
-{
-}
-
-ScrollAnimatorGeneric::~ScrollAnimatorGeneric() = default;
-
-// FIXME: Push this into the base class so that ScrollAnimatorGeneric can be removed.
-bool ScrollAnimatorGeneric::handleWheelEvent(const PlatformWheelEvent& event)
-{
-    if (m_scrollController.processWheelEventForKineticScrolling(event))
-        return true;
-
-    return ScrollAnimator::handleWheelEvent(event);
-}
-
-} // namespace WebCore

Deleted: trunk/Source/WebCore/platform/generic/ScrollAnimatorGeneric.h (283547 => 283548)


--- trunk/Source/WebCore/platform/generic/ScrollAnimatorGeneric.h	2021-10-05 13:54:20 UTC (rev 283547)
+++ trunk/Source/WebCore/platform/generic/ScrollAnimatorGeneric.h	2021-10-05 13:57:34 UTC (rev 283548)
@@ -1,47 +0,0 @@
-/*
- * Copyright (c) 2016 Igalia S.L.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- *     * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *     * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- *     * Neither the name of Google Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#pragma once
-
-#include "ScrollAnimator.h"
-
-namespace WebCore {
-
-class ScrollAnimation;
-
-class ScrollAnimatorGeneric final : public ScrollAnimator {
-public:
-    explicit ScrollAnimatorGeneric(ScrollableArea&);
-    virtual ~ScrollAnimatorGeneric();
-
-    bool handleWheelEvent(const PlatformWheelEvent&) final;
-};
-
-} // namespace WebCore
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to