Changeset 273275 in webkit


Ignore:
Timestamp:
Feb 22, 2021 1:39:40 PM (3 years ago)
Author:
Martin Robinson
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.

Location:
trunk/Source/WebCore
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r273272 r273275  
     12021-02-22  Martin Robinson  <mrobinson@webkit.org>
     2
     3        Clean up ScrollableArea and ScrollAnimator API and convert less between offsets and positions
     4        https://bugs.webkit.org/show_bug.cgi?id=222111
     5
     6        Reviewed by Simon Fraser.
     7
     8        Clean up the APIs exposed by ScrollableArea and ScrollAnimator to make them more
     9        consistent. With this change it should be a bit easier to tell if a particular
     10        method will trigger an animation or not. In addition, we accept positions (as
     11        opposed to offsets) everywhere, which allows us to reduce the number of
     12        offset <-> position conversions.
     13
     14        Finally, this change is also interesting for scroll snap, because it will
     15        make it easier to use a native animation on MacOS to use for snapping after
     16        scrollbar thumb dragging.
     17
     18        No new tests. This should not change behavior.
     19
     20        * page/FrameView.cpp:
     21        (WebCore::FrameView::setScrollPosition): Use new ScrollableArea APIs that
     22        accept positions.
     23        (WebCore::FrameView::scrollToPositionWithAnimation): Added this version
     24        of the method that uses positions.
     25        (WebCore::FrameView::scrollToOffsetWithAnimation): Deleted.
     26        * page/FrameView.h: Update method declaration.
     27        * platform/ScrollAnimator.cpp:
     28        (WebCore::ScrollAnimator::scroll): Simplified a little bit the code that handles
     29        scroll snapping here. Unified scroll snap and non-scroll snap compilation paths.
     30        (WebCore::ScrollAnimator::scrollToOffsetWithoutAnimation): This method
     31        now converts to a position and then calls scrollToPositionWithoutAnimation.
     32        (WebCore::ScrollAnimator::scrollToPositionWithoutAnimation): Split this out
     33        from scrollToOffsetWithoutAnimation.
     34        (WebCore::ScrollAnimator::scrollToOffsetWithAnimation): This method now
     35        converts to a position and calls scrollToPositionWithAnimation.
     36        (WebCore::ScrollAnimator::scrollToPositionWithAnimation): Split this
     37        out from scrollToOffsetWithAnimation.
     38        (WebCore::ScrollAnimator::handleWheelEvent): Call scrollToPositionWithAnimation
     39        instead of using the scroll(...) method.
     40        (WebCore::ScrollAnimator::notifyPositionChanged): Eliminate a conversion here.
     41        (WebCore::ScrollAnimator::scrollWithoutAnimation): Deleted.
     42        (WebCore::ScrollAnimator::scrollToOffset): Deleted.
     43        * platform/ScrollAnimator.h: Update method list.
     44        * platform/ScrollView.cpp:
     45        (WebCore::ScrollView::updateScrollbars): Eliminate a conversion here.
     46        * platform/ScrollableArea.cpp:
     47        Removed scrollToOffsetWithAnimation and added two new methods scrollToPositionWithAnimation
     48        and scrollToPositionWithoutAnimation. scrollToOffsetWithoutAnimation is still used
     49        in quite a few places, so we maintain this.
     50        (WebCore::ScrollableArea::setScrollOffsetFromInternals): Use setScrollPositionFromAnimation now.
     51        (WebCore::ScrollableArea::setScrollPositionFromAnimation): Renamed from setScrollOffsetFromAnimation
     52        and eliminated a mandatory cnoversion.
     53        (WebCore::ScrollableArea::scrollToOffsetWithAnimation): Deleted.
     54        (WebCore::ScrollableArea::setScrollOffsetFromAnimation): Deleted.
     55        * platform/ScrollableArea.h: Update method declarations.
     56        * platform/mac/ScrollAnimatorMac.h: Ditto.
     57        * platform/mac/ScrollAnimatorMac.mm:
     58        (WebCore::ScrollAnimatorMac::scroll): Handle calling into scrollToPositionWithoutAnimation
     59        and scrollToPositionWithAnimation ourselves now that we have this API. This simplifies
     60        program flow a bit.
     61        (WebCore::ScrollAnimatorMac::scrollToPositionWithAnimation):
     62        (WebCore::ScrollAnimatorMac::scrollToPositionWithoutAnimation): Expose these two new
     63        methods which are part of the base class API now.
     64        (WebCore::ScrollAnimatorMac::immediateScrollToPositionForScrollAnimation): Use
     65        ScrollAnimator::scrollToPositionWithoutAnimation because it was the same as
     66        immediateScrollToPosition.
     67        (WebCore::ScrollAnimatorMac::scrollToOffsetWithoutAnimation): Deleted.
     68        (WebCore::ScrollAnimatorMac::immediateScrollToPosition): Deleted. No longer used.
     69        * rendering/RenderLayerScrollableArea.cpp:
     70        (WebCore::RenderLayerScrollableArea::scrollToOffset): Unconditionally convert to a position
     71        here.
     72        (WebCore::RenderLayerScrollableArea::updateScrollInfoAfterLayout): Use ScrollableArea::scrollToPositionWithoutAnimation
     73        because it eliminates one conversion between units.
     74
    1752021-02-22  Peng Liu  <peng.liu6@apple.com>
    276
  • trunk/Source/WebCore/page/FrameView.cpp

    r273220 r273275  
    23282328
    23292329    ScrollOffset snappedOffset = ceiledIntPoint(scrollAnimator().adjustScrollOffsetForSnappingIfNeeded(scrollOffsetFromPosition(scrollPosition), options.snapPointSelectionMethod));
     2330    auto snappedPosition = scrollPositionFromOffset(snappedOffset);
    23302331
    23312332    if (options.animated == AnimatedScroll::Yes)
    2332         scrollToOffsetWithAnimation(snappedOffset, currentScrollType(), options.clamping);
     2333        scrollToPositionWithAnimation(snappedPosition, currentScrollType(), options.clamping);
    23332334    else
    2334         ScrollView::setScrollPosition(scrollPositionFromOffset(snappedOffset), options);
     2335        ScrollView::setScrollPosition(snappedPosition, options);
    23352336
    23362337    setCurrentScrollType(oldScrollType);
     
    37643765}
    37653766
    3766 void FrameView::scrollToOffsetWithAnimation(const ScrollOffset& offset, ScrollType scrollType, ScrollClamping)
     3767void FrameView::scrollToPositionWithAnimation(const ScrollPosition& position, ScrollType scrollType, ScrollClamping)
    37673768{
    37683769    auto previousScrollType = currentScrollType();
     
    37713772    if (currentScrollBehaviorStatus() == ScrollBehaviorStatus::InNonNativeAnimation)
    37723773        scrollAnimator().cancelAnimations();
    3773     if (offset != this->scrollOffset())
    3774         ScrollableArea::scrollToOffsetWithAnimation(offset);
     3774    if (position != this->scrollPosition())
     3775        ScrollableArea::scrollToPositionWithAnimation(position);
    37753776
    37763777    setCurrentScrollType(previousScrollType);
  • trunk/Source/WebCore/page/FrameView.h

    r273220 r273275  
    676676    void renderLayerDidScroll(const RenderLayer&);
    677677
    678     WEBCORE_EXPORT void scrollToOffsetWithAnimation(const ScrollOffset&, ScrollType = ScrollType::Programmatic, ScrollClamping = ScrollClamping::Clamped);
     678    WEBCORE_EXPORT void scrollToPositionWithAnimation(const ScrollPosition&, ScrollType = ScrollType::Programmatic, ScrollClamping = ScrollClamping::Clamped);
    679679
    680680    bool inUpdateEmbeddedObjects() const { return m_inUpdateEmbeddedObjects; }
  • trunk/Source/WebCore/platform/ScrollAnimator.cpp

    r271496 r273275  
    8484{
    8585#if ENABLE(CSS_SCROLL_SNAP)
    86     if (behavior != ScrollBehavior::DoDirectionalSnapping)
    87         return scrollWithoutAnimation(orientation, step, multiplier);
    88 
    89     FloatSize scrollOrigin = toFloatSize(m_scrollableArea.scrollOrigin());
    90     FloatPoint newPosition = positionFromStep(orientation, step, multiplier);
    91     auto newOffset = ScrollableArea::scrollOffsetFromPosition(newPosition, scrollOrigin);
    92     auto currentOffset = ScrollableArea::scrollOffsetFromPosition(this->currentPosition(), scrollOrigin);
    93     if (orientation == HorizontalScrollbar) {
    94         newOffset.setX(m_scrollController.adjustScrollDestination(ScrollEventAxis::Horizontal, newOffset.x(), multiplier, currentOffset.x()));
    95         newPosition = ScrollableArea::scrollPositionFromOffset(newOffset, scrollOrigin);
    96         return scroll(HorizontalScrollbar, granularity, newPosition.x() - this->currentPosition().x(), 1.0);
     86    if (behavior == ScrollBehavior::DoDirectionalSnapping) {
     87        auto newOffset = ScrollableArea::scrollOffsetFromPosition(positionFromStep(orientation, step, multiplier), toFloatSize(m_scrollableArea.scrollOrigin()));
     88        auto currentOffset = m_scrollableArea.scrollOffset();
     89        if (orientation == HorizontalScrollbar) {
     90            newOffset.setX(m_scrollController.adjustScrollDestination(ScrollEventAxis::Horizontal, newOffset.x(), multiplier, currentOffset.x()));
     91            return scroll(HorizontalScrollbar, granularity, newOffset.x() - currentOffset.x(), 1.0);
     92        }
     93        newOffset.setY(m_scrollController.adjustScrollDestination(ScrollEventAxis::Vertical, newOffset.y(), multiplier, currentOffset.y()));
     94        return scroll(VerticalScrollbar, granularity, newOffset.y() - currentOffset.y(), 1.0);
    9795    }
    98 
    99     newOffset.setY(m_scrollController.adjustScrollDestination(ScrollEventAxis::Vertical, newPosition.y(), multiplier, currentOffset.y()));
    100     newPosition = ScrollableArea::scrollPositionFromOffset(newOffset, scrollOrigin);
    101     return scroll(VerticalScrollbar, granularity, newPosition.y() - this->currentPosition().y(), 1.0);
    10296#else
    10397    UNUSED_PARAM(granularity);
    10498    UNUSED_PARAM(behavior);
    105     return scrollWithoutAnimation(orientation, step, multiplier);
    106 #endif
    107 }
    108 
    109 bool ScrollAnimator::scrollWithoutAnimation(ScrollbarOrientation orientation, float step, float multiplier)
     99#endif
     100
     101    return scrollToPositionWithoutAnimation(positionFromStep(orientation, step, multiplier));
     102}
     103
     104bool ScrollAnimator::scrollToOffsetWithoutAnimation(const FloatPoint& offset, ScrollClamping clamping)
     105{
     106    return scrollToPositionWithoutAnimation(ScrollableArea::scrollPositionFromOffset(offset, toFloatSize(scrollableArea().scrollOrigin())), clamping);
     107}
     108
     109bool ScrollAnimator::scrollToPositionWithoutAnimation(const FloatPoint& position, ScrollClamping clamping)
    110110{
    111111    FloatPoint currentPosition = this->currentPosition();
    112     FloatPoint newPosition = positionFromStep(orientation, step, multiplier);
    113     newPosition = newPosition.constrainedBetween(m_scrollableArea.minimumScrollPosition(), m_scrollableArea.maximumScrollPosition());
    114     if (currentPosition == newPosition)
     112    auto adjustedPosition = clamping == ScrollClamping::Clamped ? position.constrainedBetween(scrollableArea().minimumScrollPosition(), scrollableArea().maximumScrollPosition()) : position;
     113
     114    // FIXME: In some cases on iOS the ScrollableArea position is out of sync with the ScrollAnimator position.
     115    // When these cases are fixed, this extra check against the ScrollableArea position can be removed.
     116    if (adjustedPosition == currentPosition && adjustedPosition == scrollableArea().scrollPosition() && !scrollableArea().scrollOriginChanged())
    115117        return false;
    116118
    117     m_currentPosition = newPosition;
    118     notifyPositionChanged(newPosition - currentPosition);
     119    m_currentPosition = adjustedPosition;
     120    notifyPositionChanged(adjustedPosition - currentPosition);
     121    updateActiveScrollSnapIndexForOffset();
    119122    return true;
    120123}
    121124
    122 void ScrollAnimator::scrollToOffset(const FloatPoint& offset)
    123 {
     125bool ScrollAnimator::scrollToOffsetWithAnimation(const FloatPoint& offset)
     126{
     127    return scrollToPositionWithAnimation(ScrollableArea::scrollPositionFromOffset(offset, toFloatSize(scrollableArea().scrollOrigin())));
     128}
     129
     130bool ScrollAnimator::scrollToPositionWithAnimation(const FloatPoint& newPosition)
     131{
     132    bool positionChanged = newPosition != currentPosition();
     133    if (!positionChanged && !scrollableArea().scrollOriginChanged())
     134        return false;
     135
    124136    m_animationProgrammaticScroll->setCurrentPosition(m_currentPosition);
    125     auto newPosition = ScrollableArea::scrollPositionFromOffset(offset, toFloatSize(m_scrollableArea.scrollOrigin()));
    126137    m_animationProgrammaticScroll->scroll(newPosition);
    127     m_scrollableArea.setScrollBehaviorStatus(ScrollBehaviorStatus::InNonNativeAnimation);
    128 }
    129 
    130 void ScrollAnimator::scrollToOffsetWithoutAnimation(const FloatPoint& offset, ScrollClamping)
    131 {
    132     FloatPoint newPosition = ScrollableArea::scrollPositionFromOffset(offset, toFloatSize(m_scrollableArea.scrollOrigin()));
    133     FloatSize delta = newPosition - currentPosition();
    134     m_currentPosition = newPosition;
    135     notifyPositionChanged(delta);
    136     updateActiveScrollSnapIndexForOffset();
     138    scrollableArea().setScrollBehaviorStatus(ScrollBehaviorStatus::InNonNativeAnimation);
     139    return true;
    137140}
    138141
     
    209212            }
    210213            if (e.hasPreciseScrollingDeltas())
    211                 scrollWithoutAnimation(VerticalScrollbar, verticalScrollbar->pixelStep(), -deltaY);
     214                scrollToPositionWithoutAnimation(positionFromStep(VerticalScrollbar, verticalScrollbar->pixelStep(), -deltaY));
    212215            else
    213216                scroll(VerticalScrollbar, granularity, verticalScrollbar->pixelStep(), -deltaY);
     
    222225            }
    223226            if (e.hasPreciseScrollingDeltas())
    224                 scrollWithoutAnimation(HorizontalScrollbar, horizontalScrollbar->pixelStep(), -deltaX);
     227                scrollToPositionWithoutAnimation(positionFromStep(HorizontalScrollbar, horizontalScrollbar->pixelStep(), -deltaX));
    225228            else
    226229                scroll(HorizontalScrollbar, granularity, horizontalScrollbar->pixelStep(), -deltaX);
     
    258261{
    259262    UNUSED_PARAM(delta);
    260     // FIXME: need to not map back and forth all the time.
    261     m_scrollableArea.setScrollOffsetFromAnimation(m_scrollableArea.scrollOffsetFromPosition(roundedIntPoint(currentPosition())));
     263    m_scrollableArea.setScrollPositionFromAnimation(roundedIntPoint(currentPosition()));
    262264
    263265#if ENABLE(CSS_SCROLL_SNAP) || ENABLE(RUBBER_BANDING)
  • trunk/Source/WebCore/platform/ScrollAnimator.h

    r271439 r273275  
    7979    // The base class implementation always scrolls immediately, never animates.
    8080    virtual bool scroll(ScrollbarOrientation, ScrollGranularity, float step, float multiplier, ScrollBehavior = ScrollBehavior::Default);
    81     bool scrollWithoutAnimation(ScrollbarOrientation, float step, float multiplier);
    8281
    83     void scrollToOffset(const FloatPoint&);
    84     virtual void scrollToOffsetWithoutAnimation(const FloatPoint&, ScrollClamping = ScrollClamping::Clamped);
     82    bool scrollToOffsetWithoutAnimation(const FloatPoint&, ScrollClamping = ScrollClamping::Clamped);
     83    virtual bool scrollToPositionWithoutAnimation(const FloatPoint& position, ScrollClamping = ScrollClamping::Clamped);
     84
     85    bool scrollToOffsetWithAnimation(const FloatPoint&);
     86    virtual bool scrollToPositionWithAnimation(const FloatPoint&);
    8587
    8688    ScrollableArea& scrollableArea() const { return m_scrollableArea; }
  • trunk/Source/WebCore/platform/ScrollView.cpp

    r271788 r273275  
    598598
    599599        if (adjustedScrollPosition != scrollPosition() || scrollOriginChanged()) {
    600             ScrollableArea::scrollToOffsetWithoutAnimation(scrollOffsetFromPosition(adjustedScrollPosition));
     600            ScrollableArea::scrollToPositionWithoutAnimation(adjustedScrollPosition);
    601601            resetScrollOriginChanged();
    602602        }
  • trunk/Source/WebCore/platform/ScrollableArea.cpp

    r272610 r273275  
    144144}
    145145
    146 void ScrollableArea::scrollToOffsetWithAnimation(const FloatPoint& offset, ScrollClamping)
    147 {
    148     LOG_WITH_STREAM(Scrolling, stream << "ScrollableArea " << this << " scrollToOffsetWithAnimation " << offset);
    149     scrollAnimator().scrollToOffset(offset);
     146void ScrollableArea::scrollToPositionWithoutAnimation(const FloatPoint& position, ScrollClamping clamping)
     147{
     148    LOG_WITH_STREAM(Scrolling, stream << "ScrollableArea " << this << " scrollToPositionWithoutAnimation " << position);
     149    scrollAnimator().scrollToPositionWithoutAnimation(position, clamping);
     150}
     151
     152void ScrollableArea::scrollToPositionWithAnimation(const FloatPoint& position, ScrollClamping)
     153{
     154    LOG_WITH_STREAM(Scrolling, stream << "ScrollableArea " << this << " scrollToPositionWithAnimation " << position);
     155    scrollAnimator().scrollToPositionWithAnimation(position);
    150156}
    151157
     
    160166    auto currentOffset = scrollOffsetFromPosition(IntPoint(scrollAnimator().currentPosition()));
    161167    if (orientation == HorizontalScrollbar)
    162         scrollToOffsetWithoutAnimation(FloatPoint(offset, currentOffset.y()));
     168        scrollAnimator().scrollToOffsetWithoutAnimation(FloatPoint(offset, currentOffset.y()));
    163169    else
    164         scrollToOffsetWithoutAnimation(FloatPoint(currentOffset.x(), offset));
     170        scrollAnimator().scrollToOffsetWithoutAnimation(FloatPoint(currentOffset.x(), offset));
    165171}
    166172
     
    231237void ScrollableArea::setScrollOffsetFromInternals(const ScrollOffset& offset)
    232238{
    233     setScrollOffsetFromAnimation(offset);
    234 }
    235 
    236 void ScrollableArea::setScrollOffsetFromAnimation(const ScrollOffset& offset)
    237 {
    238     ScrollPosition position = scrollPositionFromOffset(offset);
    239    
     239    setScrollPositionFromAnimation(scrollPositionFromOffset(offset));
     240}
     241
     242void ScrollableArea::setScrollPositionFromAnimation(const ScrollPosition& position)
     243{
    240244    auto scrollType = currentScrollType();
    241245    auto clamping = scrollType == ScrollType::User ? ScrollClamping::Unclamped : ScrollClamping::Clamped;
     
    551555    if (correctedPosition != currentPosition) {
    552556        LOG_WITH_STREAM(ScrollSnap, stream << " adjusting position from " << currentPosition << " to " << correctedPosition);
    553         scrollToOffsetWithoutAnimation(correctedPosition);
     557        scrollToPositionWithoutAnimation(correctedPosition);
    554558    }
    555559}
  • trunk/Source/WebCore/platform/ScrollableArea.h

    r272610 r273275  
    7272
    7373    WEBCORE_EXPORT bool scroll(ScrollDirection, ScrollGranularity, float multiplier = 1);
    74     WEBCORE_EXPORT void scrollToOffsetWithAnimation(const FloatPoint&, ScrollClamping = ScrollClamping::Clamped);
     74    WEBCORE_EXPORT void scrollToPositionWithAnimation(const FloatPoint&, ScrollClamping = ScrollClamping::Clamped);
     75    WEBCORE_EXPORT void scrollToPositionWithoutAnimation(const FloatPoint&, ScrollClamping = ScrollClamping::Clamped);
     76
    7577    WEBCORE_EXPORT void scrollToOffsetWithoutAnimation(const FloatPoint&, ScrollClamping = ScrollClamping::Clamped);
    7678    void scrollToOffsetWithoutAnimation(ScrollbarOrientation, float offset);
     
    374376    // NOTE: Only called from the ScrollAnimator.
    375377    friend class ScrollAnimator;
    376     void setScrollOffsetFromAnimation(const ScrollOffset&);
     378    void setScrollPositionFromAnimation(const ScrollPosition&);
    377379
    378380    // This function should be overridden by subclasses to perform the actual
  • trunk/Source/WebCore/platform/generic/ScrollAnimatorGeneric.cpp

    r273070 r273275  
    110110#endif
    111111
    112 void ScrollAnimatorGeneric::scrollToOffsetWithoutAnimation(const FloatPoint& offset, ScrollClamping clamping)
    113 {
    114     FloatPoint position = ScrollableArea::scrollPositionFromOffset(offset, toFloatSize(m_scrollableArea.scrollOrigin()));
     112bool ScrollAnimatorGeneric::scrollToPositionWithoutAnimation(const FloatPoint& position, ScrollClamping clamping)
     113{
    115114    m_kineticAnimation->stop();
    116115    m_kineticAnimation->clearScrollHistory();
     
    121120#endif
    122121
    123     ScrollAnimator::scrollToOffsetWithoutAnimation(offset, clamping);
     122    return ScrollAnimator::scrollToPositionWithoutAnimation(position, clamping);
    124123}
    125124
  • trunk/Source/WebCore/platform/generic/ScrollAnimatorGeneric.h

    r270838 r273275  
    4848    bool scroll(ScrollbarOrientation, ScrollGranularity, float step, float multiplier, ScrollBehavior) override;
    4949#endif
    50     void scrollToOffsetWithoutAnimation(const FloatPoint&, ScrollClamping) override;
     50    bool scrollToPositionWithoutAnimation(const FloatPoint&, ScrollClamping) override;
    5151    void willEndLiveResize() override;
    5252
  • trunk/Source/WebCore/platform/mac/ScrollAnimatorMac.h

    r271081 r273275  
    8181
    8282    bool scroll(ScrollbarOrientation, ScrollGranularity, float step, float multiplier, ScrollBehavior) override;
    83     void scrollToOffsetWithoutAnimation(const FloatPoint&, ScrollClamping) override;
     83    bool scrollToPositionWithAnimation(const FloatPoint&) override;
     84    bool scrollToPositionWithoutAnimation(const FloatPoint& position, ScrollClamping = ScrollClamping::Clamped) override;
    8485
    8586#if ENABLE(RUBBER_BANDING)
     
    133134    FloatPoint adjustScrollPositionIfNecessary(const FloatPoint&) const;
    134135
    135     void immediateScrollToPosition(const FloatPoint&, ScrollClamping = ScrollClamping::Clamped);
    136 
    137136    bool isUserScrollInProgress() const override;
    138137    bool isRubberBandInProgress() const override;
  • trunk/Source/WebCore/platform/mac/ScrollAnimatorMac.mm

    r271658 r273275  
    788788    m_haveScrolledSincePageLoad = true;
    789789
    790     if (!scrollAnimationEnabledForSystem() || !m_scrollableArea.scrollAnimatorEnabled())
    791         return ScrollAnimator::scroll(orientation, granularity, step, multiplier, behavior);
    792 
    793     if (granularity == ScrollByPixel)
    794         return ScrollAnimator::scroll(orientation, granularity, step, multiplier, behavior);
    795 
    796790    // This method doesn't do directional snapping, but our base class does. It will call into
    797791    // ScrollAnimatorMac::scroll again with the snapped positions and ScrollBehavior::Default.
     
    799793        return ScrollAnimator::scroll(orientation, granularity, step, multiplier, behavior);
    800794
    801     FloatPoint currentPosition = this->currentPosition();
     795    bool shouldAnimate = scrollAnimationEnabledForSystem() && m_scrollableArea.scrollAnimatorEnabled() && granularity != ScrollByPixel;
    802796    FloatPoint newPosition = positionFromStep(orientation, step, multiplier);
    803     newPosition = newPosition.constrainedBetween(m_scrollableArea.minimumScrollPosition(), m_scrollableArea.maximumScrollPosition());
    804     if (currentPosition == newPosition)
    805         return false;
     797    newPosition = newPosition.constrainedBetween(scrollableArea().minimumScrollPosition(), scrollableArea().maximumScrollPosition());
     798
     799    LOG_WITH_STREAM(Scrolling, stream << "ScrollAnimatorMac::scroll from " << currentPosition() << " to " << newPosition);
     800
     801    if (!shouldAnimate)
     802        return scrollToPositionWithoutAnimation(newPosition);
    806803
    807804    if ([m_scrollAnimationHelper _isAnimating]) {
     
    813810    }
    814811
    815     LOG_WITH_STREAM(Scrolling, stream << "ScrollAnimatorMac::scroll " << " from " << currentPosition << " to " << newPosition);
     812    LOG_WITH_STREAM(Scrolling, stream << "ScrollAnimatorMac::scroll " << " from " << currentPosition() << " to " << newPosition);
    816813    [m_scrollAnimationHelper scrollToPoint:newPosition];
    817814    return true;
    818815}
    819816
    820 // FIXME: Maybe this should take a position.
    821 void ScrollAnimatorMac::scrollToOffsetWithoutAnimation(const FloatPoint& offset, ScrollClamping clamping)
    822 {
     817bool ScrollAnimatorMac::scrollToPositionWithAnimation(const FloatPoint& newPosition)
     818{
     819    bool positionChanged = newPosition != currentPosition();
     820    if (!positionChanged && !scrollableArea().scrollOriginChanged())
     821        return false;
     822
     823    // FIXME: This is used primarily by smooth scrolling. This should ideally use native scroll animations.
     824    // See: https://bugs.webkit.org/show_bug.cgi?id=218857
    823825    [m_scrollAnimationHelper _stopRun];
    824     immediateScrollToPosition(ScrollableArea::scrollPositionFromOffset(offset, toFloatSize(m_scrollableArea.scrollOrigin())), clamping);
     826    return ScrollAnimator::scrollToPositionWithAnimation(newPosition);
     827}
     828
     829bool ScrollAnimatorMac::scrollToPositionWithoutAnimation(const FloatPoint& position, ScrollClamping clamping)
     830{
     831    [m_scrollAnimationHelper _stopRun];
     832    return ScrollAnimator::scrollToPositionWithoutAnimation(position, clamping);
    825833}
    826834
     
    843851
    844852    m_scrollableArea.setConstrainsScrollingToContentEdge(currentlyConstrainsToContentEdge);
    845 }
    846 
    847 void ScrollAnimatorMac::immediateScrollToPosition(const FloatPoint& newPosition, ScrollClamping clamping)
    848 {
    849     FloatPoint currentPosition = this->currentPosition();
    850     FloatPoint adjustedPosition = clamping == ScrollClamping::Clamped ? adjustScrollPositionIfNecessary(newPosition) : newPosition;
    851  
    852     bool positionChanged = adjustedPosition != currentPosition;
    853     if (!positionChanged && !scrollableArea().scrollOriginChanged())
    854         return;
    855 
    856     FloatSize delta = adjustedPosition - currentPosition;
    857     m_currentPosition = adjustedPosition;
    858     notifyPositionChanged(delta);
    859     updateActiveScrollSnapIndexForOffset();
    860853}
    861854
     
    923916{
    924917    ASSERT(m_scrollAnimationHelper);
    925     immediateScrollToPosition(newPosition);
     918    ScrollAnimator::scrollToPositionWithoutAnimation(newPosition);
    926919}
    927920
  • trunk/Source/WebCore/rendering/RenderLayerScrollableArea.cpp

    r271814 r273275  
    266266
    267267    ScrollOffset snappedOffset = ceiledIntPoint(scrollAnimator().adjustScrollOffsetForSnappingIfNeeded(clampedScrollOffset, options.snapPointSelectionMethod));
     268    auto snappedPosition = scrollPositionFromOffset(snappedOffset);
    268269    if (options.animated == AnimatedScroll::Yes)
    269         ScrollableArea::scrollToOffsetWithAnimation(snappedOffset);
     270        ScrollableArea::scrollToPositionWithAnimation(snappedPosition);
    270271    else {
    271         auto snappedPosition = scrollPositionFromOffset(snappedOffset);
    272272        if (!requestScrollPositionUpdate(snappedPosition, options.type, options.clamping))
    273             scrollToOffsetWithoutAnimation(snappedOffset, options.clamping);
     273            scrollToPositionWithoutAnimation(snappedPosition, options.clamping);
    274274        setScrollBehaviorStatus(ScrollBehaviorStatus::NotInAnimation);
    275275    }
     
    11581158
    11591159    m_scrollDimensionsDirty = true;
    1160     ScrollOffset originalScrollOffset = scrollOffset();
     1160    ScrollPosition originalScrollPosition = scrollPosition();
    11611161
    11621162    computeScrollDimensions();
     
    11891189    updateScrollbarsAfterLayout();
    11901190
    1191     if (originalScrollOffset != scrollOffset())
    1192         scrollToOffsetWithoutAnimation(IntPoint(scrollOffset()));
     1191    if (originalScrollPosition != scrollPosition())
     1192        scrollToPositionWithoutAnimation(IntPoint(scrollPosition()));
    11931193
    11941194    if (m_layer.isComposited()) {
Note: See TracChangeset for help on using the changeset viewer.