Title: [273275] trunk/Source/WebCore
Revision
273275
Author
[email protected]
Date
2021-02-22 13:39:40 -0800 (Mon, 22 Feb 2021)

Log Message

Clean up ScrollableArea and ScrollAnimator API and convert less between offsets and positions
https://bugs.webkit.org/show_bug.cgi?id=222111

Reviewed by Simon Fraser.

Clean up the APIs exposed by ScrollableArea and ScrollAnimator to make them more
consistent. With this change it should be a bit easier to tell if a particular
method will trigger an animation or not. In addition, we accept positions (as
opposed to offsets) everywhere, which allows us to reduce the number of
offset <-> position conversions.

Finally, this change is also interesting for scroll snap, because it will
make it easier to use a native animation on MacOS to use for snapping after
scrollbar thumb dragging.

No new tests. This should not change behavior.

* page/FrameView.cpp:
(WebCore::FrameView::setScrollPosition): Use new ScrollableArea APIs that
accept positions.
(WebCore::FrameView::scrollToPositionWithAnimation): Added this version
of the method that uses positions.
(WebCore::FrameView::scrollToOffsetWithAnimation): Deleted.
* page/FrameView.h: Update method declaration.
* platform/ScrollAnimator.cpp:
(WebCore::ScrollAnimator::scroll): Simplified a little bit the code that handles
scroll snapping here. Unified scroll snap and non-scroll snap compilation paths.
(WebCore::ScrollAnimator::scrollToOffsetWithoutAnimation): This method
now converts to a position and then calls scrollToPositionWithoutAnimation.
(WebCore::ScrollAnimator::scrollToPositionWithoutAnimation): Split this out
from scrollToOffsetWithoutAnimation.
(WebCore::ScrollAnimator::scrollToOffsetWithAnimation): This method now
converts to a position and calls scrollToPositionWithAnimation.
(WebCore::ScrollAnimator::scrollToPositionWithAnimation): Split this
out from scrollToOffsetWithAnimation.
(WebCore::ScrollAnimator::handleWheelEvent): Call scrollToPositionWithAnimation
instead of using the scroll(...) method.
(WebCore::ScrollAnimator::notifyPositionChanged): Eliminate a conversion here.
(WebCore::ScrollAnimator::scrollWithoutAnimation): Deleted.
(WebCore::ScrollAnimator::scrollToOffset): Deleted.
* platform/ScrollAnimator.h: Update method list.
* platform/ScrollView.cpp:
(WebCore::ScrollView::updateScrollbars): Eliminate a conversion here.
* platform/ScrollableArea.cpp:
Removed scrollToOffsetWithAnimation and added two new methods scrollToPositionWithAnimation
and scrollToPositionWithoutAnimation. scrollToOffsetWithoutAnimation is still used
in quite a few places, so we maintain this.
(WebCore::ScrollableArea::setScrollOffsetFromInternals): Use setScrollPositionFromAnimation now.
(WebCore::ScrollableArea::setScrollPositionFromAnimation): Renamed from setScrollOffsetFromAnimation
and eliminated a mandatory cnoversion.
(WebCore::ScrollableArea::scrollToOffsetWithAnimation): Deleted.
(WebCore::ScrollableArea::setScrollOffsetFromAnimation): Deleted.
* platform/ScrollableArea.h: Update method declarations.
* platform/mac/ScrollAnimatorMac.h: Ditto.
* platform/mac/ScrollAnimatorMac.mm:
(WebCore::ScrollAnimatorMac::scroll): Handle calling into scrollToPositionWithoutAnimation
and scrollToPositionWithAnimation ourselves now that we have this API. This simplifies
program flow a bit.
(WebCore::ScrollAnimatorMac::scrollToPositionWithAnimation):
(WebCore::ScrollAnimatorMac::scrollToPositionWithoutAnimation): Expose these two new
methods which are part of the base class API now.
(WebCore::ScrollAnimatorMac::immediateScrollToPositionForScrollAnimation): Use
ScrollAnimator::scrollToPositionWithoutAnimation because it was the same as
immediateScrollToPosition.
(WebCore::ScrollAnimatorMac::scrollToOffsetWithoutAnimation): Deleted.
(WebCore::ScrollAnimatorMac::immediateScrollToPosition): Deleted. No longer used.
* rendering/RenderLayerScrollableArea.cpp:
(WebCore::RenderLayerScrollableArea::scrollToOffset): Unconditionally convert to a position
here.
(WebCore::RenderLayerScrollableArea::updateScrollInfoAfterLayout): Use ScrollableArea::scrollToPositionWithoutAnimation
because it eliminates one conversion between units.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (273274 => 273275)


