Changeset 266390 in webkit


Ignore:
Timestamp:
Sep 1, 2020 2:51:27 AM (4 years ago)
Author:
Chris Lord
Message:

[GTK][WPE] Add support for smooth scrolling animation with async scrolling
https://bugs.webkit.org/show_bug.cgi?id=210382

Reviewed by Carlos Garcia Campos.

This removes the dependency on ScrollableArea from
ScrollAnimationSmooth, which allows its use as a utility class for
smooth scrolling. This class is then used in the Nicosia async layer
composition scrolling code to provide smooth scrolling, when the
feature is enabled. This mirrors the work done in bug 209230 for
kinetic scrolling.

No new tests, enabling existing functionality in more situations.

  • page/scrolling/ScrollingTreeScrollingNode.cpp:

(WebCore::ScrollingTreeScrollingNode::scrollTo):

  • page/scrolling/nicosia/ScrollingTreeFrameScrollingNodeNicosia.cpp:

(WebCore::ScrollingTreeFrameScrollingNodeNicosia::ScrollingTreeFrameScrollingNodeNicosia):
(WebCore::ScrollingTreeFrameScrollingNodeNicosia::commitStateAfterChildren):
(WebCore::ScrollingTreeFrameScrollingNodeNicosia::handleWheelEvent):
(WebCore::ScrollingTreeFrameScrollingNodeNicosia::stopScrollAnimations):

  • page/scrolling/nicosia/ScrollingTreeFrameScrollingNodeNicosia.h:
  • page/scrolling/nicosia/ScrollingTreeOverflowScrollingNodeNicosia.cpp:

(WebCore::ScrollingTreeOverflowScrollingNodeNicosia::ScrollingTreeOverflowScrollingNodeNicosia):
(WebCore::ScrollingTreeOverflowScrollingNodeNicosia::commitStateAfterChildren):
(WebCore::ScrollingTreeOverflowScrollingNodeNicosia::handleWheelEvent):
(WebCore::ScrollingTreeOverflowScrollingNodeNicosia::stopScrollAnimations):

  • page/scrolling/nicosia/ScrollingTreeOverflowScrollingNodeNicosia.h:
  • platform/ScrollAnimation.h:

(WebCore::ScrollAnimation::serviceAnimation):

  • platform/ScrollAnimationKinetic.cpp:
  • platform/ScrollAnimationKinetic.h:
  • platform/ScrollAnimationSmooth.cpp:

(WebCore::ScrollAnimationSmooth::ScrollAnimationSmooth):
(WebCore::ScrollAnimationSmooth::scroll):
(WebCore::ScrollAnimationSmooth::stop):
(WebCore::ScrollAnimationSmooth::updateVisibleLengths):
(WebCore::ScrollAnimationSmooth::animationTimerFired):

  • platform/ScrollAnimationSmooth.h:
  • platform/ScrollAnimator.cpp:

(WebCore::ScrollAnimator::ScrollAnimator):

  • platform/generic/ScrollAnimatorGeneric.cpp:

(WebCore::ScrollAnimatorGeneric::ScrollAnimatorGeneric):
(WebCore::ScrollAnimatorGeneric::ensureSmoothScrollingAnimation):

