⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 286346 in webkit


Ignore:
Timestamp:
Nov 30, 2021, 6:56:24 PM (5 years ago)
Author:
timothy_horton@apple.com
Message:

Add a momentum event synthesizer
https://bugs.webkit.org/show_bug.cgi?id=233653
<rdar://problem/85571258>

Reviewed by Simon Fraser.

Source/WebCore/PAL:

  • pal/spi/mac/IOKitSPIMac.h:

Add some SPI.

Source/WebKit:

  • Platform/Logging.h:

Add ScrollAnimations log channel to WebKit (it already exists in WebCore).

  • Shared/ScrollingAccelerationCurve.cpp: Added.

(WebKit::ScrollingAccelerationCurve::ScrollingAccelerationCurve):
(WebKit::ScrollingAccelerationCurve::interpolate):
(WebKit::ScrollingAccelerationCurve::computeIntermediateValuesIfNeeded):
(WebKit::ScrollingAccelerationCurve::evaluateQuartic):
(WebKit::ScrollingAccelerationCurve::accelerationFactor):
(WebKit::ScrollingAccelerationCurve::encode const):
(WebKit::ScrollingAccelerationCurve::decode):
(WebKit::operator<<):
(WebKit::ScrollingAccelerationCurve::fromNativeWheelEvent):

  • Shared/ScrollingAccelerationCurve.h: Added.

(WebKit::ScrollingAccelerationCurve::operator== const):
(WebKit::ScrollingAccelerationCurve::operator!= const):
Add a class that represents a quartic scrolling acceleration curve with
a trailing linear tangent region, and allows interpolation between curves
and evaluation of the curve at a point.

  • Shared/mac/ScrollingAccelerationCurveMac.mm: Added.

(WebKit::fromFixedPoint):
(WebKit::readFixedPointParameter):
(WebKit::fromIOHIDCurve):
(WebKit::fromIOHIDCurveArrayWithAcceleration):
(WebKit::ScrollingAccelerationCurve::fromNativeWheelEvent):
Given a NativeWebWheelEvent, extract its underlying platform event
and fetch the ScrollingAccelerationCurve for the originating device.

  • Sources.txt:
  • SourcesCocoa.txt:
  • UIProcess/WebPageProxy.cpp:

(WebKit::WebPageProxy::handleWheelEvent):
Fetch the current ScrollingAccelerationCurve on each momentum begin event,
if the feature is enabled.

(WebKit::WebPageProxy::sendWheelEvent):
Send the ScrollingAccelerationCurve to EventDispatcher just before
we send the momentum begin event along, if it has changed.

(WebKit::WebPageProxy::windowScreenDidChange):
Keep EventDispatcher apprised of changes to the current screen of the page.

(WebKit::WebPageProxy::resetState):

  • UIProcess/WebPageProxy.h:
  • WebKit.xcodeproj/project.pbxproj:
  • WebProcess/WebPage/EventDispatcher.cpp:

(WebKit::EventDispatcher::EventDispatcher):
(WebKit::EventDispatcher::internalWheelEvent):
Factor most of wheelEvent out into internalWheelEvent, so that
MomentumEventDispatcher can call internalWheelEvent(), skipping the code
in wheelEvent() that forwards the event... to MomentumEventDispatcher.

Also, keep track of where the event came from (UI process or MomentumEventDispatcher)
and avoid sending didReceiveEvent replies to the UI process for synthetic
events that it doesn't know about.

(WebKit::EventDispatcher::wheelEvent):
Forward wheel events to MomentumEventDispatcher.

(WebKit::EventDispatcher::setScrollingAccelerationCurve):
Forward scrolling curve changes to MomentumEventDispatcher.

(WebKit::EventDispatcher::displayWasRefreshed):
Forward display refresh callbacks to MomentumEventDispatcher.

(WebKit::EventDispatcher::windowScreenDidChange):
Forward page screen changes to MomentumEventDispatcher.

  • WebProcess/WebPage/EventDispatcher.h:
  • WebProcess/WebPage/EventDispatcher.messages.in:
  • WebProcess/WebPage/WebPage.cpp:

(WebKit::WebPage::wheelEvent):
(WebKit::WebPage::dispatchWheelEventWithoutScrolling):

  • WebProcess/WebPage/WebPage.h:

Don't send didReceiveEvent for synthetic events from the main thread either.

  • WebProcess/WebPage/MomentumEventDispatcher.cpp: Added.

(WebKit::MomentumEventDispatcher::MomentumEventDispatcher):
(WebKit::MomentumEventDispatcher::~MomentumEventDispatcher):
(WebKit::MomentumEventDispatcher::eventShouldStartSyntheticMomentumPhase const):
If we have everything we need (a scrolling curve - which also implies
that the setting is enabled - and raw platform deltas), and the event
is a momentum begin event, we can use it to start a synthetic momentum phase.

(WebKit::MomentumEventDispatcher::handleWheelEvent):
Start or stop the momentum phase as appropriate.
Record any incoming fingers-down phase events in a rolling event history structure.
Block platform-event-driven events from being further handled by WebKit
if we are inside a synthetic momentum phase, since we'll be replacing them.

(WebKit::appKitScrollMultiplierForEvent):
Determine the AppKit scroll muliplier ("accelerated" vs "unaccelerated"
deltas in NSEvent parlance) from the event via division.

(WebKit::MomentumEventDispatcher::dispatchSyntheticMomentumEvent):
Dispatch a synthetic event with the given momentum phase and delta.
We borrow some properties from the event that initiated the momentum
phase (e.g. the position), and some from whatever event we've most
recently seen (even if we told the rest of WebKit to ignore it), so
that we get the most up-to-date state for e.g. the keyboard modifiers.

