Changeset 259112 in webkit


Ignore:
Timestamp:
Mar 27, 2020 5:54:38 AM (4 years ago)
Author:
Chris Lord
Message:

Source/WebCore:
[GTK][WPE] Enable kinetic scrolling with async rendering
https://bugs.webkit.org/show_bug.cgi?id=209230

Reviewed by Žan Doberšek.

Refactor ScrollAnimationKinetic so that it no longer depends on
ScrollableArea, uses RunLoop::Timer and is responsible for tracking
the history of scroll events. This allows it to be used in
ScrollingTree*ScrollingNodeNicosia to provide kinetic scrolling when
async scrolling is enabled, on GTK and WPE.

No new tests, this just enables existing functionality in more situations.

  • page/scrolling/ScrollingTreeScrollingNode.cpp:

(WebCore::ScrollingTreeScrollingNode::scrollTo):

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

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

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

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

  • page/scrolling/nicosia/ScrollingTreeOverflowScrollingNodeNicosia.h:
  • platform/ScrollAnimationKinetic.cpp:

(WebCore::ScrollAnimationKinetic::ScrollAnimationKinetic):
(WebCore::ScrollAnimationKinetic::appendToScrollHistory):
(WebCore::ScrollAnimationKinetic::clearScrollHistory):
(WebCore::ScrollAnimationKinetic::computeVelocity):
(WebCore::ScrollAnimationKinetic::start):

  • platform/ScrollAnimationKinetic.h:
  • platform/generic/ScrollAnimatorGeneric.cpp:

(WebCore::ScrollAnimatorGeneric::ScrollAnimatorGeneric):
(WebCore::ScrollAnimatorGeneric::scrollToOffsetWithoutAnimation):
(WebCore::ScrollAnimatorGeneric::handleWheelEvent):
(WebCore::ScrollAnimatorGeneric::willEndLiveResize):
(WebCore::ScrollAnimatorGeneric::didAddVerticalScrollbar):
(WebCore::ScrollAnimatorGeneric::didAddHorizontalScrollbar):

  • platform/generic/ScrollAnimatorGeneric.h:

Source/WebKit:
[GTK][WPE] Enable kinetic scrolling with async scrolling
https://bugs.webkit.org/show_bug.cgi?id=209230

Reviewed by Žan Doberšek.

Modify WPE mousewheel event delivery so that it includes the necessary
phases needed to infer press/release times and allow for kinetic
scrolling.

  • Shared/NativeWebWheelEvent.h:
  • Shared/WebEvent.h:
  • Shared/WebWheelEvent.cpp:

(WebKit::WebWheelEvent::encode const):
(WebKit::WebWheelEvent::decode):

  • Shared/libwpe/NativeWebWheelEventLibWPE.cpp:

(WebKit::NativeWebWheelEvent::NativeWebWheelEvent):

  • Shared/libwpe/WebEventFactory.cpp:

(WebKit::WebEventFactory::createWebWheelEvent):

  • Shared/libwpe/WebEventFactory.h:
  • UIProcess/API/wpe/PageClientImpl.cpp:

(WebKit::PageClientImpl::doneWithTouchEvent):

  • UIProcess/API/wpe/ScrollGestureController.cpp:

(WebKit::ScrollGestureController::handleEvent):

  • UIProcess/API/wpe/ScrollGestureController.h:

(WebKit::ScrollGestureController::phase):

  • UIProcess/API/wpe/WPEView.cpp:

(WKWPE::m_backend):

