Title: [273885] trunk/Source/WebCore
Revision
273885
Author
commit-qu...@webkit.org
Date
2021-03-04 05:22:14 -0800 (Thu, 04 Mar 2021)

Log Message

[Nicosia] Move shared scrolling animation code into a ScrollingTreeScrollingNodeDelegate
https://bugs.webkit.org/show_bug.cgi?id=222714

Patch by Martin Robinson <mrobin...@igalia.com> on 2021-03-04
Reviewed by Žan Doberšek.

No new tests. This should not change behavior.

* PlatformMac.cmake: Remove delegate parent class from Mac-specific list.
* PlatformPlayStation.cmake: Added new class to source list.
* Sources.txt: Added delegate parent class to shared source list.
* SourcesGTK.txt: Added new class.
* SourcesWPE.txt: Ditto.
* WebCore.xcodeproj/project.pbxproj: Remove source file from project, since
it is now in Sources.txt.
* page/scrolling/ScrollingTreeScrollingNodeDelegate.cpp: Changed import to include.
* page/scrolling/nicosia/ScrollingTreeFrameScrollingNodeNicosia.cpp:
Moved shared code to ScrollingTreeScrollingNodeDelegate.
* page/scrolling/nicosia/ScrollingTreeFrameScrollingNodeNicosia.h: Ditto.
* page/scrolling/nicosia/ScrollingTreeOverflowScrollingNodeNicosia.cpp: Ditto.
* page/scrolling/nicosia/ScrollingTreeOverflowScrollingNodeNicosia.h: Dito.
* page/scrolling/nicosia/ScrollingTreeScrollingNodeDelegateNicosia.cpp: Added
shared code from ScrollingTreeFrameScrollingNodeNicosia and ScrollingTreeOverflowScrollingNodeNicosia
* page/scrolling/nicosia/ScrollingTreeScrollingNodeDelegateNicosia.h: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (273884 => 273885)


--- trunk/Source/WebCore/ChangeLog	2021-03-04 13:18:16 UTC (rev 273884)
+++ trunk/Source/WebCore/ChangeLog	2021-03-04 13:22:14 UTC (rev 273885)
@@ -1,3 +1,29 @@
+2021-03-04  Martin Robinson  <mrobin...@igalia.com>
+
+        [Nicosia] Move shared scrolling animation code into a ScrollingTreeScrollingNodeDelegate
+        https://bugs.webkit.org/show_bug.cgi?id=222714
+
+        Reviewed by Žan Doberšek.
+
+        No new tests. This should not change behavior.
+
+        * PlatformMac.cmake: Remove delegate parent class from Mac-specific list.
+        * PlatformPlayStation.cmake: Added new class to source list.
+        * Sources.txt: Added delegate parent class to shared source list.
+        * SourcesGTK.txt: Added new class.
+        * SourcesWPE.txt: Ditto.
+        * WebCore.xcodeproj/project.pbxproj: Remove source file from project, since
+        it is now in Sources.txt.
+        * page/scrolling/ScrollingTreeScrollingNodeDelegate.cpp: Changed import to include.
+        * page/scrolling/nicosia/ScrollingTreeFrameScrollingNodeNicosia.cpp:
+        Moved shared code to ScrollingTreeScrollingNodeDelegate.
+        * page/scrolling/nicosia/ScrollingTreeFrameScrollingNodeNicosia.h: Ditto.
+        * page/scrolling/nicosia/ScrollingTreeOverflowScrollingNodeNicosia.cpp: Ditto.
+        * page/scrolling/nicosia/ScrollingTreeOverflowScrollingNodeNicosia.h: Dito.
+        * page/scrolling/nicosia/ScrollingTreeScrollingNodeDelegateNicosia.cpp: Added
+        shared code from ScrollingTreeFrameScrollingNodeNicosia and ScrollingTreeOverflowScrollingNodeNicosia
+        * page/scrolling/nicosia/ScrollingTreeScrollingNodeDelegateNicosia.h: Added.
+
 2021-03-04  Philippe Normand  <pnorm...@igalia.com>
 
         REGRESSION(r273644 ): [GStreamer] new webrtc failures

Modified: trunk/Source/WebCore/PlatformMac.cmake (273884 => 273885)


--- trunk/Source/WebCore/PlatformMac.cmake	2021-03-04 13:18:16 UTC (rev 273884)
+++ trunk/Source/WebCore/PlatformMac.cmake	2021-03-04 13:22:14 UTC (rev 273885)
@@ -172,8 +172,6 @@
     page/mac/TextIndicatorWindow.mm
     page/mac/WheelEventDeltaFilterMac.mm
 
-    page/scrolling/ScrollingTreeScrollingNodeDelegate.cpp
-
     page/scrolling/mac/ScrollingCoordinatorMac.mm
     page/scrolling/mac/ScrollingMomentumCalculatorMac.mm
     page/scrolling/mac/ScrollingTreeFrameScrollingNodeMac.mm

Modified: trunk/Source/WebCore/PlatformPlayStation.cmake (273884 => 273885)