(WebKit::MomentumEventDispatcher::didStartMomentumPhase):
Record relevant information about the start event, generate the
momentum curve, and start a full-rate display link. Also, send a momentum
begin event, since we blocked the real one.

(WebKit::MomentumEventDispatcher::didEndMomentumPhase):
Send a momentum ended event, shut down the display link, and reset all
per-gesture state.

(WebKit::MomentumEventDispatcher::setScrollingAccelerationCurve):
Store ScrollingAccelerationCurves on a per-page basis.

(WebKit::MomentumEventDispatcher::displayID const):
Look up the displayID for the current gesture's page.

(WebKit::MomentumEventDispatcher::startDisplayLink):
(WebKit::MomentumEventDispatcher::stopDisplayLink):
Start and stop a display link, which will - in a roundabout manner -
eventually call back into displayWasRefreshed.

(WebKit::MomentumEventDispatcher::windowScreenDidChange):
Store DisplayIDs on a per-page basis.

(WebKit::MomentumEventDispatcher::displayWasRefreshed):
When the display link calls us back, emit a single momentum changed
event of sufficient delta to move us to the desired offset along the curve.

(WebKit::MomentumEventDispatcher::didScrollWithInterval):
(WebKit::MomentumEventDispatcher::didScroll):
Record incoming scrolling events into a rolling history deque.

(WebKit::MomentumEventDispatcher::buildOffsetTableWithInitialDelta):
Compute the offsets for the entire "ideal curve" table (at 60Hz) by
running the animation and accumulating the deltas.

(WebKit::interpolate):
(WebKit::MomentumEventDispatcher::offsetAtTime):
Interpolate along the "ideal curve" to determine the intended offset
at a given time.

(WebKit::momentumDecayRate):
(WebKit::MomentumEventDispatcher::computeNextDelta):
Compute the next delta given a delta (and the event history) by applying
a bit of exponential decay and then passing it through the
ScrollingAccelerationCurve. We return both the unaccelerated
and accelerated deltas, because the input to the next iteration of
computeNextDelta is the unaccelerated delta, but the delta applied
to the actual scroll position is the accelerated delta.

  • WebProcess/WebPage/MomentumEventDispatcher.h: Added.

Source/WTF:

  • wtf/PlatformEnable.h:

Add an ENABLE().