--- trunk/Source/WebCore/ChangeLog	2021-02-22 21:38:52 UTC (rev 273274)
+++ trunk/Source/WebCore/ChangeLog	2021-02-22 21:39:40 UTC (rev 273275)
@@ -1,3 +1,77 @@
+2021-02-22  Martin Robinson  <[email protected]>
+
+        Clean up ScrollableArea and ScrollAnimator API and convert less between offsets and positions
+        https://bugs.webkit.org/show_bug.cgi?id=222111
+
+        Reviewed by Simon Fraser.
+
+        Clean up the APIs exposed by ScrollableArea and ScrollAnimator to make them more
+        consistent. With this change it should be a bit easier to tell if a particular
+        method will trigger an animation or not. In addition, we accept positions (as
+        opposed to offsets) everywhere, which allows us to reduce the number of
+        offset <-> position conversions.
+
+        Finally, this change is also interesting for scroll snap, because it will
+        make it easier to use a native animation on MacOS to use for snapping after
+        scrollbar thumb dragging.
+
+        No new tests. This should not change behavior.
+
+        * page/FrameView.cpp:
+        (WebCore::FrameView::setScrollPosition): Use new ScrollableArea APIs that
+        accept positions.
+        (WebCore::FrameView::scrollToPositionWithAnimation): Added this version
+        of the method that uses positions.
+        (WebCore::FrameView::scrollToOffsetWithAnimation): Deleted.
+        * page/FrameView.h: Update method declaration.
+        * platform/ScrollAnimator.cpp:
+        (WebCore::ScrollAnimator::scroll): Simplified a little bit the code that handles
+        scroll snapping here. Unified scroll snap and non-scroll snap compilation paths.
+        (WebCore::ScrollAnimator::scrollToOffsetWithoutAnimation): This method
+        now converts to a position and then calls scrollToPositionWithoutAnimation.
+        (WebCore::ScrollAnimator::scrollToPositionWithoutAnimation): Split this out
+        from scrollToOffsetWithoutAnimation.
+        (WebCore::ScrollAnimator::scrollToOffsetWithAnimation): This method now
+        converts to a position and calls scrollToPositionWithAnimation.
+        (WebCore::ScrollAnimator::scrollToPositionWithAnimation): Split this
+        out from scrollToOffsetWithAnimation.
+        (WebCore::ScrollAnimator::handleWheelEvent): Call scrollToPositionWithAnimation
+        instead of using the scroll(...) method.
+        (WebCore::ScrollAnimator::notifyPositionChanged): Eliminate a conversion here.
+        (WebCore::ScrollAnimator::scrollWithoutAnimation): Deleted.
+        (WebCore::ScrollAnimator::scrollToOffset): Deleted.
+        * platform/ScrollAnimator.h: Update method list.
+        * platform/ScrollView.cpp:
+        (WebCore::ScrollView::updateScrollbars): Eliminate a conversion here.
+        * platform/ScrollableArea.cpp:
+        Removed scrollToOffsetWithAnimation and added two new methods scrollToPositionWithAnimation
+        and scrollToPositionWithoutAnimation. scrollToOffsetWithoutAnimation is still used
+        in quite a few places, so we maintain this.
+        (WebCore::ScrollableArea::setScrollOffsetFromInternals): Use setScrollPositionFromAnimation now.
+        (WebCore::ScrollableArea::setScrollPositionFromAnimation): Renamed from setScrollOffsetFromAnimation
+        and eliminated a mandatory cnoversion.
+        (WebCore::ScrollableArea::scrollToOffsetWithAnimation): Deleted.
+        (WebCore::ScrollableArea::setScrollOffsetFromAnimation): Deleted.
+        * platform/ScrollableArea.h: Update method declarations.
+        * platform/mac/ScrollAnimatorMac.h: Ditto.
+        * platform/mac/ScrollAnimatorMac.mm:
+        (WebCore::ScrollAnimatorMac::scroll): Handle calling into scrollToPositionWithoutAnimation
+        and scrollToPositionWithAnimation ourselves now that we have this API. This simplifies
+        program flow a bit.
+        (WebCore::ScrollAnimatorMac::scrollToPositionWithAnimation):
+        (WebCore::ScrollAnimatorMac::scrollToPositionWithoutAnimation): Expose these two new
+        methods which are part of the base class API now.
+        (WebCore::ScrollAnimatorMac::immediateScrollToPositionForScrollAnimation): Use
+        ScrollAnimator::scrollToPositionWithoutAnimation because it was the same as
+        immediateScrollToPosition.
+        (WebCore::ScrollAnimatorMac::scrollToOffsetWithoutAnimation): Deleted.
+        (WebCore::ScrollAnimatorMac::immediateScrollToPosition): Deleted. No longer used.
+        * rendering/RenderLayerScrollableArea.cpp:
+        (WebCore::RenderLayerScrollableArea::scrollToOffset): Unconditionally convert to a position
+        here.
+        (WebCore::RenderLayerScrollableArea::updateScrollInfoAfterLayout): Use ScrollableArea::scrollToPositionWithoutAnimation
+        because it eliminates one conversion between units.
+
 2021-02-22  Peng Liu  <[email protected]>
 
         Video elements do not work as sources for TexImage2D calls in GPU Process

Modified: trunk/Source/WebCore/page/FrameView.cpp (273274 => 273275)


--- trunk/Source/WebCore/page/FrameView.cpp	2021-02-22 21:38:52 UTC (rev 273274)
+++ trunk/Source/WebCore/page/FrameView.cpp	2021-02-22 21:39:40 UTC (rev 273275)
@@ -2327,11 +2327,12 @@
         scrollAnimator().setWheelEventTestMonitor(page->wheelEventTestMonitor());
 
     ScrollOffset snappedOffset = ceiledIntPoint(scrollAnimator().adjustScrollOffsetForSnappingIfNeeded(scrollOffsetFromPosition(scrollPosition), options.snapPointSelectionMethod));
