<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[285787] trunk</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/285787">285787</a></dd>
<dt>Author</dt> <dd>simon.fraser@apple.com</dd>
<dt>Date</dt> <dd>2021-11-13 23:37:36 -0800 (Sat, 13 Nov 2021)</dd>
</dl>

<h3>Log Message</h3>
<pre>Run a ScrollAnimationMomentum for the momentum phase of a scroll
https://bugs.webkit.org/show_bug.cgi?id=232897

Reviewed by Tim Horton.
Source/WebCore:

Run an animation for the momentum phase of a scroll, rather than scrolling in response
to wheel events, because it produces a smoother result with fewer dropped frames.

We re-use ScrollAnimationMomentum which is already used for scroll snap, but have to
allow it to yield unclamped coordinates, since using it for momentum can result in
rubber-banding.

When we get the momentum "began" event, we start the ScrollAnimationMomentum
using initial velocity computed from WheelEventDeltaFilter. ScrollingEffectsController then
ignores the reset of the momentum "changed" events.

We have to stop this animation when we receive a "begin" or "mayBegin" event, since
this indicates that the user has put fingers down on the trackpad.

Rename m_dragEndedScrollingVelocity to m_scrollingVelocityForScrollSnap for clarity
(at some point we should merge this with m_scrollingVelocityForMomentumAnimation).

Tests: fast/scrolling/mac/momentum-animator-in-overflow.html
       fast/scrolling/mac/momentum-animator.html

* page/WheelEventDeltaFilter.cpp:
(WebCore::WheelEventDeltaFilter::shouldApplyFilteringForEvent):
* page/WheelEventDeltaFilter.h:
* platform/PlatformWheelEvent.cpp:
(WebCore::operator<<):
* platform/ScrollAnimationMomentum.cpp:
(WebCore::ScrollAnimationMomentum::startAnimatedScrollWithInitialVelocity):
(WebCore::ScrollAnimationMomentum::stop):
(WebCore::ScrollAnimationMomentum::serviceAnimation):
* platform/ScrollAnimationMomentum.h:
* platform/ScrollingEffectsController.cpp:
(WebCore::ScrollingEffectsController::ScrollingEffectsController):
(WebCore::ScrollingEffectsController::stopAnimatedNonRubberbandingScroll):
(WebCore::ScrollingEffectsController::startMomentumScrollWithInitialVelocity):
* platform/ScrollingEffectsController.h:
(WebCore::ScrollingEffectsController::momentumScrollingAnimatorEnabled const):
* platform/mac/ScrollingEffectsController.mm:
(WebCore::phaseToString):
(WebCore::ScrollingEffectsController::handleWheelEvent):
(WebCore::ScrollingEffectsController::startRubberBandAnimation):
(WebCore::ScrollingEffectsController::startRubberBandAnimationIfNecessary):
(WebCore::ScrollingEffectsController::processWheelEventForScrollSnap):

Source/WTF:

Set the MomentumScrollingAnimatorEnabled internal setting to off by default
while we bring up tests.

* Scripts/Preferences/WebPreferencesInternal.yaml:

LayoutTests:

Some tests that enable the momentum animator.