--- trunk/Source/WebCore/PlatformPlayStation.cmake	2021-03-04 13:18:16 UTC (rev 273884)
+++ trunk/Source/WebCore/PlatformPlayStation.cmake	2021-03-04 13:22:14 UTC (rev 273885)
@@ -28,6 +28,7 @@
     page/scrolling/nicosia/ScrollingTreeOverflowScrollProxyNode.cpp
     page/scrolling/nicosia/ScrollingTreeOverflowScrollingNodeNicosia.cpp
     page/scrolling/nicosia/ScrollingTreePositionedNode.cpp
+    page/scrolling/nicosia/ScrollingTreeScrollingNodeDelegateNicosia.cpp
     page/scrolling/nicosia/ScrollingTreeStickyNode.cpp
 
     platform/ScrollAnimationKinetic.cpp

Modified: trunk/Source/WebCore/Sources.txt (273884 => 273885)


--- trunk/Source/WebCore/Sources.txt	2021-03-04 13:18:16 UTC (rev 273884)
+++ trunk/Source/WebCore/Sources.txt	2021-03-04 13:22:14 UTC (rev 273885)
@@ -1793,6 +1793,7 @@
 page/scrolling/ScrollingTreeNode.cpp
 page/scrolling/ScrollingTreeOverflowScrollingNode.cpp
 page/scrolling/ScrollingTreeScrollingNode.cpp
+page/scrolling/ScrollingTreeScrollingNodeDelegate.cpp
 page/scrolling/ThreadedScrollingTree.cpp
 platform/CalculationValue.cpp
 platform/ContentType.cpp

Modified: trunk/Source/WebCore/SourcesGTK.txt (273884 => 273885)


--- trunk/Source/WebCore/SourcesGTK.txt	2021-03-04 13:18:16 UTC (rev 273884)
+++ trunk/Source/WebCore/SourcesGTK.txt	2021-03-04 13:22:14 UTC (rev 273885)
@@ -59,6 +59,7 @@
 page/scrolling/nicosia/ScrollingTreeOverflowScrollProxyNode.cpp
 page/scrolling/nicosia/ScrollingTreeOverflowScrollingNodeNicosia.cpp
 page/scrolling/nicosia/ScrollingTreePositionedNode.cpp
+page/scrolling/nicosia/ScrollingTreeScrollingNodeDelegateNicosia.cpp
 page/scrolling/nicosia/ScrollingTreeStickyNode.cpp
 
 platform/ScrollAnimationKinetic.cpp

Modified: trunk/Source/WebCore/SourcesWPE.txt (273884 => 273885)


--- trunk/Source/WebCore/SourcesWPE.txt	2021-03-04 13:18:16 UTC (rev 273884)
+++ trunk/Source/WebCore/SourcesWPE.txt	2021-03-04 13:22:14 UTC (rev 273885)
@@ -55,6 +55,7 @@
 page/scrolling/nicosia/ScrollingTreeOverflowScrollProxyNode.cpp
 page/scrolling/nicosia/ScrollingTreeOverflowScrollingNodeNicosia.cpp
 page/scrolling/nicosia/ScrollingTreePositionedNode.cpp