Location:
trunk/Source/WebCore
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r266388 r266390  
     12020-09-01  Chris Lord  <clord@igalia.com>
     2
     3        [GTK][WPE] Add support for smooth scrolling animation with async scrolling
     4        https://bugs.webkit.org/show_bug.cgi?id=210382
     5
     6        Reviewed by Carlos Garcia Campos.
     7
     8        This removes the dependency on ScrollableArea from
     9        ScrollAnimationSmooth, which allows its use as a utility class for
     10        smooth scrolling. This class is then used in the Nicosia async layer
     11        composition scrolling code to provide smooth scrolling, when the
     12        feature is enabled. This mirrors the work done in bug 209230 for
     13        kinetic scrolling.
     14
     15        No new tests, enabling existing functionality in more situations.
     16
     17        * page/scrolling/ScrollingTreeScrollingNode.cpp:
     18        (WebCore::ScrollingTreeScrollingNode::scrollTo):
     19        * page/scrolling/nicosia/ScrollingTreeFrameScrollingNodeNicosia.cpp:
     20        (WebCore::ScrollingTreeFrameScrollingNodeNicosia::ScrollingTreeFrameScrollingNodeNicosia):
     21        (WebCore::ScrollingTreeFrameScrollingNodeNicosia::commitStateAfterChildren):
     22        (WebCore::ScrollingTreeFrameScrollingNodeNicosia::handleWheelEvent):
     23        (WebCore::ScrollingTreeFrameScrollingNodeNicosia::stopScrollAnimations):
     24        * page/scrolling/nicosia/ScrollingTreeFrameScrollingNodeNicosia.h:
     25        * page/scrolling/nicosia/ScrollingTreeOverflowScrollingNodeNicosia.cpp:
     26        (WebCore::ScrollingTreeOverflowScrollingNodeNicosia::ScrollingTreeOverflowScrollingNodeNicosia):
     27        (WebCore::ScrollingTreeOverflowScrollingNodeNicosia::commitStateAfterChildren):
     28        (WebCore::ScrollingTreeOverflowScrollingNodeNicosia::handleWheelEvent):
     29        (WebCore::ScrollingTreeOverflowScrollingNodeNicosia::stopScrollAnimations):
     30        * page/scrolling/nicosia/ScrollingTreeOverflowScrollingNodeNicosia.h:
     31        * platform/ScrollAnimation.h:
     32        (WebCore::ScrollAnimation::serviceAnimation):
     33        * platform/ScrollAnimationKinetic.cpp:
     34        * platform/ScrollAnimationKinetic.h:
     35        * platform/ScrollAnimationSmooth.cpp:
     36        (WebCore::ScrollAnimationSmooth::ScrollAnimationSmooth):
     37        (WebCore::ScrollAnimationSmooth::scroll):
     38        (WebCore::ScrollAnimationSmooth::stop):
     39        (WebCore::ScrollAnimationSmooth::updateVisibleLengths):
     40        (WebCore::ScrollAnimationSmooth::animationTimerFired):
     41        * platform/ScrollAnimationSmooth.h:
     42        * platform/ScrollAnimator.cpp:
     43        (WebCore::ScrollAnimator::ScrollAnimator):
     44        * platform/generic/ScrollAnimatorGeneric.cpp:
     45        (WebCore::ScrollAnimatorGeneric::ScrollAnimatorGeneric):
     46        (WebCore::ScrollAnimatorGeneric::ensureSmoothScrollingAnimation):
     47
    1482020-09-01  Carlos Garcia Campos  <cgarcia@igalia.com>
    249
  • trunk/Source/WebCore/page/scrolling/ScrollingTreeScrollingNode.cpp

    r265820 r266390  
    257257        return;
    258258
    259     if (scrollType == ScrollType::Programmatic)
    260         stopScrollAnimations();
    261 
    262259    scrollingTree().setIsHandlingProgrammaticScroll(scrollType == ScrollType::Programmatic);
    263260   
  • trunk/Source/WebCore/page/scrolling/nicosia/ScrollingTreeFrameScrollingNodeNicosia.cpp

    r263838 r266390  
    4141#include "ScrollAnimationKinetic.h"
    4242#endif
     43#if ENABLE(SMOOTH_SCROLLING)
     44#include "ScrollAnimationSmooth.h"
     45#endif
    4346
    4447namespace WebCore {
     
    5457#if ENABLE(KINETIC_SCROLLING)
    5558    m_kineticAnimation = makeUnique<ScrollAnimationKinetic>(
    56         [this]() -> ScrollAnimationKinetic::ScrollExtents {
    57             return { IntPoint(minimumScrollPosition()), IntPoint(maximumScrollPosition()) };
     59        [this]() -> ScrollExtents {
     60            return { IntPoint(minimumScrollPosition()), IntPoint(maximumScrollPosition()), IntSize(scrollableAreaSize()) };
    5861        },
     62        [this](FloatPoint&& position) {
     63#if ENABLE(SMOOTH_SCROLLING)
     64            m_smoothAnimation->setCurrentPosition(position);
     65#endif
     66
     67            auto* scrollLayer = static_cast<Nicosia::PlatformLayer*>(scrolledContentsLayer());
     68            ASSERT(scrollLayer);
     69            auto& compositionLayer = downcast<Nicosia::CompositionLayer>(*scrollLayer);
     70
     71            auto updateScope = compositionLayer.createUpdateScope();
     72            scrollTo(position);
     73        });
     74#endif
     75#if ENABLE(SMOOTH_SCROLLING)
     76    m_smoothAnimation = makeUnique<ScrollAnimationSmooth>(
     77        [this]() -> ScrollExtents {
     78            return { IntPoint(minimumScrollPosition()), IntPoint(maximumScrollPosition()), IntSize(scrollableAreaSize()) };
     79        },
     80        currentScrollPosition(),
    5981        [this](FloatPoint&& position) {
    6082            auto* scrollLayer = static_cast<Nicosia::PlatformLayer*>(scrolledContentsLayer());
     
    6486            auto updateScope = compositionLayer.createUpdateScope();
    6587            scrollTo(position);
    66         });
     88        },
     89        [] { });
    6790#endif
    6891}
     
    110133    // Update the scroll position after child nodes have been updated, because they need to have updated their constraints before any scrolling happens.
    111134    if (scrollingStateNode.hasChangedProperty(ScrollingStateScrollingNode::RequestedScrollPosition)) {
     135        stopScrollAnimations();
    112136        const auto& requestedScrollData = scrollingStateNode.requestedScrollData();
    113137        scrollTo(requestedScrollData.scrollPosition, requestedScrollData.scrollType, requestedScrollData.clamping);
     138#if ENABLE(SMOOTH_SCROLLING)
     139        m_smoothAnimation->setCurrentPosition(currentScrollPosition());
     140#endif
    114141    }
    115142}
     
    120147        return WheelEventHandlingResult::unhandled();
    121148
    122     if (wheelEvent.deltaX() || wheelEvent.deltaY()) {
    123         auto* scrollLayer = static_cast<Nicosia::PlatformLayer*>(scrolledContentsLayer());
    124         ASSERT(scrollLayer);
    125         auto& compositionLayer = downcast<Nicosia::CompositionLayer>(*scrollLayer);
    126 
    127         auto updateScope = compositionLayer.createUpdateScope();
    128         scrollBy({ -wheelEvent.deltaX(), -wheelEvent.deltaY() });
    129 
    130     }
    131 
    132149#if ENABLE(KINETIC_SCROLLING)
    133150    m_kineticAnimation->appendToScrollHistory(wheelEvent);
    134 #endif
    135 
    136 #if ENABLE(KINETIC_SCROLLING)
    137151    m_kineticAnimation->stop();
    138152    if (wheelEvent.isEndOfNonMomentumScroll()) {
    139153        m_kineticAnimation->start(currentScrollPosition(), m_kineticAnimation->computeVelocity(), canHaveHorizontalScrollbar(), canHaveVerticalScrollbar());
    140154        m_kineticAnimation->clearScrollHistory();
     155        return WheelEventHandlingResult::handled();
    141156    }
    142157    if (wheelEvent.isTransitioningToMomentumScroll()) {
    143158        m_kineticAnimation->start(currentScrollPosition(), wheelEvent.swipeVelocity(), canHaveHorizontalScrollbar(), canHaveVerticalScrollbar());
    144159        m_kineticAnimation->clearScrollHistory();
    145     }
    146 #endif
    147 
    148     // FIXME: This needs to return whether the event was handled.
     160        return WheelEventHandlingResult::handled();
     161    }
     162#endif
     163
     164    float deltaX = canHaveHorizontalScrollbar() ? wheelEvent.deltaX() : 0;
     165    float deltaY = canHaveVerticalScrollbar() ? wheelEvent.deltaY() : 0;
     166    if ((deltaX < 0 && currentScrollPosition().x() >= maximumScrollPosition().x())
     167        || (deltaX > 0 && currentScrollPosition().x() <= minimumScrollPosition().x()))
     168        deltaX = 0;
     169    if ((deltaY < 0 && currentScrollPosition().y() >= maximumScrollPosition().y())
     170        || (deltaY > 0 && currentScrollPosition().y() <= minimumScrollPosition().y()))
     171        deltaY = 0;
     172
     173    if (!deltaX && !deltaY)
     174        return WheelEventHandlingResult::unhandled();
     175
     176    if (wheelEvent.granularity() == ScrollByPageWheelEvent) {
     177        if (deltaX) {
     178            bool negative = deltaX < 0;
     179            deltaX = Scrollbar::pageStepDelta(scrollableAreaSize().width());
     180            if (negative)
     181                deltaX = -deltaX;
     182        }
     183        if (deltaY) {
     184            bool negative = deltaY < 0;
     185            deltaY = Scrollbar::pageStepDelta(scrollableAreaSize().height());
     186            if (negative)
     187                deltaY = -deltaY;
     188        }
     189    }
     190
     191#if ENABLE(SMOOTH_SCROLLING)
     192    m_smoothAnimation->scroll(HorizontalScrollbar, ScrollByPixel, 1, -deltaX);
     193    m_smoothAnimation->scroll(VerticalScrollbar, ScrollByPixel, 1, -deltaY);
     194#else
     195    auto* scrollLayer = static_cast<Nicosia::PlatformLayer*>(scrolledContentsLayer());
     196    ASSERT(scrollLayer);
     197    auto& compositionLayer = downcast<Nicosia::CompositionLayer>(*scrollLayer);
     198
     199    auto updateScope = compositionLayer.createUpdateScope();
     200    scrollBy({ -deltaX, -deltaY });
     201#endif
     202
    149203    return WheelEventHandlingResult::handled();
    150204}
     
    155209    m_kineticAnimation->stop();
    156210    m_kineticAnimation->clearScrollHistory();
     211#endif
     212#if ENABLE(SMOOTH_SCROLLING)
     213    m_smoothAnimation->stop();
    157214#endif
    158215}
  • trunk/Source/WebCore/page/scrolling/nicosia/ScrollingTreeFrameScrollingNodeNicosia.h

    r262294 r266390  
    4040
    4141namespace WebCore {
     42class ScrollAnimation;
    4243class ScrollAnimationKinetic;
    4344
     
    7475    std::unique_ptr<ScrollAnimationKinetic> m_kineticAnimation;
    7576#endif
     77#if ENABLE(SMOOTH_SCROLLING)
     78    std::unique_ptr<ScrollAnimation> m_smoothAnimation;
     79#endif
    7680};
    7781
  • trunk/Source/WebCore/page/scrolling/nicosia/ScrollingTreeOverflowScrollingNodeNicosia.cpp

    r263838 r266390  
    3636#include "ScrollAnimationKinetic.h"
    3737#endif
     38#if ENABLE(SMOOTH_SCROLLING)
     39#include "ScrollAnimationSmooth.h"
     40#endif
    3841#include "ScrollingStateOverflowScrollingNode.h"
    3942#include "ScrollingTree.h"
     
    5154#if ENABLE(KINETIC_SCROLLING)
    5255    m_kineticAnimation = makeUnique<ScrollAnimationKinetic>(
    53         [this]() -> ScrollAnimationKinetic::ScrollExtents {
    54             return { IntPoint(minimumScrollPosition()), IntPoint(maximumScrollPosition()) };
     56        [this]() -> ScrollExtents {
     57            return { IntPoint(minimumScrollPosition()), IntPoint(maximumScrollPosition()), IntSize(scrollableAreaSize()) };
    5558        },
    5659        [this](FloatPoint&& position) {
    57             auto* scrollLayer = static_cast<Nicosia::PlatformLayer*>(scrolledContentsLayer());
     60#if ENABLE(SMOOTH_SCROLLING)
     61            m_smoothAnimation->setCurrentPosition(position);
     62#endif
     63
     64            auto* scrollLayer = static_cast<Nicosia::PlatformLayer*>(scrollContainerLayer());
    5865            ASSERT(scrollLayer);
    5966            auto& compositionLayer = downcast<Nicosia::CompositionLayer>(*scrollLayer);
     
    6370        });
    6471#endif
     72#if ENABLE(SMOOTH_SCROLLING)
     73    m_smoothAnimation = makeUnique<ScrollAnimationSmooth>(
     74        [this]() -> ScrollExtents {
     75            return { IntPoint(minimumScrollPosition()), IntPoint(maximumScrollPosition()), IntSize(scrollableAreaSize()) };
     76        },
     77        currentScrollPosition(),
     78        [this](FloatPoint&& position) {
     79            auto* scrollLayer = static_cast<Nicosia::PlatformLayer*>(scrollContainerLayer());
     80            ASSERT(scrollLayer);
     81            auto& compositionLayer = downcast<Nicosia::CompositionLayer>(*scrollLayer);
     82
     83            auto updateScope = compositionLayer.createUpdateScope();
     84            scrollTo(position);
     85        },
     86        [] { });
     87#endif
    6588}
    6689
     
    7396    const auto& overflowStateNode = downcast<ScrollingStateOverflowScrollingNode>(stateNode);
    7497    if (overflowStateNode.hasChangedProperty(ScrollingStateScrollingNode::RequestedScrollPosition)) {
     98        stopScrollAnimations();
    7599        const auto& requestedScrollData = overflowStateNode.requestedScrollData();
    76100        scrollTo(requestedScrollData.scrollPosition, requestedScrollData.scrollType, requestedScrollData.clamping);
     101#if ENABLE(SMOOTH_SCROLLING)
     102        m_smoothAnimation->setCurrentPosition(currentScrollPosition());
     103#endif
    77104    }
    78105}
     
    105132        return WheelEventHandlingResult::unhandled();
    106133
    107     if (wheelEvent.deltaX() || wheelEvent.deltaY()) {
    108         auto* scrollLayer = static_cast<Nicosia::PlatformLayer*>(scrollContainerLayer());
    109         ASSERT(scrollLayer);
    110         auto& compositionLayer = downcast<Nicosia::CompositionLayer>(*scrollLayer);
    111 
    112         auto updateScope = compositionLayer.createUpdateScope();
    113         scrollBy({ -wheelEvent.deltaX(), -wheelEvent.deltaY() });
    114     }
    115 
    116134#if ENABLE(KINETIC_SCROLLING)
    117135    m_kineticAnimation->appendToScrollHistory(wheelEvent);
    118 #endif
    119 
    120 #if ENABLE(KINETIC_SCROLLING)
    121136    m_kineticAnimation->stop();
    122137    if (wheelEvent.isEndOfNonMomentumScroll()) {
    123138        m_kineticAnimation->start(currentScrollPosition(), m_kineticAnimation->computeVelocity(), canHaveHorizontalScrollbar(), canHaveVerticalScrollbar());
    124139        m_kineticAnimation->clearScrollHistory();
     140        return WheelEventHandlingResult::handled();
    125141    }
    126142    if (wheelEvent.isTransitioningToMomentumScroll()) {
    127143        m_kineticAnimation->start(currentScrollPosition(), wheelEvent.swipeVelocity(), canHaveHorizontalScrollbar(), canHaveVerticalScrollbar());
    128144        m_kineticAnimation->clearScrollHistory();
    129     }
     145        return WheelEventHandlingResult::handled();
     146    }
     147#endif
     148
     149    float deltaX = canHaveHorizontalScrollbar() ? wheelEvent.deltaX() : 0;
     150    float deltaY = canHaveVerticalScrollbar() ? wheelEvent.deltaY() : 0;
     151    if ((deltaX < 0 && currentScrollPosition().x() >= maximumScrollPosition().x())
     152        || (deltaX > 0 && currentScrollPosition().x() <= minimumScrollPosition().x()))
     153        deltaX = 0;
     154    if ((deltaY < 0 && currentScrollPosition().y() >= maximumScrollPosition().y())
     155        || (deltaY > 0 && currentScrollPosition().y() <= minimumScrollPosition().y()))
     156        deltaY = 0;
     157
     158    if (!deltaX && !deltaY)
     159        return WheelEventHandlingResult::unhandled();
     160
     161    if (wheelEvent.granularity() == ScrollByPageWheelEvent) {
     162        if (deltaX) {
     163            bool negative = deltaX < 0;
     164            deltaX = Scrollbar::pageStepDelta(scrollableAreaSize().width());
     165            if (negative)
     166                deltaX = -deltaX;
     167        }
     168        if (deltaY) {
     169            bool negative = deltaY < 0;
     170            deltaY = Scrollbar::pageStepDelta(scrollableAreaSize().height());
     171            if (negative)
     172                deltaY = -deltaY;
     173        }
     174    }
     175
     176#if ENABLE(SMOOTH_SCROLLING)
     177    m_smoothAnimation->scroll(HorizontalScrollbar, ScrollByPixel, 1, -deltaX);
     178    m_smoothAnimation->scroll(VerticalScrollbar, ScrollByPixel, 1, -deltaY);
     179#else
     180    auto* scrollLayer = static_cast<Nicosia::PlatformLayer*>(scrollContainerLayer());
     181    ASSERT(scrollLayer);
     182    auto& compositionLayer = downcast<Nicosia::CompositionLayer>(*scrollLayer);
     183
     184    auto updateScope = compositionLayer.createUpdateScope();
     185    scrollBy({ -deltaX, -deltaY });
    130186#endif
    131187
     
    139195    m_kineticAnimation->clearScrollHistory();
    140196#endif
     197#if ENABLE(SMOOTH_SCROLLING)
     198    m_smoothAnimation->stop();
     199#endif
    141200}
    142201
  • trunk/Source/WebCore/page/scrolling/nicosia/ScrollingTreeOverflowScrollingNodeNicosia.h

    r262294 r266390  
    3434
    3535namespace WebCore {
     36class ScrollAnimation;
    3637class ScrollAnimationKinetic;
    3738
     
    5758    std::unique_ptr<ScrollAnimationKinetic> m_kineticAnimation;
    5859#endif
     60#if ENABLE(SMOOTH_SCROLLING)
     61    std::unique_ptr<ScrollAnimation> m_smoothAnimation;
     62#endif
    5963};
    6064
  • trunk/Source/WebCore/platform/ScrollAnimation.h

    r262933 r266390  
    3535enum class ScrollClamping : bool;
    3636
     37struct ScrollExtents {
     38    ScrollPosition minimumScrollPosition;
     39    ScrollPosition maximumScrollPosition;
     40    IntSize visibleSize;
     41};
     42
    3743class ScrollAnimation {
    3844    WTF_MAKE_FAST_ALLOCATED;
     
    4551    virtual void setCurrentPosition(const FloatPoint&) { };
    4652    virtual void serviceAnimation() { };
    47 
    48 protected:
    49     ScrollAnimation(ScrollableArea& scrollableArea)
    50         : m_scrollableArea(scrollableArea)
    51     {
    52     }
    53 
    54     ScrollableArea& m_scrollableArea;
    5553};
    5654
  • trunk/Source/WebCore/platform/ScrollAnimationKinetic.cpp

    r259325 r266390  
    2929#include "PlatformWheelEvent.h"
    3030
    31 #if USE(GLIB)
     31#if USE(GLIB_EVENT_LOOP)
    3232#include <wtf/glib/RunLoopSourcePriority.h>
    3333#endif
     
    115115    , m_animationTimer(RunLoop::current(), this, &ScrollAnimationKinetic::animationTimerFired)
    116116{
    117 #if USE(GLIB)
     117#if USE(GLIB_EVENT_LOOP)
    118118    m_animationTimer.setPriority(WTF::RunLoopSourcePriority::DisplayRefreshMonitorTimer);
    119119#endif
  • trunk/Source/WebCore/platform/ScrollAnimationKinetic.h

    r259112 r266390  
    3636class PlatformWheelEvent;
    3737
    38 class ScrollAnimationKinetic final {
    39     WTF_MAKE_FAST_ALLOCATED;
     38class ScrollAnimationKinetic final : public ScrollAnimation {
    4039private:
    4140    class PerAxisData {
     
    6059
    6160public:
    62     struct ScrollExtents {
    63         IntPoint minimumScrollPosition;
    64         IntPoint maximumScrollPosition;
    65     };
    66 
    6761    using ScrollExtentsCallback = WTF::Function<ScrollExtents(void)>;
    6862    using NotifyPositionChangedCallback = WTF::Function<void(FloatPoint&&)>;
     
    7670
    7771    void start(const FloatPoint& initialPosition, const FloatPoint& velocity, bool mayHScroll, bool mayVScroll);
    78     void stop();
     72    void stop() override;
    7973
    8074private:
  • trunk/Source/WebCore/platform/ScrollAnimationSmooth.cpp

    r255957 r266390  
    3232#include "ScrollableArea.h"
    3333
     34#if USE(GLIB_EVENT_LOOP)
     35#include <wtf/glib/RunLoopSourcePriority.h>
     36#endif
     37
    3438namespace WebCore {
    3539
     
    3943static const double smoothFactorForProgrammaticScroll = 5;
    4044
    41 ScrollAnimationSmooth::ScrollAnimationSmooth(ScrollableArea& scrollableArea, const FloatPoint& position, WTF::Function<void (FloatPoint&&)>&& notifyPositionChangedFunction)
    42     : ScrollAnimation(scrollableArea)
     45ScrollAnimationSmooth::PerAxisData::PerAxisData(ScrollbarOrientation orientation, const FloatPoint& position, ScrollExtentsCallback& extentsCallback)
     46{
     47    auto extents = extentsCallback();
     48    switch (orientation) {
     49    case HorizontalScrollbar:
     50        currentPosition = position.x();
     51        visibleLength = extents.visibleSize.width();
     52        break;
     53    case VerticalScrollbar:
     54        currentPosition = position.y();
     55        visibleLength = extents.visibleSize.height();
     56        break;
     57    }
     58
     59    desiredPosition = currentPosition;
     60}
     61
     62ScrollAnimationSmooth::ScrollAnimationSmooth(ScrollExtentsCallback&& scrollExtentsFunction, const FloatPoint& position, NotifyPositionChangedCallback&& notifyPositionChangedFunction, NotifyAnimationStoppedCallback&& notifyAnimationStoppedFunction)
     63    : m_scrollExtentsFunction(WTFMove(scrollExtentsFunction))
    4364    , m_notifyPositionChangedFunction(WTFMove(notifyPositionChangedFunction))
    44     , m_horizontalData(position.x(), scrollableArea.visibleWidth())
    45     , m_verticalData(position.y(), scrollableArea.visibleHeight())
    46     , m_animationTimer(*this, &ScrollAnimationSmooth::animationTimerFired)
    47 {
     65    , m_notifyAnimationStoppedFunction(WTFMove(notifyAnimationStoppedFunction))
     66    , m_horizontalData(HorizontalScrollbar, position, m_scrollExtentsFunction)
     67    , m_verticalData(VerticalScrollbar, position, m_scrollExtentsFunction)
     68    , m_animationTimer(RunLoop::current(), this, &ScrollAnimationSmooth::animationTimerFired)
     69{
     70#if USE(GLIB_EVENT_LOOP)
     71    m_animationTimer.setPriority(WTF::RunLoopSourcePriority::DisplayRefreshMonitorTimer);
     72#endif
    4873}
    4974
     
    5277    float minScrollPosition;
    5378    float maxScrollPosition;
     79    auto extents = m_scrollExtentsFunction();
    5480    if (orientation == HorizontalScrollbar) {
    55         minScrollPosition = m_scrollableArea.minimumScrollPosition().x();
    56         maxScrollPosition = m_scrollableArea.maximumScrollPosition().x();
     81        minScrollPosition = extents.minimumScrollPosition.x();
     82        maxScrollPosition = extents.maximumScrollPosition.x();
    5783    } else {
    58         minScrollPosition = m_scrollableArea.minimumScrollPosition().y();
    59         maxScrollPosition = m_scrollableArea.maximumScrollPosition().y();
     84        minScrollPosition = extents.minimumScrollPosition.y();
     85        maxScrollPosition = extents.maximumScrollPosition.y();
    6086    }
    6187    bool needToScroll = updatePerAxisData(orientation == HorizontalScrollbar ? m_horizontalData : m_verticalData, granularity, step * multiplier, minScrollPosition, maxScrollPosition);
     
    7096{
    7197    ScrollGranularity granularity = ScrollByPage;
    72     bool needToScroll = updatePerAxisData(m_horizontalData, granularity, position.x() - m_horizontalData.currentPosition, m_scrollableArea.minimumScrollPosition().x(), m_scrollableArea.maximumScrollPosition().x(), smoothFactorForProgrammaticScroll);
     98    auto extents = m_scrollExtentsFunction();
     99    bool needToScroll = updatePerAxisData(m_horizontalData, granularity, position.x() - m_horizontalData.currentPosition, extents.minimumScrollPosition.x(), extents.maximumScrollPosition.x(), smoothFactorForProgrammaticScroll);
    73100    needToScroll |=
    74         updatePerAxisData(m_verticalData, granularity, position.y() - m_verticalData.currentPosition, m_scrollableArea.minimumScrollPosition().y(), m_scrollableArea.maximumScrollPosition().y(), smoothFactorForProgrammaticScroll);
     101        updatePerAxisData(m_verticalData, granularity, position.y() - m_verticalData.currentPosition, extents.minimumScrollPosition.y(), extents.maximumScrollPosition.y(), smoothFactorForProgrammaticScroll);
    75102    if (needToScroll && !animationTimerActive()) {
    76103        m_startTime = m_horizontalData.startTime;
     
    82109{
    83110    m_animationTimer.stop();
    84     m_scrollableArea.setScrollBehaviorStatus(ScrollBehaviorStatus::NotInAnimation);
     111    m_notifyAnimationStoppedFunction();
    85112}
    86113
    87114void ScrollAnimationSmooth::updateVisibleLengths()
    88115{
    89     m_horizontalData.visibleLength = m_scrollableArea.visibleWidth();
    90     m_verticalData.visibleLength = m_scrollableArea.visibleHeight();
     116    auto extents = m_scrollExtentsFunction();
     117    m_horizontalData.visibleLength = extents.visibleSize.width();
     118    m_verticalData.visibleLength = extents.visibleSize.height();
    91119}
    92120
     
    412440        startNextTimer(std::max(minimumTimerInterval, deltaToNextFrame));
    413441    else
    414         m_scrollableArea.setScrollBehaviorStatus(ScrollBehaviorStatus::NotInAnimation);
     442        m_notifyAnimationStoppedFunction();
    415443
    416444    m_notifyPositionChangedFunction(FloatPoint(m_horizontalData.currentPosition, m_verticalData.currentPosition));
  • trunk/Source/WebCore/platform/ScrollAnimationSmooth.h

    r262933 r266390  
    2828#include "ScrollAnimation.h"
    2929
    30 #include "Timer.h"
     30#include <wtf/RunLoop.h>
    3131
    3232namespace WebCore {
     
    3838class ScrollAnimationSmooth final: public ScrollAnimation {
    3939public:
    40     ScrollAnimationSmooth(ScrollableArea&, const FloatPoint&, WTF::Function<void (FloatPoint&&)>&& notifyPositionChangedFunction);
     40    using ScrollExtentsCallback = WTF::Function<ScrollExtents(void)>;
     41    using NotifyPositionChangedCallback = WTF::Function<void(FloatPoint&&)>;
     42    using NotifyAnimationStoppedCallback = WTF::Function<void(void)>;
     43
     44    ScrollAnimationSmooth(ScrollExtentsCallback&&, const FloatPoint& position, NotifyPositionChangedCallback&&, NotifyAnimationStoppedCallback&&);
    4145    virtual ~ScrollAnimationSmooth();
    4246
     
    5862    struct PerAxisData {
    5963        PerAxisData() = delete;
     64
     65        PerAxisData(ScrollbarOrientation, const FloatPoint& position, ScrollExtentsCallback&);
    6066
    6167        PerAxisData(float position, int length)
     
    98104    bool animationTimerActive() const;
    99105
    100     WTF::Function<void (FloatPoint&&)> m_notifyPositionChangedFunction;
     106    ScrollExtentsCallback m_scrollExtentsFunction;
     107    NotifyPositionChangedCallback m_notifyPositionChangedFunction;
     108    NotifyAnimationStoppedCallback m_notifyAnimationStoppedFunction;
    101109
    102110    PerAxisData m_horizontalData;
     
    104112
    105113    MonotonicTime m_startTime;
    106     Timer m_animationTimer;
     114    RunLoop::Timer<ScrollAnimationSmooth> m_animationTimer;
    107115};
    108116
  • trunk/Source/WebCore/platform/ScrollAnimator.cpp

    r264908 r266390  
    5858    , m_scrollController(*this)
    5959#endif
    60     , m_animationProgrammaticScroll(makeUnique<ScrollAnimationSmooth>(scrollableArea, m_currentPosition, [this](FloatPoint&& position) {
    61         FloatSize delta = position - m_currentPosition;
    62         m_currentPosition = WTFMove(position);
    63         notifyPositionChanged(delta);
    64     }))
     60    , m_animationProgrammaticScroll(makeUnique<ScrollAnimationSmooth>(
     61        [this]() -> ScrollExtents {
     62            return { m_scrollableArea.minimumScrollPosition(), m_scrollableArea.maximumScrollPosition(), m_scrollableArea.visibleSize() };
     63        },
     64        m_currentPosition,
     65        [this](FloatPoint&& position) {
     66            FloatSize delta = position - m_currentPosition;
     67            m_currentPosition = WTFMove(position);
     68            notifyPositionChanged(delta);
     69        },
     70        [this] {
     71            m_scrollableArea.setScrollBehaviorStatus(ScrollBehaviorStatus::NotInAnimation);
     72        }))
    6573{
    6674}
  • trunk/Source/WebCore/platform/generic/ScrollAnimatorGeneric.cpp

    r263838 r266390  
    5252{
    5353    m_kineticAnimation = makeUnique<ScrollAnimationKinetic>(
    54         [this]() -> ScrollAnimationKinetic::ScrollExtents {
    55             return { m_scrollableArea.minimumScrollPosition(), m_scrollableArea.maximumScrollPosition() };
     54        [this]() -> ScrollExtents {
     55            return { m_scrollableArea.minimumScrollPosition(), m_scrollableArea.maximumScrollPosition(), m_scrollableArea.visibleSize() };
    5656        },
    5757        [this](FloatPoint&& position) {
     
    7777        return;
    7878
    79     m_smoothAnimation = makeUnique<ScrollAnimationSmooth>(m_scrollableArea, m_currentPosition, [this](FloatPoint&& position) {
    80         updatePosition(WTFMove(position));
    81     });
     79    m_smoothAnimation = makeUnique<ScrollAnimationSmooth>(
     80        [this]() -> ScrollExtents {
     81            return { m_scrollableArea.minimumScrollPosition(), m_scrollableArea.maximumScrollPosition(), m_scrollableArea.visibleSize() };
     82        },
     83        m_currentPosition,
     84        [this](FloatPoint&& position) {
     85            updatePosition(WTFMove(position));
     86        },
     87        [this] {
     88            m_scrollableArea.setScrollBehaviorStatus(ScrollBehaviorStatus::NotInAnimation);
     89        });
    8290}
    8391#endif
Note: See TracChangeset for help on using the changeset viewer.