Location:
trunk/Source
Files:
5 added
16 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r286345 r286346  
     12021-11-30  Tim Horton  <timothy_horton@apple.com>
     2
     3        Add a momentum event synthesizer
     4        https://bugs.webkit.org/show_bug.cgi?id=233653
     5        <rdar://problem/85571258>
     6
     7        Reviewed by Simon Fraser.
     8
     9        * wtf/PlatformEnable.h:
     10        Add an ENABLE().
     11
    1122021-11-30  Keith Miller  <keith_miller@apple.com>
    213
  • trunk/Source/WTF/wtf/PlatformEnable.h

    r286204 r286346  
    877877#endif
    878878
     879#if PLATFORM(MAC)
     880#define ENABLE_MOMENTUM_EVENT_DISPATCHER 1
     881#endif
     882
    879883#if !defined(ENABLE_SCROLLING_THREAD)
    880884#if USE(NICOSIA)
  • trunk/Source/WebCore/PAL/ChangeLog

    r286317 r286346  
     12021-11-30  Tim Horton  <timothy_horton@apple.com>
     2
     3        Add a momentum event synthesizer
     4        https://bugs.webkit.org/show_bug.cgi?id=233653
     5        <rdar://problem/85571258>
     6
     7        Reviewed by Simon Fraser.
     8
     9        * pal/spi/mac/IOKitSPIMac.h:
     10        Add some SPI.
     11
    1122021-11-30  Commit Queue  <commit-queue@webkit.org>
    213
  • trunk/Source/WebCore/PAL/pal/spi/mac/IOKitSPIMac.h

    r286270 r286346  
    6767void IOHIDEventSystemClientUnregisterDeviceMatchingBlock(IOHIDEventSystemClientRef);
    6868void IOHIDEventSystemClientScheduleWithDispatchQueue(IOHIDEventSystemClientRef, dispatch_queue_t);
     69void IOHIDEventSystemClientSetDispatchQueue(IOHIDEventSystemClientRef, dispatch_queue_t);
     70void IOHIDEventSystemClientActivate(IOHIDEventSystemClientRef);
    6971
    7072CFTypeRef IOHIDServiceClientCopyProperty(IOHIDServiceClientRef service, CFStringRef key);
     
    8587
    8688typedef uint32_t IOHIDEventField;
     89typedef uint64_t IOHIDEventSenderID;
    8790
    8891#ifdef __LP64__
     
    100103uint64_t IOHIDEventGetTimeStamp(IOHIDEventRef);
    101104IOHIDFloat IOHIDEventGetFloatValue(IOHIDEventRef, IOHIDEventField);
     105IOHIDEventSenderID IOHIDEventGetSenderID(IOHIDEventRef);
    102106
    103107WTF_EXTERN_C_END
  • trunk/Source/WebKit/ChangeLog

    r286329 r286346  
     12021-11-30  Tim Horton  <timothy_horton@apple.com>
     2
     3        Add a momentum event synthesizer
     4        https://bugs.webkit.org/show_bug.cgi?id=233653
     5        <rdar://problem/85571258>
     6
     7        Reviewed by Simon Fraser.
     8
     9        * Platform/Logging.h:
     10        Add ScrollAnimations log channel to WebKit (it already exists in WebCore).
     11
     12        * Shared/ScrollingAccelerationCurve.cpp: Added.
     13        (WebKit::ScrollingAccelerationCurve::ScrollingAccelerationCurve):
     14        (WebKit::ScrollingAccelerationCurve::interpolate):
     15        (WebKit::ScrollingAccelerationCurve::computeIntermediateValuesIfNeeded):
     16        (WebKit::ScrollingAccelerationCurve::evaluateQuartic):
     17        (WebKit::ScrollingAccelerationCurve::accelerationFactor):
     18        (WebKit::ScrollingAccelerationCurve::encode const):
     19        (WebKit::ScrollingAccelerationCurve::decode):
     20        (WebKit::operator<<):
     21        (WebKit::ScrollingAccelerationCurve::fromNativeWheelEvent):
     22        * Shared/ScrollingAccelerationCurve.h: Added.
     23        (WebKit::ScrollingAccelerationCurve::operator== const):
     24        (WebKit::ScrollingAccelerationCurve::operator!= const):
     25        Add a class that represents a quartic scrolling acceleration curve with
     26        a trailing linear tangent region, and allows interpolation between curves
     27        and evaluation of the curve at a point.
     28
     29        * Shared/mac/ScrollingAccelerationCurveMac.mm: Added.
     30        (WebKit::fromFixedPoint):
     31        (WebKit::readFixedPointParameter):
     32        (WebKit::fromIOHIDCurve):
     33        (WebKit::fromIOHIDCurveArrayWithAcceleration):
     34        (WebKit::ScrollingAccelerationCurve::fromNativeWheelEvent):
     35        Given a NativeWebWheelEvent, extract its underlying platform event
     36        and fetch the ScrollingAccelerationCurve for the originating device.
     37
     38        * Sources.txt:
     39        * SourcesCocoa.txt:
     40        * UIProcess/WebPageProxy.cpp:
     41        (WebKit::WebPageProxy::handleWheelEvent):
     42        Fetch the current ScrollingAccelerationCurve on each momentum begin event,
     43        if the feature is enabled.
     44
     45        (WebKit::WebPageProxy::sendWheelEvent):
     46        Send the ScrollingAccelerationCurve to EventDispatcher just before
     47        we send the momentum begin event along, if it has changed.
     48
     49        (WebKit::WebPageProxy::windowScreenDidChange):
     50        Keep EventDispatcher apprised of changes to the current screen of the page.
     51
     52        (WebKit::WebPageProxy::resetState):
     53        * UIProcess/WebPageProxy.h:
     54        * WebKit.xcodeproj/project.pbxproj:
     55        * WebProcess/WebPage/EventDispatcher.cpp:
     56        (WebKit::EventDispatcher::EventDispatcher):
     57        (WebKit::EventDispatcher::internalWheelEvent):
     58        Factor most of wheelEvent out into internalWheelEvent, so that
     59        MomentumEventDispatcher can call internalWheelEvent(), skipping the code
     60        in wheelEvent() that forwards the event... to MomentumEventDispatcher.
     61
     62        Also, keep track of where the event came from (UI process or MomentumEventDispatcher)
     63        and avoid sending didReceiveEvent replies to the UI process for synthetic
     64        events that it doesn't know about.
     65
     66        (WebKit::EventDispatcher::wheelEvent):
     67        Forward wheel events to MomentumEventDispatcher.
     68
     69        (WebKit::EventDispatcher::setScrollingAccelerationCurve):
     70        Forward scrolling curve changes to MomentumEventDispatcher.
     71
     72        (WebKit::EventDispatcher::displayWasRefreshed):
     73        Forward display refresh callbacks to MomentumEventDispatcher.
     74
     75        (WebKit::EventDispatcher::windowScreenDidChange):
     76        Forward page screen changes to MomentumEventDispatcher.
     77
     78        * WebProcess/WebPage/EventDispatcher.h:
     79        * WebProcess/WebPage/EventDispatcher.messages.in:
     80
     81        * WebProcess/WebPage/WebPage.cpp:
     82        (WebKit::WebPage::wheelEvent):
     83        (WebKit::WebPage::dispatchWheelEventWithoutScrolling):
     84        * WebProcess/WebPage/WebPage.h:
     85        Don't send didReceiveEvent for synthetic events from the main thread either.
     86
     87        * WebProcess/WebPage/MomentumEventDispatcher.cpp: Added.
     88        (WebKit::MomentumEventDispatcher::MomentumEventDispatcher):
     89        (WebKit::MomentumEventDispatcher::~MomentumEventDispatcher):
     90        (WebKit::MomentumEventDispatcher::eventShouldStartSyntheticMomentumPhase const):
     91        If we have everything we need (a scrolling curve - which also implies
     92        that the setting is enabled - and raw platform deltas), and the event
     93        is a momentum begin event, we can use it to start a synthetic momentum phase.
     94
     95        (WebKit::MomentumEventDispatcher::handleWheelEvent):
     96        Start or stop the momentum phase as appropriate.
     97        Record any incoming fingers-down phase events in a rolling event history structure.
     98        Block platform-event-driven events from being further handled by WebKit
     99        if we are inside a synthetic momentum phase, since we'll be replacing them.
     100
     101        (WebKit::appKitScrollMultiplierForEvent):
     102        Determine the AppKit scroll muliplier ("accelerated" vs "unaccelerated"
     103        deltas in NSEvent parlance) from the event via division.
     104
     105        (WebKit::MomentumEventDispatcher::dispatchSyntheticMomentumEvent):
     106        Dispatch a synthetic event with the given momentum phase and delta.
     107        We borrow some properties from the event that initiated the momentum
     108        phase (e.g. the position), and some from whatever event we've most
     109        recently seen (even if we told the rest of WebKit to ignore it), so
     110        that we get the most up-to-date state for e.g. the keyboard modifiers.
     111
     112        (WebKit::MomentumEventDispatcher::didStartMomentumPhase):
     113        Record relevant information about the start event, generate the
     114        momentum curve, and start a full-rate display link. Also, send a momentum
     115        begin event, since we blocked the real one.
     116
     117        (WebKit::MomentumEventDispatcher::didEndMomentumPhase):
     118        Send a momentum ended event, shut down the display link, and reset all
     119        per-gesture state.
     120
     121        (WebKit::MomentumEventDispatcher::setScrollingAccelerationCurve):
     122        Store ScrollingAccelerationCurves on a per-page basis.
     123
     124        (WebKit::MomentumEventDispatcher::displayID const):
     125        Look up the displayID for the current gesture's page.
     126
     127        (WebKit::MomentumEventDispatcher::startDisplayLink):
     128        (WebKit::MomentumEventDispatcher::stopDisplayLink):
     129        Start and stop a display link, which will - in a roundabout manner -
     130        eventually call back into displayWasRefreshed.
     131
     132        (WebKit::MomentumEventDispatcher::windowScreenDidChange):
     133        Store DisplayIDs on a per-page basis.
     134
     135        (WebKit::MomentumEventDispatcher::displayWasRefreshed):
     136        When the display link calls us back, emit a single momentum changed
     137        event of sufficient delta to move us to the desired offset along the curve.
     138
     139        (WebKit::MomentumEventDispatcher::didScrollWithInterval):
     140        (WebKit::MomentumEventDispatcher::didScroll):
     141        Record incoming scrolling events into a rolling history deque.
     142
     143        (WebKit::MomentumEventDispatcher::buildOffsetTableWithInitialDelta):
     144        Compute the offsets for the entire "ideal curve" table (at 60Hz) by
     145        running the animation and accumulating the deltas.
     146
     147        (WebKit::interpolate):
     148        (WebKit::MomentumEventDispatcher::offsetAtTime):
     149        Interpolate along the "ideal curve" to determine the intended offset
     150        at a given time.
     151
     152        (WebKit::momentumDecayRate):
     153        (WebKit::MomentumEventDispatcher::computeNextDelta):
     154        Compute the next delta given a delta (and the event history) by applying
     155        a bit of exponential decay and then passing it through the
     156        ScrollingAccelerationCurve. We return both the unaccelerated
     157        and accelerated deltas, because the input to the next iteration of
     158        computeNextDelta is the unaccelerated delta, but the delta applied
     159        to the actual scroll position is the accelerated delta.
     160
     161        * WebProcess/WebPage/MomentumEventDispatcher.h: Added.
     162
    11632021-11-30  BJ Burg  <bburg@apple.com>
    2164
  • trunk/Source/WebKit/Platform/Logging.h

    r285966 r286346  
    9292    M(Resize) \
    9393    M(ResourceLoadStatistics) \
     94    M(ScrollAnimations) \
    9495    M(Scrolling) \
    9596    M(Selection) \
  • trunk/Source/WebKit/Sources.txt

    r286288 r286346  
    226226Shared/RTCNetwork.cpp
    227227Shared/RTCPacketOptions.cpp
     228Shared/ScrollingAccelerationCurve.cpp
    228229Shared/ServiceWorkerInitializationData.cpp
    229230Shared/SessionState.cpp
     
    814815WebProcess/WebPage/FindController.cpp
    815816WebProcess/WebPage/IPCTestingAPI.cpp
     817WebProcess/WebPage/MomentumEventDispatcher.cpp
    816818WebProcess/WebPage/PageBanner.cpp
    817819WebProcess/WebPage/VisitedLinkTableController.cpp
  • trunk/Source/WebKit/SourcesCocoa.txt

    r285922 r286346  
    221221Shared/mac/PasteboardTypes.mm
    222222Shared/mac/PrintInfoMac.mm
     223Shared/mac/ScrollingAccelerationCurveMac.mm
    223224Shared/mac/SecItemRequestData.cpp
    224225Shared/mac/SecItemResponseData.cpp
  • trunk/Source/WebKit/UIProcess/WebPageProxy.cpp

    r286317 r286346  
    28952895    closeOverlayedViews();
    28962896
     2897#if ENABLE(MOMENTUM_EVENT_DISPATCHER)
     2898    // FIXME: We should not have to look this up repeatedly, but it can also change occasionally.
     2899    if (event.momentumPhase() == WebWheelEvent::PhaseBegan && preferences().momentumScrollingAnimatorEnabled())
     2900        m_scrollingAccelerationCurve = ScrollingAccelerationCurve::fromNativeWheelEvent(event);
     2901#endif
     2902
    28972903    if (wheelEventCoalescer().shouldDispatchEvent(event)) {
    28982904        auto event = wheelEventCoalescer().nextEventToDispatch();
     
    29422948        rubberBandableEdges.setRight(!m_backForwardList->forwardItem());
    29432949    }
     2950
     2951#if ENABLE(MOMENTUM_EVENT_DISPATCHER)
     2952    if (event.momentumPhase() == WebWheelEvent::PhaseBegan && m_scrollingAccelerationCurve != m_lastSentScrollingAccelerationCurve) {
     2953        connection->send(Messages::EventDispatcher::SetScrollingAccelerationCurve(m_webPageID, *m_scrollingAccelerationCurve), 0, { }, Thread::QOS::UserInteractive);
     2954        m_lastSentScrollingAccelerationCurve = m_scrollingAccelerationCurve;
     2955    }
     2956#endif
     2957
    29442958    connection->send(Messages::EventDispatcher::WheelEvent(m_webPageID, event, rubberBandableEdges), 0, { }, Thread::QOS::UserInteractive);
    29452959
     
    39423956        return;
    39433957
     3958    send(Messages::EventDispatcher::PageScreenDidChange(m_webPageID, displayID));
    39443959    send(Messages::WebPage::WindowScreenDidChange(displayID, nominalFramesPerSecond));
    39453960}
     
    78997914        m_xrSystem = nullptr;
    79007915    }
     7916#endif
     7917
     7918#if ENABLE(MOMENTUM_EVENT_DISPATCHER)
     7919    m_lastSentScrollingAccelerationCurve = std::nullopt;
    79017920#endif
    79027921}
  • trunk/Source/WebKit/UIProcess/WebPageProxy.h

    r286317 r286346  
    5252#include "ProcessThrottler.h"
    5353#include "SandboxExtension.h"
     54#include "ScrollingAccelerationCurve.h"
    5455#include "ShareableBitmap.h"
    5556#include "ShareableResource.h"
     
    31543155
    31553156    WebNotificationManagerMessageHandler m_notificationManagerMessageHandler;
     3157
     3158#if ENABLE(MOMENTUM_EVENT_DISPATCHER)
     3159    std::optional<ScrollingAccelerationCurve> m_scrollingAccelerationCurve;
     3160    std::optional<ScrollingAccelerationCurve> m_lastSentScrollingAccelerationCurve;
     3161#endif
    31563162};
    31573163
  • trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj

    r286320 r286346  
    35013501                2D6482492644B1AB00030335 /* RemoteLayerTreeLayers.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RemoteLayerTreeLayers.h; sourceTree = "<group>"; };
    35023502                2D64824A2644B1AB00030335 /* RemoteLayerTreeLayers.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = RemoteLayerTreeLayers.mm; sourceTree = "<group>"; };
     3503                2D65D194274B8E73009C4101 /* ScrollingAccelerationCurveMac.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = ScrollingAccelerationCurveMac.mm; sourceTree = "<group>"; };
     3504                2D65D195274B8E84009C4101 /* ScrollingAccelerationCurve.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ScrollingAccelerationCurve.h; sourceTree = "<group>"; };
     3505                2D65D196274B8E84009C4101 /* ScrollingAccelerationCurve.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = ScrollingAccelerationCurve.cpp; sourceTree = "<group>"; };
    35033506                2D6AB53F192B1C4A003A9FD1 /* WKPDFPageNumberIndicator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WKPDFPageNumberIndicator.h; path = ios/WKPDFPageNumberIndicator.h; sourceTree = "<group>"; };
    35043507                2D6AB540192B1C4A003A9FD1 /* WKPDFPageNumberIndicator.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = WKPDFPageNumberIndicator.mm; path = ios/WKPDFPageNumberIndicator.mm; sourceTree = "<group>"; };
     
    37843787                2DE9B13B2231F77C005287B7 /* _WKTextInputContextInternal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = _WKTextInputContextInternal.h; sourceTree = "<group>"; };
    37853788                2DEAC5CE1AC368BB00A195D8 /* _WKFindOptions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = _WKFindOptions.h; sourceTree = "<group>"; };
     3789                2DEE709D2755A46800FBF864 /* MomentumEventDispatcher.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MomentumEventDispatcher.h; sourceTree = "<group>"; };
     3790                2DEE709E2755A46800FBF864 /* MomentumEventDispatcher.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = MomentumEventDispatcher.cpp; sourceTree = "<group>"; };
    37863791                2DF9593418A42412009785A1 /* ViewGestureControllerIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = ViewGestureControllerIOS.mm; path = ios/ViewGestureControllerIOS.mm; sourceTree = "<group>"; };
    37873792                2DF9EEE31A781FB400B6CFBE /* APIFrameInfo.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = APIFrameInfo.cpp; sourceTree = "<group>"; };
     
    70907095                                1AAB4A8C1296F0A20023952F /* SandboxExtension.h */,
    70917096                                E1E552C316AE065E004ED653 /* SandboxInitializationParameters.h */,
     7097                                2D65D196274B8E84009C4101 /* ScrollingAccelerationCurve.cpp */,
     7098                                2D65D195274B8E84009C4101 /* ScrollingAccelerationCurve.h */,
    70927099                                5C80B3DD23690F100086E6DE /* ServiceWorkerInitializationData.cpp */,
    70937100                                5C80B3DB23690D8D0086E6DE /* ServiceWorkerInitializationData.h */,
     
    98819888                        isa = PBXGroup;
    98829889                        children = (
    9883                                 5CBB6D4D271F67CC00FD1A5D /* com.apple.webkit.webpushd.plist */,
    98849890                                5160E954274B887100567388 /* AppBundleRequest.h */,
    98859891                                5160E953274B887100567388 /* AppBundleRequest.mm */,
     9892                                5CBB6D4D271F67CC00FD1A5D /* com.apple.webkit.webpushd.plist */,
    98869893                                51F7BB75274498BB00C45A72 /* MockAppBundleForTesting.h */,
    98879894                                51F7BB74274498BA00C45A72 /* MockAppBundleForTesting.mm */,
     
    1062210629                                9B033E72252580F300501071 /* IPCTestingAPI.cpp */,
    1062310630                                9B033E71252580F300501071 /* IPCTestingAPI.h */,
     10631                                2DEE709E2755A46800FBF864 /* MomentumEventDispatcher.cpp */,
     10632                                2DEE709D2755A46800FBF864 /* MomentumEventDispatcher.h */,
    1062410633                                7C387433172F5615001BD88A /* PageBanner.cpp */,
    1062510634                                7CF47FF917275C57008ACB91 /* PageBanner.h */,
     
    1118811197                                C1E123B920A11572002646F4 /* PDFContextMenu.h */,
    1118911198                                E1CC1B8F12D7EADF00625838 /* PrintInfoMac.mm */,
     11199                                2D65D194274B8E73009C4101 /* ScrollingAccelerationCurveMac.mm */,
    1119011200                                51D1304F1382EAC000351EDD /* SecItemRequestData.cpp */,
    1119111201                                51D130501382EAC000351EDD /* SecItemRequestData.h */,
     
    1243612446                        buildActionMask = 2147483647;
    1243712447                        files = (
     12448                                5160E956274B887200567388 /* AppBundleRequest.h in Headers */,
     12449                                5C1579FC2717AF5000ED5280 /* DaemonUtilities.h in Headers */,
     12450                                51F7BB77274498BB00C45A72 /* MockAppBundleForTesting.h in Headers */,
     12451                                5160E95E274C2A0300567388 /* MockAppBundleRegistry.h in Headers */,
    1243812452                                5160E959274C0D8900567388 /* PushAppBundle.h in Headers */,
    1243912453                                51F7BB7B2744C50700C45A72 /* PushClientConnection.h in Headers */,
    12440                                 5160E95E274C2A0300567388 /* MockAppBundleRegistry.h in Headers */,
    12441                                 5C1579FC2717AF5000ED5280 /* DaemonUtilities.h in Headers */,
    12442                                 5160E956274B887200567388 /* AppBundleRequest.h in Headers */,
    1244312454                                512CD69F2723393A00F7F8EC /* WebPushDaemon.h in Headers */,
    12444                                 51F7BB77274498BB00C45A72 /* MockAppBundleForTesting.h in Headers */,
    1244512455                        );
    1244612456                        runOnlyForDeploymentPostprocessing = 0;
     
    1497614986                        buildActionMask = 2147483647;
    1497714987                        files = (
     14988                                5160E955274B887200567388 /* AppBundleRequest.mm in Sources */,
    1497814989                                5C157A012717B7FB00ED5280 /* ArgumentCoders.cpp in Sources */,
    1497914990                                51F7BB7D2745640400C45A72 /* CodeSigning.mm in Sources */,
    1498014991                                5C1579FF2717B6D200ED5280 /* DaemonDecoder.cpp in Sources */,
    14981                                 51F7BB76274498BB00C45A72 /* MockAppBundleForTesting.mm in Sources */,
    14982                                 5160E955274B887200567388 /* AppBundleRequest.mm in Sources */,
    14983                                 5160E95A274C0D8900567388 /* PushAppBundle.mm in Sources */,
    14984                                 5160E960274C2A4000567388 /* MockAppBundleRegistry.mm in Sources */,
    14985                                 51F7BB7C2744C50700C45A72 /* PushClientConnection.mm in Sources */,
    1498614992                                5C1579FE2717B6C100ED5280 /* DaemonEncoder.cpp in Sources */,
    1498714993                                5C1579FB2717AF5000ED5280 /* DaemonUtilities.mm in Sources */,
     14994                                51F7BB76274498BB00C45A72 /* MockAppBundleForTesting.mm in Sources */,
     14995                                5160E960274C2A4000567388 /* MockAppBundleRegistry.mm in Sources */,
     14996                                5160E95A274C0D8900567388 /* PushAppBundle.mm in Sources */,
     14997                                51F7BB7C2744C50700C45A72 /* PushClientConnection.mm in Sources */,
    1498814998                                512CD6A02723393A00F7F8EC /* WebPushDaemon.mm in Sources */,
    1498914999                                5C157A0C2717CA1D00ED5280 /* WebPushDaemonMain.mm in Sources */,
  • trunk/Source/WebKit/WebProcess/WebPage/EventDispatcher.cpp

    r285992 r286346  
    2828
    2929#include "EventDispatcherMessages.h"
     30#include "MomentumEventDispatcher.h"
    3031#include "WebEventConversion.h"
    3132#include "WebPage.h"
     
    6465    : m_queue(WorkQueue::create("com.apple.WebKit.EventDispatcher", WorkQueue::QOS::UserInteractive))
    6566    , m_recentWheelEventDeltaFilter(WheelEventDeltaFilter::create())
     67#if ENABLE(MOMENTUM_EVENT_DISPATCHER)
     68    , m_momentumEventDispatcher(WTF::makeUnique<MomentumEventDispatcher>(*this))
     69#endif
    6670{
    6771}
     
    98102}
    99103
    100 void EventDispatcher::wheelEvent(PageIdentifier pageID, const WebWheelEvent& wheelEvent, RectEdges<bool> rubberBandableEdges)
     104void EventDispatcher::internalWheelEvent(PageIdentifier pageID, const WebWheelEvent& wheelEvent, RectEdges<bool> rubberBandableEdges, WheelEventOrigin wheelEventOrigin)
    101105{
    102106    auto processingSteps = OptionSet<WebCore::WheelEventProcessingSteps> { WheelEventProcessingSteps::MainThreadForScrolling, WheelEventProcessingSteps::MainThreadForBlockingDOMEventDispatch };
     
    115119        auto scrollingTree = m_scrollingTrees.get(pageID);
    116120        if (!scrollingTree) {
    117             dispatchWheelEventViaMainThread(pageID, wheelEvent, processingSteps);
     121            dispatchWheelEventViaMainThread(pageID, wheelEvent, processingSteps, wheelEventOrigin);
    118122            break;
    119123        }
     
    137141        scrollingTree->willProcessWheelEvent();
    138142
    139         ScrollingThread::dispatch([scrollingTree, wheelEvent, platformWheelEvent, processingSteps, useMainThreadForScrolling, pageID, protectedThis = Ref { *this }] {
     143        ScrollingThread::dispatch([scrollingTree, wheelEvent, platformWheelEvent, processingSteps, useMainThreadForScrolling, pageID, wheelEventOrigin, protectedThis = Ref { *this }] {
    140144            if (useMainThreadForScrolling) {
    141145                scrollingTree->willSendEventToMainThread(platformWheelEvent);
    142                 protectedThis->dispatchWheelEventViaMainThread(pageID, wheelEvent, processingSteps);
     146                protectedThis->dispatchWheelEventViaMainThread(pageID, wheelEvent, processingSteps, wheelEventOrigin);
    143147                scrollingTree->waitForEventToBeProcessedByMainThread(platformWheelEvent);
    144148                return;
     
    148152
    149153            if (result.needsMainThreadProcessing()) {
    150                 protectedThis->dispatchWheelEventViaMainThread(pageID, wheelEvent, result.steps);
     154                protectedThis->dispatchWheelEventViaMainThread(pageID, wheelEvent, result.steps, wheelEventOrigin);
    151155                if (result.steps.contains(WheelEventProcessingSteps::MainThreadForScrolling))
    152156                    return;
     
    155159            // If we scrolled on the scrolling thread (even if we send the event to the main thread for passive event handlers)
    156160            // respond to the UI process that the event was handled.
    157             protectedThis->sendDidReceiveEvent(pageID, wheelEvent.type(), result.wasHandled);
     161            if (wheelEventOrigin == WheelEventOrigin::UIProcess)
     162                protectedThis->sendDidReceiveEvent(pageID, wheelEvent.type(), result.wasHandled);
    158163        });
    159164    } while (false);
     
    161166    UNUSED_PARAM(rubberBandableEdges);
    162167
    163     dispatchWheelEventViaMainThread(pageID, wheelEvent, processingSteps);
    164 #endif
    165 }
     168    dispatchWheelEventViaMainThread(pageID, wheelEvent, processingSteps, wheelEventOrigin);
     169#endif
     170}
     171
     172void EventDispatcher::wheelEvent(PageIdentifier pageID, const WebWheelEvent& wheelEvent, RectEdges<bool> rubberBandableEdges)
     173{
     174#if ENABLE(MOMENTUM_EVENT_DISPATCHER)
     175    if (m_momentumEventDispatcher->handleWheelEvent(pageID, wheelEvent, rubberBandableEdges)) {
     176        sendDidReceiveEvent(pageID, wheelEvent.type(), true);
     177        return;
     178    }
     179#endif
     180    internalWheelEvent(pageID, wheelEvent, rubberBandableEdges, WheelEventOrigin::UIProcess);
     181}
     182
     183#if ENABLE(MOMENTUM_EVENT_DISPATCHER)
     184void EventDispatcher::setScrollingAccelerationCurve(PageIdentifier pageID, std::optional<ScrollingAccelerationCurve> curve)
     185{
     186    m_momentumEventDispatcher->setScrollingAccelerationCurve(pageID, curve);
     187}
     188#endif
    166189
    167190#if ENABLE(MAC_GESTURE_EVENTS)
     
    231254#endif
    232255
    233 void EventDispatcher::dispatchWheelEventViaMainThread(WebCore::PageIdentifier pageID, const WebWheelEvent& wheelEvent, OptionSet<WheelEventProcessingSteps> processingSteps)
     256void EventDispatcher::dispatchWheelEventViaMainThread(WebCore::PageIdentifier pageID, const WebWheelEvent& wheelEvent, OptionSet<WheelEventProcessingSteps> processingSteps, WheelEventOrigin wheelEventOrigin)
    234257{
    235258    ASSERT(!RunLoop::isMain());
    236     RunLoop::main().dispatch([protectedThis = Ref { *this }, pageID, wheelEvent, steps = processingSteps - WheelEventProcessingSteps::ScrollingThread]() mutable {
    237         protectedThis->dispatchWheelEvent(pageID, wheelEvent, steps);
     259    RunLoop::main().dispatch([protectedThis = Ref { *this }, pageID, wheelEvent, wheelEventOrigin, steps = processingSteps - WheelEventProcessingSteps::ScrollingThread]() mutable {
     260        protectedThis->dispatchWheelEvent(pageID, wheelEvent, steps, wheelEventOrigin);
    238261    });
    239262}
    240263
    241 void EventDispatcher::dispatchWheelEvent(PageIdentifier pageID, const WebWheelEvent& wheelEvent, OptionSet<WheelEventProcessingSteps> processingSteps)
     264void EventDispatcher::dispatchWheelEvent(PageIdentifier pageID, const WebWheelEvent& wheelEvent, OptionSet<WheelEventProcessingSteps> processingSteps, WheelEventOrigin wheelEventOrigin)
    242265{
    243266    ASSERT(RunLoop::isMain());
     
    247270        return;
    248271
    249     webPage->wheelEvent(wheelEvent, processingSteps);
     272    webPage->wheelEvent(wheelEvent, processingSteps, wheelEventOrigin);
    250273}
    251274
     
    285308
    286309    ASSERT(!RunLoop::isMain());
     310
     311#if ENABLE(MOMENTUM_EVENT_DISPATCHER)
     312    m_momentumEventDispatcher->displayWasRefreshed(displayID, displayUpdate);
     313#endif
     314
    287315    notifyScrollingTreesDisplayWasRefreshed(displayID);
    288316
     
    296324#endif
    297325
     326void EventDispatcher::pageScreenDidChange(PageIdentifier pageID, PlatformDisplayID displayID)
     327{
     328#if ENABLE(MOMENTUM_EVENT_DISPATCHER)
     329    m_momentumEventDispatcher->pageScreenDidChange(pageID, displayID);
     330#else
     331    UNUSED_PARAM(pageID);
     332    UNUSED_PARAM(displayID);
     333#endif
     334}
     335
    298336} // namespace WebKit
  • trunk/Source/WebKit/WebProcess/WebPage/EventDispatcher.h

    r283353 r286346  
    5151namespace WebKit {
    5252
     53class MomentumEventDispatcher;
     54class ScrollingAccelerationCurve;
    5355class WebPage;
    5456class WebWheelEvent;
     
    7779    void notifyScrollingTreesDisplayWasRefreshed(WebCore::PlatformDisplayID);
    7880
     81    enum class WheelEventOrigin : bool { UIProcess, MomentumEventDispatcher };
     82    void internalWheelEvent(WebCore::PageIdentifier, const WebWheelEvent&, WebCore::RectEdges<bool> rubberBandableEdges, WheelEventOrigin);
     83
    7984private:
    8085    EventDispatcher();
     
    8590    // Message handlers
    8691    void wheelEvent(WebCore::PageIdentifier, const WebWheelEvent&, WebCore::RectEdges<bool> rubberBandableEdges);
     92#if ENABLE(MOMENTUM_EVENT_DISPATCHER)
     93    void setScrollingAccelerationCurve(WebCore::PageIdentifier, std::optional<ScrollingAccelerationCurve>);
     94#endif
    8795#if ENABLE(IOS_TOUCH_EVENTS)
    8896    void touchEvent(WebCore::PageIdentifier, const WebTouchEvent&, CompletionHandler<void(bool)>&&);
     
    94102
    95103    // This is called on the main thread.
    96     void dispatchWheelEvent(WebCore::PageIdentifier, const WebWheelEvent&, OptionSet<WebCore::WheelEventProcessingSteps>);
    97     void dispatchWheelEventViaMainThread(WebCore::PageIdentifier, const WebWheelEvent&, OptionSet<WebCore::WheelEventProcessingSteps>);
     104    void dispatchWheelEvent(WebCore::PageIdentifier, const WebWheelEvent&, OptionSet<WebCore::WheelEventProcessingSteps>, WheelEventOrigin);
     105    void dispatchWheelEventViaMainThread(WebCore::PageIdentifier, const WebWheelEvent&, OptionSet<WebCore::WheelEventProcessingSteps>, WheelEventOrigin);
    98106
    99107#if ENABLE(IOS_TOUCH_EVENTS)
     
    116124#endif
    117125
     126    void pageScreenDidChange(WebCore::PageIdentifier, WebCore::PlatformDisplayID);
     127
    118128    Ref<WorkQueue> m_queue;
    119129
     
    127137    HashMap<WebCore::PageIdentifier, TouchEventQueue> m_touchEvents WTF_GUARDED_BY_LOCK(m_touchEventsLock);
    128138#endif
     139
     140#if ENABLE(MOMENTUM_EVENT_DISPATCHER)
     141    std::unique_ptr<MomentumEventDispatcher> m_momentumEventDispatcher;
     142#endif
    129143};
    130144
  • trunk/Source/WebKit/WebProcess/WebPage/EventDispatcher.messages.in

    r283353 r286346  
    3333    DisplayWasRefreshed(uint32_t displayID, struct WebCore::DisplayUpdate update, bool sendToMainThread)
    3434#endif
     35
     36#if ENABLE(MOMENTUM_EVENT_DISPATCHER)
     37    SetScrollingAccelerationCurve(WebCore::PageIdentifier pageID, std::optional<WebKit::ScrollingAccelerationCurve> curve)
     38#endif
     39    PageScreenDidChange(WebCore::PageIdentifier pageID, uint32_t displayID)
    3540}
  • trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp

    r286218 r286346  
    30323032}
    30333033
    3034 bool WebPage::wheelEvent(const WebWheelEvent& wheelEvent, OptionSet<WheelEventProcessingSteps> processingSteps)
     3034bool WebPage::wheelEvent(const WebWheelEvent& wheelEvent, OptionSet<WheelEventProcessingSteps> processingSteps, EventDispatcher::WheelEventOrigin wheelEventOrigin)
    30353035{
    30363036    m_userActivity.impulse();
     
    30403040    bool handled = handleWheelEvent(wheelEvent, m_page.get(), processingSteps);
    30413041
    3042     if (processingSteps.contains(WheelEventProcessingSteps::MainThreadForScrolling))
     3042    if (processingSteps.contains(WheelEventProcessingSteps::MainThreadForScrolling) && wheelEventOrigin == EventDispatcher::WheelEventOrigin::UIProcess)
    30433043        send(Messages::WebPageProxy::DidReceiveEvent(static_cast<uint32_t>(wheelEvent.type()), handled));
    30443044
     
    30543054    bool isCancelable = true;
    30553055#endif
    3056     bool handled = this->wheelEvent(wheelEvent, { isCancelable ? WheelEventProcessingSteps::MainThreadForBlockingDOMEventDispatch : WheelEventProcessingSteps::MainThreadForNonBlockingDOMEventDispatch });
     3056    bool handled = this->wheelEvent(wheelEvent, { isCancelable ? WheelEventProcessingSteps::MainThreadForBlockingDOMEventDispatch : WheelEventProcessingSteps::MainThreadForNonBlockingDOMEventDispatch }, EventDispatcher::WheelEventOrigin::UIProcess);
    30573057    completionHandler(handled);
    30583058}
  • trunk/Source/WebKit/WebProcess/WebPage/WebPage.h

    r286218 r286346  
    3939#include "DrawingAreaInfo.h"
    4040#include "EditingRange.h"
     41#include "EventDispatcher.h"
    4142#include "FocusedElementInformation.h"
    4243#include "GeolocationIdentifier.h"
     
    10661067#endif
    10671068
    1068     bool wheelEvent(const WebWheelEvent&, OptionSet<WebCore::WheelEventProcessingSteps>);
     1069    bool wheelEvent(const WebWheelEvent&, OptionSet<WebCore::WheelEventProcessingSteps>, EventDispatcher::WheelEventOrigin);
    10691070
    10701071    void wheelEventHandlersChanged(bool);
Note: See TracChangeset for help on using the changeset viewer.