+page/scrolling/nicosia/ScrollingTreeScrollingNodeDelegateNicosia.cpp
 page/scrolling/nicosia/ScrollingTreeStickyNode.cpp
 
 platform/ScrollAnimationKinetic.cpp

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (273884 => 273885)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2021-03-04 13:18:16 UTC (rev 273884)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2021-03-04 13:22:14 UTC (rev 273885)
@@ -3368,7 +3368,6 @@
 		A5F36D3B18F758720054C024 /* PageDebugger.h in Headers */ = {isa = PBXBuildFile; fileRef = A5F36D3918F758720054C024 /* PageDebugger.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		A6148A7912E41E3B0044A784 /* JSHTMLKeygenElement.h in Headers */ = {isa = PBXBuildFile; fileRef = A6148A7712E41E3B0044A784 /* JSHTMLKeygenElement.h */; };
 		A6D169641346B4C1000EB770 /* ShadowRoot.h in Headers */ = {isa = PBXBuildFile; fileRef = A6D169631346B4C1000EB770 /* ShadowRoot.h */; settings = {ATTRIBUTES = (Private, ); }; };
-		A6D5A99C1629D70000297330 /* ScrollingTreeScrollingNodeDelegate.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A6D5A99A1629D6FF00297330 /* ScrollingTreeScrollingNodeDelegate.cpp */; };
 		A6D5A99D1629D70000297330 /* ScrollingTreeScrollingNodeDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = A6D5A99B1629D70000297330 /* ScrollingTreeScrollingNodeDelegate.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		A7151BD812F1558F005A0F64 /* TextCheckerClient.h in Headers */ = {isa = PBXBuildFile; fileRef = A7151BD712F1558F005A0F64 /* TextCheckerClient.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		A715E653134BBBEC00D8E713 /* ProgressShadowElement.h in Headers */ = {isa = PBXBuildFile; fileRef = A715E651134BBBEC00D8E713 /* ProgressShadowElement.h */; };
@@ -36244,7 +36243,6 @@
 				5C2B1AEC22397EBC00B91CF7 /* ResourceResponseCocoa.mm in Sources */,
 				BC51156E12B1749C00C96754 /* ScrollAnimatorMac.mm in Sources */,
 				BCEF869F0E844E9D00A85CD5 /* ScrollbarThemeMac.mm in Sources */,
-				A6D5A99C1629D70000297330 /* ScrollingTreeScrollingNodeDelegate.cpp in Sources */,
 				43B85ED418CBEC5200E31AF4 /* SelectorPseudoClassAndCompatibilityElementMap.cpp in Sources */,
 				26AA0F9E18D2A18B00419381 /* SelectorPseudoElementTypeMap.cpp in Sources */,
 				7CD58DFD1F9565A800112791 /* Settings.cpp in Sources */,

Modified: trunk/Source/WebCore/page/scrolling/ScrollingTreeScrollingNodeDelegate.cpp (273884 => 273885)


--- trunk/Source/WebCore/page/scrolling/ScrollingTreeScrollingNodeDelegate.cpp	2021-03-04 13:18:16 UTC (rev 273884)
+++ trunk/Source/WebCore/page/scrolling/ScrollingTreeScrollingNodeDelegate.cpp	2021-03-04 13:22:14 UTC (rev 273885)
@@ -23,12 +23,12 @@
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#import "config.h"
-#import "ScrollingTreeScrollingNodeDelegate.h"
+#include "config.h"
+#include "ScrollingTreeScrollingNodeDelegate.h"
 
 #if ENABLE(ASYNC_SCROLLING)
 
-#import "ScrollingTreeScrollingNode.h"
+#include "ScrollingTreeScrollingNode.h"
 
 namespace WebCore {
 

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


--- trunk/Source/WebCore/page/scrolling/nicosia/ScrollingTreeFrameScrollingNodeNicosia.cpp	2021-03-04 13:18:16 UTC (rev 273884)
+++ trunk/Source/WebCore/page/scrolling/nicosia/ScrollingTreeFrameScrollingNodeNicosia.cpp	2021-03-04 13:22:14 UTC (rev 273885)
@@ -37,13 +37,6 @@
 #include "ScrollingStateFrameScrollingNode.h"
 #include "ThreadedScrollingTree.h"
 
-#if ENABLE(KINETIC_SCROLLING)
-#include "ScrollAnimationKinetic.h"
-#endif
-#if ENABLE(SMOOTH_SCROLLING)
-#include "ScrollAnimationSmooth.h"
-#endif
-
 namespace WebCore {
 
 Ref<ScrollingTreeFrameScrollingNode> ScrollingTreeFrameScrollingNodeNicosia::create(ScrollingTree& scrollingTree, ScrollingNodeType nodeType, ScrollingNodeID nodeID)
@@ -53,8 +46,8 @@
 
 ScrollingTreeFrameScrollingNodeNicosia::ScrollingTreeFrameScrollingNodeNicosia(ScrollingTree& scrollingTree, ScrollingNodeType nodeType, ScrollingNodeID nodeID)
     : ScrollingTreeFrameScrollingNode(scrollingTree, nodeType, nodeID)
+    , m_delegate(*this, downcast<ThreadedScrollingTree>(scrollingTree).scrollAnimatorEnabled())
 {
-    m_scrollAnimatorEnabled = downcast<ThreadedScrollingTree>(scrollingTree).scrollAnimatorEnabled();
 }
 
 ScrollingTreeFrameScrollingNodeNicosia::~ScrollingTreeFrameScrollingNodeNicosia() = default;
@@ -102,141 +95,18 @@
         stopScrollAnimations();
         const auto& requestedScrollData = scrollingStateNode.requestedScrollData();
         scrollTo(requestedScrollData.scrollPosition, requestedScrollData.scrollType, requestedScrollData.clamping);
-#if ENABLE(SMOOTH_SCROLLING)
-        if (m_smoothAnimation)
-            m_smoothAnimation->setCurrentPosition(currentScrollPosition());
-#endif
+        m_delegate.resetCurrentPosition();
     }
 }
 
-#if ENABLE(KINETIC_SCROLLING)
-void ScrollingTreeFrameScrollingNodeNicosia::ensureScrollAnimationKinetic()
-{
-    if (m_kineticAnimation)
-        return;
-
-    m_kineticAnimation = makeUnique<ScrollAnimationKinetic>(
-        [this]() -> ScrollExtents {
-            return { IntPoint(minimumScrollPosition()), IntPoint(maximumScrollPosition()), IntSize(scrollableAreaSize()) };
-        },
-        [this](FloatPoint&& position) {
-#if ENABLE(SMOOTH_SCROLLING)
-            if (m_smoothAnimation)
-                m_smoothAnimation->setCurrentPosition(position);
-#endif
-
-            auto* scrollLayer = static_cast<Nicosia::PlatformLayer*>(scrolledContentsLayer());
-            ASSERT(scrollLayer);
-            auto& compositionLayer = downcast<Nicosia::CompositionLayer>(*scrollLayer);
-
-            auto updateScope = compositionLayer.createUpdateScope();
-            scrollTo(position);
-        });
-}
-#endif
-
-#if ENABLE(SMOOTH_SCROLLING)
-void ScrollingTreeFrameScrollingNodeNicosia::ensureScrollAnimationSmooth()
-{
-    if (m_smoothAnimation)
-        return;
-
-    m_smoothAnimation = makeUnique<ScrollAnimationSmooth>(
-        [this]() -> ScrollExtents {
-            return { IntPoint(minimumScrollPosition()), IntPoint(maximumScrollPosition()), IntSize(scrollableAreaSize()) };
-        },
-        currentScrollPosition(),
-        [this](FloatPoint&& position) {
-            auto* scrollLayer = static_cast<Nicosia::PlatformLayer*>(scrolledContentsLayer());
-            ASSERT(scrollLayer);
-            auto& compositionLayer = downcast<Nicosia::CompositionLayer>(*scrollLayer);
-
-            auto updateScope = compositionLayer.createUpdateScope();
-            scrollTo(position);
-        },
-        [] { });
-}
-#endif
-
 WheelEventHandlingResult ScrollingTreeFrameScrollingNodeNicosia::handleWheelEvent(const PlatformWheelEvent& wheelEvent, EventTargeting eventTargeting)
 {
-    if (!canHandleWheelEvent(wheelEvent, eventTargeting))
-        return WheelEventHandlingResult::unhandled();
-
-#if ENABLE(KINETIC_SCROLLING)
-    ensureScrollAnimationKinetic();
-    m_kineticAnimation->appendToScrollHistory(wheelEvent);
-    m_kineticAnimation->stop();
-    if (wheelEvent.isEndOfNonMomentumScroll()) {
-        m_kineticAnimation->start(currentScrollPosition(), m_kineticAnimation->computeVelocity(), canHaveHorizontalScrollbar(), canHaveVerticalScrollbar());
-        m_kineticAnimation->clearScrollHistory();
-        return WheelEventHandlingResult::handled();
-    }
-    if (wheelEvent.isTransitioningToMomentumScroll()) {
-        m_kineticAnimation->start(currentScrollPosition(), wheelEvent.swipeVelocity(), canHaveHorizontalScrollbar(), canHaveVerticalScrollbar());
-        m_kineticAnimation->clearScrollHistory();
-        return WheelEventHandlingResult::handled();
-    }
-#endif
-
-    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;
-        }
-    }
-
-#if ENABLE(SMOOTH_SCROLLING)
-    if (m_scrollAnimatorEnabled && !wheelEvent.hasPreciseScrollingDeltas()) {
-        ensureScrollAnimationSmooth();
-        m_smoothAnimation->scroll(HorizontalScrollbar, ScrollByPixel, 1, -deltaX);
-        m_smoothAnimation->scroll(VerticalScrollbar, ScrollByPixel, 1, -deltaY);
-        return WheelEventHandlingResult::handled();
-    }
-#endif
-
-    auto* scrollLayer = static_cast<Nicosia::PlatformLayer*>(scrolledContentsLayer());
-    ASSERT(scrollLayer);
-    auto& compositionLayer = downcast<Nicosia::CompositionLayer>(*scrollLayer);
-
-    auto updateScope = compositionLayer.createUpdateScope();
-    scrollBy({ -deltaX, -deltaY });
-
-    return WheelEventHandlingResult::handled();
+    return m_delegate.handleWheelEvent(wheelEvent, eventTargeting);
 }
 
 void ScrollingTreeFrameScrollingNodeNicosia::stopScrollAnimations()
 {
-#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
+    m_delegate.stopScrollAnimations();
 }
 
 FloatPoint ScrollingTreeFrameScrollingNodeNicosia::adjustedScrollPosition(const FloatPoint& position, ScrollClamping clamping) const