Location:
trunk/Source
Files:
22 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r259110 r259112  
     12020-03-27  Chris Lord  <clord@igalia.com>
     2
     3        [GTK][WPE] Enable kinetic scrolling with async rendering
     4        https://bugs.webkit.org/show_bug.cgi?id=209230
     5
     6        Reviewed by Žan Doberšek.
     7
     8        Refactor ScrollAnimationKinetic so that it no longer depends on
     9        ScrollableArea, uses RunLoop::Timer and is responsible for tracking
     10        the history of scroll events. This allows it to be used in
     11        ScrollingTree*ScrollingNodeNicosia to provide kinetic scrolling when
     12        async scrolling is enabled, on GTK and WPE.
     13
     14        No new tests, this just enables existing functionality in more situations.
     15
     16        * page/scrolling/ScrollingTreeScrollingNode.cpp:
     17        (WebCore::ScrollingTreeScrollingNode::scrollTo):
     18        * page/scrolling/ScrollingTreeScrollingNode.h:
     19        * page/scrolling/nicosia/ScrollingTreeFrameScrollingNodeNicosia.cpp:
     20        (WebCore::ScrollingTreeFrameScrollingNodeNicosia::ScrollingTreeFrameScrollingNodeNicosia):
     21        (WebCore::ScrollingTreeFrameScrollingNodeNicosia::handleWheelEvent):
     22        (WebCore::ScrollingTreeFrameScrollingNodeNicosia::stopScrollAnimations):
     23        * page/scrolling/nicosia/ScrollingTreeFrameScrollingNodeNicosia.h:
     24        * page/scrolling/nicosia/ScrollingTreeOverflowScrollingNodeNicosia.cpp:
     25        (WebCore::ScrollingTreeOverflowScrollingNodeNicosia::ScrollingTreeOverflowScrollingNodeNicosia):
     26        (WebCore::ScrollingTreeOverflowScrollingNodeNicosia::handleWheelEvent):
     27        (WebCore::ScrollingTreeOverflowScrollingNodeNicosia::stopScrollAnimations):
     28        * page/scrolling/nicosia/ScrollingTreeOverflowScrollingNodeNicosia.h:
     29        * platform/ScrollAnimationKinetic.cpp:
     30        (WebCore::ScrollAnimationKinetic::ScrollAnimationKinetic):
     31        (WebCore::ScrollAnimationKinetic::appendToScrollHistory):
     32        (WebCore::ScrollAnimationKinetic::clearScrollHistory):
     33        (WebCore::ScrollAnimationKinetic::computeVelocity):
     34        (WebCore::ScrollAnimationKinetic::start):
     35        * platform/ScrollAnimationKinetic.h:
     36        * platform/generic/ScrollAnimatorGeneric.cpp:
     37        (WebCore::ScrollAnimatorGeneric::ScrollAnimatorGeneric):
     38        (WebCore::ScrollAnimatorGeneric::scrollToOffsetWithoutAnimation):
     39        (WebCore::ScrollAnimatorGeneric::handleWheelEvent):
     40        (WebCore::ScrollAnimatorGeneric::willEndLiveResize):
     41        (WebCore::ScrollAnimatorGeneric::didAddVerticalScrollbar):
     42        (WebCore::ScrollAnimatorGeneric::didAddHorizontalScrollbar):
     43        * platform/generic/ScrollAnimatorGeneric.h:
     44
    1452020-03-27  Michael Catanzaro  <mcatanzaro@gnome.org>
    246
  • trunk/Source/WebCore/page/scrolling/ScrollingTreeScrollingNode.cpp

    r258238 r259112  
    170170        return;
    171171
     172    if (scrollType == ScrollType::Programmatic)
     173        stopScrollAnimations();
     174
    172175    scrollingTree().setIsHandlingProgrammaticScroll(scrollType == ScrollType::Programmatic);
    173176   
  • trunk/Source/WebCore/page/scrolling/ScrollingTreeScrollingNode.h

    r258012 r259112  
    6464    void scrollBy(const FloatSize&, ScrollClamping = ScrollClamping::Clamped);
    6565
     66    virtual void stopScrollAnimations() { };
     67
    6668    void wasScrolledByDelegatedScrolling(const FloatPoint& position, Optional<FloatRect> overrideLayoutViewport = { }, ScrollingLayerPositionAction = ScrollingLayerPositionAction::Sync);
    6769   
     
    7678    bool horizontalScrollbarHiddenByStyle() const { return m_scrollableAreaParameters.horizontalScrollbarHiddenByStyle; }
    7779    bool verticalScrollbarHiddenByStyle() const { return m_scrollableAreaParameters.verticalScrollbarHiddenByStyle; }
     80    bool canHaveHorizontalScrollbar() const { return m_scrollableAreaParameters.horizontalScrollbarMode != ScrollbarAlwaysOff; }
     81    bool canHaveVerticalScrollbar() const { return m_scrollableAreaParameters.verticalScrollbarMode != ScrollbarAlwaysOff; }
    7882    bool canHaveScrollbars() const { return m_scrollableAreaParameters.horizontalScrollbarMode != ScrollbarAlwaysOff || m_scrollableAreaParameters.verticalScrollbarMode != ScrollbarAlwaysOff; }
    7983
  • trunk/Source/WebCore/page/scrolling/nicosia/ScrollingTreeFrameScrollingNodeNicosia.cpp

    r258831 r259112  
    3838#include "ScrollingTree.h"
    3939
     40#if ENABLE(KINETIC_SCROLLING)
     41#include "ScrollAnimationKinetic.h"
     42#endif
     43
    4044namespace WebCore {
    4145
     
    4852    : ScrollingTreeFrameScrollingNode(scrollingTree, nodeType, nodeID)
    4953{
     54#if ENABLE(KINETIC_SCROLLING)
     55    m_kineticAnimation = makeUnique<ScrollAnimationKinetic>(
     56        [this]() -> ScrollAnimationKinetic::ScrollExtents {
     57            return { IntPoint(minimumScrollPosition()), IntPoint(maximumScrollPosition()) };
     58        },
     59        [this](FloatPoint&& position) {
     60            auto* scrollLayer = static_cast<Nicosia::PlatformLayer*>(scrolledContentsLayer());
     61            ASSERT(scrollLayer);
     62            auto& compositionLayer = downcast<Nicosia::CompositionLayer>(*scrollLayer);
     63
     64            auto updateScope = compositionLayer.createUpdateScope();
     65            scrollTo(position);
     66        });
     67#endif
    5068}
    5169
     
    109127        auto updateScope = compositionLayer.createUpdateScope();
    110128        scrollBy({ -wheelEvent.deltaX(), -wheelEvent.deltaY() });
    111     }
     129
     130#if ENABLE(KINETIC_SCROLLING)
     131        m_kineticAnimation->appendToScrollHistory(wheelEvent);
     132#endif
     133    }
     134
     135#if ENABLE(KINETIC_SCROLLING)
     136    m_kineticAnimation->stop();
     137    if (wheelEvent.isEndOfNonMomentumScroll()) {
     138        m_kineticAnimation->start(currentScrollPosition(), m_kineticAnimation->computeVelocity(), canHaveHorizontalScrollbar(), canHaveVerticalScrollbar());
     139        m_kineticAnimation->clearScrollHistory();
     140    }
     141    if (wheelEvent.isTransitioningToMomentumScroll()) {
     142        m_kineticAnimation->start(currentScrollPosition(), wheelEvent.swipeVelocity(), canHaveHorizontalScrollbar(), canHaveVerticalScrollbar());
     143        m_kineticAnimation->clearScrollHistory();
     144    }
     145#endif
    112146
    113147    scrollingTree().setOrClearLatchedNode(wheelEvent, scrollingNodeID());
     
    115149    // FIXME: This needs to return whether the event was handled.
    116150    return ScrollingEventResult::DidHandleEvent;
     151}
     152
     153void ScrollingTreeFrameScrollingNodeNicosia::stopScrollAnimations()
     154{
     155#if ENABLE(KINETIC_SCROLLING)
     156    m_kineticAnimation->stop();
     157    m_kineticAnimation->clearScrollHistory();
     158#endif
    117159}
    118160
  • trunk/Source/WebCore/page/scrolling/nicosia/ScrollingTreeFrameScrollingNodeNicosia.h

    r255037 r259112  
    4040
    4141namespace WebCore {
     42class ScrollAnimationKinetic;
    4243
    4344class ScrollingTreeFrameScrollingNodeNicosia final : public ScrollingTreeFrameScrollingNode {
     
    5455    ScrollingEventResult handleWheelEvent(const PlatformWheelEvent&) override;
    5556
     57    void stopScrollAnimations() override;
     58
    5659    FloatPoint adjustedScrollPosition(const FloatPoint&, ScrollClamping) const override;
    5760
     
    6770    RefPtr<Nicosia::CompositionLayer> m_headerLayer;
    6871    RefPtr<Nicosia::CompositionLayer> m_footerLayer;
     72
     73#if ENABLE(KINETIC_SCROLLING)
     74    std::unique_ptr<ScrollAnimationKinetic> m_kineticAnimation;
     75#endif
    6976};
    7077
  • trunk/Source/WebCore/page/scrolling/nicosia/ScrollingTreeOverflowScrollingNodeNicosia.cpp

    r258831 r259112  
    3333
    3434#include "NicosiaPlatformLayer.h"
     35#if ENABLE(KINETIC_SCROLLING)
     36#include "ScrollAnimationKinetic.h"
     37#endif
    3538#include "ScrollingStateOverflowScrollingNode.h"
    3639#include "ScrollingTree.h"
     
    4649    : ScrollingTreeOverflowScrollingNode(scrollingTree, nodeID)
    4750{
     51#if ENABLE(KINETIC_SCROLLING)
     52    m_kineticAnimation = makeUnique<ScrollAnimationKinetic>(
     53        [this]() -> ScrollAnimationKinetic::ScrollExtents {
     54            return { IntPoint(minimumScrollPosition()), IntPoint(maximumScrollPosition()) };
     55        },
     56        [this](FloatPoint&& position) {
     57            auto* scrollLayer = static_cast<Nicosia::PlatformLayer*>(scrolledContentsLayer());
     58            ASSERT(scrollLayer);
     59            auto& compositionLayer = downcast<Nicosia::CompositionLayer>(*scrollLayer);
     60
     61            auto updateScope = compositionLayer.createUpdateScope();
     62            scrollTo(position);
     63        });
     64#endif
    4865}
    4966
     
    95112        auto updateScope = compositionLayer.createUpdateScope();
    96113        scrollBy({ -wheelEvent.deltaX(), -wheelEvent.deltaY() });
     114
     115#if ENABLE(KINETIC_SCROLLING)
     116        m_kineticAnimation->appendToScrollHistory(wheelEvent);
     117#endif
    97118    }
     119
     120#if ENABLE(KINETIC_SCROLLING)
     121    m_kineticAnimation->stop();
     122    if (wheelEvent.isEndOfNonMomentumScroll()) {
     123        m_kineticAnimation->start(currentScrollPosition(), m_kineticAnimation->computeVelocity(), canHaveHorizontalScrollbar(), canHaveVerticalScrollbar());
     124        m_kineticAnimation->clearScrollHistory();
     125    }
     126    if (wheelEvent.isTransitioningToMomentumScroll()) {
     127        m_kineticAnimation->start(currentScrollPosition(), wheelEvent.swipeVelocity(), canHaveHorizontalScrollbar(), canHaveVerticalScrollbar());
     128        m_kineticAnimation->clearScrollHistory();
     129    }
     130#endif
    98131
    99132    scrollingTree().setOrClearLatchedNode(wheelEvent, scrollingNodeID());
     
    102135}
    103136
     137void ScrollingTreeOverflowScrollingNodeNicosia::stopScrollAnimations()
     138{
     139#if ENABLE(KINETIC_SCROLLING)
     140    m_kineticAnimation->stop();
     141    m_kineticAnimation->clearScrollHistory();
     142#endif
     143}
     144
    104145} // namespace WebCore
    105146
  • trunk/Source/WebCore/page/scrolling/nicosia/ScrollingTreeOverflowScrollingNodeNicosia.h

    r255037 r259112  
    3434
    3535namespace WebCore {
     36class ScrollAnimationKinetic;
    3637
    3738class ScrollingTreeOverflowScrollingNodeNicosia final : public ScrollingTreeOverflowScrollingNode {
     
    5051
    5152    ScrollingEventResult handleWheelEvent(const PlatformWheelEvent&) override;
     53
     54    void stopScrollAnimations() override;
     55
     56#if ENABLE(KINETIC_SCROLLING)
     57    std::unique_ptr<ScrollAnimationKinetic> m_kineticAnimation;
     58#endif
    5259};
    5360
  • trunk/Source/WebCore/platform/ScrollAnimationKinetic.cpp

    r240789 r259112  
    2727#include "ScrollAnimationKinetic.h"
    2828
    29 #include "ScrollableArea.h"
     29#include "PlatformWheelEvent.h"
     30#include <wtf/glib/RunLoopSourcePriority.h>
    3031
    3132/*
     
    6667static const Seconds tickTime = 1_s / frameRate;
    6768static const Seconds minimumTimerInterval { 1_ms };
     69static const Seconds scrollCaptureThreshold { 150_ms };
    6870
    6971namespace WebCore {
     
    105107}
    106108
    107 ScrollAnimationKinetic::ScrollAnimationKinetic(ScrollableArea& scrollableArea, std::function<void(FloatPoint&&)>&& notifyPositionChangedFunction)
    108     : ScrollAnimation(scrollableArea)
     109ScrollAnimationKinetic::ScrollAnimationKinetic(ScrollExtentsCallback&& scrollExtentsFunction, NotifyPositionChangedCallback&& notifyPositionChangedFunction)
     110    : m_scrollExtentsFunction(WTFMove(scrollExtentsFunction))
    109111    , m_notifyPositionChangedFunction(WTFMove(notifyPositionChangedFunction))
    110     , m_animationTimer(*this, &ScrollAnimationKinetic::animationTimerFired)
    111 {
     112    , m_animationTimer(RunLoop::current(), this, &ScrollAnimationKinetic::animationTimerFired)
     113{
     114    m_animationTimer.setPriority(WTF::RunLoopSourcePriority::DisplayRefreshMonitorTimer);
    112115}
    113116
     
    121124}
    122125
     126void ScrollAnimationKinetic::appendToScrollHistory(const PlatformWheelEvent& event)
     127{
     128    m_scrollHistory.removeAllMatching([&event] (PlatformWheelEvent& otherEvent) -> bool {
     129        return (event.timestamp() - otherEvent.timestamp()) > scrollCaptureThreshold;
     130    });
     131
     132    m_scrollHistory.append(event);
     133}
     134
     135void ScrollAnimationKinetic::clearScrollHistory()
     136{
     137    m_scrollHistory.clear();
     138}
     139
     140FloatPoint ScrollAnimationKinetic::computeVelocity()
     141{
     142    if (m_scrollHistory.isEmpty())
     143        return { };
     144
     145    auto first = m_scrollHistory[0].timestamp();
     146    auto last = m_scrollHistory.rbegin()->timestamp();
     147
     148    if (last == first)
     149        return { };
     150
     151    FloatPoint accumDelta;
     152    for (const auto& scrollEvent : m_scrollHistory)
     153        accumDelta += FloatPoint(scrollEvent.deltaX(), scrollEvent.deltaY());
     154
     155    m_scrollHistory.clear();
     156
     157    return FloatPoint(accumDelta.x() * -1 / (last - first).value(), accumDelta.y() * -1 / (last - first).value());
     158}
     159
    123160void ScrollAnimationKinetic::start(const FloatPoint& initialPosition, const FloatPoint& velocity, bool mayHScroll, bool mayVScroll)
    124161{
     
    130167        return;
    131168
     169    auto extents = m_scrollExtentsFunction();
    132170    if (mayHScroll) {
    133         m_horizontalData = PerAxisData(m_scrollableArea.minimumScrollPosition().x(),
    134             m_scrollableArea.maximumScrollPosition().x(),
     171        m_horizontalData = PerAxisData(extents.minimumScrollPosition.x(),
     172            extents.maximumScrollPosition.x(),
    135173            initialPosition.x(), velocity.x());
    136174    }
    137175    if (mayVScroll) {
    138         m_verticalData = PerAxisData(m_scrollableArea.minimumScrollPosition().y(),
    139             m_scrollableArea.maximumScrollPosition().y(),
     176        m_verticalData = PerAxisData(extents.minimumScrollPosition.y(),
     177            extents.maximumScrollPosition.y(),
    140178            initialPosition.y(), velocity.y());
    141179    }
  • trunk/Source/WebCore/platform/ScrollAnimationKinetic.h

    r239427 r259112  
    2828#include "FloatPoint.h"
    2929#include "ScrollAnimation.h"
    30 #include "Timer.h"
    3130
    3231#include <wtf/Optional.h>
     32#include <wtf/RunLoop.h>
    3333
    3434namespace WebCore {
    3535
    36 class ScrollableArea;
     36class PlatformWheelEvent;
    3737
    38 class ScrollAnimationKinetic final: public ScrollAnimation {
     38class ScrollAnimationKinetic final {
     39    WTF_MAKE_FAST_ALLOCATED;
    3940private:
    4041    class PerAxisData {
     
    5960
    6061public:
    61     ScrollAnimationKinetic(ScrollableArea&, std::function<void(FloatPoint&&)>&& notifyPositionChangedFunction);
     62    struct ScrollExtents {
     63        IntPoint minimumScrollPosition;
     64        IntPoint maximumScrollPosition;
     65    };
     66
     67    using ScrollExtentsCallback = WTF::Function<ScrollExtents(void)>;
     68    using NotifyPositionChangedCallback = WTF::Function<void(FloatPoint&&)>;
     69
     70    ScrollAnimationKinetic(ScrollExtentsCallback&&, NotifyPositionChangedCallback&&);
    6271    virtual ~ScrollAnimationKinetic();
    6372
     73    void appendToScrollHistory(const PlatformWheelEvent&);
     74    void clearScrollHistory();
     75    FloatPoint computeVelocity();
     76
    6477    void start(const FloatPoint& initialPosition, const FloatPoint& velocity, bool mayHScroll, bool mayVScroll);
     78    void stop();
    6579
    6680private:
    67     void stop() override;
    6881    void animationTimerFired();
    6982
    70     std::function<void(FloatPoint&&)> m_notifyPositionChangedFunction;
     83    ScrollExtentsCallback m_scrollExtentsFunction;
     84    NotifyPositionChangedCallback m_notifyPositionChangedFunction;
    7185
    7286    Optional<PerAxisData> m_horizontalData;
     
    7488
    7589    MonotonicTime m_startTime;
    76     Timer m_animationTimer;
     90    RunLoop::Timer<ScrollAnimationKinetic> m_animationTimer;
    7791    FloatPoint m_position;
     92    Vector<PlatformWheelEvent> m_scrollHistory;
    7893};
    7994
  • trunk/Source/WebCore/platform/generic/ScrollAnimatorGeneric.cpp

    r254890 r259112  
    4141static const Seconds overflowScrollbarsAnimationDuration { 1_s };
    4242static const Seconds overflowScrollbarsAnimationHideDelay { 2_s };
    43 static const Seconds scrollCaptureThreshold { 150_ms };
    4443
    4544std::unique_ptr<ScrollAnimator> ScrollAnimator::create(ScrollableArea& scrollableArea)
     
    5251    , m_overlayScrollbarAnimationTimer(*this, &ScrollAnimatorGeneric::overlayScrollbarAnimationTimerFired)
    5352{
    54     m_kineticAnimation = makeUnique<ScrollAnimationKinetic>(m_scrollableArea, [this](FloatPoint&& position) {
    55 #if ENABLE(SMOOTH_SCROLLING)
    56         if (m_smoothAnimation)
    57             m_smoothAnimation->setCurrentPosition(position);
    58 #endif
    59         updatePosition(WTFMove(position));
    60     });
     53    m_kineticAnimation = makeUnique<ScrollAnimationKinetic>(
     54        [this]() -> ScrollAnimationKinetic::ScrollExtents {
     55            return { m_scrollableArea.minimumScrollPosition(), m_scrollableArea.maximumScrollPosition() };
     56        },
     57        [this](FloatPoint&& position) {
     58#if ENABLE(SMOOTH_SCROLLING)
     59            if (m_smoothAnimation)
     60                m_smoothAnimation->setCurrentPosition(position);
     61#endif
     62            updatePosition(WTFMove(position));
     63        });
    6164
    6265#if ENABLE(SMOOTH_SCROLLING)
     
    9598    FloatPoint position = ScrollableArea::scrollPositionFromOffset(offset, toFloatSize(m_scrollableArea.scrollOrigin()));
    9699    m_kineticAnimation->stop();
    97     m_scrollHistory.clear();
     100    m_kineticAnimation->clearScrollHistory();
    98101
    99102#if ENABLE(SMOOTH_SCROLLING)
     
    105108}
    106109
    107 FloatPoint ScrollAnimatorGeneric::computeVelocity()
    108 {
    109     if (m_scrollHistory.isEmpty())
    110         return { };
    111 
    112     auto first = m_scrollHistory[0].timestamp();
    113     auto last = m_scrollHistory.rbegin()->timestamp();
    114 
    115     if (last == first)
    116         return { };
    117 
    118     FloatPoint accumDelta;
    119     for (const auto& scrollEvent : m_scrollHistory)
    120         accumDelta += FloatPoint(scrollEvent.deltaX(), scrollEvent.deltaY());
    121 
    122     m_scrollHistory.clear();
    123 
    124     return FloatPoint(accumDelta.x() * -1 / (last - first).value(), accumDelta.y() * -1 / (last - first).value());
    125 }
    126 
    127110bool ScrollAnimatorGeneric::handleWheelEvent(const PlatformWheelEvent& event)
    128111{
    129112    m_kineticAnimation->stop();
    130 
    131     m_scrollHistory.removeAllMatching([&event] (PlatformWheelEvent& otherEvent) -> bool {
    132         return (event.timestamp() - otherEvent.timestamp()) > scrollCaptureThreshold;
    133     });
    134113
    135114#if ENABLE(KINETIC_SCROLLING)
    136115    if (event.isEndOfNonMomentumScroll()) {
    137116        // We don't need to add the event to the history as its delta will be (0, 0).
    138         static_cast<ScrollAnimationKinetic*>(m_kineticAnimation.get())->start(m_currentPosition, computeVelocity(), m_scrollableArea.horizontalScrollbar(), m_scrollableArea.verticalScrollbar());
     117        m_kineticAnimation->start(m_currentPosition, m_kineticAnimation->computeVelocity(), m_scrollableArea.horizontalScrollbar(), m_scrollableArea.verticalScrollbar());
    139118        return true;
    140119    }
    141120    if (event.isTransitioningToMomentumScroll()) {
    142         m_scrollHistory.clear();
    143         static_cast<ScrollAnimationKinetic*>(m_kineticAnimation.get())->start(m_currentPosition, event.swipeVelocity(), m_scrollableArea.horizontalScrollbar(), m_scrollableArea.verticalScrollbar());
     121        m_kineticAnimation->clearScrollHistory();
     122        m_kineticAnimation->start(m_currentPosition, event.swipeVelocity(), m_scrollableArea.horizontalScrollbar(), m_scrollableArea.verticalScrollbar());
    144123        return true;
    145124    }
    146 #endif
    147 
    148     m_scrollHistory.append(event);
     125
     126    m_kineticAnimation->appendToScrollHistory(event);
     127#endif
    149128
    150129    return ScrollAnimator::handleWheelEvent(event);
     
    153132void ScrollAnimatorGeneric::willEndLiveResize()
    154133{
    155     m_kineticAnimation->updateVisibleLengths();
    156 
    157134#if ENABLE(SMOOTH_SCROLLING)
    158135    if (m_smoothAnimation)
     
    170147void ScrollAnimatorGeneric::didAddVerticalScrollbar(Scrollbar* scrollbar)
    171148{
    172     m_kineticAnimation->updateVisibleLengths();
    173 
    174149#if ENABLE(SMOOTH_SCROLLING)
    175150    if (m_smoothAnimation)
     
    187162void ScrollAnimatorGeneric::didAddHorizontalScrollbar(Scrollbar* scrollbar)
    188163{
    189     m_kineticAnimation->updateVisibleLengths();
    190 
    191164#if ENABLE(SMOOTH_SCROLLING)
    192165    if (m_smoothAnimation)
  • trunk/Source/WebCore/platform/generic/ScrollAnimatorGeneric.h

    r238675 r259112  
    3737
    3838class ScrollAnimation;
     39class ScrollAnimationKinetic;
    3940
    4041class ScrollAnimatorGeneric final : public ScrollAnimator {
     
    7273    void updateOverlayScrollbarsOpacity();
    7374
    74     FloatPoint computeVelocity();
    75 
    7675#if ENABLE(SMOOTH_SCROLLING)
    7776    void ensureSmoothScrollingAnimation();
     
    7978    std::unique_ptr<ScrollAnimation> m_smoothAnimation;
    8079#endif
    81     std::unique_ptr<ScrollAnimation> m_kineticAnimation;
    82     Vector<PlatformWheelEvent> m_scrollHistory;
     80    std::unique_ptr<ScrollAnimationKinetic> m_kineticAnimation;
    8381    Scrollbar* m_horizontalOverlayScrollbar { nullptr };
    8482    Scrollbar* m_verticalOverlayScrollbar { nullptr };
  • trunk/Source/WebKit/ChangeLog

    r259105 r259112  
     12020-03-27  Chris Lord  <clord@igalia.com>
     2
     3        [GTK][WPE] Enable kinetic scrolling with async scrolling
     4        https://bugs.webkit.org/show_bug.cgi?id=209230
     5
     6        Reviewed by Žan Doberšek.
     7
     8        Modify WPE mousewheel event delivery so that it includes the necessary
     9        phases needed to infer press/release times and allow for kinetic
     10        scrolling.
     11
     12        * Shared/NativeWebWheelEvent.h:
     13        * Shared/WebEvent.h:
     14        * Shared/WebWheelEvent.cpp:
     15        (WebKit::WebWheelEvent::encode const):
     16        (WebKit::WebWheelEvent::decode):
     17        * Shared/libwpe/NativeWebWheelEventLibWPE.cpp:
     18        (WebKit::NativeWebWheelEvent::NativeWebWheelEvent):
     19        * Shared/libwpe/WebEventFactory.cpp:
     20        (WebKit::WebEventFactory::createWebWheelEvent):
     21        * Shared/libwpe/WebEventFactory.h:
     22        * UIProcess/API/wpe/PageClientImpl.cpp:
     23        (WebKit::PageClientImpl::doneWithTouchEvent):
     24        * UIProcess/API/wpe/ScrollGestureController.cpp:
     25        (WebKit::ScrollGestureController::handleEvent):
     26        * UIProcess/API/wpe/ScrollGestureController.h:
     27        (WebKit::ScrollGestureController::phase):
     28        * UIProcess/API/wpe/WPEView.cpp:
     29        (WKWPE::m_backend):
     30
    1312020-03-26  David Kilzer  <ddkilzer@apple.com>
    232
  • trunk/Source/WebKit/Shared/NativeWebWheelEvent.h

    r238384 r259112  
    5858    NativeWebWheelEvent(GdkEvent*, WebWheelEvent::Phase, WebWheelEvent::Phase momentumPhase);
    5959#elif USE(LIBWPE)
    60     NativeWebWheelEvent(struct wpe_input_axis_event*, float deviceScaleFactor);
     60    NativeWebWheelEvent(struct wpe_input_axis_event*, float deviceScaleFactor, WebWheelEvent::Phase, WebWheelEvent::Phase momentumPhase);
    6161#elif PLATFORM(WIN)
    6262    NativeWebWheelEvent(HWND, UINT message, WPARAM, LPARAM);
  • trunk/Source/WebKit/Shared/WebEvent.h

    r254494 r259112  
    206206#if PLATFORM(COCOA)
    207207    WebWheelEvent(Type, const WebCore::IntPoint& position, const WebCore::IntPoint& globalPosition, const WebCore::FloatSize& delta, const WebCore::FloatSize& wheelTicks, Granularity, bool directionInvertedFromDevice, Phase, Phase momentumPhase, bool hasPreciseScrollingDeltas, uint32_t scrollCount, const WebCore::FloatSize& unacceleratedScrollingDelta, OptionSet<Modifier>, WallTime timestamp);
    208 #elif PLATFORM(GTK)
     208#elif PLATFORM(GTK) || PLATFORM(WPE)
    209209    WebWheelEvent(Type, const WebCore::IntPoint& position, const WebCore::IntPoint& globalPosition, const WebCore::FloatSize& delta, const WebCore::FloatSize& wheelTicks, Phase, Phase momentumPhase, Granularity, OptionSet<Modifier>, WallTime timestamp);
    210210#endif
  • trunk/Source/WebKit/Shared/WebWheelEvent.cpp

    r254494 r259112  
    6666    ASSERT(isWheelEventType(type));
    6767}
    68 #elif PLATFORM(GTK)
     68#elif PLATFORM(GTK) || PLATFORM(WPE)
    6969WebWheelEvent::WebWheelEvent(Type type, const IntPoint& position, const IntPoint& globalPosition, const FloatSize& delta, const FloatSize& wheelTicks, Phase phase, Phase momentumPhase, Granularity granularity, OptionSet<Modifier> modifiers, WallTime timestamp)
    7070    : WebEvent(type, modifiers, timestamp)
     
    9292    encoder << m_granularity;
    9393    encoder << m_directionInvertedFromDevice;
    94 #if PLATFORM(COCOA) || PLATFORM(GTK)
     94#if PLATFORM(COCOA) || PLATFORM(GTK) || PLATFORM(WPE)
    9595    encoder << m_phase;
    9696    encoder << m_momentumPhase;
     
    119119    if (!decoder.decode(t.m_directionInvertedFromDevice))
    120120        return false;
    121 #if PLATFORM(COCOA) || PLATFORM(GTK)
     121#if PLATFORM(COCOA) || PLATFORM(GTK) || PLATFORM(WPE)
    122122    if (!decoder.decode(t.m_phase))
    123123        return false;
  • trunk/Source/WebKit/Shared/libwpe/NativeWebWheelEventLibWPE.cpp

    r238384 r259112  
    3333namespace WebKit {
    3434
    35 NativeWebWheelEvent::NativeWebWheelEvent(struct wpe_input_axis_event* event, float deviceScaleFactor)
    36     : WebWheelEvent(WebEventFactory::createWebWheelEvent(event, deviceScaleFactor))
     35NativeWebWheelEvent::NativeWebWheelEvent(struct wpe_input_axis_event* event, float deviceScaleFactor, WebWheelEvent::Phase phase, WebWheelEvent::Phase momentumPhase)
     36    : WebWheelEvent(WebEventFactory::createWebWheelEvent(event, deviceScaleFactor, phase, momentumPhase))
    3737{
    3838}
  • trunk/Source/WebKit/Shared/libwpe/WebEventFactory.cpp

    r256913 r259112  
    143143}
    144144
    145 WebWheelEvent WebEventFactory::createWebWheelEvent(struct wpe_input_axis_event* event, float deviceScaleFactor)
     145WebWheelEvent WebEventFactory::createWebWheelEvent(struct wpe_input_axis_event* event, float deviceScaleFactor, WebWheelEvent::Phase phase, WebWheelEvent::Phase momentumPhase)
    146146{
    147147    WebCore::IntPoint position(event->x, event->y);
     
    169169
    170170        return WebWheelEvent(WebEvent::Wheel, position, position,
    171             delta, wheelTicks, WebWheelEvent::ScrollByPixelWheelEvent,
     171            delta, wheelTicks, phase, momentumPhase,
     172            WebWheelEvent::ScrollByPixelWheelEvent,
    172173            OptionSet<WebEvent::Modifier> { }, wallTimeForEventTime(event->time));
    173174    }
     
    201202
    202203    return WebWheelEvent(WebEvent::Wheel, position, position,
    203         delta, wheelTicks, WebWheelEvent::ScrollByPixelWheelEvent,
     204        delta, wheelTicks, phase, momentumPhase,
     205        WebWheelEvent::ScrollByPixelWheelEvent,
    204206        OptionSet<WebEvent::Modifier> { }, wallTimeForEventTime(event->time));
    205207}
  • trunk/Source/WebKit/Shared/libwpe/WebEventFactory.h

    r253881 r259112  
    4141    static WebKeyboardEvent createWebKeyboardEvent(struct wpe_input_keyboard_event*, const String&, bool handledByInputMethod, Optional<Vector<WebCore::CompositionUnderline>>&&, Optional<EditingRange>&&);
    4242    static WebMouseEvent createWebMouseEvent(struct wpe_input_pointer_event*, float deviceScaleFactor);
    43     static WebWheelEvent createWebWheelEvent(struct wpe_input_axis_event*, float deviceScaleFactor);
     43    static WebWheelEvent createWebWheelEvent(struct wpe_input_axis_event*, float deviceScaleFactor, WebWheelEvent::Phase, WebWheelEvent::Phase momentumPhase);
    4444#if ENABLE(TOUCH_EVENTS)
    4545    static WebTouchEvent createWebTouchEvent(struct wpe_input_touch_event*, float deviceScaleFactor);
  • trunk/Source/WebKit/UIProcess/API/wpe/PageClientImpl.cpp

    r255488 r259112  
    218218        struct wpe_input_axis_event* axisEvent = scrollGestureController.axisEvent();
    219219        if (axisEvent->type != wpe_input_axis_event_type_null)
    220             page.handleWheelEvent(WebKit::NativeWebWheelEvent(axisEvent, m_view.page().deviceScaleFactor()));
     220            page.handleWheelEvent(WebKit::NativeWebWheelEvent(axisEvent, m_view.page().deviceScaleFactor(), WebWheelEvent::Phase::PhaseNone, WebWheelEvent::Phase::PhaseNone));
    221221        return;
    222222    }
  • trunk/Source/WebKit/UIProcess/API/wpe/ScrollGestureController.cpp

    r258831 r259112  
    7070            m_offset.x = touchPoint->x;
    7171            m_offset.y = touchPoint->y;
     72            m_phase = WebWheelEvent::Phase::PhaseChanged;
    7273            return true;
    7374        }
     
    7879#if WPE_CHECK_VERSION(1, 5, 0)
    7980            m_axisEvent.base = {
    80                 wpe_input_axis_event_type_null,
    81                 0, 0, 0, 0, 0, 0
     81                m_axisEvent.base.type,
     82                touchPoint->time, m_start.x, m_start.y,
     83                0, 0, 0
    8284            };
    8385            m_axisEvent.x_axis = m_axisEvent.y_axis = 0;
    8486#else
    8587            m_axisEvent = {
    86                 wpe_input_axis_event_type_null,
    87                 0, 0, 0, 0, 0, 0
     88                m_axisEvent.type,
     89                touchPoint->time, m_start.x, m_start.y,
     90                0, 0, 0
    8891            };
    8992#endif
     93            m_offset.x = m_offset.y = 0;
     94            m_phase = WebWheelEvent::Phase::PhaseEnded;
    9095            return true;
    9196        }
  • trunk/Source/WebKit/UIProcess/API/wpe/ScrollGestureController.h

    r256913 r259112  
    2626#pragma once
    2727
     28#include "WebEvent.h"
    2829#include <wpe/wpe.h>
    2930
     
    4344#endif
    4445    }
     46
     47    WebWheelEvent::Phase phase() { return m_phase; }
    4548
    4649    bool isHandling() const { return m_handling; }
     
    6568    struct wpe_input_axis_event m_axisEvent;
    6669#endif
     70    WebWheelEvent::Phase m_phase { WebWheelEvent::Phase::PhaseNone };
    6771};
    6872
  • trunk/Source/WebKit/UIProcess/API/wpe/WPEView.cpp

    r258131 r259112  
    162162        {
    163163            auto& page = reinterpret_cast<View*>(data)->page();
    164             page.handleWheelEvent(WebKit::NativeWebWheelEvent(event, page.deviceScaleFactor()));
     164            page.handleWheelEvent(WebKit::NativeWebWheelEvent(event, page.deviceScaleFactor(), WebWheelEvent::Phase::PhaseNone, WebWheelEvent::Phase::PhaseNone));
    165165        },
    166166        // handle_touch_event
     
    176176                const struct wpe_input_touch_event_raw* touchPoint = touchEvent.nativeFallbackTouchPoint();
    177177                if (touchPoint->type != wpe_input_touch_event_type_null && scrollGestureController.handleEvent(touchPoint)) {
    178                     struct wpe_input_axis_event* axisEvent = scrollGestureController.axisEvent();
    179                     if (axisEvent->type != wpe_input_axis_event_type_null)
    180                         page.handleWheelEvent(WebKit::NativeWebWheelEvent(axisEvent, page.deviceScaleFactor()));
     178                    page.handleWheelEvent(WebKit::NativeWebWheelEvent(scrollGestureController.axisEvent(), page.deviceScaleFactor(), scrollGestureController.phase(), WebWheelEvent::Phase::PhaseNone));
    181179                    return;
    182180                }
Note: See TracChangeset for help on using the changeset viewer.