Title: [285367] trunk
Revision
285367
Author
[email protected]
Date
2021-11-05 23:58:25 -0700 (Fri, 05 Nov 2021)

Log Message

Simplify code that makes use of WheelEventDeltaFilter
https://bugs.webkit.org/show_bug.cgi?id=232536

Reviewed by Wenson Hsieh.

Source/WebCore:

Push the decision about which kinds of wheel events to apply filtering to down into
WheelEventDeltaFilter, which simplifies call sites. WheelEventDeltaFilterMac::updateFromEvent()
now determines when to call into m_predominantAxisFilter based on the event phase. We
also simplify the timing logic by computing WallTime from when the WheelEventDeltaFilterMac
is constructed.

EventHandler code is cleaned up to simplify the logic a little but the behavior should
be the same.

Test: fast/scrolling/mac/wheel-event-deltas-are-not-filtered.html

* page/EventHandler.cpp:
(WebCore::EventHandler::handleWheelEventInternal):
(WebCore::EventHandler::handleWheelEventInAppropriateEnclosingBox):
(WebCore::EventHandler::clearLatchedState):
(WebCore::EventHandler::defaultWheelEventHandler): Move the filtering code out of the latching
#ifdef.
(WebCore::EventHandler::recordWheelEventForDeltaFilter): Deleted.
* page/EventHandler.h:
* page/WheelEventDeltaFilter.cpp:
(WebCore::WheelEventDeltaFilter::shouldApplyFilteringForEvent const):
(WebCore::WheelEventDeltaFilter::eventCopyWithFilteredDeltas const):
(WebCore::BasicWheelEventDeltaFilter::updateFromEvent):
(WebCore::BasicWheelEventDeltaFilter::updateWithDelta):
(WebCore::BasicWheelEventDeltaFilter::reset):
(WebCore::BasicWheelEventDeltaFilter::dominantAxis const):
(WebCore::WheelEventDeltaFilter::isFilteringDeltas const): Deleted.
(WebCore::BasicWheelEventDeltaFilter::updateFromDelta): Deleted.
(WebCore::BasicWheelEventDeltaFilter::beginFilteringDeltas): Deleted.
(WebCore::BasicWheelEventDeltaFilter::endFilteringDeltas): Deleted.
(WebCore::BasicWheelEventDeltaFilter::dominantScrollGestureDirection const): Deleted.
* page/WheelEventDeltaFilter.h:
* page/mac/EventHandlerMac.mm:
(WebCore::EventHandler::determineWheelEventTarget):
(WebCore::EventHandler::recordWheelEventForDeltaFilter): Deleted.
* page/mac/WheelEventDeltaFilterMac.h:
* page/mac/WheelEventDeltaFilterMac.mm:
(WebCore::WheelEventDeltaFilterMac::WheelEventDeltaFilterMac):
(WebCore::WheelEventDeltaFilterMac::updateFromEvent):
(WebCore::WheelEventDeltaFilterMac::reset):
(WebCore::WheelEventDeltaFilterMac::beginFilteringDeltas): Deleted.
(WebCore::WheelEventDeltaFilterMac::updateFromDelta): Deleted.
(WebCore::WheelEventDeltaFilterMac::endFilteringDeltas): Deleted.
* platform/PlatformWheelEvent.h:
(WebCore::PlatformWheelEvent::copyWithDeltaAndVelocity const): Take a FloatSize for the delta.
(WebCore::PlatformWheelEvent::copyWithDeltasAndVelocity const): Deleted.

Source/WebKit:

Push the decision about which kinds of wheel events to apply filtering to down into
WheelEventDeltaFilter, which simplifies call sites.

* WebProcess/WebPage/EventDispatcher.cpp:
(WebKit::EventDispatcher::wheelEvent):

LayoutTests:

Add a test to verify that wheel events sent to JS aren't affected by the wheel event
delta filter.

* fast/scrolling/mac/wheel-event-deltas-are-not-filtered-expected.txt: Added.
* fast/scrolling/mac/wheel-event-deltas-are-not-filtered.html: Added.
* tiled-drawing/scrolling/scroll-snap/scroll-snap-mandatory-2d-overflow.html:
Adjust the test for the fact that the momentum phase is now axis-locked.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (285366 => 285367)