@@ -315,10 +185,7 @@
             applyLayerPosition(*m_footerLayer, FloatPoint(horizontalScrollOffsetForBanner, FrameView::yPositionForFooterLayer(scrollPosition, topContentInset, totalContentsSize().height(), footerHeight())));
     }
 
-#if ENABLE(SMOOTH_SCROLLING)
-    if (m_smoothAnimation)
-        m_smoothAnimation->updateVisibleLengths();
-#endif
+    m_delegate.updateVisibleLengths();
 }
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/page/scrolling/nicosia/ScrollingTreeFrameScrollingNodeNicosia.h (273884 => 273885)


--- trunk/Source/WebCore/page/scrolling/nicosia/ScrollingTreeFrameScrollingNodeNicosia.h	2021-03-04 13:18:16 UTC (rev 273884)
+++ trunk/Source/WebCore/page/scrolling/nicosia/ScrollingTreeFrameScrollingNodeNicosia.h	2021-03-04 13:22:14 UTC (rev 273885)
@@ -31,7 +31,7 @@
 #if ENABLE(ASYNC_SCROLLING) && USE(NICOSIA)
 
 #include "ScrollingTreeFrameScrollingNode.h"
-
+#include "ScrollingTreeScrollingNodeDelegateNicosia.h"
 #include <wtf/RefPtr.h>
 
 namespace Nicosia {
@@ -55,21 +55,11 @@
     void commitStateBeforeChildren(const ScrollingStateNode&) override;
     void commitStateAfterChildren(const ScrollingStateNode&) override;
 
-#if ENABLE(KINETIC_SCROLLING)
-    void ensureScrollAnimationKinetic();
-#endif
-#if ENABLE(SMOOTH_SCROLLING)
-    void ensureScrollAnimationSmooth();
-#endif
 
     WheelEventHandlingResult handleWheelEvent(const PlatformWheelEvent&, EventTargeting) override;
-
-    void stopScrollAnimations() override;
-
     FloatPoint adjustedScrollPosition(const FloatPoint&, ScrollClamping) const override;
-
     void currentScrollPositionChanged(ScrollType, ScrollingLayerPositionAction) override;
-
+    void stopScrollAnimations() override;
     void repositionScrollingLayers() override;
     void repositionRelatedLayers() override;
 
@@ -80,13 +70,7 @@
     RefPtr<Nicosia::CompositionLayer> m_headerLayer;
     RefPtr<Nicosia::CompositionLayer> m_footerLayer;
 
-    bool m_scrollAnimatorEnabled { false };
-#if ENABLE(KINETIC_SCROLLING)
-    std::unique_ptr<ScrollAnimationKinetic> m_kineticAnimation;
-#endif
-#if ENABLE(SMOOTH_SCROLLING)
-    std::unique_ptr<ScrollAnimation> m_smoothAnimation;
-#endif
+    ScrollingTreeScrollingNodeDelegateNicosia m_delegate;
 };
 
 } // namespace WebCore

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


