Title: [286126] trunk/Source/WebCore
Revision
286126
Author
[email protected]
Date
2021-11-22 18:28:18 -0800 (Mon, 22 Nov 2021)

Log Message

Have ScrollAnimator::scrollToPositionWithAnimation() take a clamping argument
https://bugs.webkit.org/show_bug.cgi?id=233438

Reviewed by Cameron McCormack.

Create symmetry between scrollToPositionWithAnimation() and scrollToPositionWithoutAnimation()
by adding a ScrollClamping argument to the former. Neither need to be virtual.

ScrollAnimator::cancelAnimations() does not need to be virtual.

Rename ScrollableArea::constrainScrollPosition() to ScrollableArea::constrainedScrollPosition()
because it just returns a new position.

* platform/KeyboardScrollingAnimator.cpp:
(WebCore::KeyboardScrollingAnimator::updateKeyboardScrollPosition):
(WebCore::KeyboardScrollingAnimator::stopKeyboardScrollAnimation):
* platform/ScrollAnimator.cpp:
(WebCore::ScrollAnimator::scrollToPositionWithAnimation):
(WebCore::ScrollAnimator::adjustScrollPositionToBoundsIfNecessary):
(WebCore::ScrollAnimator::adjustScrollPositionIfNecessary const):
* platform/ScrollAnimator.h:
* platform/ScrollableArea.cpp:
(WebCore::ScrollableArea::scrollToPositionWithAnimation):
* platform/ScrollableArea.h:
(WebCore::ScrollableArea::constrainedScrollPosition const):
(WebCore::ScrollableArea::constrainScrollPosition const): Deleted.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (286125 => 286126)


--- trunk/Source/WebCore/ChangeLog	2021-11-23 02:24:59 UTC (rev 286125)
+++ trunk/Source/WebCore/ChangeLog	2021-11-23 02:28:18 UTC (rev 286126)
@@ -1,3 +1,32 @@
+2021-11-22  Simon Fraser  <[email protected]>
+
+        Have ScrollAnimator::scrollToPositionWithAnimation() take a clamping argument
+        https://bugs.webkit.org/show_bug.cgi?id=233438
+
+        Reviewed by Cameron McCormack.
+
+        Create symmetry between scrollToPositionWithAnimation() and scrollToPositionWithoutAnimation()
+        by adding a ScrollClamping argument to the former. Neither need to be virtual.
+
+        ScrollAnimator::cancelAnimations() does not need to be virtual.
+
+        Rename ScrollableArea::constrainScrollPosition() to ScrollableArea::constrainedScrollPosition()
+        because it just returns a new position.
+
+        * platform/KeyboardScrollingAnimator.cpp:
+        (WebCore::KeyboardScrollingAnimator::updateKeyboardScrollPosition):
+        (WebCore::KeyboardScrollingAnimator::stopKeyboardScrollAnimation):
+        * platform/ScrollAnimator.cpp:
+        (WebCore::ScrollAnimator::scrollToPositionWithAnimation):
+        (WebCore::ScrollAnimator::adjustScrollPositionToBoundsIfNecessary):
+        (WebCore::ScrollAnimator::adjustScrollPositionIfNecessary const):
+        * platform/ScrollAnimator.h:
+        * platform/ScrollableArea.cpp:
+        (WebCore::ScrollableArea::scrollToPositionWithAnimation):
+        * platform/ScrollableArea.h:
+        (WebCore::ScrollableArea::constrainedScrollPosition const):
+        (WebCore::ScrollableArea::constrainScrollPosition const): Deleted.
+
 2021-11-22  Wenson Hsieh  <[email protected]>
 
         Remove old concurrent display list logic that's no longer necessary

Modified: trunk/Source/WebCore/platform/KeyboardScrollingAnimator.cpp (286125 => 286126)


--- trunk/Source/WebCore/platform/KeyboardScrollingAnimator.cpp	2021-11-23 02:24:59 UTC (rev 286125)
+++ trunk/Source/WebCore/platform/KeyboardScrollingAnimator.cpp	2021-11-23 02:28:18 UTC (rev 286126)
@@ -124,7 +124,7 @@
             force.setHeight(0);
     }
 
-    ScrollPosition idealPosition = m_scrollAnimator.scrollableArea().constrainScrollPosition(IntPoint(m_currentKeyboardScroll ? m_scrollAnimator.currentPosition() : m_idealPosition));
+    ScrollPosition idealPosition = m_scrollAnimator.scrollableArea().constrainedScrollPosition(IntPoint(m_currentKeyboardScroll ? m_scrollAnimator.currentPosition() : m_idealPosition));
     FloatSize displacement = m_scrollAnimator.currentPosition() - idealPosition;
 
     auto springForce = -displacement.scaled(params.springStiffness) - m_velocity.scaled(params.springDamping);
@@ -317,7 +317,7 @@
     // for an instantaneous tap, move the settling position of the spring
     // out to that point.
     ScrollPosition farthestPoint = farthestPointInDirection(m_scrollAnimator.currentPosition() + displacement, m_idealPositionForMinimumTravel, m_currentKeyboardScroll->direction);
-    m_idealPosition = m_scrollAnimator.scrollableArea().constrainScrollPosition(farthestPoint);
+    m_idealPosition = m_scrollAnimator.scrollableArea().constrainedScrollPosition(farthestPoint);
 
     m_currentKeyboardScroll = std::nullopt;
 }

Modified: trunk/Source/WebCore/platform/ScrollAnimator.cpp (286125 => 286126)