--- trunk/LayoutTests/ChangeLog	2021-11-06 06:53:26 UTC (rev 285366)
+++ trunk/LayoutTests/ChangeLog	2021-11-06 06:58:25 UTC (rev 285367)
@@ -1,3 +1,18 @@
+2021-11-05  Simon Fraser  <[email protected]>
+
+        Simplify code that makes use of WheelEventDeltaFilter
+        https://bugs.webkit.org/show_bug.cgi?id=232536
+
+        Reviewed by Wenson Hsieh.
+
+        Add a test to verify that wheel events sent to JS aren't affected by the wheel event
+        delta filter.
+
+        * fast/scrolling/mac/wheel-event-deltas-are-not-filtered-expected.txt: Added.
+        * fast/scrolling/mac/wheel-event-deltas-are-not-filtered.html: Added.
+        * tiled-drawing/scrolling/scroll-snap/scroll-snap-mandatory-2d-overflow.html:
+        Adjust the test for the fact that the momentum phase is now axis-locked.
+
 2021-11-05  Alan Bujtas  <[email protected]>
 
         Rebaseline for fast/text/midword-break-after-breakable-char.html

Added: trunk/LayoutTests/fast/scrolling/mac/wheel-event-deltas-are-not-filtered-expected.txt (0 => 285367)


--- trunk/LayoutTests/fast/scrolling/mac/wheel-event-deltas-are-not-filtered-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/scrolling/mac/wheel-event-deltas-are-not-filtered-expected.txt	2021-11-06 06:58:25 UTC (rev 285367)
@@ -0,0 +1,9 @@
+-10 10
+-10 20
+-10 10
+-10 20
+-20 30
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/scrolling/mac/wheel-event-deltas-are-not-filtered.html (0 => 285367)


--- trunk/LayoutTests/fast/scrolling/mac/wheel-event-deltas-are-not-filtered.html	                        (rev 0)
+++ trunk/LayoutTests/fast/scrolling/mac/wheel-event-deltas-are-not-filtered.html	2021-11-06 06:58:25 UTC (rev 285367)
@@ -0,0 +1,39 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <script src=""
+    <script src=""
+    <script>
+        var jsTestIsAsync = true;
+
+        async function dispatchWheelEvents()
+        {
+            eventSender.monitorWheelEvents();
+            eventSender.mouseMoveTo(100, 100);
+
+            eventSender.mouseScrollByWithWheelAndMomentumPhases(1, -1, "began", "none");
+            eventSender.mouseScrollByWithWheelAndMomentumPhases(1, -2, "changed", "none");
+            eventSender.mouseScrollByWithWheelAndMomentumPhases(0, 0, "ended", "none");
+            eventSender.mouseScrollByWithWheelAndMomentumPhases(1, -1, "none", "begin");
+            eventSender.mouseScrollByWithWheelAndMomentumPhases(1, -2, "none", "continue");
+            eventSender.mouseScrollByWithWheelAndMomentumPhases(2, -3, "none", "continue");
+            eventSender.mouseScrollByWithWheelAndMomentumPhases(0, 0, "none", "end");
+            await UIHelper.waitForScrollCompletion();
+            finishJSTest();
+        }
+
+        window.addEventListener('load', () => {
+
+            window.addEventListener('wheel', (event) => {
+                debug(`${event.deltaX} ${event.deltaY}`)
+            });
+
+            dispatchWheelEvents();
+        }, false);
+    </script>
+</head>
+<body>
+    
+    <script src=""
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (285366 => 285367)


--- trunk/Source/WebCore/ChangeLog	2021-11-06 06:53:26 UTC (rev 285366)
+++ trunk/Source/WebCore/ChangeLog	2021-11-06 06:58:25 UTC (rev 285367)
@@ -1,5 +1,59 @@
 2021-11-05  Simon Fraser  <[email protected]>
 