--- trunk/Source/WebCore/page/scrolling/nicosia/ScrollingTreeOverflowScrollingNodeNicosia.cpp	2021-03-04 13:18:16 UTC (rev 273884)
+++ trunk/Source/WebCore/page/scrolling/nicosia/ScrollingTreeOverflowScrollingNodeNicosia.cpp	2021-03-04 13:22:14 UTC (rev 273885)
@@ -32,15 +32,6 @@
 #if ENABLE(ASYNC_SCROLLING) && USE(NICOSIA)
 
 #include "NicosiaPlatformLayer.h"
-#if ENABLE(KINETIC_SCROLLING)
-#include "ScrollAnimationKinetic.h"
-#endif
-#if ENABLE(SMOOTH_SCROLLING)
-#include "ScrollAnimationSmooth.h"
-#endif
-#include "ScrollingStateOverflowScrollingNode.h"
-#include "ThreadedScrollingTree.h"
-
 namespace WebCore {
 
 Ref<ScrollingTreeOverflowScrollingNode> ScrollingTreeOverflowScrollingNodeNicosia::create(ScrollingTree& scrollingTree, ScrollingNodeID nodeID)
@@ -50,8 +41,8 @@
 
 ScrollingTreeOverflowScrollingNodeNicosia::ScrollingTreeOverflowScrollingNodeNicosia(ScrollingTree& scrollingTree, ScrollingNodeID nodeID)
     : ScrollingTreeOverflowScrollingNode(scrollingTree, nodeID)
+    , m_delegate(*this, downcast<ThreadedScrollingTree>(scrollingTree).scrollAnimatorEnabled())
 {
-    m_scrollAnimatorEnabled = downcast<ThreadedScrollingTree>(scrollingTree).scrollAnimatorEnabled();
 }
 
 ScrollingTreeOverflowScrollingNodeNicosia::~ScrollingTreeOverflowScrollingNodeNicosia() = default;
@@ -65,10 +56,7 @@
         stopScrollAnimations();
         const auto& requestedScrollData = overflowStateNode.requestedScrollData();
         scrollTo(requestedScrollData.scrollPosition, requestedScrollData.scrollType, requestedScrollData.clamping);
-#if ENABLE(SMOOTH_SCROLLING)
-        if (m_smoothAnimation)
-            m_smoothAnimation->setCurrentPosition(currentScrollPosition());
-#endif
+        m_delegate.resetCurrentPosition();
     }
 }
 
@@ -93,140 +81,17 @@
             state.delta.boundsOriginChanged = true;
         });
 
-#if ENABLE(SMOOTH_SCROLLING)
-    if (m_smoothAnimation)
-        m_smoothAnimation->updateVisibleLengths();
-#endif
+    m_delegate.updateVisibleLengths();
 }
 
