⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 286126 in webkit


Ignore:
Timestamp:
Nov 22, 2021, 6:28:18 PM (5 years ago)
Author:
Simon Fraser
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.

Location:
trunk/Source/WebCore
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r286125 r286126  
     12021-11-22  Simon Fraser  <simon.fraser@apple.com>
     2
     3        Have ScrollAnimator::scrollToPositionWithAnimation() take a clamping argument
     4        https://bugs.webkit.org/show_bug.cgi?id=233438
     5
     6        Reviewed by Cameron McCormack.
     7
     8        Create symmetry between scrollToPositionWithAnimation() and scrollToPositionWithoutAnimation()
     9        by adding a ScrollClamping argument to the former. Neither need to be virtual.
     10
     11        ScrollAnimator::cancelAnimations() does not need to be virtual.
     12
     13        Rename ScrollableArea::constrainScrollPosition() to ScrollableArea::constrainedScrollPosition()
     14        because it just returns a new position.
     15
     16        * platform/KeyboardScrollingAnimator.cpp:
     17        (WebCore::KeyboardScrollingAnimator::updateKeyboardScrollPosition):
     18        (WebCore::KeyboardScrollingAnimator::stopKeyboardScrollAnimation):
     19        * platform/ScrollAnimator.cpp:
     20        (WebCore::ScrollAnimator::scrollToPositionWithAnimation):
     21        (WebCore::ScrollAnimator::adjustScrollPositionToBoundsIfNecessary):
     22        (WebCore::ScrollAnimator::adjustScrollPositionIfNecessary const):
     23        * platform/ScrollAnimator.h:
     24        * platform/ScrollableArea.cpp:
     25        (WebCore::ScrollableArea::scrollToPositionWithAnimation):
     26        * platform/ScrollableArea.h:
     27        (WebCore::ScrollableArea::constrainedScrollPosition const):
     28        (WebCore::ScrollableArea::constrainScrollPosition const): Deleted.
     29
    1302021-11-22  Wenson Hsieh  <wenson_hsieh@apple.com>
    231
  • trunk/Source/WebCore/platform/KeyboardScrollingAnimator.cpp

    r286115 r286126  
    125125    }
    126126
    127     ScrollPosition idealPosition = m_scrollAnimator.scrollableArea().constrainScrollPosition(IntPoint(m_currentKeyboardScroll ? m_scrollAnimator.currentPosition() : m_idealPosition));
     127    ScrollPosition idealPosition = m_scrollAnimator.scrollableArea().constrainedScrollPosition(IntPoint(m_currentKeyboardScroll ? m_scrollAnimator.currentPosition() : m_idealPosition));
    128128    FloatSize displacement = m_scrollAnimator.currentPosition() - idealPosition;
    129129
     
    318318    // out to that point.
    319319    ScrollPosition farthestPoint = farthestPointInDirection(m_scrollAnimator.currentPosition() + displacement, m_idealPositionForMinimumTravel, m_currentKeyboardScroll->direction);
    320     m_idealPosition = m_scrollAnimator.scrollableArea().constrainScrollPosition(farthestPoint);
     320    m_idealPosition = m_scrollAnimator.scrollableArea().constrainedScrollPosition(farthestPoint);
    321321
    322322    m_currentKeyboardScroll = std::nullopt;
  • trunk/Source/WebCore/platform/ScrollAnimator.cpp

    r286119 r286126  
    108108}
    109109
    110 bool ScrollAnimator::scrollToPositionWithAnimation(const FloatPoint& newPosition)
    111 {
    112     bool positionChanged = newPosition != currentPosition();
     110bool ScrollAnimator::scrollToPositionWithAnimation(const FloatPoint& position, ScrollClamping clamping)
     111{
     112    auto adjustedPosition = clamping == ScrollClamping::Clamped ? position.constrainedBetween(scrollableArea().minimumScrollPosition(), scrollableArea().maximumScrollPosition()) : position;
     113    bool positionChanged = adjustedPosition != currentPosition();
    113114    if (!positionChanged && !scrollableArea().scrollOriginChanged())
    114115        return false;
    115116
    116     return m_scrollController.startAnimatedScrollToDestination(offsetFromPosition(m_currentPosition), offsetFromPosition(newPosition));
     117    return m_scrollController.startAnimatedScrollToDestination(offsetFromPosition(m_currentPosition), offsetFromPosition(adjustedPosition));
    117118}
    118119
     
    310311
    311312    auto currentScrollPosition = m_scrollableArea.scrollPosition();
    312     auto constrainedPosition = m_scrollableArea.constrainScrollPosition(currentScrollPosition);
     313    auto constrainedPosition = m_scrollableArea.constrainedScrollPosition(currentScrollPosition);
    313314    immediateScrollBy(constrainedPosition - currentScrollPosition);
    314315
     
    321322        return position;
    322323
    323     return m_scrollableArea.constrainScrollPosition(ScrollPosition(position));
     324    return m_scrollableArea.constrainedScrollPosition(ScrollPosition(position));
    324325}
    325326
  • trunk/Source/WebCore/platform/ScrollAnimator.h

    r286115 r286126  
    7777    bool singleAxisScroll(ScrollEventAxis, float delta, OptionSet<ScrollBehavior>);
    7878
    79     virtual bool scrollToPositionWithoutAnimation(const FloatPoint&, ScrollClamping = ScrollClamping::Clamped);
    80     bool scrollToPositionWithAnimation(const FloatPoint&);
     79    bool scrollToPositionWithoutAnimation(const FloatPoint&, ScrollClamping = ScrollClamping::Clamped);
     80    bool scrollToPositionWithAnimation(const FloatPoint&, ScrollClamping = ScrollClamping::Clamped);
    8181
    8282    void retargetRunningAnimation(const FloatPoint& newPosition);
    8383
    8484    virtual bool handleWheelEvent(const PlatformWheelEvent&);
    85 
    8685    virtual bool processWheelEventForScrollSnap(const PlatformWheelEvent&) { return false; }
    8786
     
    9695#endif
    9796
    98     virtual void cancelAnimations();
     97    void cancelAnimations();
    9998
    10099    virtual bool isRubberBandInProgress() const { return false; }
  • trunk/Source/WebCore/platform/ScrollableArea.cpp

    r286119 r286126  
    144144    bool startedAnimation = requestAnimatedScrollToPosition(roundedIntPoint(position), clamping);
    145145    if (!startedAnimation)
    146         startedAnimation = scrollAnimator().scrollToPositionWithAnimation(position);
     146        startedAnimation = scrollAnimator().scrollToPositionWithAnimation(position, clamping);
    147147
    148148    if (startedAnimation)
  • trunk/Source/WebCore/platform/ScrollableArea.h

    r286119 r286126  
    237237    virtual ScrollPosition maximumScrollPosition() const;
    238238
    239     ScrollPosition constrainScrollPosition(const ScrollPosition& position) const
     239    ScrollPosition constrainedScrollPosition(const ScrollPosition& position) const
    240240    {
    241241        return position.constrainedBetween(minimumScrollPosition(), maximumScrollPosition());
Note: See TracChangeset for help on using the changeset viewer.