+        Simplify code that makes use of WheelEventDeltaFilter
+        https://bugs.webkit.org/show_bug.cgi?id=232536
+
+        Reviewed by Wenson Hsieh.
+
+        Push the decision about which kinds of wheel events to apply filtering to down into
+        WheelEventDeltaFilter, which simplifies call sites. WheelEventDeltaFilterMac::updateFromEvent()
+        now determines when to call into m_predominantAxisFilter based on the event phase. We
+        also simplify the timing logic by computing WallTime from when the WheelEventDeltaFilterMac
+        is constructed.
+
+        EventHandler code is cleaned up to simplify the logic a little but the behavior should
+        be the same.
+
+        Test: fast/scrolling/mac/wheel-event-deltas-are-not-filtered.html
+
+        * page/EventHandler.cpp:
+        (WebCore::EventHandler::handleWheelEventInternal):
+        (WebCore::EventHandler::handleWheelEventInAppropriateEnclosingBox):
+        (WebCore::EventHandler::clearLatchedState):
+        (WebCore::EventHandler::defaultWheelEventHandler): Move the filtering code out of the latching
+        #ifdef.
+        (WebCore::EventHandler::recordWheelEventForDeltaFilter): Deleted.
+        * page/EventHandler.h:
+        * page/WheelEventDeltaFilter.cpp:
+        (WebCore::WheelEventDeltaFilter::shouldApplyFilteringForEvent const):
+        (WebCore::WheelEventDeltaFilter::eventCopyWithFilteredDeltas const):
+        (WebCore::BasicWheelEventDeltaFilter::updateFromEvent):
+        (WebCore::BasicWheelEventDeltaFilter::updateWithDelta):
+        (WebCore::BasicWheelEventDeltaFilter::reset):
+        (WebCore::BasicWheelEventDeltaFilter::dominantAxis const):
+        (WebCore::WheelEventDeltaFilter::isFilteringDeltas const): Deleted.
+        (WebCore::BasicWheelEventDeltaFilter::updateFromDelta): Deleted.
+        (WebCore::BasicWheelEventDeltaFilter::beginFilteringDeltas): Deleted.
+        (WebCore::BasicWheelEventDeltaFilter::endFilteringDeltas): Deleted.
+        (WebCore::BasicWheelEventDeltaFilter::dominantScrollGestureDirection const): Deleted.
+        * page/WheelEventDeltaFilter.h:
+        * page/mac/EventHandlerMac.mm:
+        (WebCore::EventHandler::determineWheelEventTarget):
+        (WebCore::EventHandler::recordWheelEventForDeltaFilter): Deleted.
+        * page/mac/WheelEventDeltaFilterMac.h:
+        * page/mac/WheelEventDeltaFilterMac.mm:
+        (WebCore::WheelEventDeltaFilterMac::WheelEventDeltaFilterMac):
+        (WebCore::WheelEventDeltaFilterMac::updateFromEvent):
+        (WebCore::WheelEventDeltaFilterMac::reset):
+        (WebCore::WheelEventDeltaFilterMac::beginFilteringDeltas): Deleted.
+        (WebCore::WheelEventDeltaFilterMac::updateFromDelta): Deleted.
+        (WebCore::WheelEventDeltaFilterMac::endFilteringDeltas): Deleted.
+        * platform/PlatformWheelEvent.h:
+        (WebCore::PlatformWheelEvent::copyWithDeltaAndVelocity const): Take a FloatSize for the delta.
+        (WebCore::PlatformWheelEvent::copyWithDeltasAndVelocity const): Deleted.
+
+2021-11-05  Simon Fraser  <[email protected]>
+
         Make it possible to avoid retargeting a ScrollingMomentumCalculator
         https://bugs.webkit.org/show_bug.cgi?id=232778
 

Modified: trunk/Source/WebCore/page/EventHandler.cpp (285366 => 285367)


--- trunk/Source/WebCore/page/EventHandler.cpp	2021-11-06 06:53:26 UTC (rev 285366)
+++ trunk/Source/WebCore/page/EventHandler.cpp	2021-11-06 06:58:25 UTC (rev 285367)
@@ -2813,12 +2813,6 @@
 {
 }
 
-void EventHandler::recordWheelEventForDeltaFilter(const PlatformWheelEvent& event)
-{
-    if (auto* page = m_frame.page())
-        page->wheelEventDeltaFilter()->updateFromDelta(FloatSize(event.deltaX(), event.deltaY()));
-}
-
 bool EventHandler::processWheelEventForScrolling(const PlatformWheelEvent& event, const WeakPtr<ScrollableArea>&, OptionSet<EventHandling> eventHandling)
 {
     Ref<Frame> protectedFrame(m_frame);
@@ -2972,7 +2966,7 @@
 #if ENABLE(WHEEL_EVENT_LATCHING)
         m_frame.page()->scrollLatchingController().receivedWheelEvent(event);
 #endif
-        recordWheelEventForDeltaFilter(event);
+        m_frame.page()->wheelEventDeltaFilter()->updateFromEvent(event);
     }
 
     HitTestRequest request;
@@ -3086,7 +3080,7 @@
             auto platformEvent = wheelEvent.underlyingPlatformEvent();
             bool scrollingWasHandled;
             if (platformEvent) {
-                auto copiedEvent = platformEvent->copyWithDeltasAndVelocity(filteredPlatformDelta.width(), filteredPlatformDelta.height(), filteredVelocity);
+                auto copiedEvent = platformEvent->copyWithDeltaAndVelocity(filteredPlatformDelta, filteredVelocity);
                 scrollingWasHandled = scrollableAreaCanHandleEvent(copiedEvent, *boxScrollableArea) && handleWheelEventInScrollableArea(copiedEvent, *boxScrollableArea, eventHandling);
             } else
                 scrollingWasHandled = didScrollInScrollableArea(*boxScrollableArea, wheelEvent);
@@ -3153,8 +3147,6 @@
     if (auto* scrollLatchingController = page->scrollLatchingControllerIfExists())
         scrollLatchingController->removeLatchingStateForFrame(m_frame);
 #endif
-    if (auto* filter = page->wheelEventDeltaFilter())
-        filter->endFilteringDeltas();
 }
 
 void EventHandler::defaultWheelEventHandler(Node* startNode, WheelEvent& wheelEvent)