-#if ENABLE(KINETIC_SCROLLING)
-void ScrollingTreeOverflowScrollingNodeNicosia::ensureScrollAnimationKinetic()
-{
-    if (m_kineticAnimation)
-        return;
-
-    m_kineticAnimation = makeUnique<ScrollAnimationKinetic>(
-        [this]() -> ScrollExtents {
-            return { IntPoint(minimumScrollPosition()), IntPoint(maximumScrollPosition()), IntSize(scrollableAreaSize()) };
-        },
-        [this](FloatPoint&& position) {
-#if ENABLE(SMOOTH_SCROLLING)
-            if (m_smoothAnimation)
-                m_smoothAnimation->setCurrentPosition(position);
-#endif
-
-            auto* scrollLayer = static_cast<Nicosia::PlatformLayer*>(scrollContainerLayer());
-            ASSERT(scrollLayer);
-            auto& compositionLayer = downcast<Nicosia::CompositionLayer>(*scrollLayer);
-
-            auto updateScope = compositionLayer.createUpdateScope();
-            scrollTo(position);
-        });
-}
-#endif
-
-#if ENABLE(SMOOTH_SCROLLING)
-void ScrollingTreeOverflowScrollingNodeNicosia::ensureScrollAnimationSmooth()
-{
-    if (m_smoothAnimation)
-        return;
-
-    m_smoothAnimation = makeUnique<ScrollAnimationSmooth>(
-        [this]() -> ScrollExtents {
-            return { IntPoint(minimumScrollPosition()), IntPoint(maximumScrollPosition()), IntSize(scrollableAreaSize()) };
-        },
-        currentScrollPosition(),
-        [this](FloatPoint&& position) {
-            auto* scrollLayer = static_cast<Nicosia::PlatformLayer*>(scrollContainerLayer());
-            ASSERT(scrollLayer);
-            auto& compositionLayer = downcast<Nicosia::CompositionLayer>(*scrollLayer);
-
-            auto updateScope = compositionLayer.createUpdateScope();
-            scrollTo(position);
-        },
-        [] { });
-}
-#endif
-
 WheelEventHandlingResult ScrollingTreeOverflowScrollingNodeNicosia::handleWheelEvent(const PlatformWheelEvent& wheelEvent, EventTargeting eventTargeting)
 {
-    if (!canHandleWheelEvent(wheelEvent, eventTargeting))
-        return WheelEventHandlingResult::unhandled();
-
-#if ENABLE(KINETIC_SCROLLING)
-    ensureScrollAnimationKinetic();
-    m_kineticAnimation->appendToScrollHistory(wheelEvent);
-    m_kineticAnimation->stop();
-    if (wheelEvent.isEndOfNonMomentumScroll()) {
-        m_kineticAnimation->start(currentScrollPosition(), m_kineticAnimation->computeVelocity(), canHaveHorizontalScrollbar(), canHaveVerticalScrollbar());
-        m_kineticAnimation->clearScrollHistory();
-        return WheelEventHandlingResult::handled();
-    }
-    if (wheelEvent.isTransitioningToMomentumScroll()) {
-        m_kineticAnimation->start(currentScrollPosition(), wheelEvent.swipeVelocity(), canHaveHorizontalScrollbar(), canHaveVerticalScrollbar());
-        m_kineticAnimation->clearScrollHistory();
-        return WheelEventHandlingResult::handled();
-    }
-#endif
-
-    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;
-        }
-    }
-
-#if ENABLE(SMOOTH_SCROLLING)
-    if (m_scrollAnimatorEnabled && !wheelEvent.hasPreciseScrollingDeltas()) {
-        ensureScrollAnimationSmooth();
-        m_smoothAnimation->scroll(HorizontalScrollbar, ScrollByPixel, 1, -deltaX);
-        m_smoothAnimation->scroll(VerticalScrollbar, ScrollByPixel, 1, -deltaY);
-        return WheelEventHandlingResult::handled();
-    }
-#endif
-
-    auto* scrollLayer = static_cast<Nicosia::PlatformLayer*>(scrollContainerLayer());
-    ASSERT(scrollLayer);
-    auto& compositionLayer = downcast<Nicosia::CompositionLayer>(*scrollLayer);
-
-    auto updateScope = compositionLayer.createUpdateScope();
-    scrollBy({ -deltaX, -deltaY });
-
-    return WheelEventHandlingResult::handled();
+    return m_delegate.handleWheelEvent(wheelEvent, eventTargeting);
 }
 
 void ScrollingTreeOverflowScrollingNodeNicosia::stopScrollAnimations()
 {
-#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
+    m_delegate.stopScrollAnimations();
 }
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/page/scrolling/nicosia/ScrollingTreeOverflowScrollingNodeNicosia.h (273884 => 273885)


--- trunk/Source/WebCore/page/scrolling/nicosia/ScrollingTreeOverflowScrollingNodeNicosia.h	2021-03-04 13:18:16 UTC (rev 273884)
+++ trunk/Source/WebCore/page/scrolling/nicosia/ScrollingTreeOverflowScrollingNodeNicosia.h	2021-03-04 13:22:14 UTC (rev 273885)
@@ -31,6 +31,7 @@
 #if ENABLE(ASYNC_SCROLLING) && USE(NICOSIA)
 
 #include "ScrollingTreeOverflowScrollingNode.h"