+    auto snappedPosition = scrollPositionFromOffset(snappedOffset);
 
     if (options.animated == AnimatedScroll::Yes)
-        scrollToOffsetWithAnimation(snappedOffset, currentScrollType(), options.clamping);
+        scrollToPositionWithAnimation(snappedPosition, currentScrollType(), options.clamping);
     else
-        ScrollView::setScrollPosition(scrollPositionFromOffset(snappedOffset), options);
+        ScrollView::setScrollPosition(snappedPosition, options);
 
     setCurrentScrollType(oldScrollType);
 }
@@ -3763,7 +3764,7 @@
     didChangeScrollOffset();
 }
 
-void FrameView::scrollToOffsetWithAnimation(const ScrollOffset& offset, ScrollType scrollType, ScrollClamping)
+void FrameView::scrollToPositionWithAnimation(const ScrollPosition& position, ScrollType scrollType, ScrollClamping)
 {
     auto previousScrollType = currentScrollType();
     setCurrentScrollType(scrollType);
@@ -3770,8 +3771,8 @@
 
     if (currentScrollBehaviorStatus() == ScrollBehaviorStatus::InNonNativeAnimation)
         scrollAnimator().cancelAnimations();
-    if (offset != this->scrollOffset())
-        ScrollableArea::scrollToOffsetWithAnimation(offset);
+    if (position != this->scrollPosition())
+        ScrollableArea::scrollToPositionWithAnimation(position);
 
     setCurrentScrollType(previousScrollType);
 }

Modified: trunk/Source/WebCore/page/FrameView.h (273274 => 273275)


--- trunk/Source/WebCore/page/FrameView.h	2021-02-22 21:38:52 UTC (rev 273274)
+++ trunk/Source/WebCore/page/FrameView.h	2021-02-22 21:39:40 UTC (rev 273275)
@@ -675,7 +675,7 @@
 
     void renderLayerDidScroll(const RenderLayer&);
 
-    WEBCORE_EXPORT void scrollToOffsetWithAnimation(const ScrollOffset&, ScrollType = ScrollType::Programmatic, ScrollClamping = ScrollClamping::Clamped);
+    WEBCORE_EXPORT void scrollToPositionWithAnimation(const ScrollPosition&, ScrollType = ScrollType::Programmatic, ScrollClamping = ScrollClamping::Clamped);
 
     bool inUpdateEmbeddedObjects() const { return m_inUpdateEmbeddedObjects; }
 

Modified: trunk/Source/WebCore/platform/ScrollAnimator.cpp (273274 => 273275)