@@ -3175,21 +3167,20 @@
 
     FloatSize filteredPlatformDelta(wheelEvent.deltaX(), wheelEvent.deltaY());
     FloatSize filteredVelocity;
-    if (auto platformWheelEvent = wheelEvent.underlyingPlatformEvent()) {
-        filteredPlatformDelta.setWidth(platformWheelEvent->deltaX());
-        filteredPlatformDelta.setHeight(platformWheelEvent->deltaY());
-    }
+    if (platformEvent)
+        filteredPlatformDelta = platformEvent->delta();
 
     OptionSet<EventHandling> eventHandling = { EventHandling::DispatchedToDOM };
     if (wheelEvent.defaultPrevented())
         eventHandling.add(EventHandling::DefaultPrevented);
 
-#if ENABLE(WHEEL_EVENT_LATCHING)
-    if (m_frame.page()->wheelEventDeltaFilter()->isFilteringDeltas()) {
-        filteredPlatformDelta = m_frame.page()->wheelEventDeltaFilter()->filteredDelta();
-        filteredVelocity = m_frame.page()->wheelEventDeltaFilter()->filteredVelocity();
+    auto* deltaFilter = m_frame.page()->wheelEventDeltaFilter();
+    if (platformEvent && deltaFilter && deltaFilter->shouldApplyFilteringForEvent(*platformEvent)) {
+        filteredPlatformDelta = deltaFilter->filteredDelta();
+        filteredVelocity = deltaFilter->filteredVelocity();
     }
 
+#if ENABLE(WHEEL_EVENT_LATCHING)
     WeakPtr<ScrollableArea> latchedScroller;
     if (!m_frame.page()->scrollLatchingController().latchingAllowsScrollingInFrame(m_frame, latchedScroller))
         return;
@@ -3201,7 +3192,7 @@
         }
 
         if (platformEvent) {
-            auto copiedEvent = platformEvent->copyWithDeltasAndVelocity(filteredPlatformDelta.width(), filteredPlatformDelta.height(), filteredVelocity);
+            auto copiedEvent = platformEvent->copyWithDeltaAndVelocity(filteredPlatformDelta, filteredVelocity);
             if (handleWheelEventInScrollableArea(copiedEvent, *latchedScroller, eventHandling))
                 wheelEvent.setDefaultHandled();
             return;

Modified: trunk/Source/WebCore/page/EventHandler.h (285366 => 285367)


--- trunk/Source/WebCore/page/EventHandler.h	2021-11-06 06:53:26 UTC (rev 285366)
+++ trunk/Source/WebCore/page/EventHandler.h	2021-11-06 06:58:25 UTC (rev 285367)
@@ -470,7 +470,6 @@
     bool handleWheelEventInternal(const PlatformWheelEvent&, OptionSet<WheelEventProcessingSteps>, OptionSet<EventHandling>&);
     bool passWheelEventToWidget(const PlatformWheelEvent&, Widget&, OptionSet<WheelEventProcessingSteps>);
     void determineWheelEventTarget(const PlatformWheelEvent&, RefPtr<Element>& eventTarget, WeakPtr<ScrollableArea>&, bool& isOverWidget);
-    void recordWheelEventForDeltaFilter(const PlatformWheelEvent&);
     bool processWheelEventForScrolling(const PlatformWheelEvent&, const WeakPtr<ScrollableArea>&, OptionSet<EventHandling>);
     void processWheelEventForScrollSnap(const PlatformWheelEvent&, const WeakPtr<ScrollableArea>&);
     bool completeWidgetWheelEvent(const PlatformWheelEvent&, const WeakPtr<Widget>&, const WeakPtr<ScrollableArea>&);

Modified: trunk/Source/WebCore/page/WheelEventDeltaFilter.cpp (285366 => 285367)


--- trunk/Source/WebCore/page/WheelEventDeltaFilter.cpp	2021-11-06 06:53:26 UTC (rev 285366)
+++ trunk/Source/WebCore/page/WheelEventDeltaFilter.cpp	2021-11-06 06:58:25 UTC (rev 285367)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2015-2016 Apple Inc. All rights reserved.
+ * Copyright (C) 2015-2021 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -28,6 +28,7 @@
 
 #include "FloatSize.h"
 #include "Logging.h"
+#include "PlatformWheelEvent.h"
 #include <wtf/text/TextStream.h>
 
 #if PLATFORM(MAC)
@@ -49,11 +50,22 @@
 #endif
 }
 
-bool WheelEventDeltaFilter::isFilteringDeltas() const
+bool WheelEventDeltaFilter::shouldApplyFilteringForEvent(const PlatformWheelEvent& event) const
 {
-    return m_isFilteringDeltas;
+#if ENABLE(KINETIC_SCROLLING)
+    // Maybe it's a per-platform decision about which event phases get filtered. Ideally we'd filter momentum events too (but that breaks some diagonal scrolling cases).
+    auto phase = event.phase();
+    return phase == PlatformWheelEventPhase::Began || phase == PlatformWheelEventPhase::Changed;
+#else
+    return false;
+#endif
 }
 
