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

Changeset 286717 in webkit


Ignore:
Timestamp:
Dec 8, 2021, 1:25:37 PM (5 years ago)
Author:
Alan Coon
Message:

Cherry-pick r286346. rdar://problem/85928816

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().

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@286346 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Location:
branches/safari-612.4.2.1-branch/Source
Files:
5 added
16 edited

Legend:

Unmodified
Added
Removed
  • branches/safari-612.4.2.1-branch/Source/WTF/ChangeLog

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

    r285465 r286717  
    869869#endif
    870870
     871#if PLATFORM(MAC)
     872#define ENABLE_MOMENTUM_EVENT_DISPATCHER 1
     873#endif
     874
    871875#if !defined(ENABLE_SCROLLING_THREAD)
    872876#if USE(NICOSIA)
  • branches/safari-612.4.2.1-branch/Source/WebCore/PAL/ChangeLog

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

    r286713 r286717  
    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
  • branches/safari-612.4.2.1-branch/Source/WebKit/ChangeLog

    r286716 r286717  
     12021-12-01  Alan Coon  <alancoon@apple.com>
     2
     3        Cherry-pick r286346. rdar://problem/85928816
     4
     5    Add a momentum event synthesizer
     6    https://bugs.webkit.org/show_bug.cgi?id=233653
     7    <rdar://problem/85571258>
     8   
     9    Reviewed by Simon Fraser.
     10   
     11    Source/WebCore/PAL:
     12   
     13    * pal/spi/mac/IOKitSPIMac.h:
     14    Add some SPI.
     15   
     16    Source/WebKit:
     17   
     18    * Platform/Logging.h:
     19    Add ScrollAnimations log channel to WebKit (it already exists in WebCore).
     20   
     21    * Shared/ScrollingAccelerationCurve.cpp: Added.
     22    (WebKit::ScrollingAccelerationCurve::ScrollingAccelerationCurve):
     23    (WebKit::ScrollingAccelerationCurve::interpolate):
     24    (WebKit::ScrollingAccelerationCurve::computeIntermediateValuesIfNeeded):
     25    (WebKit::ScrollingAccelerationCurve::evaluateQuartic):
     26    (WebKit::ScrollingAccelerationCurve::accelerationFactor):
     27    (WebKit::ScrollingAccelerationCurve::encode const):
     28    (WebKit::ScrollingAccelerationCurve::decode):
     29    (WebKit::operator<<):
     30    (WebKit::ScrollingAccelerationCurve::fromNativeWheelEvent):
     31    * Shared/ScrollingAccelerationCurve.h: Added.
     32    (WebKit::ScrollingAccelerationCurve::operator== const):
     33    (WebKit::ScrollingAccelerationCurve::operator!= const):
     34    Add a class that represents a quartic scrolling acceleration curve with
     35    a trailing linear tangent region, and allows interpolation between curves
     36    and evaluation of the curve at a point.
     37   
     38    * Shared/mac/ScrollingAccelerationCurveMac.mm: Added.
     39    (WebKit::fromFixedPoint):
     40    (WebKit::readFixedPointParameter):
     41    (WebKit::fromIOHIDCurve):
     42    (WebKit::fromIOHIDCurveArrayWithAcceleration):
     43    (WebKit::ScrollingAccelerationCurve::fromNativeWheelEvent):
     44    Given a NativeWebWheelEvent, extract its underlying platform event
     45    and fetch the ScrollingAccelerationCurve for the originating device.
     46   
     47    * Sources.txt:
     48    * SourcesCocoa.txt:
     49    * UIProcess/WebPageProxy.cpp:
     50    (WebKit::WebPageProxy::handleWheelEvent):
     51    Fetch the current ScrollingAccelerationCurve on each momentum begin event,
     52    if the feature is enabled.
     53   
     54    (WebKit::WebPageProxy::sendWheelEvent):
     55    Send the ScrollingAccelerationCurve to EventDispatcher just before
     56    we send the momentum begin event along, if it has changed.
     57   
     58    (WebKit::WebPageProxy::windowScreenDidChange):
     59    Keep EventDispatcher apprised of changes to the current screen of the page.
     60   
     61    (WebKit::WebPageProxy::resetState):
     62    * UIProcess/WebPageProxy.h:
     63    * WebKit.xcodeproj/project.pbxproj:
     64    * WebProcess/WebPage/EventDispatcher.cpp:
     65    (WebKit::EventDispatcher::EventDispatcher):
     66    (WebKit::EventDispatcher::internalWheelEvent):
     67    Factor most of wheelEvent out into internalWheelEvent, so that
     68    MomentumEventDispatcher can call internalWheelEvent(), skipping the code
     69    in wheelEvent() that forwards the event... to MomentumEventDispatcher.
     70   
     71    Also, keep track of where the event came from (UI process or MomentumEventDispatcher)
     72    and avoid sending didReceiveEvent replies to the UI process for synthetic
     73    events that it doesn't know about.
     74   
     75    (WebKit::EventDispatcher::wheelEvent):
     76    Forward wheel events to MomentumEventDispatcher.
     77   
     78    (WebKit::EventDispatcher::setScrollingAccelerationCurve):
     79    Forward scrolling curve changes to MomentumEventDispatcher.
     80   
     81    (WebKit::EventDispatcher::displayWasRefreshed):
     82    Forward display refresh callbacks to MomentumEventDispatcher.
     83   
     84    (WebKit::EventDispatcher::windowScreenDidChange):
     85    Forward page screen changes to MomentumEventDispatcher.
     86   
     87    * WebProcess/WebPage/EventDispatcher.h:
     88    * WebProcess/WebPage/EventDispatcher.messages.in:
     89   
     90    * WebProcess/WebPage/WebPage.cpp:
     91    (WebKit::WebPage::wheelEvent):
     92    (WebKit::WebPage::dispatchWheelEventWithoutScrolling):
     93    * WebProcess/WebPage/WebPage.h:
     94    Don't send didReceiveEvent for synthetic events from the main thread either.
     95   
     96    * WebProcess/WebPage/MomentumEventDispatcher.cpp: Added.
     97    (WebKit::MomentumEventDispatcher::MomentumEventDispatcher):
     98    (WebKit::MomentumEventDispatcher::~MomentumEventDispatcher):
     99    (WebKit::MomentumEventDispatcher::eventShouldStartSyntheticMomentumPhase const):
     100    If we have everything we need (a scrolling curve - which also implies
     101    that the setting is enabled - and raw platform deltas), and the event
     102    is a momentum begin event, we can use it to start a synthetic momentum phase.
     103   
     104    (WebKit::MomentumEventDispatcher::handleWheelEvent):
     105    Start or stop the momentum phase as appropriate.
     106    Record any incoming fingers-down phase events in a rolling event history structure.
     107    Block platform-event-driven events from being further handled by WebKit
     108    if we are inside a synthetic momentum phase, since we'll be replacing them.
     109   
     110    (WebKit::appKitScrollMultiplierForEvent):
     111    Determine the AppKit scroll muliplier ("accelerated" vs "unaccelerated"
     112    deltas in NSEvent parlance) from the event via division.
     113   
     114    (WebKit::MomentumEventDispatcher::dispatchSyntheticMomentumEvent):
     115    Dispatch a synthetic event with the given momentum phase and delta.
     116    We borrow some properties from the event that initiated the momentum
     117    phase (e.g. the position), and some from whatever event we've most
     118    recently seen (even if we told the rest of WebKit to ignore it), so
     119    that we get the most up-to-date state for e.g. the keyboard modifiers.
     120   
     121    (WebKit::MomentumEventDispatcher::didStartMomentumPhase):
     122    Record relevant information about the start event, generate the
     123    momentum curve, and start a full-rate display link. Also, send a momentum
     124    begin event, since we blocked the real one.
     125   
     126    (WebKit::MomentumEventDispatcher::didEndMomentumPhase):
     127    Send a momentum ended event, shut down the display link, and reset all
     128    per-gesture state.
     129   
     130    (WebKit::MomentumEventDispatcher::setScrollingAccelerationCurve):
     131    Store ScrollingAccelerationCurves on a per-page basis.
     132   
     133    (WebKit::MomentumEventDispatcher::displayID const):
     134    Look up the displayID for the current gesture's page.
     135   
     136    (WebKit::MomentumEventDispatcher::startDisplayLink):
     137    (WebKit::MomentumEventDispatcher::stopDisplayLink):
     138    Start and stop a display link, which will - in a roundabout manner -
     139    eventually call back into displayWasRefreshed.
     140   
     141    (WebKit::MomentumEventDispatcher::windowScreenDidChange):
     142    Store DisplayIDs on a per-page basis.
     143   
     144    (WebKit::MomentumEventDispatcher::displayWasRefreshed):
     145    When the display link calls us back, emit a single momentum changed
     146    event of sufficient delta to move us to the desired offset along the curve.
     147   
     148    (WebKit::MomentumEventDispatcher::didScrollWithInterval):
     149    (WebKit::MomentumEventDispatcher::didScroll):
     150    Record incoming scrolling events into a rolling history deque.
     151   
     152    (WebKit::MomentumEventDispatcher::buildOffsetTableWithInitialDelta):
     153    Compute the offsets for the entire "ideal curve" table (at 60Hz) by
     154    running the animation and accumulating the deltas.
     155   
     156    (WebKit::interpolate):
     157    (WebKit::MomentumEventDispatcher::offsetAtTime):
     158    Interpolate along the "ideal curve" to determine the intended offset
     159    at a given time.
     160   
     161    (WebKit::momentumDecayRate):
     162    (WebKit::MomentumEventDispatcher::computeNextDelta):
     163    Compute the next delta given a delta (and the event history) by applying
     164    a bit of exponential decay and then passing it through the
     165    ScrollingAccelerationCurve. We return both the unaccelerated
     166    and accelerated deltas, because the input to the next iteration of
     167    computeNextDelta is the unaccelerated delta, but the delta applied
     168    to the actual scroll position is the accelerated delta.
     169   
     170    * WebProcess/WebPage/MomentumEventDispatcher.h: Added.
     171   
     172    Source/WTF:
     173   
     174    * wtf/PlatformEnable.h:
     175    Add an ENABLE().
     176   
     177    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@286346 268f45cc-cd09-0410-ab3c-d52691b4dbfc
     178
     179    2021-11-30  Tim Horton  <timothy_horton@apple.com>
     180
     181            Add a momentum event synthesizer
     182            https://bugs.webkit.org/show_bug.cgi?id=233653
     183            <rdar://problem/85571258>
     184
     185            Reviewed by Simon Fraser.
     186
     187            * Platform/Logging.h:
     188            Add ScrollAnimations log channel to WebKit (it already exists in WebCore).
     189
     190            * Shared/ScrollingAccelerationCurve.cpp: Added.
     191            (WebKit::ScrollingAccelerationCurve::ScrollingAccelerationCurve):
     192            (WebKit::ScrollingAccelerationCurve::interpolate):
     193            (WebKit::ScrollingAccelerationCurve::computeIntermediateValuesIfNeeded):
     194            (WebKit::ScrollingAccelerationCurve::evaluateQuartic):
     195            (WebKit::ScrollingAccelerationCurve::accelerationFactor):
     196            (WebKit::ScrollingAccelerationCurve::encode const):
     197            (WebKit::ScrollingAccelerationCurve::decode):
     198            (WebKit::operator<<):
     199            (WebKit::ScrollingAccelerationCurve::fromNativeWheelEvent):
     200            * Shared/ScrollingAccelerationCurve.h: Added.
     201            (WebKit::ScrollingAccelerationCurve::operator== const):
     202            (WebKit::ScrollingAccelerationCurve::operator!= const):
     203            Add a class that represents a quartic scrolling acceleration curve with
     204            a trailing linear tangent region, and allows interpolation between curves
     205            and evaluation of the curve at a point.
     206
     207            * Shared/mac/ScrollingAccelerationCurveMac.mm: Added.
     208            (WebKit::fromFixedPoint):
     209            (WebKit::readFixedPointParameter):
     210            (WebKit::fromIOHIDCurve):
     211            (WebKit::fromIOHIDCurveArrayWithAcceleration):
     212            (WebKit::ScrollingAccelerationCurve::fromNativeWheelEvent):
     213            Given a NativeWebWheelEvent, extract its underlying platform event
     214            and fetch the ScrollingAccelerationCurve for the originating device.
     215
     216            * Sources.txt:
     217            * SourcesCocoa.txt:
     218            * UIProcess/WebPageProxy.cpp:
     219            (WebKit::WebPageProxy::handleWheelEvent):
     220            Fetch the current ScrollingAccelerationCurve on each momentum begin event,
     221            if the feature is enabled.
     222
     223            (WebKit::WebPageProxy::sendWheelEvent):
     224            Send the ScrollingAccelerationCurve to EventDispatcher just before
     225            we send the momentum begin event along, if it has changed.
     226
     227            (WebKit::WebPageProxy::windowScreenDidChange):
     228            Keep EventDispatcher apprised of changes to the current screen of the page.
     229
     230            (WebKit::WebPageProxy::resetState):
     231            * UIProcess/WebPageProxy.h:
     232            * WebKit.xcodeproj/project.pbxproj:
     233            * WebProcess/WebPage/EventDispatcher.cpp:
     234            (WebKit::EventDispatcher::EventDispatcher):
     235            (WebKit::EventDispatcher::internalWheelEvent):
     236            Factor most of wheelEvent out into internalWheelEvent, so that
     237            MomentumEventDispatcher can call internalWheelEvent(), skipping the code
     238            in wheelEvent() that forwards the event... to MomentumEventDispatcher.
     239
     240            Also, keep track of where the event came from (UI process or MomentumEventDispatcher)
     241            and avoid sending didReceiveEvent replies to the UI process for synthetic
     242            events that it doesn't know about.
     243
     244            (WebKit::EventDispatcher::wheelEvent):
     245            Forward wheel events to MomentumEventDispatcher.
     246
     247            (WebKit::EventDispatcher::setScrollingAccelerationCurve):
     248            Forward scrolling curve changes to MomentumEventDispatcher.
     249
     250            (WebKit::EventDispatcher::displayWasRefreshed):
     251            Forward display refresh callbacks to MomentumEventDispatcher.
     252
     253            (WebKit::EventDispatcher::windowScreenDidChange):
     254            Forward page screen changes to MomentumEventDispatcher.
     255
     256            * WebProcess/WebPage/EventDispatcher.h:
     257            * WebProcess/WebPage/EventDispatcher.messages.in:
     258
     259            * WebProcess/WebPage/WebPage.cpp:
     260            (WebKit::WebPage::wheelEvent):
     261            (WebKit::WebPage::dispatchWheelEventWithoutScrolling):
     262            * WebProcess/WebPage/WebPage.h:
     263            Don't send didReceiveEvent for synthetic events from the main thread either.
     264
     265            * WebProcess/WebPage/MomentumEventDispatcher.cpp: Added.
     266            (WebKit::MomentumEventDispatcher::MomentumEventDispatcher):
     267            (WebKit::MomentumEventDispatcher::~MomentumEventDispatcher):
     268            (WebKit::MomentumEventDispatcher::eventShouldStartSyntheticMomentumPhase const):
     269            If we have everything we need (a scrolling curve - which also implies
     270            that the setting is enabled - and raw platform deltas), and the event
     271            is a momentum begin event, we can use it to start a synthetic momentum phase.
     272
     273            (WebKit::MomentumEventDispatcher::handleWheelEvent):
     274            Start or stop the momentum phase as appropriate.
     275            Record any incoming fingers-down phase events in a rolling event history structure.
     276            Block platform-event-driven events from being further handled by WebKit
     277            if we are inside a synthetic momentum phase, since we'll be replacing them.
     278
     279            (WebKit::appKitScrollMultiplierForEvent):
     280            Determine the AppKit scroll muliplier ("accelerated" vs "unaccelerated"
     281            deltas in NSEvent parlance) from the event via division.
     282
     283            (WebKit::MomentumEventDispatcher::dispatchSyntheticMomentumEvent):
     284            Dispatch a synthetic event with the given momentum phase and delta.
     285            We borrow some properties from the event that initiated the momentum
     286            phase (e.g. the position), and some from whatever event we've most
     287            recently seen (even if we told the rest of WebKit to ignore it), so
     288            that we get the most up-to-date state for e.g. the keyboard modifiers.
     289
     290            (WebKit::MomentumEventDispatcher::didStartMomentumPhase):
     291            Record relevant information about the start event, generate the
     292            momentum curve, and start a full-rate display link. Also, send a momentum
     293            begin event, since we blocked the real one.
     294
     295            (WebKit::MomentumEventDispatcher::didEndMomentumPhase):
     296            Send a momentum ended event, shut down the display link, and reset all
     297            per-gesture state.
     298
     299            (WebKit::MomentumEventDispatcher::setScrollingAccelerationCurve):
     300            Store ScrollingAccelerationCurves on a per-page basis.
     301
     302            (WebKit::MomentumEventDispatcher::displayID const):
     303            Look up the displayID for the current gesture's page.
     304
     305            (WebKit::MomentumEventDispatcher::startDisplayLink):
     306            (WebKit::MomentumEventDispatcher::stopDisplayLink):
     307            Start and stop a display link, which will - in a roundabout manner -
     308            eventually call back into displayWasRefreshed.
     309
     310            (WebKit::MomentumEventDispatcher::windowScreenDidChange):
     311            Store DisplayIDs on a per-page basis.
     312
     313            (WebKit::MomentumEventDispatcher::displayWasRefreshed):
     314            When the display link calls us back, emit a single momentum changed
     315            event of sufficient delta to move us to the desired offset along the curve.
     316
     317            (WebKit::MomentumEventDispatcher::didScrollWithInterval):
     318            (WebKit::MomentumEventDispatcher::didScroll):
     319            Record incoming scrolling events into a rolling history deque.
     320
     321            (WebKit::MomentumEventDispatcher::buildOffsetTableWithInitialDelta):
     322            Compute the offsets for the entire "ideal curve" table (at 60Hz) by
     323            running the animation and accumulating the deltas.
     324
     325            (WebKit::interpolate):
     326            (WebKit::MomentumEventDispatcher::offsetAtTime):
     327            Interpolate along the "ideal curve" to determine the intended offset
     328            at a given time.
     329
     330            (WebKit::momentumDecayRate):
     331            (WebKit::MomentumEventDispatcher::computeNextDelta):
     332            Compute the next delta given a delta (and the event history) by applying
     333            a bit of exponential decay and then passing it through the
     334            ScrollingAccelerationCurve. We return both the unaccelerated
     335            and accelerated deltas, because the input to the next iteration of
     336            computeNextDelta is the unaccelerated delta, but the delta applied
     337            to the actual scroll position is the accelerated delta.
     338
     339            * WebProcess/WebPage/MomentumEventDispatcher.h: Added.
     340
    13412021-12-01  Alan Coon  <alancoon@apple.com>
    2342
  • branches/safari-612.4.2.1-branch/Source/WebKit/Platform/Logging.h

    r280811 r286717  
    9090    M(Resize) \
    9191    M(ResourceLoadStatistics) \
     92    M(ScrollAnimations) \
    9293    M(Scrolling) \
    9394    M(Selection) \
  • branches/safari-612.4.2.1-branch/Source/WebKit/Sources.txt

    r284424 r286717  
    198198Shared/RTCNetwork.cpp
    199199Shared/RTCPacketOptions.cpp
     200Shared/ScrollingAccelerationCurve.cpp
    200201Shared/ServiceWorkerInitializationData.cpp
    201202Shared/SessionState.cpp
     
    723724WebProcess/WebPage/FindController.cpp
    724725WebProcess/WebPage/IPCTestingAPI.cpp
     726WebProcess/WebPage/MomentumEventDispatcher.cpp
    725727WebProcess/WebPage/PageBanner.cpp
    726728WebProcess/WebPage/VisitedLinkTableController.cpp
  • branches/safari-612.4.2.1-branch/Source/WebKit/SourcesCocoa.txt

    r284953 r286717  
    214214Shared/mac/PasteboardTypes.mm
    215215Shared/mac/PrintInfoMac.mm
     216Shared/mac/ScrollingAccelerationCurveMac.mm
    216217Shared/mac/SecItemRequestData.cpp
    217218Shared/mac/SecItemResponseData.cpp
  • branches/safari-612.4.2.1-branch/Source/WebKit/UIProcess/WebPageProxy.cpp

    r286716 r286717  
    28872887    closeOverlayedViews();
    28882888
     2889#if ENABLE(MOMENTUM_EVENT_DISPATCHER)
     2890    // FIXME: We should not have to look this up repeatedly, but it can also change occasionally.
     2891    if (event.momentumPhase() == WebWheelEvent::PhaseBegan && preferences().momentumScrollingAnimatorEnabled())
     2892        m_scrollingAccelerationCurve = ScrollingAccelerationCurve::fromNativeWheelEvent(event);
     2893#endif
     2894
    28892895    if (wheelEventCoalescer().shouldDispatchEvent(event)) {
    28902896        auto event = wheelEventCoalescer().nextEventToDispatch();
     
    29322938        rubberBandableEdges.setRight(!m_backForwardList->forwardItem());
    29332939    }
    2934     connection -> send(Messages::EventDispatcher::WheelEvent(m_webPageID, event, rubberBandableEdges), 0);
     2940
     2941#if ENABLE(MOMENTUM_EVENT_DISPATCHER)
     2942    if (event.momentumPhase() == WebWheelEvent::PhaseBegan && m_scrollingAccelerationCurve != m_lastSentScrollingAccelerationCurve) {
     2943        connection->send(Messages::EventDispatcher::SetScrollingAccelerationCurve(m_webPageID, *m_scrollingAccelerationCurve), 0, { }, Thread::QOS::UserInteractive);
     2944        m_lastSentScrollingAccelerationCurve = m_scrollingAccelerationCurve;
     2945    }
     2946#endif
     2947
     2948    connection->send(Messages::EventDispatcher::WheelEvent(m_webPageID, event, rubberBandableEdges), 0, { }, Thread::QOS::UserInteractive);
    29352949
    29362950    // Manually ping the web process to check for responsiveness since our wheel
     
    39944008        return;
    39954009
     4010    send(Messages::EventDispatcher::PageScreenDidChange(m_webPageID, displayID));
    39964011    send(Messages::WebPage::WindowScreenDidChange(displayID, nominalFramesPerSecond));
    39974012}
     
    79057920        m_xrSystem = nullptr;
    79067921    }
     7922#endif
     7923
     7924#if ENABLE(MOMENTUM_EVENT_DISPATCHER)
     7925    m_lastSentScrollingAccelerationCurve = std::nullopt;
    79077926#endif
    79087927}
  • branches/safari-612.4.2.1-branch/Source/WebKit/UIProcess/WebPageProxy.h

    r286716 r286717  
    5252#include "ProcessThrottler.h"
    5353#include "SandboxExtension.h"
     54#include "ScrollingAccelerationCurve.h"
    5455#include "ShareableBitmap.h"
    5556#include "ShareableResource.h"
     
    30933094
    30943095    bool m_needsSiteSpecificViewportQuirks { true };
     3096
     3097#if ENABLE(MOMENTUM_EVENT_DISPATCHER)
     3098    std::optional<ScrollingAccelerationCurve> m_scrollingAccelerationCurve;
     3099    std::optional<ScrollingAccelerationCurve> m_lastSentScrollingAccelerationCurve;
     3100#endif
    30953101};
    30963102
  • branches/safari-612.4.2.1-branch/Source/WebKit/WebKit.xcodeproj/project.pbxproj

    r284953 r286717  
    32753275                2D6482492644B1AB00030335 /* RemoteLayerTreeLayers.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RemoteLayerTreeLayers.h; sourceTree = "<group>"; };
    32763276                2D64824A2644B1AB00030335 /* RemoteLayerTreeLayers.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = RemoteLayerTreeLayers.mm; sourceTree = "<group>"; };
     3277                2D65D194274B8E73009C4101 /* ScrollingAccelerationCurveMac.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = ScrollingAccelerationCurveMac.mm; sourceTree = "<group>"; };
     3278                2D65D195274B8E84009C4101 /* ScrollingAccelerationCurve.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ScrollingAccelerationCurve.h; sourceTree = "<group>"; };
     3279                2D65D196274B8E84009C4101 /* ScrollingAccelerationCurve.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = ScrollingAccelerationCurve.cpp; sourceTree = "<group>"; };
    32773280                2D6AB53F192B1C4A003A9FD1 /* WKPDFPageNumberIndicator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WKPDFPageNumberIndicator.h; path = ios/WKPDFPageNumberIndicator.h; sourceTree = "<group>"; };
    32783281                2D6AB540192B1C4A003A9FD1 /* WKPDFPageNumberIndicator.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = WKPDFPageNumberIndicator.mm; path = ios/WKPDFPageNumberIndicator.mm; sourceTree = "<group>"; };
     
    35573560                2DE9B13B2231F77C005287B7 /* _WKTextInputContextInternal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = _WKTextInputContextInternal.h; sourceTree = "<group>"; };
    35583561                2DEAC5CE1AC368BB00A195D8 /* _WKFindOptions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = _WKFindOptions.h; sourceTree = "<group>"; };
     3562                2DEE709D2755A46800FBF864 /* MomentumEventDispatcher.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MomentumEventDispatcher.h; sourceTree = "<group>"; };
     3563                2DEE709E2755A46800FBF864 /* MomentumEventDispatcher.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = MomentumEventDispatcher.cpp; sourceTree = "<group>"; };
    35593564                2DF9593418A42412009785A1 /* ViewGestureControllerIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = ViewGestureControllerIOS.mm; path = ios/ViewGestureControllerIOS.mm; sourceTree = "<group>"; };
    35603565                2DF9EEE31A781FB400B6CFBE /* APIFrameInfo.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = APIFrameInfo.cpp; sourceTree = "<group>"; };
     
    68966901                                1AAB4A8C1296F0A20023952F /* SandboxExtension.h */,
    68976902                                E1E552C316AE065E004ED653 /* SandboxInitializationParameters.h */,
     6903                                2D65D196274B8E84009C4101 /* ScrollingAccelerationCurve.cpp */,
     6904                                2D65D195274B8E84009C4101 /* ScrollingAccelerationCurve.h */,
    68986905                                5C80B3DD23690F100086E6DE /* ServiceWorkerInitializationData.cpp */,
    68996906                                5C80B3DB23690D8D0086E6DE /* ServiceWorkerInitializationData.h */,
     
    1007210079                                9B033E72252580F300501071 /* IPCTestingAPI.cpp */,
    1007310080                                9B033E71252580F300501071 /* IPCTestingAPI.h */,
     10081                                2DEE709E2755A46800FBF864 /* MomentumEventDispatcher.cpp */,
     10082                                2DEE709D2755A46800FBF864 /* MomentumEventDispatcher.h */,
    1007410083                                7C387433172F5615001BD88A /* PageBanner.cpp */,
    1007510084                                7CF47FF917275C57008ACB91 /* PageBanner.h */,
     
    1064410653                                C1E123B920A11572002646F4 /* PDFContextMenu.h */,
    1064510654                                E1CC1B8F12D7EADF00625838 /* PrintInfoMac.mm */,
     10655                                2D65D194274B8E73009C4101 /* ScrollingAccelerationCurveMac.mm */,
    1064610656                                51D1304F1382EAC000351EDD /* SecItemRequestData.cpp */,
    1064710657                                51D130501382EAC000351EDD /* SecItemRequestData.h */,
  • branches/safari-612.4.2.1-branch/Source/WebKit/WebProcess/WebPage/EventDispatcher.cpp

    r286716 r286717  
    2828
    2929#include "EventDispatcherMessages.h"
     30#include "MomentumEventDispatcher.h"
    3031#include "WebEventConversion.h"
    3132#include "WebPage.h"
     
    6364    : m_queue(WorkQueue::create("com.apple.WebKit.EventDispatcher", WorkQueue::Type::Serial, WorkQueue::QOS::UserInteractive))
    6465    , m_recentWheelEventDeltaFilter(WheelEventDeltaFilter::create())
     66#if ENABLE(MOMENTUM_EVENT_DISPATCHER)
     67    , m_momentumEventDispatcher(WTF::makeUnique<MomentumEventDispatcher>(*this))
     68#endif
    6569{
    6670}
     
    97101}
    98102
    99 void EventDispatcher::wheelEvent(PageIdentifier pageID, const WebWheelEvent& wheelEvent, RectEdges<bool> rubberBandableEdges)
     103void EventDispatcher::internalWheelEvent(PageIdentifier pageID, const WebWheelEvent& wheelEvent, RectEdges<bool> rubberBandableEdges, WheelEventOrigin wheelEventOrigin)
    100104{
    101105#if PLATFORM(COCOA) || ENABLE(SCROLLING_THREAD)
     
    129133        auto scrollingTree = m_scrollingTrees.get(pageID);
    130134        if (!scrollingTree) {
    131             dispatchWheelEventViaMainThread(pageID, wheelEvent, processingSteps);
     135            dispatchWheelEventViaMainThread(pageID, wheelEvent, processingSteps, wheelEventOrigin);
    132136            break;
    133137        }
     
    144148        scrollingTree->willProcessWheelEvent();
    145149
    146         ScrollingThread::dispatch([scrollingTree, wheelEvent, platformWheelEvent, processingSteps, pageID, protectedThis = makeRef(*this)] {
     150        ScrollingThread::dispatch([scrollingTree, wheelEvent, platformWheelEvent, processingSteps, pageID, wheelEventOrigin, protectedThis = makeRef(*this)] {
    147151            if (processingSteps.contains(WheelEventProcessingSteps::MainThreadForScrolling)) {
    148152                scrollingTree->willSendEventToMainThread(platformWheelEvent);
    149                 protectedThis->dispatchWheelEventViaMainThread(pageID, wheelEvent, processingSteps);
     153                protectedThis->dispatchWheelEventViaMainThread(pageID, wheelEvent, processingSteps, wheelEventOrigin);
    150154                scrollingTree->waitForEventToBeProcessedByMainThread(platformWheelEvent);
    151155                return;
     
    155159
    156160            if (result.needsMainThreadProcessing()) {
    157                 protectedThis->dispatchWheelEventViaMainThread(pageID, wheelEvent, result.steps);
     161                protectedThis->dispatchWheelEventViaMainThread(pageID, wheelEvent, result.steps, wheelEventOrigin);
    158162                if (result.steps.contains(WheelEventProcessingSteps::MainThreadForScrolling))
    159163                    return;
     
    162166            // If we scrolled on the scrolling thread (even if we send the event to the main thread for passive event handlers)
    163167            // respond to the UI process that the event was handled.
    164             protectedThis->sendDidReceiveEvent(pageID, wheelEvent.type(), result.wasHandled);
     168            if (wheelEventOrigin == WheelEventOrigin::UIProcess)
     169                protectedThis->sendDidReceiveEvent(pageID, wheelEvent.type(), result.wasHandled);
    165170        });
    166171    } while (false);
     
    168173    UNUSED_PARAM(rubberBandableEdges);
    169174
    170     dispatchWheelEventViaMainThread(pageID, wheelEvent, processingSteps);
    171 #endif
    172 }
     175    dispatchWheelEventViaMainThread(pageID, wheelEvent, processingSteps, wheelEventOrigin);
     176#endif
     177}
     178
     179void EventDispatcher::wheelEvent(PageIdentifier pageID, const WebWheelEvent& wheelEvent, RectEdges<bool> rubberBandableEdges)
     180{
     181#if ENABLE(MOMENTUM_EVENT_DISPATCHER)
     182    if (m_momentumEventDispatcher->handleWheelEvent(pageID, wheelEvent, rubberBandableEdges)) {
     183        sendDidReceiveEvent(pageID, wheelEvent.type(), true);
     184        return;
     185    }
     186#endif
     187    internalWheelEvent(pageID, wheelEvent, rubberBandableEdges, WheelEventOrigin::UIProcess);
     188}
     189
     190#if ENABLE(MOMENTUM_EVENT_DISPATCHER)
     191void EventDispatcher::setScrollingAccelerationCurve(PageIdentifier pageID, std::optional<ScrollingAccelerationCurve> curve)
     192{
     193    m_momentumEventDispatcher->setScrollingAccelerationCurve(pageID, curve);
     194}
     195#endif
    173196
    174197#if ENABLE(MAC_GESTURE_EVENTS)
     
    238261#endif
    239262
    240 void EventDispatcher::dispatchWheelEventViaMainThread(WebCore::PageIdentifier pageID, const WebWheelEvent& wheelEvent, OptionSet<WheelEventProcessingSteps> processingSteps)
     263void EventDispatcher::dispatchWheelEventViaMainThread(WebCore::PageIdentifier pageID, const WebWheelEvent& wheelEvent, OptionSet<WheelEventProcessingSteps> processingSteps, WheelEventOrigin wheelEventOrigin)
    241264{
    242265    ASSERT(!RunLoop::isMain());
    243     RunLoop::main().dispatch([protectedThis = makeRef(*this), pageID, wheelEvent, steps = processingSteps - WheelEventProcessingSteps::ScrollingThread]() mutable {
    244         protectedThis->dispatchWheelEvent(pageID, wheelEvent, steps);
     266    RunLoop::main().dispatch([protectedThis = makeRef(*this), pageID, wheelEvent, wheelEventOrigin, steps = processingSteps - WheelEventProcessingSteps::ScrollingThread]() mutable {
     267        protectedThis->dispatchWheelEvent(pageID, wheelEvent, steps, wheelEventOrigin);
    245268    });
    246269}
    247270
    248 void EventDispatcher::dispatchWheelEvent(PageIdentifier pageID, const WebWheelEvent& wheelEvent, OptionSet<WheelEventProcessingSteps> processingSteps)
     271void EventDispatcher::dispatchWheelEvent(PageIdentifier pageID, const WebWheelEvent& wheelEvent, OptionSet<WheelEventProcessingSteps> processingSteps, WheelEventOrigin wheelEventOrigin)
    249272{
    250273    ASSERT(RunLoop::isMain());
     
    254277        return;
    255278
    256     webPage->wheelEvent(wheelEvent, processingSteps);
     279    webPage->wheelEvent(wheelEvent, processingSteps, wheelEventOrigin);
    257280}
    258281
     
    292315
    293316    ASSERT(!RunLoop::isMain());
     317
     318#if ENABLE(MOMENTUM_EVENT_DISPATCHER)
     319    m_momentumEventDispatcher->displayWasRefreshed(displayID, displayUpdate);
     320#endif
     321
    294322    notifyScrollingTreesDisplayWasRefreshed(displayID);
    295323
     
    303331#endif
    304332
     333void EventDispatcher::pageScreenDidChange(PageIdentifier pageID, PlatformDisplayID displayID)
     334{
     335#if ENABLE(MOMENTUM_EVENT_DISPATCHER)
     336    m_momentumEventDispatcher->pageScreenDidChange(pageID, displayID);
     337#else
     338    UNUSED_PARAM(pageID);
     339    UNUSED_PARAM(displayID);
     340#endif
     341}
     342
    305343} // namespace WebKit
  • branches/safari-612.4.2.1-branch/Source/WebKit/WebProcess/WebPage/EventDispatcher.h

    r286716 r286717  
    5252namespace WebKit {
    5353
     54class MomentumEventDispatcher;
     55class ScrollingAccelerationCurve;
    5456class WebPage;
    5557class WebWheelEvent;
     
    7880    void notifyScrollingTreesDisplayWasRefreshed(WebCore::PlatformDisplayID);
    7981
     82    enum class WheelEventOrigin : bool { UIProcess, MomentumEventDispatcher };
     83    void internalWheelEvent(WebCore::PageIdentifier, const WebWheelEvent&, WebCore::RectEdges<bool> rubberBandableEdges, WheelEventOrigin);
     84
    8085private:
    8186    EventDispatcher();
     
    8691    // Message handlers
    8792    void wheelEvent(WebCore::PageIdentifier, const WebWheelEvent&, WebCore::RectEdges<bool> rubberBandableEdges);
     93#if ENABLE(MOMENTUM_EVENT_DISPATCHER)
     94    void setScrollingAccelerationCurve(WebCore::PageIdentifier, std::optional<ScrollingAccelerationCurve>);
     95#endif
    8896#if ENABLE(IOS_TOUCH_EVENTS)
    8997    void touchEvent(WebCore::PageIdentifier, const WebTouchEvent&, CompletionHandler<void(bool)>&&);
     
    95103
    96104    // This is called on the main thread.
    97     void dispatchWheelEvent(WebCore::PageIdentifier, const WebWheelEvent&, OptionSet<WebCore::WheelEventProcessingSteps>);
    98     void dispatchWheelEventViaMainThread(WebCore::PageIdentifier, const WebWheelEvent&, OptionSet<WebCore::WheelEventProcessingSteps>);
     105    void dispatchWheelEvent(WebCore::PageIdentifier, const WebWheelEvent&, OptionSet<WebCore::WheelEventProcessingSteps>, WheelEventOrigin);
     106    void dispatchWheelEventViaMainThread(WebCore::PageIdentifier, const WebWheelEvent&, OptionSet<WebCore::WheelEventProcessingSteps>, WheelEventOrigin);
    99107
    100108#if ENABLE(IOS_TOUCH_EVENTS)
     
    117125#endif
    118126
     127    void pageScreenDidChange(WebCore::PageIdentifier, WebCore::PlatformDisplayID);
     128
    119129    Ref<WorkQueue> m_queue;
    120130
     
    128138    HashMap<WebCore::PageIdentifier, TouchEventQueue> m_touchEvents WTF_GUARDED_BY_LOCK(m_touchEventsLock);
    129139#endif
     140
     141#if ENABLE(MOMENTUM_EVENT_DISPATCHER)
     142    std::unique_ptr<MomentumEventDispatcher> m_momentumEventDispatcher;
     143#endif
    130144};
    131145
  • branches/safari-612.4.2.1-branch/Source/WebKit/WebProcess/WebPage/EventDispatcher.messages.in

    r286716 r286717  
    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}
  • branches/safari-612.4.2.1-branch/Source/WebKit/WebProcess/WebPage/WebPage.cpp

    r286716 r286717  
    30583058}
    30593059
    3060 bool WebPage::wheelEvent(const WebWheelEvent& wheelEvent, OptionSet<WheelEventProcessingSteps> processingSteps)
     3060bool WebPage::wheelEvent(const WebWheelEvent& wheelEvent, OptionSet<WheelEventProcessingSteps> processingSteps, EventDispatcher::WheelEventOrigin wheelEventOrigin)
    30613061{
    30623062    m_userActivity.impulse();
     
    30663066    bool handled = handleWheelEvent(wheelEvent, m_page.get(), processingSteps);
    30673067
    3068     if (processingSteps.contains(WheelEventProcessingSteps::MainThreadForScrolling))
     3068    if (processingSteps.contains(WheelEventProcessingSteps::MainThreadForScrolling) && wheelEventOrigin == EventDispatcher::WheelEventOrigin::UIProcess)
    30693069        send(Messages::WebPageProxy::DidReceiveEvent(static_cast<uint32_t>(wheelEvent.type()), handled));
    30703070
     
    30803080    bool isCancelable = true;
    30813081#endif
    3082     bool handled = this->wheelEvent(wheelEvent, { isCancelable ? WheelEventProcessingSteps::MainThreadForBlockingDOMEventDispatch : WheelEventProcessingSteps::MainThreadForNonBlockingDOMEventDispatch });
     3082    bool handled = this->wheelEvent(wheelEvent, { isCancelable ? WheelEventProcessingSteps::MainThreadForBlockingDOMEventDispatch : WheelEventProcessingSteps::MainThreadForNonBlockingDOMEventDispatch }, EventDispatcher::WheelEventOrigin::UIProcess);
    30833083    completionHandler(handled);
    30843084}
  • branches/safari-612.4.2.1-branch/Source/WebKit/WebProcess/WebPage/WebPage.h

    r286716 r286717  
    3939#include "DrawingAreaInfo.h"
    4040#include "EditingRange.h"
     41#include "EventDispatcher.h"
    4142#include "FocusedElementInformation.h"
    4243#include "GeolocationIdentifier.h"
     
    10631064#endif
    10641065
    1065     bool wheelEvent(const WebWheelEvent&, OptionSet<WebCore::WheelEventProcessingSteps>);
     1066    bool wheelEvent(const WebWheelEvent&, OptionSet<WebCore::WheelEventProcessingSteps>, EventDispatcher::WheelEventOrigin);
    10661067
    10671068    void wheelEventHandlersChanged(bool);
Note: See TracChangeset for help on using the changeset viewer.