--- trunk/Source/WebCore/platform/ScrollAnimator.cpp	2021-02-22 21:38:52 UTC (rev 273274)
+++ trunk/Source/WebCore/platform/ScrollAnimator.cpp	2021-02-22 21:39:40 UTC (rev 273275)
@@ -83,57 +83,60 @@
 bool ScrollAnimator::scroll(ScrollbarOrientation orientation, ScrollGranularity granularity, float step, float multiplier, ScrollBehavior behavior)
 {
 #if ENABLE(CSS_SCROLL_SNAP)
-    if (behavior != ScrollBehavior::DoDirectionalSnapping)
-        return scrollWithoutAnimation(orientation, step, multiplier);
-
-    FloatSize scrollOrigin = toFloatSize(m_scrollableArea.scrollOrigin());
-    FloatPoint newPosition = positionFromStep(orientation, step, multiplier);
-    auto newOffset = ScrollableArea::scrollOffsetFromPosition(newPosition, scrollOrigin);
-    auto currentOffset = ScrollableArea::scrollOffsetFromPosition(this->currentPosition(), scrollOrigin);
-    if (orientation == HorizontalScrollbar) {
-        newOffset.setX(m_scrollController.adjustScrollDestination(ScrollEventAxis::Horizontal, newOffset.x(), multiplier, currentOffset.x()));
-        newPosition = ScrollableArea::scrollPositionFromOffset(newOffset, scrollOrigin);
-        return scroll(HorizontalScrollbar, granularity, newPosition.x() - this->currentPosition().x(), 1.0);
+    if (behavior == ScrollBehavior::DoDirectionalSnapping) {
+        auto newOffset = ScrollableArea::scrollOffsetFromPosition(positionFromStep(orientation, step, multiplier), toFloatSize(m_scrollableArea.scrollOrigin()));
+        auto currentOffset = m_scrollableArea.scrollOffset();
+        if (orientation == HorizontalScrollbar) {
+            newOffset.setX(m_scrollController.adjustScrollDestination(ScrollEventAxis::Horizontal, newOffset.x(), multiplier, currentOffset.x()));
+            return scroll(HorizontalScrollbar, granularity, newOffset.x() - currentOffset.x(), 1.0);
+        }
+        newOffset.setY(m_scrollController.adjustScrollDestination(ScrollEventAxis::Vertical, newOffset.y(), multiplier, currentOffset.y()));
+        return scroll(VerticalScrollbar, granularity, newOffset.y() - currentOffset.y(), 1.0);
     }
-
-    newOffset.setY(m_scrollController.adjustScrollDestination(ScrollEventAxis::Vertical, newPosition.y(), multiplier, currentOffset.y()));
-    newPosition = ScrollableArea::scrollPositionFromOffset(newOffset, scrollOrigin);
-    return scroll(VerticalScrollbar, granularity, newPosition.y() - this->currentPosition().y(), 1.0);
 #else
     UNUSED_PARAM(granularity);
     UNUSED_PARAM(behavior);
-    return scrollWithoutAnimation(orientation, step, multiplier);
 #endif
+
+    return scrollToPositionWithoutAnimation(positionFromStep(orientation, step, multiplier));
 }
 
-bool ScrollAnimator::scrollWithoutAnimation(ScrollbarOrientation orientation, float step, float multiplier)
+bool ScrollAnimator::scrollToOffsetWithoutAnimation(const FloatPoint& offset, ScrollClamping clamping)
 {
+    return scrollToPositionWithoutAnimation(ScrollableArea::scrollPositionFromOffset(offset, toFloatSize(scrollableArea().scrollOrigin())), clamping);
+}
+
+bool ScrollAnimator::scrollToPositionWithoutAnimation(const FloatPoint& position, ScrollClamping clamping)
+{
     FloatPoint currentPosition = this->currentPosition();
-    FloatPoint newPosition = positionFromStep(orientation, step, multiplier);
-    newPosition = newPosition.constrainedBetween(m_scrollableArea.minimumScrollPosition(), m_scrollableArea.maximumScrollPosition());
-    if (currentPosition == newPosition)
+    auto adjustedPosition = clamping == ScrollClamping::Clamped ? position.constrainedBetween(scrollableArea().minimumScrollPosition(), scrollableArea().maximumScrollPosition()) : position;
+
+    // FIXME: In some cases on iOS the ScrollableArea position is out of sync with the ScrollAnimator position.
+    // When these cases are fixed, this extra check against the ScrollableArea position can be removed.
+    if (adjustedPosition == currentPosition && adjustedPosition == scrollableArea().scrollPosition() && !scrollableArea().scrollOriginChanged())
         return false;
 
-    m_currentPosition = newPosition;
-    notifyPositionChanged(newPosition - currentPosition);
+    m_currentPosition = adjustedPosition;
+    notifyPositionChanged(adjustedPosition - currentPosition);
+    updateActiveScrollSnapIndexForOffset();
     return true;
 }
 
-void ScrollAnimator::scrollToOffset(const FloatPoint& offset)
+bool ScrollAnimator::scrollToOffsetWithAnimation(const FloatPoint& offset)
 {
-    m_animationProgrammaticScroll->setCurrentPosition(m_currentPosition);
-    auto newPosition = ScrollableArea::scrollPositionFromOffset(offset, toFloatSize(m_scrollableArea.scrollOrigin()));
-    m_animationProgrammaticScroll->scroll(newPosition);
-    m_scrollableArea.setScrollBehaviorStatus(ScrollBehaviorStatus::InNonNativeAnimation);
+    return scrollToPositionWithAnimation(ScrollableArea::scrollPositionFromOffset(offset, toFloatSize(scrollableArea().scrollOrigin())));
 }
 
-void ScrollAnimator::scrollToOffsetWithoutAnimation(const FloatPoint& offset, ScrollClamping)
+bool ScrollAnimator::scrollToPositionWithAnimation(const FloatPoint& newPosition)
 {
-    FloatPoint newPosition = ScrollableArea::scrollPositionFromOffset(offset, toFloatSize(m_scrollableArea.scrollOrigin()));
-    FloatSize delta = newPosition - currentPosition();
-    m_currentPosition = newPosition;
-    notifyPositionChanged(delta);
-    updateActiveScrollSnapIndexForOffset();
+    bool positionChanged = newPosition != currentPosition();
+    if (!positionChanged && !scrollableArea().scrollOriginChanged())
+        return false;
+
+    m_animationProgrammaticScroll->setCurrentPosition(m_currentPosition);
+    m_animationProgrammaticScroll->scroll(newPosition);
+    scrollableArea().setScrollBehaviorStatus(ScrollBehaviorStatus::InNonNativeAnimation);
+    return true;
 }
 
 FloatPoint ScrollAnimator::positionFromStep(ScrollbarOrientation orientation, float step, float multiplier)
@@ -208,7 +211,7 @@
                     deltaY = -deltaY;
             }
             if (e.hasPreciseScrollingDeltas())
-                scrollWithoutAnimation(VerticalScrollbar, verticalScrollbar->pixelStep(), -deltaY);
+                scrollToPositionWithoutAnimation(positionFromStep(VerticalScrollbar, verticalScrollbar->pixelStep(), -deltaY));
             else
                 scroll(VerticalScrollbar, granularity, verticalScrollbar->pixelStep(), -deltaY);
         }
@@ -221,7 +224,7 @@
                     deltaX = -deltaX;
             }
             if (e.hasPreciseScrollingDeltas())
