Changeset 268522 in webkit


Ignore:
Timestamp:
Oct 15, 2020 6:46:54 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.

Source/WebCore:

Respect smooth-scrolling setting and fix deadlock issues with async
scrolling on nicosia path.

No new tests, no functional change.

  • page/scrolling/AsyncScrollingCoordinator.cpp:

(WebCore::AsyncScrollingCoordinator::scrollAnimatorEnabled const):

  • page/scrolling/AsyncScrollingCoordinator.h:
  • page/scrolling/ThreadedScrollingTree.cpp:

(WebCore::ThreadedScrollingTree::ThreadedScrollingTree):

  • page/scrolling/ThreadedScrollingTree.h:

(WebCore::ThreadedScrollingTree::scrollAnimatorEnabled const):

  • page/scrolling/nicosia/ScrollingTreeFrameScrollingNodeNicosia.cpp:

(WebCore::ScrollingTreeFrameScrollingNodeNicosia::ScrollingTreeFrameScrollingNodeNicosia):
(WebCore::ScrollingTreeFrameScrollingNodeNicosia::commitStateAfterChildren):
(WebCore::ScrollingTreeFrameScrollingNodeNicosia::ensureScrollAnimationKinetic):
(WebCore::ScrollingTreeFrameScrollingNodeNicosia::ensureScrollAnimationSmooth):
(WebCore::ScrollingTreeFrameScrollingNodeNicosia::handleWheelEvent):
(WebCore::ScrollingTreeFrameScrollingNodeNicosia::stopScrollAnimations):
(WebCore::ScrollingTreeFrameScrollingNodeNicosia::repositionRelatedLayers):

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

(WebCore::ScrollingTreeOverflowScrollingNodeNicosia::ScrollingTreeOverflowScrollingNodeNicosia):
(WebCore::ScrollingTreeOverflowScrollingNodeNicosia::commitStateAfterChildren):
(WebCore::ScrollingTreeOverflowScrollingNodeNicosia::repositionScrollingLayers):
(WebCore::ScrollingTreeOverflowScrollingNodeNicosia::ensureScrollAnimationKinetic):
(WebCore::ScrollingTreeOverflowScrollingNodeNicosia::ensureScrollAnimationSmooth):
(WebCore::ScrollingTreeOverflowScrollingNodeNicosia::handleWheelEvent):
(WebCore::ScrollingTreeOverflowScrollingNodeNicosia::stopScrollAnimations):

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

(WebCore::ScrollAnimationKinetic::isActive const):

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

(WebCore::ScrollAnimationSmooth::scroll):
(WebCore::ScrollAnimationSmooth::isActive const):

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

(WebCore::ScrollAnimatorGeneric::ensureSmoothScrollingAnimation):

Source/WebKit:

Add hasPreciseScrollingDeltas to GTK/WPE wheel events.

No new tests needed.

  • Shared/WebEventConversion.cpp:

(WebKit::WebKit2PlatformWheelEvent::WebKit2PlatformWheelEvent):

  • Shared/WebWheelEvent.cpp:

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

  • Shared/WebWheelEvent.h:
  • Shared/WebWheelEventCoalescer.cpp:

(WebKit::WebWheelEventCoalescer::canCoalesce):
(WebKit::WebWheelEventCoalescer::coalesce):

  • Shared/gtk/NativeWebWheelEventGtk.cpp:

(WebKit::NativeWebWheelEvent::NativeWebWheelEvent):

  • Shared/gtk/WebEventFactory.cpp:

(WebKit::WebEventFactory::createWebWheelEvent):

  • Shared/libwpe/WebEventFactory.cpp:

(WebKit::WebEventFactory::createWebWheelEvent):

