Changeset 270338 in webkit


Ignore:
Timestamp:
Dec 1, 2020, 7:25:42 PM (5 years ago)
Author:
Simon Fraser
Message:

Simplify some callsites of WheelEventTestMonitor
https://bugs.webkit.org/show_bug.cgi?id=219416

Reviewed by Daniel Bates.

Migrate towards more usage of WheelEventTestMonitorCompletionDeferrer, using a pattern
where we WTFMove() one into a completion handler to pair the defer/undefer pairs,
rather than having manual deferral/undeferral.

To make this work, WheelEventTestMonitorCompletionDeferrer gains a move constructor,
that nullifies the m_monitor in the source to prevent double firing.

Remove the WheelEventTestMonitor::RequestedScrollPosition deferral, since that code path
is now synchronous.

  • page/EventHandler.cpp:

(WebCore::EventHandler::handleWheelEventInternal):

  • page/FrameView.cpp:

(WebCore::FrameView::scrollOffsetChangedViaPlatformWidgetImpl):

  • page/WheelEventTestMonitor.cpp:

(WebCore::WheelEventTestMonitor::removeDeferralForReason):

  • page/WheelEventTestMonitor.h:

(WebCore::WheelEventTestMonitorCompletionDeferrer::WheelEventTestMonitorCompletionDeferrer):

  • page/scrolling/AsyncScrollingCoordinator.cpp:

(WebCore::AsyncScrollingCoordinator::requestScrollPositionUpdate):
(WebCore::AsyncScrollingCoordinator::synchronizeStateFromScrollingTree):
(WebCore::AsyncScrollingCoordinator::applyPendingScrollUpdates):
(WebCore::AsyncScrollingCoordinator::applyScrollUpdate):
(WebCore::AsyncScrollingCoordinator::updateScrollPositionAfterAsyncScroll):
(WebCore::AsyncScrollingCoordinator::noteScrollingThreadSyncCompleteForNode): Deleted.

  • page/scrolling/AsyncScrollingCoordinator.h:
  • page/scrolling/ScrollingTree.h:

(WebCore::ScrollingTree::wheelEventTestMonitor):

  • page/scrolling/ThreadedScrollingTree.cpp:

(WebCore::ThreadedScrollingTree::scrollingTreeNodeDidScroll):
(WebCore::ThreadedScrollingTree::setActiveScrollSnapIndices):
(WebCore::ThreadedScrollingTree::scrollingTreeNodeRequestsScroll): Deleted.

  • page/scrolling/ThreadedScrollingTree.h:
  • page/scrolling/mac/ScrollingCoordinatorMac.mm:

(WebCore::ScrollingCoordinatorMac::wheelEventWasProcessedByMainThread):

  • page/scrolling/mac/ScrollingTreeMac.h:
  • page/scrolling/mac/ScrollingTreeScrollingNodeDelegateMac.mm:

(WebCore::ScrollingTreeScrollingNodeDelegateMac::handleWheelEvent):