-                scrollWithoutAnimation(HorizontalScrollbar, horizontalScrollbar->pixelStep(), -deltaX);
+                scrollToPositionWithoutAnimation(positionFromStep(HorizontalScrollbar, horizontalScrollbar->pixelStep(), -deltaX));
             else
                 scroll(HorizontalScrollbar, granularity, horizontalScrollbar->pixelStep(), -deltaX);
         }
@@ -257,8 +260,7 @@
 void ScrollAnimator::notifyPositionChanged(const FloatSize& delta)
 {
     UNUSED_PARAM(delta);
-    // FIXME: need to not map back and forth all the time.
-    m_scrollableArea.setScrollOffsetFromAnimation(m_scrollableArea.scrollOffsetFromPosition(roundedIntPoint(currentPosition())));
+    m_scrollableArea.setScrollPositionFromAnimation(roundedIntPoint(currentPosition()));
 
 #if ENABLE(CSS_SCROLL_SNAP) || ENABLE(RUBBER_BANDING)
     m_scrollController.scrollPositionChanged();

Modified: trunk/Source/WebCore/platform/ScrollAnimator.h (273274 => 273275)


--- trunk/Source/WebCore/platform/ScrollAnimator.h	2021-02-22 21:38:52 UTC (rev 273274)
+++ trunk/Source/WebCore/platform/ScrollAnimator.h	2021-02-22 21:39:40 UTC (rev 273275)
@@ -78,11 +78,13 @@
     // destination and returns true.  Scrolling may be immediate or animated.
     // The base class implementation always scrolls immediately, never animates.
     virtual bool scroll(ScrollbarOrientation, ScrollGranularity, float step, float multiplier, ScrollBehavior = ScrollBehavior::Default);
-    bool scrollWithoutAnimation(ScrollbarOrientation, float step, float multiplier);
 
-    void scrollToOffset(const FloatPoint&);
-    virtual void scrollToOffsetWithoutAnimation(const FloatPoint&, ScrollClamping = ScrollClamping::Clamped);
+    bool scrollToOffsetWithoutAnimation(const FloatPoint&, ScrollClamping = ScrollClamping::Clamped);
+    virtual bool scrollToPositionWithoutAnimation(const FloatPoint& position, ScrollClamping = ScrollClamping::Clamped);
 
+    bool scrollToOffsetWithAnimation(const FloatPoint&);
+    virtual bool scrollToPositionWithAnimation(const FloatPoint&);
+
     ScrollableArea& scrollableArea() const { return m_scrollableArea; }
 
     virtual bool handleWheelEvent(const PlatformWheelEvent&);

Modified: trunk/Source/WebCore/platform/ScrollView.cpp (273274 => 273275)


--- trunk/Source/WebCore/platform/ScrollView.cpp	2021-02-22 21:38:52 UTC (rev 273274)
+++ trunk/Source/WebCore/platform/ScrollView.cpp	2021-02-22 21:39:40 UTC (rev 273275)
@@ -597,7 +597,7 @@
             adjustedScrollPosition = adjustScrollPositionWithinRange(adjustedScrollPosition);
 
         if (adjustedScrollPosition != scrollPosition() || scrollOriginChanged()) {
-            ScrollableArea::scrollToOffsetWithoutAnimation(scrollOffsetFromPosition(adjustedScrollPosition));
+            ScrollableArea::scrollToPositionWithoutAnimation(adjustedScrollPosition);
             resetScrollOriginChanged();
         }
     };

Modified: trunk/Source/WebCore/platform/ScrollableArea.cpp (273274 => 273275)


--- trunk/Source/WebCore/platform/ScrollableArea.cpp	2021-02-22 21:38:52 UTC (rev 273274)
+++ trunk/Source/WebCore/platform/ScrollableArea.cpp	2021-02-22 21:39:40 UTC (rev 273275)
@@ -143,12 +143,18 @@
     return scrollAnimator().scroll(orientation, granularity, step, multiplier, ScrollAnimator::ScrollBehavior::DoDirectionalSnapping);
 }
 
-void ScrollableArea::scrollToOffsetWithAnimation(const FloatPoint& offset, ScrollClamping)
+void ScrollableArea::scrollToPositionWithoutAnimation(const FloatPoint& position, ScrollClamping clamping)
 {
-    LOG_WITH_STREAM(Scrolling, stream << "ScrollableArea " << this << " scrollToOffsetWithAnimation " << offset);
-    scrollAnimator().scrollToOffset(offset);
+    LOG_WITH_STREAM(Scrolling, stream << "ScrollableArea " << this << " scrollToPositionWithoutAnimation " << position);
+    scrollAnimator().scrollToPositionWithoutAnimation(position, clamping);
 }
 