Location:
trunk/Source
Files:
24 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r268521 r268522  
     12020-10-15  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        Respect smooth-scrolling setting and fix deadlock issues with async
     9        scrolling on nicosia path.
     10
     11        No new tests, no functional change.
     12
     13        * page/scrolling/AsyncScrollingCoordinator.cpp:
     14        (WebCore::AsyncScrollingCoordinator::scrollAnimatorEnabled const):
     15        * page/scrolling/AsyncScrollingCoordinator.h:
     16        * page/scrolling/ThreadedScrollingTree.cpp:
     17        (WebCore::ThreadedScrollingTree::ThreadedScrollingTree):
     18        * page/scrolling/ThreadedScrollingTree.h:
     19        (WebCore::ThreadedScrollingTree::scrollAnimatorEnabled const):
     20        * page/scrolling/nicosia/ScrollingTreeFrameScrollingNodeNicosia.cpp:
     21        (WebCore::ScrollingTreeFrameScrollingNodeNicosia::ScrollingTreeFrameScrollingNodeNicosia):
     22        (WebCore::ScrollingTreeFrameScrollingNodeNicosia::commitStateAfterChildren):
     23        (WebCore::ScrollingTreeFrameScrollingNodeNicosia::ensureScrollAnimationKinetic):
     24        (WebCore::ScrollingTreeFrameScrollingNodeNicosia::ensureScrollAnimationSmooth):
     25        (WebCore::ScrollingTreeFrameScrollingNodeNicosia::handleWheelEvent):
     26        (WebCore::ScrollingTreeFrameScrollingNodeNicosia::stopScrollAnimations):
     27        (WebCore::ScrollingTreeFrameScrollingNodeNicosia::repositionRelatedLayers):
     28        * page/scrolling/nicosia/ScrollingTreeFrameScrollingNodeNicosia.h:
     29        * page/scrolling/nicosia/ScrollingTreeOverflowScrollingNodeNicosia.cpp:
     30        (WebCore::ScrollingTreeOverflowScrollingNodeNicosia::ScrollingTreeOverflowScrollingNodeNicosia):
     31        (WebCore::ScrollingTreeOverflowScrollingNodeNicosia::commitStateAfterChildren):
     32        (WebCore::ScrollingTreeOverflowScrollingNodeNicosia::repositionScrollingLayers):
     33        (WebCore::ScrollingTreeOverflowScrollingNodeNicosia::ensureScrollAnimationKinetic):
     34        (WebCore::ScrollingTreeOverflowScrollingNodeNicosia::ensureScrollAnimationSmooth):
     35        (WebCore::ScrollingTreeOverflowScrollingNodeNicosia::handleWheelEvent):
     36        (WebCore::ScrollingTreeOverflowScrollingNodeNicosia::stopScrollAnimations):
     37        * page/scrolling/nicosia/ScrollingTreeOverflowScrollingNodeNicosia.h:
     38        * platform/PlatformWheelEvent.h:
     39        * platform/ScrollAnimation.h:
     40        * platform/ScrollAnimationKinetic.cpp:
     41        (WebCore::ScrollAnimationKinetic::isActive const):
     42        * platform/ScrollAnimationKinetic.h:
     43        * platform/ScrollAnimationSmooth.cpp:
     44        (WebCore::ScrollAnimationSmooth::scroll):
     45        (WebCore::ScrollAnimationSmooth::isActive const):
     46        * platform/ScrollAnimationSmooth.h:
     47        * platform/generic/ScrollAnimatorGeneric.cpp:
     48        (WebCore::ScrollAnimatorGeneric::ensureSmoothScrollingAnimation):
     49
    1502020-10-15  Youenn Fablet  <youenn@apple.com>
    251
  • trunk/Source/WebCore/page/scrolling/AsyncScrollingCoordinator.cpp

    r268075 r268522  
    958958}
    959959
     960#if ENABLE(SMOOTH_SCROLLING)
     961bool AsyncScrollingCoordinator::scrollAnimatorEnabled() const
     962{
     963    ASSERT(isMainThread());
     964    auto& settings = m_page->mainFrame().settings();
     965    return settings.scrollAnimatorEnabled();
     966}
     967#endif
     968
    960969} // namespace WebCore
    961970
  • trunk/Source/WebCore/page/scrolling/AsyncScrollingCoordinator.h

    r267002 r268522  
    7272    void reportSynchronousScrollingReasonsChanged(MonotonicTime, OptionSet<SynchronousScrollingReason>);
    7373
     74#if ENABLE(SMOOTH_SCROLLING)
     75    bool scrollAnimatorEnabled() const;
     76#endif
     77
    7478protected:
    7579    WEBCORE_EXPORT AsyncScrollingCoordinator(Page*);
  • trunk/Source/WebCore/page/scrolling/ThreadedScrollingTree.cpp

    r268417 r268522  
    4848    : m_scrollingCoordinator(&scrollingCoordinator)
    4949{
     50#if ENABLE(SMOOTH_SCROLLING)
     51    m_scrollAnimatorEnabled = scrollingCoordinator.scrollAnimatorEnabled();
     52#endif
    5053}
    5154
  • trunk/Source/WebCore/page/scrolling/ThreadedScrollingTree.h

    r268417 r268522  
    5959    Lock& treeMutex() { return m_treeMutex; }
    6060
     61    bool scrollAnimatorEnabled() const { return m_scrollAnimatorEnabled; }
     62
    6163protected:
    6264    explicit ThreadedScrollingTree(AsyncScrollingCoordinator&);
     
    104106    // Dynamically allocated because it has to use the ScrollingThread's runloop.
    105107    std::unique_ptr<RunLoop::Timer<ThreadedScrollingTree>> m_delayedRenderingUpdateDetectionTimer;
     108
     109    bool m_scrollAnimatorEnabled { false };
    106110};
    107111
  • trunk/Source/WebCore/page/scrolling/nicosia/ScrollingTreeFrameScrollingNodeNicosia.cpp

    r266390 r268522  
    3636#include "NicosiaPlatformLayer.h"
    3737#include "ScrollingStateFrameScrollingNode.h"
    38 #include "ScrollingTree.h"
     38#include "ThreadedScrollingTree.h"
    3939
    4040#if ENABLE(KINETIC_SCROLLING)
     
    5555    : ScrollingTreeFrameScrollingNode(scrollingTree, nodeType, nodeID)
    5656{
     57    m_scrollAnimatorEnabled = downcast<ThreadedScrollingTree>(scrollingTree).scrollAnimatorEnabled();
     58}
     59
     60ScrollingTreeFrameScrollingNodeNicosia::~ScrollingTreeFrameScrollingNodeNicosia() = default;
     61
     62void ScrollingTreeFrameScrollingNodeNicosia::commitStateBeforeChildren(const ScrollingStateNode& stateNode)
     63{
     64    ScrollingTreeFrameScrollingNode::commitStateBeforeChildren(stateNode);
     65
     66    const auto& scrollingStateNode = downcast<ScrollingStateFrameScrollingNode>(stateNode);
     67
     68    if (scrollingStateNode.hasChangedProperty(ScrollingStateFrameScrollingNode::RootContentsLayer)) {
     69        auto* layer = static_cast<Nicosia::PlatformLayer*>(scrollingStateNode.rootContentsLayer());
     70        m_rootContentsLayer = downcast<Nicosia::CompositionLayer>(layer);
     71    }
     72    if (scrollingStateNode.hasChangedProperty(ScrollingStateFrameScrollingNode::CounterScrollingLayer)) {
     73        auto* layer = static_cast<Nicosia::PlatformLayer*>(scrollingStateNode.counterScrollingLayer());
     74        m_counterScrollingLayer = downcast<Nicosia::CompositionLayer>(layer);
     75    }
     76    if (scrollingStateNode.hasChangedProperty(ScrollingStateFrameScrollingNode::InsetClipLayer)) {
     77        auto* layer = static_cast<Nicosia::PlatformLayer*>(scrollingStateNode.insetClipLayer());
     78        m_insetClipLayer = downcast<Nicosia::CompositionLayer>(layer);
     79    }
     80    if (scrollingStateNode.hasChangedProperty(ScrollingStateFrameScrollingNode::ContentShadowLayer)) {
     81        auto* layer = static_cast<Nicosia::PlatformLayer*>(scrollingStateNode.contentShadowLayer());
     82        m_contentShadowLayer = downcast<Nicosia::CompositionLayer>(layer);
     83    }
     84    if (scrollingStateNode.hasChangedProperty(ScrollingStateFrameScrollingNode::HeaderLayer)) {
     85        auto* layer = static_cast<Nicosia::PlatformLayer*>(scrollingStateNode.headerLayer());
     86        m_headerLayer = downcast<Nicosia::CompositionLayer>(layer);
     87    }
     88    if (scrollingStateNode.hasChangedProperty(ScrollingStateFrameScrollingNode::FooterLayer)) {
     89        auto* layer = static_cast<Nicosia::PlatformLayer*>(scrollingStateNode.footerLayer());
     90        m_footerLayer = downcast<Nicosia::CompositionLayer>(layer);
     91    }
     92}
     93
     94void ScrollingTreeFrameScrollingNodeNicosia::commitStateAfterChildren(const ScrollingStateNode& stateNode)
     95{
     96    ScrollingTreeFrameScrollingNode::commitStateAfterChildren(stateNode);
     97
     98    const auto& scrollingStateNode = downcast<ScrollingStateScrollingNode>(stateNode);
     99
     100    // Update the scroll position after child nodes have been updated, because they need to have updated their constraints before any scrolling happens.
     101    if (scrollingStateNode.hasChangedProperty(ScrollingStateScrollingNode::RequestedScrollPosition)) {
     102        stopScrollAnimations();
     103        const auto& requestedScrollData = scrollingStateNode.requestedScrollData();
     104        scrollTo(requestedScrollData.scrollPosition, requestedScrollData.scrollType, requestedScrollData.clamping);
     105#if ENABLE(SMOOTH_SCROLLING)
     106        if (m_smoothAnimation)
     107            m_smoothAnimation->setCurrentPosition(currentScrollPosition());
     108#endif
     109    }
     110}
     111
    57112#if ENABLE(KINETIC_SCROLLING)
     113void ScrollingTreeFrameScrollingNodeNicosia::ensureScrollAnimationKinetic()
     114{
     115    if (m_kineticAnimation)
     116        return;
     117
    58118    m_kineticAnimation = makeUnique<ScrollAnimationKinetic>(
    59119        [this]() -> ScrollExtents {
     
    62122        [this](FloatPoint&& position) {
    63123#if ENABLE(SMOOTH_SCROLLING)
    64             m_smoothAnimation->setCurrentPosition(position);
     124            if (m_smoothAnimation)
     125                m_smoothAnimation->setCurrentPosition(position);
    65126#endif
    66127
     
    72133            scrollTo(position);
    73134        });
    74 #endif
    75 #if ENABLE(SMOOTH_SCROLLING)
     135}
     136#endif
     137
     138#if ENABLE(SMOOTH_SCROLLING)
     139void ScrollingTreeFrameScrollingNodeNicosia::ensureScrollAnimationSmooth()
     140{
     141    if (m_smoothAnimation)
     142        return;
     143
    76144    m_smoothAnimation = makeUnique<ScrollAnimationSmooth>(
    77145        [this]() -> ScrollExtents {
     
    88156        },
    89157        [] { });
    90 #endif
    91 }
    92 
    93 ScrollingTreeFrameScrollingNodeNicosia::~ScrollingTreeFrameScrollingNodeNicosia() = default;
    94 
    95 void ScrollingTreeFrameScrollingNodeNicosia::commitStateBeforeChildren(const ScrollingStateNode& stateNode)
    96 {
    97     ScrollingTreeFrameScrollingNode::commitStateBeforeChildren(stateNode);
    98 
    99     const auto& scrollingStateNode = downcast<ScrollingStateFrameScrollingNode>(stateNode);
    100 
    101     if (scrollingStateNode.hasChangedProperty(ScrollingStateFrameScrollingNode::RootContentsLayer)) {
    102         auto* layer = static_cast<Nicosia::PlatformLayer*>(scrollingStateNode.rootContentsLayer());
    103         m_rootContentsLayer = downcast<Nicosia::CompositionLayer>(layer);
    104     }
    105     if (scrollingStateNode.hasChangedProperty(ScrollingStateFrameScrollingNode::CounterScrollingLayer)) {
    106         auto* layer = static_cast<Nicosia::PlatformLayer*>(scrollingStateNode.counterScrollingLayer());
    107         m_counterScrollingLayer = downcast<Nicosia::CompositionLayer>(layer);
    108     }
    109     if (scrollingStateNode.hasChangedProperty(ScrollingStateFrameScrollingNode::InsetClipLayer)) {
    110         auto* layer = static_cast<Nicosia::PlatformLayer*>(scrollingStateNode.insetClipLayer());
    111         m_insetClipLayer = downcast<Nicosia::CompositionLayer>(layer);
    112     }
    113     if (scrollingStateNode.hasChangedProperty(ScrollingStateFrameScrollingNode::ContentShadowLayer)) {
    114         auto* layer = static_cast<Nicosia::PlatformLayer*>(scrollingStateNode.contentShadowLayer());
    115         m_contentShadowLayer = downcast<Nicosia::CompositionLayer>(layer);
    116     }
    117     if (scrollingStateNode.hasChangedProperty(ScrollingStateFrameScrollingNode::HeaderLayer)) {
    118         auto* layer = static_cast<Nicosia::PlatformLayer*>(scrollingStateNode.headerLayer());
    119         m_headerLayer = downcast<Nicosia::CompositionLayer>(layer);
    120     }
    121     if (scrollingStateNode.hasChangedProperty(ScrollingStateFrameScrollingNode::FooterLayer)) {
    122         auto* layer = static_cast<Nicosia::PlatformLayer*>(scrollingStateNode.footerLayer());
    123         m_footerLayer = downcast<Nicosia::CompositionLayer>(layer);
    124     }
    125 }
    126 
    127 void ScrollingTreeFrameScrollingNodeNicosia::commitStateAfterChildren(const ScrollingStateNode& stateNode)
    128 {
    129     ScrollingTreeFrameScrollingNode::commitStateAfterChildren(stateNode);
    130 
    131     const auto& scrollingStateNode = downcast<ScrollingStateScrollingNode>(stateNode);
    132 
    133     // Update the scroll position after child nodes have been updated, because they need to have updated their constraints before any scrolling happens.
    134     if (scrollingStateNode.hasChangedProperty(ScrollingStateScrollingNode::RequestedScrollPosition)) {
    135         stopScrollAnimations();
    136         const auto& requestedScrollData = scrollingStateNode.requestedScrollData();
    137         scrollTo(requestedScrollData.scrollPosition, requestedScrollData.scrollType, requestedScrollData.clamping);
    138 #if ENABLE(SMOOTH_SCROLLING)
    139         m_smoothAnimation->setCurrentPosition(currentScrollPosition());
    140 #endif
    141     }
    142 }
     158}
     159#endif
    143160
    144161WheelEventHandlingResult ScrollingTreeFrameScrollingNodeNicosia::handleWheelEvent(const PlatformWheelEvent& wheelEvent)
     
    148165
    149166#if ENABLE(KINETIC_SCROLLING)
     167    ensureScrollAnimationKinetic();
    150168    m_kineticAnimation->appendToScrollHistory(wheelEvent);
    151169    m_kineticAnimation->stop();
     
    190208
    191209#if ENABLE(SMOOTH_SCROLLING)
    192     m_smoothAnimation->scroll(HorizontalScrollbar, ScrollByPixel, 1, -deltaX);
    193     m_smoothAnimation->scroll(VerticalScrollbar, ScrollByPixel, 1, -deltaY);
    194 #else
     210    if (m_scrollAnimatorEnabled && !wheelEvent.hasPreciseScrollingDeltas()) {
     211        ensureScrollAnimationSmooth();
     212        m_smoothAnimation->scroll(HorizontalScrollbar, ScrollByPixel, 1, -deltaX);
     213        m_smoothAnimation->scroll(VerticalScrollbar, ScrollByPixel, 1, -deltaY);
     214        return WheelEventHandlingResult::handled();
     215    }
     216#endif
     217
    195218    auto* scrollLayer = static_cast<Nicosia::PlatformLayer*>(scrolledContentsLayer());
    196219    ASSERT(scrollLayer);
     
    199222    auto updateScope = compositionLayer.createUpdateScope();
    200223    scrollBy({ -deltaX, -deltaY });
    201 #endif
    202224
    203225    return WheelEventHandlingResult::handled();
     
    207229{
    208230#if ENABLE(KINETIC_SCROLLING)
    209     m_kineticAnimation->stop();
    210     m_kineticAnimation->clearScrollHistory();
    211 #endif
    212 #if ENABLE(SMOOTH_SCROLLING)
    213     m_smoothAnimation->stop();
     231    if (m_kineticAnimation) {
     232        m_kineticAnimation->stop();
     233        m_kineticAnimation->clearScrollHistory();
     234    }
     235#endif
     236#if ENABLE(SMOOTH_SCROLLING)
     237    if (m_smoothAnimation)
     238        m_smoothAnimation->stop();
    214239#endif
    215240}
     
    290315            applyLayerPosition(*m_footerLayer, FloatPoint(horizontalScrollOffsetForBanner, FrameView::yPositionForFooterLayer(scrollPosition, topContentInset, totalContentsSize().height(), footerHeight())));
    291316    }
     317
     318#if ENABLE(SMOOTH_SCROLLING)
     319    if (m_smoothAnimation)
     320        m_smoothAnimation->updateVisibleLengths();
     321#endif
    292322}
    293323
  • trunk/Source/WebCore/page/scrolling/nicosia/ScrollingTreeFrameScrollingNodeNicosia.h

    r266390 r268522  
    5454    void commitStateAfterChildren(const ScrollingStateNode&) override;
    5555
     56#if ENABLE(KINETIC_SCROLLING)
     57    void ensureScrollAnimationKinetic();
     58#endif
     59#if ENABLE(SMOOTH_SCROLLING)
     60    void ensureScrollAnimationSmooth();
     61#endif
     62
    5663    WheelEventHandlingResult handleWheelEvent(const PlatformWheelEvent&) override;
    5764
     
    7279    RefPtr<Nicosia::CompositionLayer> m_footerLayer;
    7380
     81    bool m_scrollAnimatorEnabled { false };
    7482#if ENABLE(KINETIC_SCROLLING)
    7583    std::unique_ptr<ScrollAnimationKinetic> m_kineticAnimation;
  • trunk/Source/WebCore/page/scrolling/nicosia/ScrollingTreeOverflowScrollingNodeNicosia.cpp

    r266390 r268522  
    4040#endif
    4141#include "ScrollingStateOverflowScrollingNode.h"
    42 #include "ScrollingTree.h"
     42#include "ThreadedScrollingTree.h"
    4343
    4444namespace WebCore {
     
    5252    : ScrollingTreeOverflowScrollingNode(scrollingTree, nodeID)
    5353{
    54 #if ENABLE(KINETIC_SCROLLING)
     54    m_scrollAnimatorEnabled = downcast<ThreadedScrollingTree>(scrollingTree).scrollAnimatorEnabled();
     55}
     56
     57ScrollingTreeOverflowScrollingNodeNicosia::~ScrollingTreeOverflowScrollingNodeNicosia() = default;
     58
     59void ScrollingTreeOverflowScrollingNodeNicosia::commitStateAfterChildren(const ScrollingStateNode& stateNode)
     60{
     61    ScrollingTreeOverflowScrollingNode::commitStateAfterChildren(stateNode);
     62
     63    const auto& overflowStateNode = downcast<ScrollingStateOverflowScrollingNode>(stateNode);
     64    if (overflowStateNode.hasChangedProperty(ScrollingStateScrollingNode::RequestedScrollPosition)) {
     65        stopScrollAnimations();
     66        const auto& requestedScrollData = overflowStateNode.requestedScrollData();
     67        scrollTo(requestedScrollData.scrollPosition, requestedScrollData.scrollType, requestedScrollData.clamping);
     68#if ENABLE(SMOOTH_SCROLLING)
     69        if (m_smoothAnimation)
     70            m_smoothAnimation->setCurrentPosition(currentScrollPosition());
     71#endif
     72    }
     73}
     74
     75FloatPoint ScrollingTreeOverflowScrollingNodeNicosia::adjustedScrollPosition(const FloatPoint& position, ScrollClamping clamping) const
     76{
     77    FloatPoint scrollPosition(roundf(position.x()), roundf(position.y()));
     78    return ScrollingTreeOverflowScrollingNode::adjustedScrollPosition(scrollPosition, clamping);
     79}
     80
     81void ScrollingTreeOverflowScrollingNodeNicosia::repositionScrollingLayers()
     82{
     83    auto* scrollLayer = static_cast<Nicosia::PlatformLayer*>(scrolledContentsLayer());
     84    ASSERT(scrollLayer);
     85    auto& compositionLayer = downcast<Nicosia::CompositionLayer>(*scrollLayer);
     86
     87    auto scrollOffset = currentScrollOffset();
     88
     89    compositionLayer.updateState(
     90        [&scrollOffset](Nicosia::CompositionLayer::LayerState& state)
     91        {
     92            state.boundsOrigin = scrollOffset;
     93            state.delta.boundsOriginChanged = true;
     94        });
     95
     96#if ENABLE(SMOOTH_SCROLLING)
     97    if (m_smoothAnimation)
     98        m_smoothAnimation->updateVisibleLengths();
     99#endif
     100}
     101
     102#if ENABLE(KINETIC_SCROLLING)
     103void ScrollingTreeOverflowScrollingNodeNicosia::ensureScrollAnimationKinetic()
     104{
     105    if (m_kineticAnimation)
     106        return;
     107
    55108    m_kineticAnimation = makeUnique<ScrollAnimationKinetic>(
    56109        [this]() -> ScrollExtents {
     
    59112        [this](FloatPoint&& position) {
    60113#if ENABLE(SMOOTH_SCROLLING)
    61             m_smoothAnimation->setCurrentPosition(position);
     114            if (m_smoothAnimation)
     115                m_smoothAnimation->setCurrentPosition(position);
    62116#endif
    63117
     
    69123            scrollTo(position);
    70124        });
    71 #endif
    72 #if ENABLE(SMOOTH_SCROLLING)
     125}
     126#endif
     127
     128#if ENABLE(SMOOTH_SCROLLING)
     129void ScrollingTreeOverflowScrollingNodeNicosia::ensureScrollAnimationSmooth()
     130{
     131    if (m_smoothAnimation)
     132        return;
     133
    73134    m_smoothAnimation = makeUnique<ScrollAnimationSmooth>(
    74135        [this]() -> ScrollExtents {
     
    85146        },
    86147        [] { });
    87 #endif
    88 }
    89 
    90 ScrollingTreeOverflowScrollingNodeNicosia::~ScrollingTreeOverflowScrollingNodeNicosia() = default;
    91 
    92 void ScrollingTreeOverflowScrollingNodeNicosia::commitStateAfterChildren(const ScrollingStateNode& stateNode)
    93 {
    94     ScrollingTreeOverflowScrollingNode::commitStateAfterChildren(stateNode);
    95 
    96     const auto& overflowStateNode = downcast<ScrollingStateOverflowScrollingNode>(stateNode);
    97     if (overflowStateNode.hasChangedProperty(ScrollingStateScrollingNode::RequestedScrollPosition)) {
    98         stopScrollAnimations();
    99         const auto& requestedScrollData = overflowStateNode.requestedScrollData();
    100         scrollTo(requestedScrollData.scrollPosition, requestedScrollData.scrollType, requestedScrollData.clamping);
    101 #if ENABLE(SMOOTH_SCROLLING)
    102         m_smoothAnimation->setCurrentPosition(currentScrollPosition());
    103 #endif
    104     }
    105 }
    106 
    107 FloatPoint ScrollingTreeOverflowScrollingNodeNicosia::adjustedScrollPosition(const FloatPoint& position, ScrollClamping clamping) const
    108 {
    109     FloatPoint scrollPosition(roundf(position.x()), roundf(position.y()));
    110     return ScrollingTreeOverflowScrollingNode::adjustedScrollPosition(scrollPosition, clamping);
    111 }
    112 
    113 void ScrollingTreeOverflowScrollingNodeNicosia::repositionScrollingLayers()
    114 {
    115     auto* scrollLayer = static_cast<Nicosia::PlatformLayer*>(scrolledContentsLayer());
    116     ASSERT(scrollLayer);
    117     auto& compositionLayer = downcast<Nicosia::CompositionLayer>(*scrollLayer);
    118 
    119     auto scrollOffset = currentScrollOffset();
    120 
    121     compositionLayer.updateState(
    122         [&scrollOffset](Nicosia::CompositionLayer::LayerState& state)
    123         {
    124             state.boundsOrigin = scrollOffset;
    125             state.delta.boundsOriginChanged = true;
    126         });
    127 }
     148}
     149#endif
    128150
    129151WheelEventHandlingResult ScrollingTreeOverflowScrollingNodeNicosia::handleWheelEvent(const PlatformWheelEvent& wheelEvent)
     
    133155
    134156#if ENABLE(KINETIC_SCROLLING)
     157    ensureScrollAnimationKinetic();
    135158    m_kineticAnimation->appendToScrollHistory(wheelEvent);
    136159    m_kineticAnimation->stop();
     
    175198
    176199#if ENABLE(SMOOTH_SCROLLING)
    177     m_smoothAnimation->scroll(HorizontalScrollbar, ScrollByPixel, 1, -deltaX);
    178     m_smoothAnimation->scroll(VerticalScrollbar, ScrollByPixel, 1, -deltaY);
    179 #else
     200    if (m_scrollAnimatorEnabled && !wheelEvent.hasPreciseScrollingDeltas()) {
     201        ensureScrollAnimationSmooth();
     202        m_smoothAnimation->scroll(HorizontalScrollbar, ScrollByPixel, 1, -deltaX);
     203        m_smoothAnimation->scroll(VerticalScrollbar, ScrollByPixel, 1, -deltaY);
     204        return WheelEventHandlingResult::handled();
     205    }
     206#endif
     207
    180208    auto* scrollLayer = static_cast<Nicosia::PlatformLayer*>(scrollContainerLayer());
    181209    ASSERT(scrollLayer);
     
    184212    auto updateScope = compositionLayer.createUpdateScope();
    185213    scrollBy({ -deltaX, -deltaY });
    186 #endif
    187214
    188215    return WheelEventHandlingResult::handled();
     
    192219{
    193220#if ENABLE(KINETIC_SCROLLING)
    194     m_kineticAnimation->stop();
    195     m_kineticAnimation->clearScrollHistory();
    196 #endif
    197 #if ENABLE(SMOOTH_SCROLLING)
    198     m_smoothAnimation->stop();
     221    if (m_kineticAnimation) {
     222        m_kineticAnimation->stop();
     223        m_kineticAnimation->clearScrollHistory();
     224    }
     225#endif
     226#if ENABLE(SMOOTH_SCROLLING)
     227    if (m_smoothAnimation)
     228        m_smoothAnimation->stop();
    199229#endif
    200230}
  • trunk/Source/WebCore/page/scrolling/nicosia/ScrollingTreeOverflowScrollingNodeNicosia.h

    r266390 r268522  
    5151    void repositionScrollingLayers() override;
    5252
     53#if ENABLE(KINETIC_SCROLLING)
     54    void ensureScrollAnimationKinetic();
     55#endif
     56#if ENABLE(SMOOTH_SCROLLING)
     57    void ensureScrollAnimationSmooth();
     58#endif
     59
    5360    WheelEventHandlingResult handleWheelEvent(const PlatformWheelEvent&) override;
    5461
    5562    void stopScrollAnimations() override;
    5663
     64    bool m_scrollAnimatorEnabled { false };
    5765#if ENABLE(KINETIC_SCROLLING)
    5866    std::unique_ptr<ScrollAnimationKinetic> m_kineticAnimation;
  • trunk/Source/WebCore/platform/PlatformWheelEvent.h

    r268287 r268522  
    142142#endif
    143143
    144 #if PLATFORM(COCOA)
     144#if PLATFORM(COCOA) || PLATFORM(GTK) || USE(LIBWPE)
    145145    bool hasPreciseScrollingDeltas() const { return m_hasPreciseScrollingDeltas; }
    146146    void setHasPreciseScrollingDeltas(bool hasPreciseScrollingDeltas) { m_hasPreciseScrollingDeltas = hasPreciseScrollingDeltas; }
     147#endif
     148
     149#if PLATFORM(COCOA)
    147150    unsigned scrollCount() const { return m_scrollCount; }
    148151    float unacceleratedScrollingDeltaX() const { return m_unacceleratedScrollingDeltaX; }
     
    194197    PlatformWheelEventPhase m_momentumPhase { PlatformWheelEventPhaseNone };
    195198#endif
     199#if PLATFORM(COCOA) || PLATFORM(GTK) || USE(LIBWPE)
     200    bool m_hasPreciseScrollingDeltas { false };
     201#endif
    196202#if PLATFORM(COCOA)
    197     bool m_hasPreciseScrollingDeltas { false };
    198203    unsigned m_scrollCount { 0 };
    199204    float m_unacceleratedScrollingDeltaX { 0 };
  • trunk/Source/WebCore/platform/ScrollAnimation.h

    r266390 r268522  
    5151    virtual void setCurrentPosition(const FloatPoint&) { };
    5252    virtual void serviceAnimation() { };
     53    virtual bool isActive() const = 0;
    5354};
    5455
  • trunk/Source/WebCore/platform/ScrollAnimationKinetic.cpp

    r266390 r268522  
    129129}
    130130
     131bool ScrollAnimationKinetic::isActive() const
     132{
     133    return m_animationTimer.isActive();
     134}
     135
    131136void ScrollAnimationKinetic::appendToScrollHistory(const PlatformWheelEvent& event)
    132137{
  • trunk/Source/WebCore/platform/ScrollAnimationKinetic.h

    r266390 r268522  
    7171    void start(const FloatPoint& initialPosition, const FloatPoint& velocity, bool mayHScroll, bool mayVScroll);
    7272    void stop() override;
     73    bool isActive() const override;
    7374
    7475private:
  • trunk/Source/WebCore/platform/ScrollAnimationSmooth.cpp

    r266390 r268522  
    8686    }
    8787    bool needToScroll = updatePerAxisData(orientation == HorizontalScrollbar ? m_horizontalData : m_verticalData, granularity, step * multiplier, minScrollPosition, maxScrollPosition);
    88     if (needToScroll && !animationTimerActive()) {
     88    if (needToScroll && !isActive()) {
    8989        m_startTime = orientation == HorizontalScrollbar ? m_horizontalData.startTime : m_verticalData.startTime;
    9090        animationTimerFired();
     
    100100    needToScroll |=
    101101        updatePerAxisData(m_verticalData, granularity, position.y() - m_verticalData.currentPosition, extents.minimumScrollPosition.y(), extents.maximumScrollPosition.y(), smoothFactorForProgrammaticScroll);
    102     if (needToScroll && !animationTimerActive()) {
     102    if (needToScroll && !isActive()) {
    103103        m_startTime = m_horizontalData.startTime;
    104104        animationTimerFired();
     
    450450}
    451451
    452 bool ScrollAnimationSmooth::animationTimerActive() const
     452bool ScrollAnimationSmooth::isActive() const
    453453{
    454454    return m_animationTimer.isActive();
  • trunk/Source/WebCore/platform/ScrollAnimationSmooth.h

    r266390 r268522  
    5959    void updateVisibleLengths() override;
    6060    void setCurrentPosition(const FloatPoint&) override;
     61    bool isActive() const override;
    6162
    6263    struct PerAxisData {
     
    102103    void startNextTimer(Seconds delay);
    103104    void animationTimerFired();
    104     bool animationTimerActive() const;
    105105
    106106    ScrollExtentsCallback m_scrollExtentsFunction;
  • trunk/Source/WebCore/platform/generic/ScrollAnimatorGeneric.cpp

    r266390 r268522  
    7474void ScrollAnimatorGeneric::ensureSmoothScrollingAnimation()
    7575{
    76     if (m_smoothAnimation)
    77         return;
     76    if (m_smoothAnimation) {
     77        if (!m_smoothAnimation->isActive())
     78            m_smoothAnimation->setCurrentPosition(m_currentPosition);
     79        return;
     80    }
    7881
    7982    m_smoothAnimation = makeUnique<ScrollAnimationSmooth>(
  • trunk/Source/WebKit/ChangeLog

    r268521 r268522  
     12020-10-15  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        Add hasPreciseScrollingDeltas to GTK/WPE wheel events.
     9
     10        No new tests needed.
     11
     12        * Shared/WebEventConversion.cpp:
     13        (WebKit::WebKit2PlatformWheelEvent::WebKit2PlatformWheelEvent):
     14        * Shared/WebWheelEvent.cpp:
     15        (WebKit::WebWheelEvent::WebWheelEvent):
     16        (WebKit::WebWheelEvent::encode const):
     17        (WebKit::WebWheelEvent::decode):
     18        * Shared/WebWheelEvent.h:
     19        * Shared/WebWheelEventCoalescer.cpp:
     20        (WebKit::WebWheelEventCoalescer::canCoalesce):
     21        (WebKit::WebWheelEventCoalescer::coalesce):
     22        * Shared/gtk/NativeWebWheelEventGtk.cpp:
     23        (WebKit::NativeWebWheelEvent::NativeWebWheelEvent):
     24        * Shared/gtk/WebEventFactory.cpp:
     25        (WebKit::WebEventFactory::createWebWheelEvent):
     26        * Shared/libwpe/WebEventFactory.cpp:
     27        (WebKit::WebEventFactory::createWebWheelEvent):
     28
    1292020-10-15  Youenn Fablet  <youenn@apple.com>
    230
  • trunk/Source/WebKit/Shared/WebEventConversion.cpp

    r267916 r268522  
    165165        m_momentumPhase = static_cast<WebCore::PlatformWheelEventPhase>(webEvent.momentumPhase());
    166166#endif
     167#if PLATFORM(COCOA) || PLATFORM(GTK) || USE(LIBWPE)
     168        m_hasPreciseScrollingDeltas = webEvent.hasPreciseScrollingDeltas();
     169#endif
    167170#if PLATFORM(COCOA)
    168         m_hasPreciseScrollingDeltas = webEvent.hasPreciseScrollingDeltas();
    169171        m_scrollCount = webEvent.scrollCount();
    170172        m_unacceleratedScrollingDeltaX = webEvent.unacceleratedScrollingDelta().width();
  • trunk/Source/WebKit/Shared/WebWheelEvent.cpp

    r267916 r268522  
    6262}
    6363#elif PLATFORM(GTK) || USE(LIBWPE)
    64 WebWheelEvent::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)
     64WebWheelEvent::WebWheelEvent(Type type, const IntPoint& position, const IntPoint& globalPosition, const FloatSize& delta, const FloatSize& wheelTicks, Phase phase, Phase momentumPhase, Granularity granularity, bool hasPreciseScrollingDeltas, OptionSet<Modifier> modifiers, WallTime timestamp)
    6565    : WebEvent(type, modifiers, timestamp)
    6666    , m_position(position)
     
    7171    , m_phase(phase)
    7272    , m_momentumPhase(momentumPhase)
     73    , m_hasPreciseScrollingDeltas(hasPreciseScrollingDeltas)
    7374{
    7475    ASSERT(isWheelEventType(type));
     
    8990    encoder << m_phase;
    9091    encoder << m_momentumPhase;
     92    encoder << m_hasPreciseScrollingDeltas;
    9193#endif
    9294#if PLATFORM(COCOA)
    93     encoder << m_hasPreciseScrollingDeltas;
    9495    encoder << m_scrollCount;
    9596    encoder << m_unacceleratedScrollingDelta;
     
    118119    if (!decoder.decode(t.m_momentumPhase))
    119120        return false;
     121    if (!decoder.decode(t.m_hasPreciseScrollingDeltas))
     122        return false;
    120123#endif
    121124#if PLATFORM(COCOA)
    122     if (!decoder.decode(t.m_hasPreciseScrollingDeltas))
    123         return false;
    124125    if (!decoder.decode(t.m_scrollCount))
    125126        return false;
  • trunk/Source/WebKit/Shared/WebWheelEvent.h

    r267916 r268522  
    5656    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);
    5757#elif PLATFORM(GTK) || USE(LIBWPE)
    58     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);
     58    WebWheelEvent(Type, const WebCore::IntPoint& position, const WebCore::IntPoint& globalPosition, const WebCore::FloatSize& delta, const WebCore::FloatSize& wheelTicks, Phase, Phase momentumPhase, Granularity, bool hasPreciseScrollingDeltas, OptionSet<Modifier>, WallTime timestamp);
    5959#endif
    6060
     
    6767    Phase phase() const { return static_cast<Phase>(m_phase); }
    6868    Phase momentumPhase() const { return static_cast<Phase>(m_momentumPhase); }
     69#if PLATFORM(COCOA) || PLATFORM(GTK) || USE(LIBWPE)
     70    bool hasPreciseScrollingDeltas() const { return m_hasPreciseScrollingDeltas; }
     71#endif
    6972#if PLATFORM(COCOA)
    70     bool hasPreciseScrollingDeltas() const { return m_hasPreciseScrollingDeltas; }
    7173    uint32_t scrollCount() const { return m_scrollCount; }
    7274    const WebCore::FloatSize& unacceleratedScrollingDelta() const { return m_unacceleratedScrollingDelta; }
     
    8789    uint32_t m_momentumPhase { Phase::PhaseNone };
    8890    bool m_directionInvertedFromDevice { false };
     91#if PLATFORM(COCOA) || PLATFORM(GTK) || USE(LIBWPE)
     92    bool m_hasPreciseScrollingDeltas { false };
     93#endif
    8994#if PLATFORM(COCOA)
    90     bool m_hasPreciseScrollingDeltas { false };
    9195    uint32_t m_scrollCount { 0 };
    9296    WebCore::FloatSize m_unacceleratedScrollingDelta;
  • trunk/Source/WebKit/Shared/WebWheelEventCoalescer.cpp

    r268287 r268522  
    6060    if (a.momentumPhase() != b.momentumPhase())
    6161        return false;
     62#endif
     63#if PLATFORM(COCOA) || PLATFORM(GTK) || USE(LIBWPE)
    6264    if (a.hasPreciseScrollingDeltas() != b.hasPreciseScrollingDeltas())
    6365        return false;
     
    7880
    7981    return WebWheelEvent(WebEvent::Wheel, b.position(), b.globalPosition(), mergedDelta, mergedWheelTicks, b.granularity(), b.directionInvertedFromDevice(), b.phase(), b.momentumPhase(), b.hasPreciseScrollingDeltas(), b.scrollCount(), mergedUnacceleratedScrollingDelta, b.modifiers(), b.timestamp());
     82#elif PLATFORM(GTK) || USE(LIBWPE)
     83    return WebWheelEvent(WebEvent::Wheel, b.position(), b.globalPosition(), mergedDelta, mergedWheelTicks, b.phase(), b.momentumPhase(), b.granularity(), b.hasPreciseScrollingDeltas(), b.modifiers(), b.timestamp());
    8084#else
    8185    return WebWheelEvent(WebEvent::Wheel, b.position(), b.globalPosition(), mergedDelta, mergedWheelTicks, b.granularity(), b.modifiers(), b.timestamp());
  • trunk/Source/WebKit/Shared/gtk/NativeWebWheelEventGtk.cpp

    r263887 r268522  
    5151
    5252NativeWebWheelEvent::NativeWebWheelEvent(const WebCore::IntPoint& position, const WebCore::IntPoint& globalPosition, const WebCore::FloatSize& delta, const WebCore::FloatSize& wheelTicks, WebWheelEvent::Phase phase, WebWheelEvent::Phase momentumPhase)
    53     : WebWheelEvent(WebEvent::Wheel, position, globalPosition, delta, wheelTicks, phase, momentumPhase, WebWheelEvent::ScrollByPixelWheelEvent, { }, WallTime::now())
     53    : WebWheelEvent(WebEvent::Wheel, position, globalPosition, delta, wheelTicks, phase, momentumPhase, WebWheelEvent::ScrollByPixelWheelEvent, false, { }, WallTime::now())
    5454{
    5555}
    5656
    5757NativeWebWheelEvent::NativeWebWheelEvent(const NativeWebWheelEvent& event)
    58     : WebWheelEvent(event.type(), event.position(), event.globalPosition(), event.delta(), event.wheelTicks(), event.phase(), event.momentumPhase(), event.granularity(), event.modifiers(), event.timestamp())
     58    : WebWheelEvent(event.type(), event.position(), event.globalPosition(), event.delta(), event.wheelTicks(), event.phase(), event.momentumPhase(), event.granularity(), event.hasPreciseScrollingDeltas(), event.modifiers(), event.timestamp())
    5959    , m_nativeEvent(event.nativeEvent() ? gdk_event_copy(event.nativeEvent()) : nullptr)
    6060{
  • trunk/Source/WebKit/Shared/gtk/WebEventFactory.cpp

    r263887 r268522  
    289289        momentumPhase,
    290290        WebWheelEvent::ScrollByPixelWheelEvent,
     291        false,
    291292        modifiersForEvent(event),
    292293        wallTimeForEvent(event));
  • trunk/Source/WebKit/Shared/libwpe/WebEventFactory.cpp

    r262702 r268522  
    165165    WebCore::FloatSize wheelTicks;
    166166    WebCore::FloatSize delta;
     167    bool hasPreciseScrollingDeltas = false;
    167168
    168169#if WPE_CHECK_VERSION(1, 5, 0)
     
    178179            wheelTicks = WebCore::FloatSize(event2D->x_axis / deviceScaleFactor, event2D->y_axis / deviceScaleFactor);
    179180            delta = wheelTicks;
     181            hasPreciseScrollingDeltas = true;
    180182            break;
    181183        default:
     
    185187        return WebWheelEvent(WebEvent::Wheel, position, position,
    186188            delta, wheelTicks, phase, momentumPhase,
    187             WebWheelEvent::ScrollByPixelWheelEvent,
     189            WebWheelEvent::ScrollByPixelWheelEvent, hasPreciseScrollingDeltas,
    188190            OptionSet<WebEvent::Modifier> { }, wallTimeForEventTime(event->time));
    189191    }
     
    211213        wheelTicks = WebCore::FloatSize(0, event->value / deviceScaleFactor);
    212214        delta = wheelTicks;
     215        hasPreciseScrollingDeltas = true;
    213216        break;
    214217    default:
     
    218221    return WebWheelEvent(WebEvent::Wheel, position, position,
    219222        delta, wheelTicks, phase, momentumPhase,
    220         WebWheelEvent::ScrollByPixelWheelEvent,
     223        WebWheelEvent::ScrollByPixelWheelEvent, hasPreciseScrollingDeltas,
    221224        OptionSet<WebEvent::Modifier> { }, wallTimeForEventTime(event->time));
    222225}
Note: See TracChangeset for help on using the changeset viewer.