* fast/scrolling/mac/momentum-animator-expected.txt: Added.
* fast/scrolling/mac/momentum-animator-in-overflow-expected.txt: Added.
* fast/scrolling/mac/momentum-animator-in-overflow.html: Added.
* fast/scrolling/mac/momentum-animator.html: Added.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkSourceWTFChangeLog">trunk/Source/WTF/ChangeLog</a></li>
<li><a href="#trunkSourceWTFScriptsPreferencesWebPreferencesInternalyaml">trunk/Source/WTF/Scripts/Preferences/WebPreferencesInternal.yaml</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCorepageWheelEventDeltaFiltercpp">trunk/Source/WebCore/page/WheelEventDeltaFilter.cpp</a></li>
<li><a href="#trunkSourceWebCorepageWheelEventDeltaFilterh">trunk/Source/WebCore/page/WheelEventDeltaFilter.h</a></li>
<li><a href="#trunkSourceWebCoreplatformPlatformWheelEventcpp">trunk/Source/WebCore/platform/PlatformWheelEvent.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformScrollAnimationMomentumcpp">trunk/Source/WebCore/platform/ScrollAnimationMomentum.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformScrollAnimationMomentumh">trunk/Source/WebCore/platform/ScrollAnimationMomentum.h</a></li>
<li><a href="#trunkSourceWebCoreplatformScrollingEffectsControllercpp">trunk/Source/WebCore/platform/ScrollingEffectsController.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformScrollingEffectsControllerh">trunk/Source/WebCore/platform/ScrollingEffectsController.h</a></li>
<li><a href="#trunkSourceWebCoreplatformmacScrollingEffectsControllermm">trunk/Source/WebCore/platform/mac/ScrollingEffectsController.mm</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsfastscrollingmacmomentumanimatorexpectedtxt">trunk/LayoutTests/fast/scrolling/mac/momentum-animator-expected.txt</a></li>
<li><a href="#trunkLayoutTestsfastscrollingmacmomentumanimatorinoverflowexpectedtxt">trunk/LayoutTests/fast/scrolling/mac/momentum-animator-in-overflow-expected.txt</a></li>
<li><a href="#trunkLayoutTestsfastscrollingmacmomentumanimatorinoverflowhtml">trunk/LayoutTests/fast/scrolling/mac/momentum-animator-in-overflow.html</a></li>
<li><a href="#trunkLayoutTestsfastscrollingmacmomentumanimatorhtml">trunk/LayoutTests/fast/scrolling/mac/momentum-animator.html</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (285786 => 285787)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog      2021-11-14 05:05:59 UTC (rev 285786)
+++ trunk/LayoutTests/ChangeLog 2021-11-14 07:37:36 UTC (rev 285787)
</span><span class="lines">@@ -1,3 +1,17 @@
</span><ins>+2021-11-13  Simon Fraser  <simon.fraser@apple.com>
+
+        Run a ScrollAnimationMomentum for the momentum phase of a scroll
+        https://bugs.webkit.org/show_bug.cgi?id=232897
+
+        Reviewed by Tim Horton.
+
+        Some tests that enable the momentum animator.
+
+        * fast/scrolling/mac/momentum-animator-expected.txt: Added.
+        * fast/scrolling/mac/momentum-animator-in-overflow-expected.txt: Added.
+        * fast/scrolling/mac/momentum-animator-in-overflow.html: Added.
+        * fast/scrolling/mac/momentum-animator.html: Added.
+
</ins><span class="cx"> 2021-11-13  Said Abou-Hallawa  <said@apple.com>
</span><span class="cx"> 
</span><span class="cx">         REGRESSION (r285618): [mac-wk1] ASSERTION FAILED: cgContext == [currentContext CGContext]
</span></span></pre></div>
<a id="trunkLayoutTestsfastscrollingmacmomentumanimatorexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/scrolling/mac/momentum-animator-expected.txt (0 => 285787)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/scrolling/mac/momentum-animator-expected.txt                              (rev 0)
+++ trunk/LayoutTests/fast/scrolling/mac/momentum-animator-expected.txt 2021-11-14 07:37:36 UTC (rev 285787)
</span><span class="lines">@@ -0,0 +1,5 @@
</span><ins>+PASS window.scrollY > 150 is true
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
</ins></span></pre></div>
<a id="trunkLayoutTestsfastscrollingmacmomentumanimatorinoverflowexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/scrolling/mac/momentum-animator-in-overflow-expected.txt (0 => 285787)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/scrolling/mac/momentum-animator-in-overflow-expected.txt                          (rev 0)
+++ trunk/LayoutTests/fast/scrolling/mac/momentum-animator-in-overflow-expected.txt     2021-11-14 07:37:36 UTC (rev 285787)
</span><span class="lines">@@ -0,0 +1,6 @@
</span><ins>+PASS window.scrollY is 0
+PASS scroller.scrollTop > 200 is true
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
</ins></span></pre></div>
<a id="trunkLayoutTestsfastscrollingmacmomentumanimatorinoverflowhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/scrolling/mac/momentum-animator-in-overflow.html (0 => 285787)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/scrolling/mac/momentum-animator-in-overflow.html                          (rev 0)
+++ trunk/LayoutTests/fast/scrolling/mac/momentum-animator-in-overflow.html     2021-11-14 07:37:36 UTC (rev 285787)
</span><span class="lines">@@ -0,0 +1,89 @@
</span><ins>+<!DOCTYPE html> <!-- webkit-test-runner [ MomentumScrollingAnimatorEnabled=true AsyncOverflowScrollingEnabled=true ] -->
+<html>
+<head>
+    <style>
+        body {
+            height: 2000px;
+            width: 200%;
+        }
+        
+        .scroller {
+            height: 500px;
+            width: 400px;
+            border: 1px solid black;
+            overflow: auto;
+        }
+        
+        .content {
+            width: 200%;
+            height: 500%;
+        }
+    </style>
+    <script src="../../../resources/js-test-pre.js"></script>
+    <script src="../../../resources/ui-helper.js"></script>
+    <script>
+        var jsTestIsAsync = true;
+        
+        let scroller;
+        async function testEventSequence()
+        {
+            const wheelEventSquence = {
+                "events" : [
+                    {
+                        type : "wheel",
+                        viewX : 100,
+                        viewY : 100,
+                        deltaY : -10, // Note that this delta is currently ignored.
+                        phase : "began"
+                    },
+                    {
+                        type : "wheel",
+                        deltaY : -100,
+                        phase : "changed"
+                    },
+                    {
+                        type : "wheel",
+                        phase : "ended"
+                    },
+                    {
+                        type : "wheel",
+                        deltaY : -100,
+                        momentumPhase : "began"
+                    },
+                    {
+                        type : "wheel",
+                        deltaY : -80,
+                        momentumPhase : "changed"
+                    },
+                    {
+                        type : "wheel",
+                        momentumPhase : "ended"
+                    }
+                ]
+            };
+
+            await UIHelper.mouseWheelSequence(wheelEventSquence);
+            shouldBe('window.scrollY', '0');
+            scroller = document.querySelector('.scroller');
+            // Make sure we scrolled some non-trivial amount.
+            shouldBeTrue('scroller.scrollTop > 200');
+        }
+
+        async function scrollTest()
+        {
+            await testEventSequence();
+            finishJSTest();
+        }
+
+        window.addEventListener('load', () => {
+            setTimeout(scrollTest, 0);
+        }, false);
+    </script>
+</head>
+<body>
+    <div class="scroller">
+        <div class="content"></div>
+    </div>
+    <script src="../../../resources/js-test-post.js"></script>
+</body>
+</html>
</ins></span></pre></div>
<a id="trunkLayoutTestsfastscrollingmacmomentumanimatorhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/scrolling/mac/momentum-animator.html (0 => 285787)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/scrolling/mac/momentum-animator.html                              (rev 0)
+++ trunk/LayoutTests/fast/scrolling/mac/momentum-animator.html 2021-11-14 07:37:36 UTC (rev 285787)
</span><span class="lines">@@ -0,0 +1,71 @@
</span><ins>+<!DOCTYPE html> <!-- webkit-test-runner [ MomentumScrollingAnimatorEnabled=true ] -->
+<html>
+<head>
+    <style>
+        body {
+            height: 2000px;
+            width: 200%;
+        }
+    </style>
+    <script src="../../../resources/js-test-pre.js"></script>
+    <script src="../../../resources/ui-helper.js"></script>
+    <script>
+        var jsTestIsAsync = true;
+        
+        async function testEventSequence()
+        {
+            const wheelEventSquence = {
+                "events" : [
+                    {
+                        type : "wheel",
+                        viewX : 100,
+                        viewY : 100,
+                        deltaY : -10, // Note that this delta is currently ignored.
+                        phase : "began"
+                    },
+                    {
+                        type : "wheel",
+                        deltaY : -100,
+                        phase : "changed"
+                    },
+                    {
+                        type : "wheel",
+                        phase : "ended"
+                    },
+                    {
+                        type : "wheel",
+                        deltaY : -100,
+                        momentumPhase : "began"
+                    },
+                    {
+                        type: "wheel",
+                        deltaY: -80,
+                        momentumPhase: "changed"
+                    },
+                    {
+                        type : "wheel",
+                        momentumPhase : "ended"
+                    }
+                ]
+            };
+
+            await UIHelper.mouseWheelSequence(wheelEventSquence);
+            // Make sure we scrolled some non-trivial amount.
+            shouldBeTrue('window.scrollY > 150');
+        }
+
+        async function scrollTest()
+        {
+            await testEventSequence();
+            finishJSTest();
+        }
+
+        window.addEventListener('load', () => {
+            setTimeout(scrollTest, 0);
+        }, false);
+    </script>
+</head>
+<body>
+    <script src="../../../resources/js-test-post.js"></script>
+</body>
+</html>
</ins></span></pre></div>
<a id="trunkSourceWTFChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/ChangeLog (285786 => 285787)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/ChangeLog       2021-11-14 05:05:59 UTC (rev 285786)
+++ trunk/Source/WTF/ChangeLog  2021-11-14 07:37:36 UTC (rev 285787)
</span><span class="lines">@@ -1,3 +1,15 @@
</span><ins>+2021-11-13  Simon Fraser  <simon.fraser@apple.com>
+
+        Run a ScrollAnimationMomentum for the momentum phase of a scroll
+        https://bugs.webkit.org/show_bug.cgi?id=232897
+
+        Reviewed by Tim Horton.
+
+        Set the MomentumScrollingAnimatorEnabled internal setting to off by default
+        while we bring up tests.
+
+        * Scripts/Preferences/WebPreferencesInternal.yaml:
+
</ins><span class="cx"> 2021-11-12  Chris Dumez  <cdumez@apple.com>
</span><span class="cx"> 
</span><span class="cx">         Disable MathML when in Captive Portal Mode
</span></span></pre></div>
<a id="trunkSourceWTFScriptsPreferencesWebPreferencesInternalyaml"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/Scripts/Preferences/WebPreferencesInternal.yaml (285786 => 285787)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/Scripts/Preferences/WebPreferencesInternal.yaml 2021-11-14 05:05:59 UTC (rev 285786)
+++ trunk/Source/WTF/Scripts/Preferences/WebPreferencesInternal.yaml    2021-11-14 07:37:36 UTC (rev 285787)
</span><span class="lines">@@ -542,13 +542,10 @@
</span><span class="cx">   humanReadableDescription: "Drive momentum scrolling via an internal animator instead of using momentum events"
</span><span class="cx">   defaultValue:
</span><span class="cx">     WebKitLegacy:
</span><del>-      "PLATFORM(MAC)": true
</del><span class="cx">       default: false
</span><span class="cx">     WebKit:
</span><del>-      "PLATFORM(MAC)": true
</del><span class="cx">       default: false
</span><span class="cx">     WebCore:
</span><del>-      "PLATFORM(MAC)": true
</del><span class="cx">       default: false
</span><span class="cx"> 
</span><span class="cx"> MouseEventsSimulationEnabled:
</span></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (285786 => 285787)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog   2021-11-14 05:05:59 UTC (rev 285786)
+++ trunk/Source/WebCore/ChangeLog      2021-11-14 07:37:36 UTC (rev 285787)
</span><span class="lines">@@ -1,3 +1,53 @@
</span><ins>+2021-11-13  Simon Fraser  <simon.fraser@apple.com>
+
+        Run a ScrollAnimationMomentum for the momentum phase of a scroll
+        https://bugs.webkit.org/show_bug.cgi?id=232897
+
+        Reviewed by Tim Horton.
+        
+        Run an animation for the momentum phase of a scroll, rather than scrolling in response
+        to wheel events, because it produces a smoother result with fewer dropped frames.
+        
+        We re-use ScrollAnimationMomentum which is already used for scroll snap, but have to
+        allow it to yield unclamped coordinates, since using it for momentum can result in
+        rubber-banding.
+        
+        When we get the momentum "began" event, we start the ScrollAnimationMomentum
+        using initial velocity computed from WheelEventDeltaFilter. ScrollingEffectsController then
+        ignores the reset of the momentum "changed" events.
+
+        We have to stop this animation when we receive a "begin" or "mayBegin" event, since
+        this indicates that the user has put fingers down on the trackpad.
+        
+        Rename m_dragEndedScrollingVelocity to m_scrollingVelocityForScrollSnap for clarity
+        (at some point we should merge this with m_scrollingVelocityForMomentumAnimation).
+
+        Tests: fast/scrolling/mac/momentum-animator-in-overflow.html
+               fast/scrolling/mac/momentum-animator.html
+
+        * page/WheelEventDeltaFilter.cpp:
+        (WebCore::WheelEventDeltaFilter::shouldApplyFilteringForEvent):
+        * page/WheelEventDeltaFilter.h:
+        * platform/PlatformWheelEvent.cpp:
+        (WebCore::operator<<):
+        * platform/ScrollAnimationMomentum.cpp:
+        (WebCore::ScrollAnimationMomentum::startAnimatedScrollWithInitialVelocity):
+        (WebCore::ScrollAnimationMomentum::stop):
+        (WebCore::ScrollAnimationMomentum::serviceAnimation):
+        * platform/ScrollAnimationMomentum.h:
+        * platform/ScrollingEffectsController.cpp:
+        (WebCore::ScrollingEffectsController::ScrollingEffectsController):
+        (WebCore::ScrollingEffectsController::stopAnimatedNonRubberbandingScroll):
+        (WebCore::ScrollingEffectsController::startMomentumScrollWithInitialVelocity):
+        * platform/ScrollingEffectsController.h:
+        (WebCore::ScrollingEffectsController::momentumScrollingAnimatorEnabled const):
+        * platform/mac/ScrollingEffectsController.mm:
+        (WebCore::phaseToString):
+        (WebCore::ScrollingEffectsController::handleWheelEvent):
+        (WebCore::ScrollingEffectsController::startRubberBandAnimation):
+        (WebCore::ScrollingEffectsController::startRubberBandAnimationIfNecessary):
+        (WebCore::ScrollingEffectsController::processWheelEventForScrollSnap):
+
</ins><span class="cx"> 2021-11-13  Tim Horton  <timothy_horton@apple.com>
</span><span class="cx"> 
</span><span class="cx">         Clean up IOKit SPI headers
</span></span></pre></div>
<a id="trunkSourceWebCorepageWheelEventDeltaFiltercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/WheelEventDeltaFilter.cpp (285786 => 285787)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/WheelEventDeltaFilter.cpp      2021-11-14 05:05:59 UTC (rev 285786)
+++ trunk/Source/WebCore/page/WheelEventDeltaFilter.cpp 2021-11-14 07:37:36 UTC (rev 285787)
</span><span class="lines">@@ -54,6 +54,7 @@
</span><span class="cx"> {
</span><span class="cx"> #if ENABLE(KINETIC_SCROLLING)
</span><span class="cx">     // Maybe it's a per-platform decision about which event phases get filtered. Ideally we'd filter momentum events too (but that breaks some diagonal scrolling cases).
</span><ins>+    // Also, ScrollingEffectsController should ask WheelEventDeltaFilter directly for the filtered velocity, rather than sending the velocity via PlatformWheelEvent.
</ins><span class="cx">     auto phase = event.phase();
</span><span class="cx">     return phase == PlatformWheelEventPhase::Began || phase == PlatformWheelEventPhase::Changed;
</span><span class="cx"> #else
</span></span></pre></div>
<a id="trunkSourceWebCorepageWheelEventDeltaFilterh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/WheelEventDeltaFilter.h (285786 => 285787)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/WheelEventDeltaFilter.h        2021-11-14 05:05:59 UTC (rev 285786)
+++ trunk/Source/WebCore/page/WheelEventDeltaFilter.h   2021-11-14 07:37:36 UTC (rev 285787)
</span><span class="lines">@@ -62,7 +62,7 @@
</span><span class="cx"> 
</span><span class="cx"> private:
</span><span class="cx">     std::optional<ScrollEventAxis> dominantAxis() const;
</span><del>-    
</del><ins>+
</ins><span class="cx">     void reset();
</span><span class="cx">     void updateWithDelta(FloatSize);
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformPlatformWheelEventcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/PlatformWheelEvent.cpp (285786 => 285787)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/PlatformWheelEvent.cpp     2021-11-14 05:05:59 UTC (rev 285786)
+++ trunk/Source/WebCore/platform/PlatformWheelEvent.cpp        2021-11-14 07:37:36 UTC (rev 285787)
</span><span class="lines">@@ -108,6 +108,7 @@
</span><span class="cx"> #if ENABLE(KINETIC_SCROLLING)
</span><span class="cx">     ts << " phase \"" << event.phase() << "\" momentum phase \"" << event.momentumPhase() << "\"";
</span><span class="cx"> #endif
</span><ins>+    ts << " velocity " << event.scrollingVelocity();
</ins><span class="cx"> 
</span><span class="cx">     return ts;
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformScrollAnimationMomentumcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/ScrollAnimationMomentum.cpp (285786 => 285787)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/ScrollAnimationMomentum.cpp        2021-11-14 05:05:59 UTC (rev 285786)
+++ trunk/Source/WebCore/platform/ScrollAnimationMomentum.cpp   2021-11-14 07:37:36 UTC (rev 285787)
</span><span class="lines">@@ -55,6 +55,9 @@
</span><span class="cx">         }
</span><span class="cx">     }
</span><span class="cx"> 
</span><ins>+    LOG(ScrollAnimations, "ScrollAnimationMomentum::startAnimatedScrollWithInitialVelocity: velocity %.2f,%.2f from %.2f,%.2f to %.2f,%.2f",
+        initialVelocity.width(), initialVelocity.height(), initialOffset.x(), initialOffset.y(), destinationScrollOffset.x(), destinationScrollOffset.y());
+
</ins><span class="cx">     if (destinationScrollOffset == initialOffset) {
</span><span class="cx">         m_momentumCalculator = nullptr;
</span><span class="cx">         return false;
</span><span class="lines">@@ -81,6 +84,8 @@
</span><span class="cx"> 
</span><span class="cx"> void ScrollAnimationMomentum::stop()
</span><span class="cx"> {
</span><ins>+    LOG(ScrollAnimations, "ScrollAnimationMomentum::stop: offset %.2f,%.2f", m_currentOffset.x(), m_currentOffset.y());
+
</ins><span class="cx">     m_momentumCalculator = nullptr;
</span><span class="cx">     ScrollAnimation::stop();
</span><span class="cx"> }
</span><span class="lines">@@ -98,6 +103,8 @@
</span><span class="cx"> 
</span><span class="cx">     m_client.scrollAnimationDidUpdate(*this, m_currentOffset);
</span><span class="cx"> 
</span><ins>+    LOG(ScrollAnimations, "ScrollAnimationMomentum::serviceAnimation: offset %.2f,%.2f complete %d", m_currentOffset.x(), m_currentOffset.y(), animationComplete);
+
</ins><span class="cx">     if (animationComplete)
</span><span class="cx">         didEnd();
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformScrollAnimationMomentumh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/ScrollAnimationMomentum.h (285786 => 285787)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/ScrollAnimationMomentum.h  2021-11-14 05:05:59 UTC (rev 285786)
+++ trunk/Source/WebCore/platform/ScrollAnimationMomentum.h     2021-11-14 07:37:36 UTC (rev 285787)
</span><span class="lines">@@ -42,6 +42,7 @@
</span><span class="cx">     void updateScrollExtents() final;
</span><span class="cx"> 
</span><span class="cx"> private:
</span><ins>+    ScrollClamping clamping() const final { return ScrollClamping::Unclamped; }
</ins><span class="cx">     String debugDescription() const final;
</span><span class="cx"> 
</span><span class="cx">     std::unique_ptr<ScrollingMomentumCalculator> m_momentumCalculator;
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformScrollingEffectsControllercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/ScrollingEffectsController.cpp (285786 => 285787)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/ScrollingEffectsController.cpp     2021-11-14 05:05:59 UTC (rev 285786)
+++ trunk/Source/WebCore/platform/ScrollingEffectsController.cpp        2021-11-14 07:37:36 UTC (rev 285787)
</span><span class="lines">@@ -49,6 +49,7 @@
</span><span class="cx"> 
</span><span class="cx"> ScrollingEffectsController::ScrollingEffectsController(ScrollingEffectsControllerClient& client)
</span><span class="cx">     : m_client(client)
</span><ins>+    , m_momentumScrollingAnimatorEnabled(client.momentumScrollingAnimatorEnabled())
</ins><span class="cx"> {
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -131,6 +132,30 @@
</span><span class="cx">     return false;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void ScrollingEffectsController::stopAnimatedNonRubberbandingScroll()
+{
+    LOG_WITH_STREAM(ScrollAnimations, stream << "ScrollingEffectsController " << this << " stopAnimatedNonRubberbandingScroll");
+
+    if (!m_currentAnimation)
+        return;
+
+#if HAVE(RUBBER_BANDING)
+    if (is<ScrollAnimationRubberBand>(m_currentAnimation))
+        return;
+#endif
+
+    if (is<ScrollAnimationMomentum>(m_currentAnimation)) {
+        // If the animation is currently triggering rubberbanding, let it run. Ideally we'd check if the animation will cause rubberbanding at any time in the future.
+        auto currentOffset = m_currentAnimation->currentOffset();
+        auto extents = m_client.scrollExtents();
+        auto constrainedOffset = currentOffset.constrainedBetween(extents.minimumScrollOffset(), extents.maximumScrollOffset());
+        if (currentOffset != constrainedOffset)
+            return;
+    }
+
+    m_currentAnimation->stop();
+}
+
</ins><span class="cx"> void ScrollingEffectsController::stopAnimatedScroll()
</span><span class="cx"> {
</span><span class="cx">     LOG_WITH_STREAM(ScrollAnimations, stream << "ScrollingEffectsController " << this << " stopAnimatedScroll");
</span><span class="lines">@@ -151,7 +176,7 @@
</span><span class="cx">         m_currentAnimation = makeUnique<ScrollAnimationMomentum>(*this);
</span><span class="cx"> 
</span><span class="cx">     bool started = downcast<ScrollAnimationMomentum>(*m_currentAnimation).startAnimatedScrollWithInitialVelocity(initialOffset, initialVelocity, initialDelta, destinationModifier);
</span><del>-    LOG_WITH_STREAM(ScrollAnimations, stream << "ScrollingEffectsController::startMomentumScrollWithInitialVelocity() - animation " << *m_currentAnimation << " started " << started);
</del><ins>+    LOG_WITH_STREAM(ScrollAnimations, stream << "ScrollingEffectsController::startMomentumScrollWithInitialVelocity() - animation " << *m_currentAnimation << " initialVelocity " << initialVelocity << " initialDelta " << initialDelta << " started " << started);
</ins><span class="cx">     return started;
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformScrollingEffectsControllerh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/ScrollingEffectsController.h (285786 => 285787)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/ScrollingEffectsController.h       2021-11-14 05:05:59 UTC (rev 285786)
+++ trunk/Source/WebCore/platform/ScrollingEffectsController.h  2021-11-14 07:37:36 UTC (rev 285787)
</span><span class="lines">@@ -138,7 +138,9 @@
</span><span class="cx">     bool startAnimatedScrollToDestination(FloatPoint startOffset, FloatPoint destinationOffset);
</span><span class="cx">     bool retargetAnimatedScroll(FloatPoint newDestinationOffset);
</span><span class="cx">     bool retargetAnimatedScrollBy(FloatSize);
</span><ins>+
</ins><span class="cx">     void stopAnimatedScroll();
</span><ins>+    void stopAnimatedNonRubberbandingScroll();
</ins><span class="cx"> 
</span><span class="cx">     void stopKeyboardScrolling();
</span><span class="cx"> 
</span><span class="lines">@@ -221,6 +223,8 @@
</span><span class="cx"> 
</span><span class="cx">     void startOrStopAnimationCallbacks();
</span><span class="cx"> 
</span><ins>+    bool momentumScrollingAnimatorEnabled() const { return m_momentumScrollingAnimatorEnabled; }
+
</ins><span class="cx">     // ScrollAnimationClient
</span><span class="cx">     void scrollAnimationDidUpdate(ScrollAnimation&, const FloatPoint& /* currentOffset */) final;
</span><span class="cx">     void scrollAnimationWillStart(ScrollAnimation&) final;
</span><span class="lines">@@ -248,6 +252,7 @@
</span><span class="cx">     bool m_isAnimatingScrollSnap { false };
</span><span class="cx">     bool m_isAnimatingKeyboardScrolling { false };
</span><span class="cx">     bool m_inScrollGesture { false };
</span><ins>+    bool m_momentumScrollingAnimatorEnabled { false };
</ins><span class="cx"> 
</span><span class="cx"> #if PLATFORM(MAC)
</span><span class="cx">     WallTime m_lastMomentumScrollTimestamp;
</span><span class="lines">@@ -255,11 +260,16 @@
</span><span class="cx">     FloatSize m_stretchScrollForce;
</span><span class="cx">     FloatSize m_momentumVelocity;
</span><span class="cx"> 
</span><ins>+    FloatSize m_scrollingVelocityForMomentumAnimation; // Do we need both this, m_scrollingVelocityForScrollSnap and m_momentumVelocity?
+    FloatSize m_scrollingVelocityForScrollSnap;
+#if !LOG_DISABLED
+    FloatPoint m_eventDrivenScrollOffset;
+#endif
+
</ins><span class="cx">     bool m_momentumScrollInProgress { false };
</span><span class="cx">     bool m_ignoreMomentumScrolls { false };
</span><span class="cx">     bool m_isRubberBanding { false };
</span><span class="cx"> 
</span><del>-    FloatSize m_dragEndedScrollingVelocity;
</del><span class="cx">     std::unique_ptr<ScrollingEffectsControllerTimer> m_statelessSnapTransitionTimer;
</span><span class="cx"> 
</span><span class="cx"> #if HAVE(RUBBER_BANDING)
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformmacScrollingEffectsControllermm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/mac/ScrollingEffectsController.mm (285786 => 285787)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/mac/ScrollingEffectsController.mm  2021-11-14 05:05:59 UTC (rev 285786)
+++ trunk/Source/WebCore/platform/mac/ScrollingEffectsController.mm     2021-11-14 07:37:36 UTC (rev 285787)
</span><span class="lines">@@ -30,6 +30,7 @@
</span><span class="cx"> #import "PlatformWheelEvent.h"
</span><span class="cx"> #import "ScrollAnimationRubberBand.h"
</span><span class="cx"> #import "ScrollExtents.h"
</span><ins>+#import "WheelEventDeltaFilter.h"
</ins><span class="cx"> #import "WheelEventTestMonitor.h"
</span><span class="cx"> #import <pal/spi/mac/NSScrollViewSPI.h>
</span><span class="cx"> #import <sys/sysctl.h>
</span><span class="lines">@@ -110,15 +111,44 @@
</span><span class="cx">     return ScrollableArea::targetSideForScrollDelta(delta, dominantAxis);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+#if !LOG_DISABLED
+static const char* phaseToString(PlatformWheelEventPhase phase)
+{
+    switch (phase) {
+    case PlatformWheelEventPhase::None: return "none";
+    case PlatformWheelEventPhase::Began: return "began";
+    case PlatformWheelEventPhase::Stationary: return "stationary";
+    case PlatformWheelEventPhase::Changed: return "changed";
+    case PlatformWheelEventPhase::Ended: return "ended";
+    case PlatformWheelEventPhase::Cancelled: return "cancelled";
+    case PlatformWheelEventPhase::MayBegin: return "mayBegin";
+    }
+    return "";
+}
+#endif
+
</ins><span class="cx"> bool ScrollingEffectsController::handleWheelEvent(const PlatformWheelEvent& wheelEvent)
</span><span class="cx"> {
</span><ins>+    if (WheelEventDeltaFilter::shouldApplyFilteringForEvent(wheelEvent))
+        m_scrollingVelocityForMomentumAnimation = -wheelEvent.scrollingVelocity(); // Note that event delta is reversed from scroll direction.
+
</ins><span class="cx">     if (processWheelEventForScrollSnap(wheelEvent))
</span><span class="cx">         return true;
</span><span class="cx"> 
</span><del>-    if (wheelEvent.phase() == PlatformWheelEventPhase::MayBegin || wheelEvent.phase() == PlatformWheelEventPhase::Cancelled)
</del><ins>+    if (wheelEvent.phase() == PlatformWheelEventPhase::MayBegin || wheelEvent.phase() == PlatformWheelEventPhase::Cancelled) {
+        if (momentumScrollingAnimatorEnabled()) {
+            LOG(ScrollAnimations, "Event (%s, %s): stopping animated scroll", phaseToString(wheelEvent.phase()), phaseToString(wheelEvent.momentumPhase()));
+            stopAnimatedScroll();
+        }
</ins><span class="cx">         return false;
</span><ins>+    }
</ins><span class="cx"> 
</span><span class="cx">     if (wheelEvent.phase() == PlatformWheelEventPhase::Began) {
</span><ins>+        if (momentumScrollingAnimatorEnabled()) {
+            LOG(ScrollAnimations, "Event (%s, %s): stopping animated scroll", phaseToString(wheelEvent.phase()), phaseToString(wheelEvent.momentumPhase()));
+            stopAnimatedScroll();
+        }
+
</ins><span class="cx">         // FIXME: Trying to decide if a gesture is horizontal or vertical at the "began" phase is very error-prone.
</span><span class="cx">         auto horizontalSide = ScrollableArea::targetSideForScrollDelta(-wheelEvent.delta(), ScrollEventAxis::Horizontal);
</span><span class="cx">         if (horizontalSide && m_client.isPinnedOnSide(*horizontalSide) && !shouldRubberBandOnSide(*horizontalSide))
</span><span class="lines">@@ -177,9 +207,25 @@
</span><span class="cx">     delta = deltaAlignedToDominantAxis(delta);
</span><span class="cx"> 
</span><span class="cx">     auto momentumPhase = wheelEvent.momentumPhase();
</span><del>-    if (!m_momentumScrollInProgress && (momentumPhase == PlatformWheelEventPhase::Began || momentumPhase == PlatformWheelEventPhase::Changed))
</del><ins>+    if (!m_momentumScrollInProgress && (momentumPhase == PlatformWheelEventPhase::Began || momentumPhase == PlatformWheelEventPhase::Changed)) {
</ins><span class="cx">         m_momentumScrollInProgress = true;
</span><ins>+        if (momentumScrollingAnimatorEnabled()) {
+            startMomentumScrollWithInitialVelocity(m_client.scrollOffset(), m_scrollingVelocityForMomentumAnimation, -wheelEvent.delta(), [](const FloatPoint& targetOffset) { return targetOffset; });
+#if !LOG_DISABLED
+            m_eventDrivenScrollOffset = m_client.scrollOffset();
+#endif
+        }
+    }
</ins><span class="cx"> 
</span><ins>+    if (momentumPhase == PlatformWheelEventPhase::Changed && momentumScrollingAnimatorEnabled()) {
+#if !LOG_DISABLED
+        m_eventDrivenScrollOffset -= wheelEvent.delta();
+#endif
+        LOG(ScrollAnimations, "Event (%s, %s): ignoring - would have scrolled to %.2f,%.2f", phaseToString(wheelEvent.phase()), phaseToString(wheelEvent.momentumPhase()),
+            m_eventDrivenScrollOffset.x(), m_eventDrivenScrollOffset.y());
+        return true;
+    }
+
</ins><span class="cx">     bool shouldStretch = false;
</span><span class="cx">     auto timeDelta = wheelEvent.timestamp() - m_lastMomentumScrollTimestamp;
</span><span class="cx">     if (m_inScrollGesture || m_momentumScrollInProgress) {
</span><span class="lines">@@ -393,6 +439,11 @@
</span><span class="cx"> 
</span><span class="cx"> bool ScrollingEffectsController::startRubberBandAnimation(const FloatPoint& targetOffset, const FloatSize& initialVelocity, const FloatSize& initialOverscroll)
</span><span class="cx"> {
</span><ins>+    if (is<ScrollAnimationMomentum>(m_currentAnimation) && m_currentAnimation->isActive()) {
+        LOG_WITH_STREAM(ScrollAnimations, stream << "ScrollingEffectsController::startRubberBandAnimation() - momentum animation is present");
+        return false;
+    }
+
</ins><span class="cx">     if (m_currentAnimation)
</span><span class="cx">         m_currentAnimation->stop();
</span><span class="cx"> 
</span><span class="lines">@@ -439,9 +490,6 @@
</span><span class="cx">     bool willOverscroll = targetOffset != contrainedOffset;
</span><span class="cx"> 
</span><span class="cx">     auto stretchAmount = m_client.stretchAmount();
</span><del>-
-    LOG_WITH_STREAM(ScrollAnimations, stream << "ScrollingEffectsController::startRubberBandAnimationIfNecessary() - rubberBandAnimationRunning " << m_isAnimatingRubberBand << " stretchAmount " << stretchAmount << " targetOffset " << targetOffset);
-
</del><span class="cx">     if (stretchAmount.isZero() && !willOverscroll)
</span><span class="cx">         return;
</span><span class="cx"> 
</span><span class="lines">@@ -459,6 +507,7 @@
</span><span class="cx">     if (!m_client.allowsVerticalScrolling())
</span><span class="cx">         initialVelocity.setHeight(0);
</span><span class="cx"> 
</span><ins>+    LOG_WITH_STREAM(ScrollAnimations, stream << "ScrollingEffectsController::startRubberBandAnimationIfNecessary() - rubberBandAnimationRunning " << m_isAnimatingRubberBand << " stretchAmount " << stretchAmount << " contrainedOffset " << contrainedOffset << " initialVelocity " << initialVelocity);
</ins><span class="cx">     startRubberBandAnimation(contrainedOffset, initialVelocity, stretchAmount);
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -635,7 +684,7 @@
</span><span class="cx">     case WheelEventStatus::UserScrolling:
</span><span class="cx">         stopScrollSnapAnimation();
</span><span class="cx">         m_scrollSnapState->transitionToUserInteractionState();
</span><del>-        m_dragEndedScrollingVelocity = -wheelEvent.scrollingVelocity();
</del><ins>+        m_scrollingVelocityForScrollSnap = -wheelEvent.scrollingVelocity();
</ins><span class="cx">         break;
</span><span class="cx">     case WheelEventStatus::UserScrollEnd:
</span><span class="cx">         if (m_scrollSnapState->transitionToSnapAnimationState(m_client.scrollExtents(), m_client.pageScaleFactor(), m_client.scrollOffset()))
</span><span class="lines">@@ -642,11 +691,11 @@
</span><span class="cx">             startScrollSnapAnimation();
</span><span class="cx">         break;
</span><span class="cx">     case WheelEventStatus::MomentumScrollBegin:
</span><del>-        if (m_scrollSnapState->transitionToGlideAnimationState(m_client.scrollExtents(), m_client.pageScaleFactor(), m_client.scrollOffset(), m_dragEndedScrollingVelocity, FloatSize(-wheelEvent.deltaX(), -wheelEvent.deltaY()))) {
</del><ins>+        if (m_scrollSnapState->transitionToGlideAnimationState(m_client.scrollExtents(), m_client.pageScaleFactor(), m_client.scrollOffset(), m_scrollingVelocityForScrollSnap, -wheelEvent.delta())) {
</ins><span class="cx">             startScrollSnapAnimation();
</span><span class="cx">             isMomentumScrolling = true;
</span><span class="cx">         }
</span><del>-        m_dragEndedScrollingVelocity = { };
</del><ins>+        m_scrollingVelocityForScrollSnap = { };
</ins><span class="cx">         break;
</span><span class="cx">     case WheelEventStatus::MomentumScrolling:
</span><span class="cx">     case WheelEventStatus::MomentumScrollEnd:
</span></span></pre>
</div>
</div>

</body>
</html>