+void ScrollableArea::scrollToPositionWithAnimation(const FloatPoint& position, ScrollClamping)
+{
+    LOG_WITH_STREAM(Scrolling, stream << "ScrollableArea " << this << " scrollToPositionWithAnimation " << position);
+    scrollAnimator().scrollToPositionWithAnimation(position);
+}
+
 void ScrollableArea::scrollToOffsetWithoutAnimation(const FloatPoint& offset, ScrollClamping clamping)
 {
     LOG_WITH_STREAM(Scrolling, stream << "ScrollableArea " << this << " scrollToOffsetWithoutAnimation " << offset);
@@ -159,9 +165,9 @@
 {
     auto currentOffset = scrollOffsetFromPosition(IntPoint(scrollAnimator().currentPosition()));
     if (orientation == HorizontalScrollbar)
-        scrollToOffsetWithoutAnimation(FloatPoint(offset, currentOffset.y()));
+        scrollAnimator().scrollToOffsetWithoutAnimation(FloatPoint(offset, currentOffset.y()));
     else
-        scrollToOffsetWithoutAnimation(FloatPoint(currentOffset.x(), offset));
+        scrollAnimator().scrollToOffsetWithoutAnimation(FloatPoint(currentOffset.x(), offset));
 }
 
 void ScrollableArea::notifyScrollPositionChanged(const ScrollPosition& position)
@@ -230,13 +236,11 @@
 // NOTE: Only called from Internals for testing.
 void ScrollableArea::setScrollOffsetFromInternals(const ScrollOffset& offset)
 {
-    setScrollOffsetFromAnimation(offset);
+    setScrollPositionFromAnimation(scrollPositionFromOffset(offset));
 }
 
-void ScrollableArea::setScrollOffsetFromAnimation(const ScrollOffset& offset)
+void ScrollableArea::setScrollPositionFromAnimation(const ScrollPosition& position)
 {
-    ScrollPosition position = scrollPositionFromOffset(offset);
-    
     auto scrollType = currentScrollType();
     auto clamping = scrollType == ScrollType::User ? ScrollClamping::Unclamped : ScrollClamping::Clamped;
     if (requestScrollPositionUpdate(position, scrollType, clamping))
@@ -550,7 +554,7 @@
 
     if (correctedPosition != currentPosition) {
         LOG_WITH_STREAM(ScrollSnap, stream << " adjusting position from " << currentPosition << " to " << correctedPosition);
-        scrollToOffsetWithoutAnimation(correctedPosition);
+        scrollToPositionWithoutAnimation(correctedPosition);
     }
 }
 #else

Modified: trunk/Source/WebCore/platform/ScrollableArea.h (273274 => 273275)


--- trunk/Source/WebCore/platform/ScrollableArea.h	2021-02-22 21:38:52 UTC (rev 273274)
+++ trunk/Source/WebCore/platform/ScrollableArea.h	2021-02-22 21:39:40 UTC (rev 273275)
@@ -71,7 +71,9 @@
     void setScrollBehaviorStatus(ScrollBehaviorStatus status) { m_currentScrollBehaviorStatus = static_cast<unsigned>(status); }
 
     WEBCORE_EXPORT bool scroll(ScrollDirection, ScrollGranularity, float multiplier = 1);
-    WEBCORE_EXPORT void scrollToOffsetWithAnimation(const FloatPoint&, ScrollClamping = ScrollClamping::Clamped);
+    WEBCORE_EXPORT void scrollToPositionWithAnimation(const FloatPoint&, ScrollClamping = ScrollClamping::Clamped);
+    WEBCORE_EXPORT void scrollToPositionWithoutAnimation(const FloatPoint&, ScrollClamping = ScrollClamping::Clamped);
+
     WEBCORE_EXPORT void scrollToOffsetWithoutAnimation(const FloatPoint&, ScrollClamping = ScrollClamping::Clamped);
     void scrollToOffsetWithoutAnimation(ScrollbarOrientation, float offset);
 
@@ -373,7 +375,7 @@
     
     // NOTE: Only called from the ScrollAnimator.
     friend class ScrollAnimator;
-    void setScrollOffsetFromAnimation(const ScrollOffset&);
+    void setScrollPositionFromAnimation(const ScrollPosition&);
 
     // This function should be overridden by subclasses to perform the actual
     // scroll of the content.

Modified: trunk/Source/WebCore/platform/generic/ScrollAnimatorGeneric.cpp (273274 => 273275)


--- trunk/Source/WebCore/platform/generic/ScrollAnimatorGeneric.cpp	2021-02-22 21:38:52 UTC (rev 273274)
+++ trunk/Source/WebCore/platform/generic/ScrollAnimatorGeneric.cpp	2021-02-22 21:39:40 UTC (rev 273275)
@@ -109,9 +109,8 @@
 }
 #endif
 
-void ScrollAnimatorGeneric::scrollToOffsetWithoutAnimation(const FloatPoint& offset, ScrollClamping clamping)
+bool ScrollAnimatorGeneric::scrollToPositionWithoutAnimation(const FloatPoint& position, ScrollClamping clamping)
 {
-    FloatPoint position = ScrollableArea::scrollPositionFromOffset(offset, toFloatSize(m_scrollableArea.scrollOrigin()));
     m_kineticAnimation->stop();
     m_kineticAnimation->clearScrollHistory();
 
@@ -120,7 +119,7 @@
         m_smoothAnimation->setCurrentPosition(position);
 #endif
 
-    ScrollAnimator::scrollToOffsetWithoutAnimation(offset, clamping);
+    return ScrollAnimator::scrollToPositionWithoutAnimation(position, clamping);
 }
 
 bool ScrollAnimatorGeneric::handleWheelEvent(const PlatformWheelEvent& event)