Location:
trunk/Source/WebCore
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r270334 r270338  
     12020-12-01  Simon Fraser  <simon.fraser@apple.com>
     2
     3        Simplify some callsites of WheelEventTestMonitor
     4        https://bugs.webkit.org/show_bug.cgi?id=219416
     5
     6        Reviewed by Daniel Bates.
     7
     8        Migrate towards more usage of WheelEventTestMonitorCompletionDeferrer, using a pattern
     9        where we WTFMove() one into a completion handler to pair the defer/undefer pairs,
     10        rather than having manual deferral/undeferral.
     11
     12        To make this work, WheelEventTestMonitorCompletionDeferrer gains a move constructor,
     13        that nullifies the m_monitor in the source to prevent double firing.
     14       
     15        Remove the WheelEventTestMonitor::RequestedScrollPosition deferral, since that code path
     16        is now synchronous.
     17
     18        * page/EventHandler.cpp:
     19        (WebCore::EventHandler::handleWheelEventInternal):
     20        * page/FrameView.cpp:
     21        (WebCore::FrameView::scrollOffsetChangedViaPlatformWidgetImpl):
     22        * page/WheelEventTestMonitor.cpp:
     23        (WebCore::WheelEventTestMonitor::removeDeferralForReason):
     24        * page/WheelEventTestMonitor.h:
     25        (WebCore::WheelEventTestMonitorCompletionDeferrer::WheelEventTestMonitorCompletionDeferrer):
     26        * page/scrolling/AsyncScrollingCoordinator.cpp:
     27        (WebCore::AsyncScrollingCoordinator::requestScrollPositionUpdate):
     28        (WebCore::AsyncScrollingCoordinator::synchronizeStateFromScrollingTree):
     29        (WebCore::AsyncScrollingCoordinator::applyPendingScrollUpdates):
     30        (WebCore::AsyncScrollingCoordinator::applyScrollUpdate):
     31        (WebCore::AsyncScrollingCoordinator::updateScrollPositionAfterAsyncScroll):
     32        (WebCore::AsyncScrollingCoordinator::noteScrollingThreadSyncCompleteForNode): Deleted.
     33        * page/scrolling/AsyncScrollingCoordinator.h:
     34        * page/scrolling/ScrollingTree.h:
     35        (WebCore::ScrollingTree::wheelEventTestMonitor):
     36        * page/scrolling/ThreadedScrollingTree.cpp:
     37        (WebCore::ThreadedScrollingTree::scrollingTreeNodeDidScroll):
     38        (WebCore::ThreadedScrollingTree::setActiveScrollSnapIndices):
     39        (WebCore::ThreadedScrollingTree::scrollingTreeNodeRequestsScroll): Deleted.
     40        * page/scrolling/ThreadedScrollingTree.h:
     41        * page/scrolling/mac/ScrollingCoordinatorMac.mm:
     42        (WebCore::ScrollingCoordinatorMac::wheelEventWasProcessedByMainThread):
     43        * page/scrolling/mac/ScrollingTreeMac.h:
     44        * page/scrolling/mac/ScrollingTreeScrollingNodeDelegateMac.mm:
     45        (WebCore::ScrollingTreeScrollingNodeDelegateMac::handleWheelEvent):
     46
    1472020-12-01  Peng Liu  <peng.liu6@apple.com>
    248
  • trunk/Source/WebCore/page/EventHandler.cpp

    r270278 r270338  
    29002900#if PLATFORM(COCOA)
    29012901    LOG_WITH_STREAM(Scrolling, stream << "EventHandler::handleWheelEvent " << event << " processing steps " << processingSteps);
    2902     if (auto monitor = m_frame.page()->wheelEventTestMonitor())
     2902    auto monitor = m_frame.page()->wheelEventTestMonitor();
     2903    if (monitor)
    29032904        monitor->receivedWheelEvent(event);
    29042905
    2905     WheelEventTestMonitorCompletionDeferrer deferrer(m_frame.page()->wheelEventTestMonitor().get(), this, WheelEventTestMonitor::DeferReason::HandlingWheelEventOnMainThread);
     2906    auto deferrer = WheelEventTestMonitorCompletionDeferrer { monitor.get(), this, WheelEventTestMonitor::DeferReason::HandlingWheelEventOnMainThread };
    29062907#endif
    29072908
  • trunk/Source/WebCore/page/FrameView.cpp

    r270278 r270338  
    24852485{
    24862486#if PLATFORM(COCOA)
    2487     WheelEventTestMonitorCompletionDeferrer deferrer(frame().page()->wheelEventTestMonitor().get(), this, WheelEventTestMonitor::DeferReason::ContentScrollInProgress);
     2487    auto deferrer = WheelEventTestMonitorCompletionDeferrer { frame().page()->wheelEventTestMonitor().get(), this, WheelEventTestMonitor::DeferReason::ContentScrollInProgress };
    24882488#endif
    24892489
  • trunk/Source/WebCore/page/WheelEventTestMonitor.cpp

    r269973 r270338  
    9696
    9797    auto it = m_deferCompletionReasons.find(identifier);
    98     if (it == m_deferCompletionReasons.end())
     98    if (it == m_deferCompletionReasons.end()) {
     99        LOG_WITH_STREAM(WheelEventTestMonitor, stream << "      (=) WheelEventTestMonitor::removeDeferralForReason: failed to find defer for id=" << identifier << ", reason=" << reason);
    99100        return;
     101    }
    100102
    101103    LOG_WITH_STREAM(WheelEventTestMonitor, stream << "      (=) WheelEventTestMonitor::removeDeferralForReason: id=" << identifier << ", reason=" << reason);
  • trunk/Source/WebCore/page/WheelEventTestMonitor.h

    r269973 r270338  
    9494    }
    9595   
     96    WheelEventTestMonitorCompletionDeferrer(WheelEventTestMonitorCompletionDeferrer&& other)
     97        : m_monitor(WTFMove(other.m_monitor))
     98        , m_identifier(other.m_identifier)
     99        , m_reason(other.m_reason)
     100    {
     101    }
     102
    96103    ~WheelEventTestMonitorCompletionDeferrer()
    97104    {
  • trunk/Source/WebCore/page/scrolling/AsyncScrollingCoordinator.cpp

    r270156 r270338  
    271271    bool inProgrammaticScroll = scrollableArea.currentScrollType() == ScrollType::Programmatic;
    272272    if (inProgrammaticScroll || inBackForwardCache)
    273         applyScrollUpdate(scrollingNodeID, scrollPosition, { }, ScrollType::Programmatic, ScrollingLayerPositionAction::Set, InformWheelEventMonitor::No);
     273        applyScrollUpdate(scrollingNodeID, scrollPosition, { }, ScrollType::Programmatic, ScrollingLayerPositionAction::Set);
    274274
    275275    ASSERT(inProgrammaticScroll == (scrollType == ScrollType::Programmatic));
     
    284284        return false;
    285285
    286 #if PLATFORM(MAC)
    287     if (m_page && m_page->isMonitoringWheelEvents()) {
    288         LOG_WITH_STREAM(WheelEventTestMonitor, stream << "    (!) AsyncScrollingCoordinator::requestScrollPositionUpdate: Adding deferral on " << scrollingNodeID << " for reason " << WheelEventTestMonitor::RequestedScrollPosition);
    289         m_page->wheelEventTestMonitor()->deferForReason(reinterpret_cast<WheelEventTestMonitor::ScrollableAreaIdentifier>(scrollingNodeID), WheelEventTestMonitor::RequestedScrollPosition);
    290     }
    291 #endif
    292 
    293286    stateNode->setRequestedScrollData({ scrollPosition, scrollType, clamping });
    294287    commitTreeStateIfNeeded();
     
    309302        if (scrollPosition && scrolledSinceLastCommit) {
    310303            LOG_WITH_STREAM(Scrolling, stream << "AsyncScrollingCoordinator::synchronizeStateFromScrollingTree - node " << nodeID << " scroll position " << scrollPosition);
    311             updateScrollPositionAfterAsyncScroll(nodeID, scrollPosition.value(), layoutViewportOrigin, ScrollType::User, ScrollingLayerPositionAction::Set, InformWheelEventMonitor::No);
     304            updateScrollPositionAfterAsyncScroll(nodeID, scrollPosition.value(), layoutViewportOrigin, ScrollType::User, ScrollingLayerPositionAction::Set);
    312305        }
    313306    });
    314 }
    315 
    316 void AsyncScrollingCoordinator::noteScrollingThreadSyncCompleteForNode(ScrollingNodeID nodeID)
    317 {
    318 #if PLATFORM(MAC)
    319     if (m_page && m_page->isMonitoringWheelEvents()) {
    320         LOG_WITH_STREAM(WheelEventTestMonitor, stream << "    (!) AsyncScrollingCoordinator::noteScrollingThreadSyncCompleteForNode: Removing deferral on " << nodeID << " for reason " << WheelEventTestMonitor::ScrollingThreadSyncNeeded);
    321         m_page->wheelEventTestMonitor()->removeDeferralForReason(reinterpret_cast<WheelEventTestMonitor::ScrollableAreaIdentifier>(nodeID), WheelEventTestMonitor::ScrollingThreadSyncNeeded);
    322     }
    323 #else
    324     UNUSED_PARAM(nodeID);
    325 #endif
    326307}
    327308
     
    334315    for (auto& update : scrollUpdates) {
    335316        LOG_WITH_STREAM(Scrolling, stream << "AsyncScrollingCoordinator::applyPendingScrollUpdates - node " << update.nodeID << " scroll position " << update.scrollPosition);
    336         updateScrollPositionAfterAsyncScroll(update.nodeID, update.scrollPosition, update.layoutViewportOrigin, ScrollType::User, update.updateLayerPositionAction, InformWheelEventMonitor::Yes);
     317        updateScrollPositionAfterAsyncScroll(update.nodeID, update.scrollPosition, update.layoutViewportOrigin, ScrollType::User, update.updateLayerPositionAction);
    337318    }
    338319}
     
    370351}
    371352
    372 void AsyncScrollingCoordinator::applyScrollUpdate(ScrollingNodeID scrollingNodeID, const FloatPoint& scrollPosition, Optional<FloatPoint> layoutViewportOrigin, ScrollType scrollType, ScrollingLayerPositionAction scrollingLayerPositionAction, InformWheelEventMonitor informWheelEventMonitor)
     353void AsyncScrollingCoordinator::applyScrollUpdate(ScrollingNodeID scrollingNodeID, const FloatPoint& scrollPosition, Optional<FloatPoint> layoutViewportOrigin, ScrollType scrollType, ScrollingLayerPositionAction scrollingLayerPositionAction)
    373354{
    374355    applyPendingScrollUpdates();
    375     updateScrollPositionAfterAsyncScroll(scrollingNodeID, scrollPosition, layoutViewportOrigin, scrollType, scrollingLayerPositionAction, informWheelEventMonitor);
    376 }
    377 
    378 void AsyncScrollingCoordinator::updateScrollPositionAfterAsyncScroll(ScrollingNodeID scrollingNodeID, const FloatPoint& scrollPosition, Optional<FloatPoint> layoutViewportOrigin, ScrollType scrollType, ScrollingLayerPositionAction scrollingLayerPositionAction, InformWheelEventMonitor informWheelEventMonitor)
     356    updateScrollPositionAfterAsyncScroll(scrollingNodeID, scrollPosition, layoutViewportOrigin, scrollType, scrollingLayerPositionAction);
     357}
     358
     359void AsyncScrollingCoordinator::updateScrollPositionAfterAsyncScroll(ScrollingNodeID scrollingNodeID, const FloatPoint& scrollPosition, Optional<FloatPoint> layoutViewportOrigin, ScrollType scrollType, ScrollingLayerPositionAction scrollingLayerPositionAction)
    379360{
    380361    ASSERT(isMainThread());
    381 
    382     if (informWheelEventMonitor == InformWheelEventMonitor::Yes)
    383         noteScrollingThreadSyncCompleteForNode(scrollingNodeID);
    384362
    385363    if (!m_page)
  • trunk/Source/WebCore/page/scrolling/AsyncScrollingCoordinator.h

    r270156 r270338  
    5454    void applyPendingScrollUpdates();
    5555
    56     enum class InformWheelEventMonitor { Yes, No };
    57     WEBCORE_EXPORT void applyScrollUpdate(ScrollingNodeID, const FloatPoint&, Optional<FloatPoint> layoutViewportOrigin, ScrollType, ScrollingLayerPositionAction, InformWheelEventMonitor = InformWheelEventMonitor::Yes);
     56    WEBCORE_EXPORT void applyScrollUpdate(ScrollingNodeID, const FloatPoint&, Optional<FloatPoint> layoutViewportOrigin, ScrollType, ScrollingLayerPositionAction);
    5857
    5958#if PLATFORM(COCOA)
     
    160159    void updateEventTrackingRegions();
    161160   
    162     void noteScrollingThreadSyncCompleteForNode(ScrollingNodeID);
    163 
    164     void updateScrollPositionAfterAsyncScroll(ScrollingNodeID, const FloatPoint&, Optional<FloatPoint> layoutViewportOrigin, ScrollType, ScrollingLayerPositionAction, InformWheelEventMonitor);
     161    void updateScrollPositionAfterAsyncScroll(ScrollingNodeID, const FloatPoint&, Optional<FloatPoint> layoutViewportOrigin, ScrollType, ScrollingLayerPositionAction);
    165162   
    166163    FrameView* frameViewForScrollingNode(ScrollingNodeID) const;
  • trunk/Source/WebCore/page/scrolling/ScrollingTree.h

    r270156 r270338  
    146146    WEBCORE_EXPORT TrackingType eventTrackingTypeForPoint(const AtomString& eventName, IntPoint);
    147147
     148    virtual WheelEventTestMonitor* wheelEventTestMonitor() { return nullptr; }
     149
    148150#if PLATFORM(MAC)
    149151    virtual void handleWheelEventPhase(ScrollingNodeID, PlatformWheelEventPhase) = 0;
  • trunk/Source/WebCore/page/scrolling/ThreadedScrollingTree.cpp

    r270292 r270338  
    149149        layoutViewportOrigin = downcast<ScrollingTreeFrameScrollingNode>(node).layoutViewport().location();
    150150
    151 #if PLATFORM(MAC)
    152     if (isMonitoringWheelEvents())
    153         deferWheelEventTestCompletionForReason(reinterpret_cast<WheelEventTestMonitor::ScrollableAreaIdentifier>(node.scrollingNodeID()), WheelEventTestMonitor::ScrollingThreadSyncNeeded);
    154 #endif
    155 
    156151    if (RunLoop::isMain()) {
    157152        m_scrollingCoordinator->applyScrollUpdate(node.scrollingNodeID(), scrollPosition, layoutViewportOrigin, ScrollType::User, scrollingLayerPositionAction);
     
    164159    addPendingScrollUpdate(WTFMove(scrollUpdate));
    165160
    166     RunLoop::main().dispatch([strongThis = makeRef(*this)] {
     161    auto deferrer = WheelEventTestMonitorCompletionDeferrer { wheelEventTestMonitor(), reinterpret_cast<WheelEventTestMonitor::ScrollableAreaIdentifier>(node.scrollingNodeID()), WheelEventTestMonitor::ScrollingThreadSyncNeeded };
     162    RunLoop::main().dispatch([strongThis = makeRef(*this), deferrer = WTFMove(deferrer)] {
    167163        if (auto* scrollingCoordinator = strongThis->m_scrollingCoordinator.get())
    168164            scrollingCoordinator->applyPendingScrollUpdates();
     
    215211        scrollingCoordinator->setActiveScrollSnapIndices(nodeID, horizontalIndex, verticalIndex);
    216212    });
    217 }
    218 
    219 void ThreadedScrollingTree::scrollingTreeNodeRequestsScroll(ScrollingNodeID nodeID, const FloatPoint& /*scrollPosition*/, ScrollType, ScrollClamping)
    220 {
    221     removeWheelEventTestCompletionDeferralForReason(reinterpret_cast<WheelEventTestMonitor::ScrollableAreaIdentifier>(nodeID), WheelEventTestMonitor::RequestedScrollPosition);
    222213}
    223214#endif
  • trunk/Source/WebCore/page/scrolling/ThreadedScrollingTree.h

    r270278 r270338  
    6969    void handleWheelEventPhase(ScrollingNodeID, PlatformWheelEventPhase) override;
    7070    void setActiveScrollSnapIndices(ScrollingNodeID, unsigned horizontalIndex, unsigned verticalIndex) override;
    71     void scrollingTreeNodeRequestsScroll(ScrollingNodeID, const FloatPoint& /*scrollPosition*/, ScrollType, ScrollClamping) override;
    7271#endif
    7372
  • trunk/Source/WebCore/page/scrolling/mac/ScrollingCoordinatorMac.mm

    r270278 r270338  
    9999void ScrollingCoordinatorMac::wheelEventWasProcessedByMainThread(const PlatformWheelEvent& wheelEvent, OptionSet<EventHandling> defaultHandling)
    100100{
    101     uint64_t deferIdentifier = 0;
    102     if (m_page && m_page->isMonitoringWheelEvents()) {
    103         deferIdentifier = nextDeferIdentifier();
    104         m_page->wheelEventTestMonitor()->deferForReason(reinterpret_cast<WheelEventTestMonitor::ScrollableAreaIdentifier>(deferIdentifier), WheelEventTestMonitor::ReportDOMEventHandling);
    105     }
     101    auto deferrer = WheelEventTestMonitorCompletionDeferrer { m_page->wheelEventTestMonitor().get(), reinterpret_cast<WheelEventTestMonitor::ScrollableAreaIdentifier>(nextDeferIdentifier()), WheelEventTestMonitor::ReportDOMEventHandling };
    106102
    107103    RefPtr<ThreadedScrollingTree> threadedScrollingTree = downcast<ThreadedScrollingTree>(scrollingTree());
    108     ScrollingThread::dispatch([threadedScrollingTree, wheelEvent, defaultHandling, deferIdentifier] {
     104    ScrollingThread::dispatch([threadedScrollingTree, wheelEvent, defaultHandling, deferrer = WTFMove(deferrer)] {
    109105        threadedScrollingTree->wheelEventWasProcessedByMainThread(wheelEvent, defaultHandling);
    110 
    111         if (threadedScrollingTree->isMonitoringWheelEvents())
    112             threadedScrollingTree->removeWheelEventTestCompletionDeferralForReason(reinterpret_cast<WheelEventTestMonitor::ScrollableAreaIdentifier>(deferIdentifier), WheelEventTestMonitor::ReportDOMEventHandling);
    113106    });
    114107}
  • trunk/Source/WebCore/page/scrolling/mac/ScrollingTreeMac.h

    r265823 r270338  
    4949
    5050    void setWheelEventTestMonitor(RefPtr<WheelEventTestMonitor>&&) final;
     51    WheelEventTestMonitor* wheelEventTestMonitor() final { return m_wheelEventTestMonitor.get(); }
    5152
    5253    void receivedWheelEvent(const PlatformWheelEvent&) final;
  • trunk/Source/WebCore/page/scrolling/mac/ScrollingTreeScrollingNodeDelegateMac.mm

    r269659 r270338  
    136136
    137137#if ENABLE(CSS_SCROLL_SNAP) || ENABLE(RUBBER_BANDING)
    138     if (scrollingTree().isMonitoringWheelEvents())
    139         deferWheelEventTestCompletionForReason(reinterpret_cast<WheelEventTestMonitor::ScrollableAreaIdentifier>(scrollingNode().scrollingNodeID()), WheelEventTestMonitor::HandlingWheelEvent);
     138    auto deferrer = WheelEventTestMonitorCompletionDeferrer { scrollingTree().wheelEventTestMonitor(), reinterpret_cast<WheelEventTestMonitor::ScrollableAreaIdentifier>(scrollingNode().scrollingNodeID()), WheelEventTestMonitor::HandlingWheelEvent };
    140139#endif
    141140
     
    151150        return true;
    152151
    153     auto handled = m_scrollController.handleWheelEvent(wheelEvent);
    154 
    155 #if ENABLE(CSS_SCROLL_SNAP) || ENABLE(RUBBER_BANDING)
    156     if (scrollingTree().isMonitoringWheelEvents())
    157         removeWheelEventTestCompletionDeferralForReason(reinterpret_cast<WheelEventTestMonitor::ScrollableAreaIdentifier>(scrollingNode().scrollingNodeID()), WheelEventTestMonitor::HandlingWheelEvent);
    158 #endif
    159 
    160     return handled;
     152    return m_scrollController.handleWheelEvent(wheelEvent);
    161153}
    162154
Note: See TracChangeset for help on using the changeset viewer.