--- trunk/Source/WebCore/platform/ScrollAnimator.cpp	2021-11-23 02:24:59 UTC (rev 286125)
+++ trunk/Source/WebCore/platform/ScrollAnimator.cpp	2021-11-23 02:28:18 UTC (rev 286126)
@@ -107,13 +107,14 @@
     return true;
 }
 
-bool ScrollAnimator::scrollToPositionWithAnimation(const FloatPoint& newPosition)
+bool ScrollAnimator::scrollToPositionWithAnimation(const FloatPoint& position, ScrollClamping clamping)
 {
-    bool positionChanged = newPosition != currentPosition();
+    auto adjustedPosition = clamping == ScrollClamping::Clamped ? position.constrainedBetween(scrollableArea().minimumScrollPosition(), scrollableArea().maximumScrollPosition()) : position;
+    bool positionChanged = adjustedPosition != currentPosition();
     if (!positionChanged && !scrollableArea().scrollOriginChanged())
         return false;
 
-    return m_scrollController.startAnimatedScrollToDestination(offsetFromPosition(m_currentPosition), offsetFromPosition(newPosition));
+    return m_scrollController.startAnimatedScrollToDestination(offsetFromPosition(m_currentPosition), offsetFromPosition(adjustedPosition));
 }
 
 void ScrollAnimator::retargetRunningAnimation(const FloatPoint& newPosition)
@@ -309,7 +310,7 @@
     m_scrollableArea.setScrollClamping(ScrollClamping::Clamped);
 
     auto currentScrollPosition = m_scrollableArea.scrollPosition();
-    auto constrainedPosition = m_scrollableArea.constrainScrollPosition(currentScrollPosition);
+    auto constrainedPosition = m_scrollableArea.constrainedScrollPosition(currentScrollPosition);
     immediateScrollBy(constrainedPosition - currentScrollPosition);
 
     m_scrollableArea.setScrollClamping(previousClamping);
@@ -320,7 +321,7 @@
     if (m_scrollableArea.scrollClamping() == ScrollClamping::Unclamped)
         return position;
 
-    return m_scrollableArea.constrainScrollPosition(ScrollPosition(position));
+    return m_scrollableArea.constrainedScrollPosition(ScrollPosition(position));
 }
 
 void ScrollAnimator::immediateScrollBy(const FloatSize& delta, ScrollClamping clamping)

Modified: trunk/Source/WebCore/platform/ScrollAnimator.h (286125 => 286126)


--- trunk/Source/WebCore/platform/ScrollAnimator.h	2021-11-23 02:24:59 UTC (rev 286125)
+++ trunk/Source/WebCore/platform/ScrollAnimator.h	2021-11-23 02:28:18 UTC (rev 286126)
@@ -76,13 +76,12 @@
     // The base class implementation always scrolls immediately, never animates.
     bool singleAxisScroll(ScrollEventAxis, float delta, OptionSet<ScrollBehavior>);
 
-    virtual bool scrollToPositionWithoutAnimation(const FloatPoint&, ScrollClamping = ScrollClamping::Clamped);
-    bool scrollToPositionWithAnimation(const FloatPoint&);
+    bool scrollToPositionWithoutAnimation(const FloatPoint&, ScrollClamping = ScrollClamping::Clamped);
+    bool scrollToPositionWithAnimation(const FloatPoint&, ScrollClamping = ScrollClamping::Clamped);
 
     void retargetRunningAnimation(const FloatPoint& newPosition);
 
     virtual bool handleWheelEvent(const PlatformWheelEvent&);
-
     virtual bool processWheelEventForScrollSnap(const PlatformWheelEvent&) { return false; }
 
     void stopKeyboardScrollAnimation();
@@ -95,7 +94,7 @@
     virtual bool handleTouchEvent(const PlatformTouchEvent&);
 #endif
 
-    virtual void cancelAnimations();
+    void cancelAnimations();
 
     virtual bool isRubberBandInProgress() const { return false; }
 

Modified: trunk/Source/WebCore/platform/ScrollableArea.cpp (286125 => 286126)


--- trunk/Source/WebCore/platform/ScrollableArea.cpp	2021-11-23 02:24:59 UTC (rev 286125)
+++ trunk/Source/WebCore/platform/ScrollableArea.cpp	2021-11-23 02:28:18 UTC (rev 286126)
@@ -143,7 +143,7 @@
 
     bool startedAnimation = requestAnimatedScrollToPosition(roundedIntPoint(position), clamping);
     if (!startedAnimation)
-        startedAnimation = scrollAnimator().scrollToPositionWithAnimation(position);
+        startedAnimation = scrollAnimator().scrollToPositionWithAnimation(position, clamping);
 
     if (startedAnimation)
         setScrollAnimationStatus(ScrollAnimationStatus::Animating);

Modified: trunk/Source/WebCore/platform/ScrollableArea.h (286125 => 286126)


--- trunk/Source/WebCore/platform/ScrollableArea.h	2021-11-23 02:24:59 UTC (rev 286125)
+++ trunk/Source/WebCore/platform/ScrollableArea.h	2021-11-23 02:28:18 UTC (rev 286126)
@@ -236,7 +236,7 @@
     virtual ScrollPosition minimumScrollPosition() const;
     virtual ScrollPosition maximumScrollPosition() const;
 
-    ScrollPosition constrainScrollPosition(const ScrollPosition& position) const
+    ScrollPosition constrainedScrollPosition(const ScrollPosition& position) const
     {
         return position.constrainedBetween(minimumScrollPosition(), maximumScrollPosition());
     }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to