Modified: trunk/Source/WebCore/platform/generic/ScrollAnimatorGeneric.h (273274 => 273275)


--- trunk/Source/WebCore/platform/generic/ScrollAnimatorGeneric.h	2021-02-22 21:38:52 UTC (rev 273274)
+++ trunk/Source/WebCore/platform/generic/ScrollAnimatorGeneric.h	2021-02-22 21:39:40 UTC (rev 273275)
@@ -47,7 +47,7 @@
 #if ENABLE(SMOOTH_SCROLLING)
     bool scroll(ScrollbarOrientation, ScrollGranularity, float step, float multiplier, ScrollBehavior) override;
 #endif
-    void scrollToOffsetWithoutAnimation(const FloatPoint&, ScrollClamping) override;
+    bool scrollToPositionWithoutAnimation(const FloatPoint&, ScrollClamping) override;
     void willEndLiveResize() override;
 
     bool handleWheelEvent(const PlatformWheelEvent&) override;

Modified: trunk/Source/WebCore/platform/mac/ScrollAnimatorMac.h (273274 => 273275)


--- trunk/Source/WebCore/platform/mac/ScrollAnimatorMac.h	2021-02-22 21:38:52 UTC (rev 273274)
+++ trunk/Source/WebCore/platform/mac/ScrollAnimatorMac.h	2021-02-22 21:39:40 UTC (rev 273275)
@@ -80,7 +80,8 @@
     FloatSize m_contentAreaScrolledTimerScrollDelta;
 
     bool scroll(ScrollbarOrientation, ScrollGranularity, float step, float multiplier, ScrollBehavior) override;
-    void scrollToOffsetWithoutAnimation(const FloatPoint&, ScrollClamping) override;
+    bool scrollToPositionWithAnimation(const FloatPoint&) override;
+    bool scrollToPositionWithoutAnimation(const FloatPoint& position, ScrollClamping = ScrollClamping::Clamped) override;
 
 #if ENABLE(RUBBER_BANDING)
     bool shouldForwardWheelEventsToParent(const PlatformWheelEvent&) const;
@@ -132,8 +133,6 @@
 
     FloatPoint adjustScrollPositionIfNecessary(const FloatPoint&) const;
 
-    void immediateScrollToPosition(const FloatPoint&, ScrollClamping = ScrollClamping::Clamped);
-
     bool isUserScrollInProgress() const override;
     bool isRubberBandInProgress() const override;
     bool isScrollSnapInProgress() const override;

Modified: trunk/Source/WebCore/platform/mac/ScrollAnimatorMac.mm (273274 => 273275)


--- trunk/Source/WebCore/platform/mac/ScrollAnimatorMac.mm	2021-02-22 21:38:52 UTC (rev 273274)
+++ trunk/Source/WebCore/platform/mac/ScrollAnimatorMac.mm	2021-02-22 21:39:40 UTC (rev 273275)
@@ -787,23 +787,20 @@
 {
     m_haveScrolledSincePageLoad = true;
 
-    if (!scrollAnimationEnabledForSystem() || !m_scrollableArea.scrollAnimatorEnabled())
-        return ScrollAnimator::scroll(orientation, granularity, step, multiplier, behavior);
-
-    if (granularity == ScrollByPixel)
-        return ScrollAnimator::scroll(orientation, granularity, step, multiplier, behavior);
-
     // This method doesn't do directional snapping, but our base class does. It will call into
     // ScrollAnimatorMac::scroll again with the snapped positions and ScrollBehavior::Default.
     if (behavior == ScrollBehavior::DoDirectionalSnapping)
         return ScrollAnimator::scroll(orientation, granularity, step, multiplier, behavior);
 
-    FloatPoint currentPosition = this->currentPosition();
+    bool shouldAnimate = scrollAnimationEnabledForSystem() && m_scrollableArea.scrollAnimatorEnabled() && granularity != ScrollByPixel;
     FloatPoint newPosition = positionFromStep(orientation, step, multiplier);
-    newPosition = newPosition.constrainedBetween(m_scrollableArea.minimumScrollPosition(), m_scrollableArea.maximumScrollPosition());
-    if (currentPosition == newPosition)
-        return false;
+    newPosition = newPosition.constrainedBetween(scrollableArea().minimumScrollPosition(), scrollableArea().maximumScrollPosition());
 
+    LOG_WITH_STREAM(Scrolling, stream << "ScrollAnimatorMac::scroll from " << currentPosition() << " to " << newPosition);
+
+    if (!shouldAnimate)
+        return scrollToPositionWithoutAnimation(newPosition);
+
     if ([m_scrollAnimationHelper _isAnimating]) {
         NSPoint targetOrigin = [m_scrollAnimationHelper targetOrigin];
         if (orientation == HorizontalScrollbar)
@@ -812,18 +809,29 @@
             newPosition.setX(targetOrigin.x);
     }
 
-    LOG_WITH_STREAM(Scrolling, stream << "ScrollAnimatorMac::scroll " << " from " << currentPosition << " to " << newPosition);
+    LOG_WITH_STREAM(Scrolling, stream << "ScrollAnimatorMac::scroll " << " from " << currentPosition() << " to " << newPosition);
     [m_scrollAnimationHelper scrollToPoint:newPosition];
     return true;
 }
 