+#include "ScrollingTreeScrollingNodeDelegateNicosia.h"
 
 namespace WebCore {
 class ScrollAnimation;
@@ -45,29 +46,12 @@
     ScrollingTreeOverflowScrollingNodeNicosia(ScrollingTree&, ScrollingNodeID);
 
     void commitStateAfterChildren(const ScrollingStateNode&) override;
-
     FloatPoint adjustedScrollPosition(const FloatPoint&, ScrollClamping) const override;
-
     void repositionScrollingLayers() override;
-
-#if ENABLE(KINETIC_SCROLLING)
-    void ensureScrollAnimationKinetic();
-#endif
-#if ENABLE(SMOOTH_SCROLLING)
-    void ensureScrollAnimationSmooth();
-#endif
-
     WheelEventHandlingResult handleWheelEvent(const PlatformWheelEvent&, EventTargeting) override;
-
     void stopScrollAnimations() override;
 
-    bool m_scrollAnimatorEnabled { false };
-#if ENABLE(KINETIC_SCROLLING)
-    std::unique_ptr<ScrollAnimationKinetic> m_kineticAnimation;
-#endif
-#if ENABLE(SMOOTH_SCROLLING)
-    std::unique_ptr<ScrollAnimation> m_smoothAnimation;
-#endif
+    ScrollingTreeScrollingNodeDelegateNicosia m_delegate;
 };
 
 } // namespace WebCore

Added: trunk/Source/WebCore/page/scrolling/nicosia/ScrollingTreeScrollingNodeDelegateNicosia.cpp (0 => 273885)