+PlatformWheelEvent WheelEventDeltaFilter::eventCopyWithFilteredDeltas(const PlatformWheelEvent& event) const
+{
+    return event.copyWithDeltaAndVelocity(m_currentFilteredDelta, m_currentFilteredVelocity);
+}
+
 FloatSize WheelEventDeltaFilter::filteredDelta() const
 {
     return m_currentFilteredDelta;
@@ -69,60 +81,80 @@
 {
 }
 
-const size_t basicWheelEventDeltaFilterWindowSize = 3;
+void BasicWheelEventDeltaFilter::updateFromEvent(const PlatformWheelEvent& event)
+{
+#if ENABLE(KINETIC_SCROLLING)
+    switch (event.phase()) {
+    case PlatformWheelEventPhase::MayBegin:
+    case PlatformWheelEventPhase::Cancelled:
+    case PlatformWheelEventPhase::Stationary:
+    case PlatformWheelEventPhase::Ended:
+        reset();
+        break;
 
-void BasicWheelEventDeltaFilter::updateFromDelta(const FloatSize& delta)
+    case PlatformWheelEventPhase::None:
+        break;
+
+    case PlatformWheelEventPhase::Began:
+    case PlatformWheelEventPhase::Changed:
+        updateWithDelta(event.delta());
+        break;
+    }
+#else
+    m_currentFilteredDelta = event.delta();
+#endif
+}
+
+constexpr size_t basicWheelEventDeltaFilterWindowSize = 3;
+
+void BasicWheelEventDeltaFilter::updateWithDelta(FloatSize delta)
 {
     m_currentFilteredDelta = delta;
-    if (!m_isFilteringDeltas)
-        return;
-    
+
     m_recentWheelEventDeltas.append(delta);
     if (m_recentWheelEventDeltas.size() > basicWheelEventDeltaFilterWindowSize)
         m_recentWheelEventDeltas.removeFirst();
     
-    DominantScrollGestureDirection scrollDirection = dominantScrollGestureDirection();
-    if (scrollDirection == DominantScrollGestureDirection::Vertical)
+    auto scrollAxis = dominantAxis();
+    if (!scrollAxis)
+        return;
+
+    if (scrollAxis.value() == ScrollEventAxis::Vertical)
         m_currentFilteredDelta.setWidth(0);
-    else if (scrollDirection == DominantScrollGestureDirection::Horizontal)
+    else if (scrollAxis.value() == ScrollEventAxis::Horizontal)
         m_currentFilteredDelta.setHeight(0);
 }
 
-void BasicWheelEventDeltaFilter::beginFilteringDeltas()
+void BasicWheelEventDeltaFilter::reset()
 {
     m_recentWheelEventDeltas.clear();
-    m_isFilteringDeltas = true;
+    m_currentFilteredDelta = { };
+    m_currentFilteredVelocity = { };
 }
 
-void BasicWheelEventDeltaFilter::endFilteringDeltas()
-{
-    m_currentFilteredDelta = FloatSize(0, 0);
-    m_isFilteringDeltas = false;
-}
-
 static inline bool deltaIsPredominantlyVertical(const FloatSize& delta)
 {
     return fabs(delta.height()) > fabs(delta.width());
 }
 
-DominantScrollGestureDirection BasicWheelEventDeltaFilter::dominantScrollGestureDirection() const
+std::optional<ScrollEventAxis> BasicWheelEventDeltaFilter::dominantAxis() const
 {
     bool allVertical = m_recentWheelEventDeltas.size();
     bool allHorizontal = m_recentWheelEventDeltas.size();
-    
+
     for (const auto& delta : m_recentWheelEventDeltas) {
         bool isVertical = deltaIsPredominantlyVertical(delta);
         allVertical &= isVertical;
         allHorizontal &= !isVertical;
     }
-    
+
     if (allVertical)
-        return DominantScrollGestureDirection::Vertical;
-    
+        return ScrollEventAxis::Vertical;
+
     if (allHorizontal)
-        return DominantScrollGestureDirection::Horizontal;
-    
-    return DominantScrollGestureDirection::None;
+        return ScrollEventAxis::Horizontal;
+
+    return std::nullopt;
 }
 
 };

Modified: trunk/Source/WebCore/page/WheelEventDeltaFilter.h (285366 => 285367)


--- trunk/Source/WebCore/page/WheelEventDeltaFilter.h	2021-11-06 06:53:26 UTC (rev 285366)
+++ trunk/Source/WebCore/page/WheelEventDeltaFilter.h	2021-11-06 06:58:25 UTC (rev 285367)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2015 Apple Inc. All rights reserved.
+ * Copyright (C) 2021 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -26,10 +26,13 @@
 #pragma once
 
 #include "FloatSize.h"