-// FIXME: Maybe this should take a position.
-void ScrollAnimatorMac::scrollToOffsetWithoutAnimation(const FloatPoint& offset, ScrollClamping clamping)
+bool ScrollAnimatorMac::scrollToPositionWithAnimation(const FloatPoint& newPosition)
 {
+    bool positionChanged = newPosition != currentPosition();
+    if (!positionChanged && !scrollableArea().scrollOriginChanged())
+        return false;
+
+    // FIXME: This is used primarily by smooth scrolling. This should ideally use native scroll animations.
+    // See: https://bugs.webkit.org/show_bug.cgi?id=218857
     [m_scrollAnimationHelper _stopRun];
-    immediateScrollToPosition(ScrollableArea::scrollPositionFromOffset(offset, toFloatSize(m_scrollableArea.scrollOrigin())), clamping);
+    return ScrollAnimator::scrollToPositionWithAnimation(newPosition);
 }
 
+bool ScrollAnimatorMac::scrollToPositionWithoutAnimation(const FloatPoint& position, ScrollClamping clamping)
+{
+    [m_scrollAnimationHelper _stopRun];
+    return ScrollAnimator::scrollToPositionWithoutAnimation(position, clamping);
+}
+
 FloatPoint ScrollAnimatorMac::adjustScrollPositionIfNecessary(const FloatPoint& position) const
 {
     if (!m_scrollableArea.constrainsScrollingToContentEdge())
@@ -844,21 +852,6 @@
     m_scrollableArea.setConstrainsScrollingToContentEdge(currentlyConstrainsToContentEdge);
 }
 
-void ScrollAnimatorMac::immediateScrollToPosition(const FloatPoint& newPosition, ScrollClamping clamping)
-{
-    FloatPoint currentPosition = this->currentPosition();
-    FloatPoint adjustedPosition = clamping == ScrollClamping::Clamped ? adjustScrollPositionIfNecessary(newPosition) : newPosition;
- 
-    bool positionChanged = adjustedPosition != currentPosition;
-    if (!positionChanged && !scrollableArea().scrollOriginChanged())
-        return;
-
-    FloatSize delta = adjustedPosition - currentPosition;
-    m_currentPosition = adjustedPosition;
-    notifyPositionChanged(delta);
-    updateActiveScrollSnapIndexForOffset();
-}
-
 bool ScrollAnimatorMac::isUserScrollInProgress() const
 {
     return m_scrollController.isUserScrollInProgress();
@@ -922,7 +915,7 @@
 void ScrollAnimatorMac::immediateScrollToPositionForScrollAnimation(const FloatPoint& newPosition)
 {
     ASSERT(m_scrollAnimationHelper);
-    immediateScrollToPosition(newPosition);
+    ScrollAnimator::scrollToPositionWithoutAnimation(newPosition);
 }
 
 void ScrollAnimatorMac::notifyPositionChanged(const FloatSize& delta)

Modified: trunk/Source/WebCore/rendering/RenderLayerScrollableArea.cpp (273274 => 273275)


--- trunk/Source/WebCore/rendering/RenderLayerScrollableArea.cpp	2021-02-22 21:38:52 UTC (rev 273274)
+++ trunk/Source/WebCore/rendering/RenderLayerScrollableArea.cpp	2021-02-22 21:39:40 UTC (rev 273275)
@@ -265,12 +265,12 @@
     setCurrentScrollType(options.type);
 
     ScrollOffset snappedOffset = ceiledIntPoint(scrollAnimator().adjustScrollOffsetForSnappingIfNeeded(clampedScrollOffset, options.snapPointSelectionMethod));
+    auto snappedPosition = scrollPositionFromOffset(snappedOffset);
     if (options.animated == AnimatedScroll::Yes)
-        ScrollableArea::scrollToOffsetWithAnimation(snappedOffset);
+        ScrollableArea::scrollToPositionWithAnimation(snappedPosition);
     else {
-        auto snappedPosition = scrollPositionFromOffset(snappedOffset);
         if (!requestScrollPositionUpdate(snappedPosition, options.type, options.clamping))
-            scrollToOffsetWithoutAnimation(snappedOffset, options.clamping);
+            scrollToPositionWithoutAnimation(snappedPosition, options.clamping);
         setScrollBehaviorStatus(ScrollBehaviorStatus::NotInAnimation);
     }
 
@@ -1157,7 +1157,7 @@
         return;
 
     m_scrollDimensionsDirty = true;
-    ScrollOffset originalScrollOffset = scrollOffset();
+    ScrollPosition originalScrollPosition = scrollPosition();
 
     computeScrollDimensions();
     m_layer.updateSelfPaintingLayer();
@@ -1188,8 +1188,8 @@
 
     updateScrollbarsAfterLayout();
 
-    if (originalScrollOffset != scrollOffset())
-        scrollToOffsetWithoutAnimation(IntPoint(scrollOffset()));
+    if (originalScrollPosition != scrollPosition())
+        scrollToPositionWithoutAnimation(IntPoint(scrollPosition()));
 
     if (m_layer.isComposited()) {
         m_layer.setNeedsCompositingGeometryUpdate();
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to