--- trunk/Source/WebCore/page/scrolling/nicosia/ScrollingTreeScrollingNodeDelegateNicosia.cpp	                        (rev 0)
+++ trunk/Source/WebCore/page/scrolling/nicosia/ScrollingTreeScrollingNodeDelegateNicosia.cpp	2021-03-04 13:22:14 UTC (rev 273885)
@@ -0,0 +1,196 @@
+/*
+ * Copyright (C) 2019 Apple Inc. All rights reserved.
+ * Copyright (C) 2019, 2021 Igalia S.L.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS 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 APPLE INC. OR ITS 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 "ScrollingTreeScrollingNodeDelegateNicosia.h"
+
+#include "NicosiaPlatformLayer.h"
+
+#if ENABLE(ASYNC_SCROLLING) && USE(NICOSIA)
+
+namespace WebCore {
+class ScrollAnimation;
+class ScrollAnimationKinetic;
+
+ScrollingTreeScrollingNodeDelegateNicosia::ScrollingTreeScrollingNodeDelegateNicosia(ScrollingTreeScrollingNode& scrollingNode, bool scrollAnimatorEnabled)
+    : ScrollingTreeScrollingNodeDelegate(scrollingNode)
+    , m_scrollAnimatorEnabled(scrollAnimatorEnabled)
+{
+}
+
+ScrollingTreeScrollingNodeDelegateNicosia::~ScrollingTreeScrollingNodeDelegateNicosia()
+{
+}
+
+std::unique_ptr<Nicosia::SceneIntegration::UpdateScope> ScrollingTreeScrollingNodeDelegateNicosia::createUpdateScope()
+{
+    auto* scrollLayer = static_cast<Nicosia::PlatformLayer*>(scrollingNode().scrollContainerLayer());
+    if (is<ScrollingTreeFrameScrollingNode>(scrollingNode()))
+        scrollLayer = static_cast<Nicosia::PlatformLayer*>(scrollingNode().scrolledContentsLayer());
+
+    ASSERT(scrollLayer);
+    auto& compositionLayer = downcast<Nicosia::CompositionLayer>(*scrollLayer);
+    return compositionLayer.createUpdateScope();
+}
+
+void ScrollingTreeScrollingNodeDelegateNicosia::resetCurrentPosition()
+{
+#if ENABLE(SMOOTH_SCROLLING)
+    if (m_smoothAnimation)
+        m_smoothAnimation->setCurrentPosition(scrollingNode().currentScrollPosition());
+#endif
+}
+
+void ScrollingTreeScrollingNodeDelegateNicosia::updateVisibleLengths()
+{
+#if ENABLE(SMOOTH_SCROLLING)
+    if (m_smoothAnimation)
+        m_smoothAnimation->updateVisibleLengths();
+#endif
+}
+
+#if ENABLE(KINETIC_SCROLLING)
+void ScrollingTreeScrollingNodeDelegateNicosia::ensureScrollAnimationKinetic()
+{
+    if (m_kineticAnimation)
+        return;
+
+    m_kineticAnimation = makeUnique<ScrollAnimationKinetic>(
+        [this]() -> ScrollExtents {
+            return { IntPoint(minimumScrollPosition()), IntPoint(maximumScrollPosition()), IntSize(scrollableAreaSize()) };
+        },
+        [this](FloatPoint&& position) {
+#if ENABLE(SMOOTH_SCROLLING)
+            if (m_smoothAnimation)
+                m_smoothAnimation->setCurrentPosition(position);
+#endif
+            auto updateScope = createUpdateScope();
+            scrollingNode().scrollTo(position);
+        });
+}
+#endif
+
+#if ENABLE(SMOOTH_SCROLLING)
+void ScrollingTreeScrollingNodeDelegateNicosia::ensureScrollAnimationSmooth()
+{
+    if (m_smoothAnimation)
+        return;
+
+    m_smoothAnimation = makeUnique<ScrollAnimationSmooth>(
+        [this]() -> ScrollExtents {
+            return { IntPoint(minimumScrollPosition()), IntPoint(maximumScrollPosition()), IntSize(scrollableAreaSize()) };
+        },
+        currentScrollPosition(),
+        [this](FloatPoint&& position) {
+            auto updateScope = createUpdateScope();
+            scrollingNode().scrollTo(position);
+        },
+        [] { });
+}
+#endif
+
+WheelEventHandlingResult ScrollingTreeScrollingNodeDelegateNicosia::handleWheelEvent(const PlatformWheelEvent& wheelEvent, EventTargeting eventTargeting)
+{
+    if (!scrollingNode().canHandleWheelEvent(wheelEvent, eventTargeting))
+        return WheelEventHandlingResult::unhandled();
+
+    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->start(currentScrollPosition(), m_kineticAnimation->computeVelocity(), canHaveHorizontalScrollbar, canHaveVerticalScrollbar);
+        m_kineticAnimation->clearScrollHistory();
+        return WheelEventHandlingResult::handled();
+    }
+    if (wheelEvent.isTransitioningToMomentumScroll()) {
+        m_kineticAnimation->start(currentScrollPosition(), wheelEvent.swipeVelocity(), canHaveHorizontalScrollbar, canHaveVerticalScrollbar);
+        m_kineticAnimation->clearScrollHistory();
+        return WheelEventHandlingResult::handled();
+    }
+#endif
+
+    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;
+        }
+    }
+
+#if ENABLE(SMOOTH_SCROLLING)
+    if (m_scrollAnimatorEnabled && !wheelEvent.hasPreciseScrollingDeltas()) {
+        ensureScrollAnimationSmooth();
+        m_smoothAnimation->scroll(HorizontalScrollbar, ScrollByPixel, 1, -deltaX);
+        m_smoothAnimation->scroll(VerticalScrollbar, ScrollByPixel, 1, -deltaY);
+        return WheelEventHandlingResult::handled();
+    }
+#endif
+
+    auto updateScope = createUpdateScope();
+    scrollingNode().scrollBy({ -deltaX, -deltaY });
+
+    return WheelEventHandlingResult::handled();
+}
+
+void ScrollingTreeScrollingNodeDelegateNicosia::stopScrollAnimations()
+{
+#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
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(ASYNC_SCROLLING) && USE(NICOSIA)

Added: trunk/Source/WebCore/page/scrolling/nicosia/ScrollingTreeScrollingNodeDelegateNicosia.h (0 => 273885)


--- trunk/Source/WebCore/page/scrolling/nicosia/ScrollingTreeScrollingNodeDelegateNicosia.h	                        (rev 0)
+++ trunk/Source/WebCore/page/scrolling/nicosia/ScrollingTreeScrollingNodeDelegateNicosia.h	2021-03-04 13:22:14 UTC (rev 273885)
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 2019 Apple Inc. All rights reserved.
+ * Copyright (C) 2019, 2021 Igalia S.L.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS 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 APPLE INC. OR ITS 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 "ScrollingTreeScrollingNodeDelegate.h"
+
+#if ENABLE(ASYNC_SCROLLING) && USE(NICOSIA)
+
+#include "NicosiaPlatformLayer.h"
+#include "ScrollingStateOverflowScrollingNode.h"
+#include "ThreadedScrollingTree.h"
+
+#if ENABLE(KINETIC_SCROLLING)
+#include "ScrollAnimationKinetic.h"
+#endif
+
+#if ENABLE(SMOOTH_SCROLLING)
+#include "ScrollAnimationSmooth.h"
+#endif
+
+namespace WebCore {
+
+class ScrollingTreeScrollingNodeDelegateNicosia : public ScrollingTreeScrollingNodeDelegate {
+public:
+    explicit ScrollingTreeScrollingNodeDelegateNicosia(ScrollingTreeScrollingNode&, bool scrollAnimatorEnabled);
+    virtual ~ScrollingTreeScrollingNodeDelegateNicosia();
+
+    std::unique_ptr<Nicosia::SceneIntegration::UpdateScope> createUpdateScope();
+    void resetCurrentPosition();
+    void updateVisibleLengths();
+    WheelEventHandlingResult handleWheelEvent(const PlatformWheelEvent&, EventTargeting);
+    void stopScrollAnimations();
+
+private:
+    bool m_scrollAnimatorEnabled { false };
+
+#if ENABLE(KINETIC_SCROLLING)
+    void ensureScrollAnimationKinetic();
+#endif
+#if ENABLE(SMOOTH_SCROLLING)
+    void ensureScrollAnimationSmooth();
+#endif
+
+#if ENABLE(KINETIC_SCROLLING)
+    std::unique_ptr<ScrollAnimationKinetic> m_kineticAnimation;
+#endif
+#if ENABLE(SMOOTH_SCROLLING)
+    std::unique_ptr<ScrollAnimation> m_smoothAnimation;
+#endif
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(ASYNC_SCROLLING) && USE(NICOSIA)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to