+#include "ScrollTypes.h"
 #include <wtf/Deque.h>
 
 namespace WebCore {
 
+class PlatformWheelEvent;
+
 class WheelEventDeltaFilter {
 public:
     WheelEventDeltaFilter();
@@ -36,35 +39,31 @@
     virtual ~WheelEventDeltaFilter();
 
     WEBCORE_EXPORT static std::unique_ptr<WheelEventDeltaFilter> create();
-    WEBCORE_EXPORT virtual void updateFromDelta(const FloatSize&) = 0;
-    WEBCORE_EXPORT virtual void beginFilteringDeltas() = 0;
-    WEBCORE_EXPORT virtual void endFilteringDeltas() = 0;
+
+    WEBCORE_EXPORT virtual void updateFromEvent(const PlatformWheelEvent&) = 0;
+
+    WEBCORE_EXPORT bool shouldApplyFilteringForEvent(const PlatformWheelEvent&) const;
+    WEBCORE_EXPORT PlatformWheelEvent eventCopyWithFilteredDeltas(const PlatformWheelEvent&) const;
+
     WEBCORE_EXPORT FloatSize filteredVelocity() const;
-    WEBCORE_EXPORT bool isFilteringDeltas() const;
     WEBCORE_EXPORT FloatSize filteredDelta() const;
 
 protected:
     FloatSize m_currentFilteredDelta;
     FloatSize m_currentFilteredVelocity;
-    bool m_isFilteringDeltas { false };
 };
 
-enum class DominantScrollGestureDirection {
-    None,
-    Vertical,
-    Horizontal
-};
-
 class BasicWheelEventDeltaFilter final : public WheelEventDeltaFilter {
     WTF_MAKE_FAST_ALLOCATED;
 public:
     BasicWheelEventDeltaFilter();
-    void updateFromDelta(const FloatSize&) override;
-    void beginFilteringDeltas() override;
-    void endFilteringDeltas() override;
+    void updateFromEvent(const PlatformWheelEvent&) final;
 
 private:
-    DominantScrollGestureDirection dominantScrollGestureDirection() const;
+    std::optional<ScrollEventAxis> dominantAxis() const;
+    
+    void reset();
+    void updateWithDelta(FloatSize);
 
     Deque<FloatSize> m_recentWheelEventDeltas;
 };

Modified: trunk/Source/WebCore/page/mac/EventHandlerMac.mm (285366 => 285367)


--- trunk/Source/WebCore/page/mac/EventHandlerMac.mm	2021-11-06 06:53:26 UTC (rev 285366)
+++ trunk/Source/WebCore/page/mac/EventHandlerMac.mm	2021-11-06 06:58:25 UTC (rev 285367)
@@ -885,31 +885,9 @@
     if (wheelEvent.shouldResetLatching() || wheelEvent.isNonGestureEvent())
         return;
 
-    if (m_frame.isMainFrame() && wheelEvent.isGestureStart())
-        page->wheelEventDeltaFilter()->beginFilteringDeltas();
-
     page->scrollLatchingController().updateAndFetchLatchingStateForFrame(m_frame, wheelEvent, wheelEventTarget, scrollableArea, isOverWidget);
 }
 
-void EventHandler::recordWheelEventForDeltaFilter(const PlatformWheelEvent& wheelEvent)
-{
-    auto* page = m_frame.page();
-    if (!page)
-        return;
-
-    switch (wheelEvent.phase()) {
-    case PlatformWheelEventPhase::Began:
-        page->wheelEventDeltaFilter()->beginFilteringDeltas();
-        break;
-    case PlatformWheelEventPhase::Ended:
-        page->wheelEventDeltaFilter()->endFilteringDeltas();
-        break;
-    default:
-        break;
-    }
-    page->wheelEventDeltaFilter()->updateFromDelta(FloatSize(wheelEvent.deltaX(), wheelEvent.deltaY()));
-}
-
 bool EventHandler::processWheelEventForScrolling(const PlatformWheelEvent& wheelEvent, const WeakPtr<ScrollableArea>& scrollableArea, OptionSet<EventHandling> eventHandling)
 {
     LOG_WITH_STREAM(ScrollLatching, stream << "EventHandler::processWheelEventForScrolling " << wheelEvent << " - scrollableArea " << ValueOrNull(scrollableArea.get()) << " use latched element " << wheelEvent.useLatchedEventElement());

Modified: trunk/Source/WebCore/page/mac/WheelEventDeltaFilterMac.h (285366 => 285367)


--- trunk/Source/WebCore/page/mac/WheelEventDeltaFilterMac.h	2021-11-06 06:53:26 UTC (rev 285366)
+++ trunk/Source/WebCore/page/mac/WheelEventDeltaFilterMac.h	2021-11-06 06:58:25 UTC (rev 285367)
@@ -40,13 +40,13 @@
 public:
     WheelEventDeltaFilterMac();
 
-    void updateFromDelta(const FloatSize&) override;
-    void beginFilteringDeltas() override;
-    void endFilteringDeltas() override;
+    void updateFromEvent(const PlatformWheelEvent&) final;
 
 private:
+    void reset();
+
     RetainPtr<_NSScrollingPredominantAxisFilter> m_predominantAxisFilter;
-    MonotonicTime m_beginFilteringDeltasTime;
+    WallTime m_initialWallTime;
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/page/mac/WheelEventDeltaFilterMac.mm (285366 => 285367)


--- trunk/Source/WebCore/page/mac/WheelEventDeltaFilterMac.mm	2021-11-06 06:53:26 UTC (rev 285366)
+++ trunk/Source/WebCore/page/mac/WheelEventDeltaFilterMac.mm	2021-11-06 06:58:25 UTC (rev 285367)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2015 Apple Inc. All rights reserved.
+ * Copyright (C) 2015-2021 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -29,6 +29,7 @@
 #import "WheelEventDeltaFilterMac.h"
 
 #import "FloatPoint.h"
+#import "PlatformWheelEvent.h"
 #import <pal/spi/mac/NSScrollingInputFilterSPI.h>
 
 namespace WebCore {
@@ -36,33 +37,46 @@
 WheelEventDeltaFilterMac::WheelEventDeltaFilterMac()
     : WheelEventDeltaFilter()
     , m_predominantAxisFilter(adoptNS([[_NSScrollingPredominantAxisFilter alloc] init]))
+    , m_initialWallTime(WallTime::now())
 {
 }
 
-void WheelEventDeltaFilterMac::beginFilteringDeltas()
+void WheelEventDeltaFilterMac::updateFromEvent(const PlatformWheelEvent& event)
 {
-    m_beginFilteringDeltasTime = MonotonicTime::now();
-    m_isFilteringDeltas = true;
-}
-
-void WheelEventDeltaFilterMac::updateFromDelta(const FloatSize& delta)
-{
-    if (!m_isFilteringDeltas)
+    if (event.momentumPhase() != PlatformWheelEventPhase::None)
         return;
 
-    NSPoint filteredDeltaResult;
-    NSPoint filteredVelocityResult;
-    [m_predominantAxisFilter filterInputDelta:NSPoint(FloatPoint(delta.width(), delta.height())) timestamp:(MonotonicTime::now() - m_beginFilteringDeltasTime).seconds() outputDelta:&filteredDeltaResult velocity:&filteredVelocityResult];
-    m_currentFilteredVelocity = FloatSize(filteredVelocityResult.x, filteredVelocityResult.y);
-    m_currentFilteredDelta = FloatSize(filteredDeltaResult.x, filteredDeltaResult.y);
+    // The absolute value of timestamp doesn't matter; the filter looks at deltas from the previous event.
+    auto timestamp = event.timestamp() - m_initialWallTime;
+
+    switch (event.phase()) {
+    case PlatformWheelEventPhase::None:
+        break;
+
+    case PlatformWheelEventPhase::Began:
+    case PlatformWheelEventPhase::Changed: {
+        NSPoint filteredDeltaResult;
+        NSPoint filteredVelocityResult;
+
+        [m_predominantAxisFilter filterInputDelta:toFloatPoint(event.delta()) timestamp:timestamp.seconds() outputDelta:&filteredDeltaResult velocity:&filteredVelocityResult];
+        m_currentFilteredVelocity = toFloatSize(filteredVelocityResult);
+        m_currentFilteredDelta = toFloatSize(filteredDeltaResult);
+        break;
+    }
+    case PlatformWheelEventPhase::MayBegin:
+    case PlatformWheelEventPhase::Cancelled:
+    case PlatformWheelEventPhase::Stationary:
+    case PlatformWheelEventPhase::Ended:
+        reset();
+        break;
+    }
 }
 
-void WheelEventDeltaFilterMac::endFilteringDeltas()
+void WheelEventDeltaFilterMac::reset()
 {
-    m_currentFilteredDelta = FloatSize(0, 0);
-    m_beginFilteringDeltasTime = MonotonicTime();
     [m_predominantAxisFilter reset];
-    m_isFilteringDeltas = false;
+    m_currentFilteredVelocity = { };
+    m_currentFilteredDelta = { };
 }
 
 }

Modified: trunk/Source/WebCore/platform/PlatformWheelEvent.h (285366 => 285367)


--- trunk/Source/WebCore/platform/PlatformWheelEvent.h	2021-11-06 06:53:26 UTC (rev 285366)
+++ trunk/Source/WebCore/platform/PlatformWheelEvent.h	2021-11-06 06:58:25 UTC (rev 285367)
@@ -120,11 +120,11 @@
         return copy;
     }
 
-    PlatformWheelEvent copyWithDeltasAndVelocity(float deltaX, float deltaY, const FloatSize& velocity) const
+    PlatformWheelEvent copyWithDeltaAndVelocity(FloatSize delta, FloatSize velocity) const
     {
         PlatformWheelEvent copy = *this;
-        copy.m_deltaX = deltaX;
-        copy.m_deltaY = deltaY;
+        copy.m_deltaX = delta.width();
+        copy.m_deltaY = delta.height();
         copy.m_scrollingVelocity = velocity;
         return copy;
     }

Modified: trunk/Source/WebKit/ChangeLog (285366 => 285367)


--- trunk/Source/WebKit/ChangeLog	2021-11-06 06:53:26 UTC (rev 285366)
+++ trunk/Source/WebKit/ChangeLog	2021-11-06 06:58:25 UTC (rev 285367)
@@ -1,3 +1,16 @@
+2021-11-05  Simon Fraser  <[email protected]>
+
+        Simplify code that makes use of WheelEventDeltaFilter
+        https://bugs.webkit.org/show_bug.cgi?id=232536
+
+        Reviewed by Wenson Hsieh.
+
+        Push the decision about which kinds of wheel events to apply filtering to down into
+        WheelEventDeltaFilter, which simplifies call sites.
+
+        * WebProcess/WebPage/EventDispatcher.cpp:
+        (WebKit::EventDispatcher::wheelEvent):
+
 2021-11-05  Chris Dumez  <[email protected]>
 
         [iOS] IPC decoder for ResourceRequest loses systemPreviewInfo when there is platform data

Modified: trunk/Source/WebKit/WebProcess/WebPage/EventDispatcher.cpp (285366 => 285367)


--- trunk/Source/WebKit/WebProcess/WebPage/EventDispatcher.cpp	2021-11-06 06:53:26 UTC (rev 285366)
+++ trunk/Source/WebKit/WebProcess/WebPage/EventDispatcher.cpp	2021-11-06 06:58:25 UTC (rev 285367)
@@ -98,34 +98,17 @@
 
 void EventDispatcher::wheelEvent(PageIdentifier pageID, const WebWheelEvent& wheelEvent, RectEdges<bool> rubberBandableEdges)
 {
-#if PLATFORM(COCOA) || ENABLE(SCROLLING_THREAD)
-    PlatformWheelEvent platformWheelEvent = platform(wheelEvent);
-#endif
-
+    auto processingSteps = OptionSet<WebCore::WheelEventProcessingSteps> { WheelEventProcessingSteps::MainThreadForScrolling, WheelEventProcessingSteps::MainThreadForBlockingDOMEventDispatch };
+#if ENABLE(SCROLLING_THREAD)
+    do {
+        auto platformWheelEvent = platform(wheelEvent);
 #if PLATFORM(COCOA)
-    switch (wheelEvent.phase()) {
-    case WebWheelEvent::PhaseBegan:
-        m_recentWheelEventDeltaFilter->beginFilteringDeltas();
-        break;
-    case WebWheelEvent::PhaseEnded:
-        m_recentWheelEventDeltaFilter->endFilteringDeltas();
-        break;
-    default:
-        break;
-    }
-
-    if (m_recentWheelEventDeltaFilter->isFilteringDeltas()) {
-        m_recentWheelEventDeltaFilter->updateFromDelta(FloatSize(platformWheelEvent.deltaX(), platformWheelEvent.deltaY()));
-        FloatSize filteredDelta = m_recentWheelEventDeltaFilter->filteredDelta();
-        platformWheelEvent = platformWheelEvent.copyWithDeltasAndVelocity(filteredDelta.width(), filteredDelta.height(), m_recentWheelEventDeltaFilter->filteredVelocity());
-    }
+        m_recentWheelEventDeltaFilter->updateFromEvent(platformWheelEvent);
+        if (m_recentWheelEventDeltaFilter->shouldApplyFilteringForEvent(platformWheelEvent))
+            platformWheelEvent = m_recentWheelEventDeltaFilter->eventCopyWithFilteredDeltas(platformWheelEvent);
 #endif
 
-    auto processingSteps = OptionSet<WebCore::WheelEventProcessingSteps> { WheelEventProcessingSteps::MainThreadForScrolling, WheelEventProcessingSteps::MainThreadForBlockingDOMEventDispatch };
-#if ENABLE(SCROLLING_THREAD)
-    do {
         Locker locker { m_scrollingTreesLock };
-
         auto scrollingTree = m_scrollingTrees.get(pageID);
         if (!scrollingTree) {
             dispatchWheelEventViaMainThread(pageID, wheelEvent, processingSteps);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to