Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[macOS] Scrolling with a physical mouse wheel should not always anima…
…te to the closest snap point https://bugs.webkit.org/show_bug.cgi?id=255493 rdar://107885426 Reviewed by Simon Fraser. When scrolling using a physical mouse wheel in a scroll snap container, WebKit's current scroll snap implementation handles each wheel event in a stateless manner, kicking off a scroll snap animation to the closest snap point if no other wheel event is observed after 750 ms. This can lead to some unintuitive behaviors when distances between scroll snap points are large, since the user may scroll for a single wheel tick expecting to advance to the next page, only for the scroll position to animate back to where they started. This patch improves this by treating a stream of discrete wheel events similarly to trackpad-based momentum scrolling, and animates to the appropriate snap point in the direction of scrolling; this also aligns our implementation more closely with both Gecko and Blink. See below for more details. Test: css3/scroll-snap/scroll-snap-discrete-wheel-event-in-mainframe.html * LayoutTests/css3/scroll-snap/scroll-snap-discrete-wheel-event-in-mainframe-expected.txt: Added. * LayoutTests/css3/scroll-snap/scroll-snap-discrete-wheel-event-in-mainframe.html: Added. Add a new layout test to exercise the change, in a mainframe (root) scroll snapping context. * LayoutTests/css3/scroll-snap/scroll-snap-wheel-event.html: Adjust an existing stateless scroll snapping test to exercise the change by lowering the scrolling tick count from 3 to 1. Without this change, this adjustment would've bumped us back to the original scroll position; after this change, we'll now animate to the next snap point. * LayoutTests/platform/glib/TestExpectations: * LayoutTests/platform/ios-wk2/TestExpectations: * LayoutTests/platform/mac-wk1/TestExpectations: Discrete wheel events on the root don't seem to trigger scroll snapping at all in WebKit1, both before and after this patch. I filed webkit.org/b/255498, to track that issue separately. * Source/WebCore/platform/ScrollingEffectsController.h: Maintain a LIFO queue of up to three discrete wheel event deltas, which we use to determine the user's intended scrolling direction after finishing a stream of discrete wheel events. * Source/WebCore/platform/mac/ScrollingEffectsController.mm: (WebCore::ScrollingEffectsController::stopAllTimers): (WebCore::toWheelEventStatus): (WebCore::operator<<): (WebCore::ScrollingEffectsController::scheduleDiscreteScrollSnap): (WebCore::ScrollingEffectsController::discreteSnapTransitionTimerFired): Rename "stateless" -> "discrete", to reflect the fact that the new implementation is now stateful by way of maintaining a queue of recent discrete wheel event deltas. Additionally, use `transitionToGlideAnimationState()` to kick off scroll snapping if the average wheel event delta is nonzero. (WebCore::ScrollingEffectsController::processWheelEventForScrollSnap): (WebCore::ScrollingEffectsController::scheduleStatelessScrollSnap): Deleted. Dramatically reduce the delay before firing the scroll snap timer for discrete wheel events, now that the purpose is no longer to wait for the user to manually scroll to the next page before snapping, but rather observe enough events to estimate the user's intended scrolling direction. (WebCore::ScrollingEffectsController::statelessSnapTransitionTimerFired): Deleted. Canonical link: https://commits.webkit.org/263071@main
- Loading branch information
Showing
8 changed files
with
135 additions
and
25 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
LayoutTests/css3/scroll-snap/scroll-snap-discrete-wheel-event-in-mainframe-expected.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
This test verifies that discrete wheel events trigger scroll snapping in the mainframe. | ||
To manually run the test, scroll using a physical mouse wheel and verify that a single scroll | ||
tick animates to the next snap point, and a second scroll tick should not trigger snapping (due | ||
to the content being too tall) | ||
|
||
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE". | ||
|
||
PASS pageYOffset became 600 | ||
PASS pageYOffset > 600 became true | ||
PASS pageYOffset < 1500 is true | ||
PASS successfullyParsed is true | ||
|
||
TEST COMPLETE | ||
|
65 changes: 65 additions & 0 deletions
65
LayoutTests/css3/scroll-snap/scroll-snap-discrete-wheel-event-in-mainframe.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<style> | ||
:root { | ||
scroll-snap-type: y mandatory; | ||
overflow-x: hidden; | ||
} | ||
|
||
body, html { | ||
width: 100%; | ||
height: 100%; | ||
margin: 0; | ||
} | ||
|
||
.snap { | ||
width: 100%; | ||
height: 100%; | ||
scroll-snap-align: start; | ||
} | ||
|
||
#extra-tall { | ||
height: 150%; | ||
} | ||
|
||
.output { | ||
color: white; | ||
position: fixed; | ||
top: 0; | ||
} | ||
</style> | ||
<script src="../../resources/js-test.js"></script> | ||
<script src="../../resources/ui-helper.js"></script> | ||
<script> | ||
jsTestIsAsync = true; | ||
|
||
addEventListener("load", async () => { | ||
description(`This test verifies that discrete wheel events trigger scroll snapping in the mainframe. | ||
To manually run the test, scroll using a physical mouse wheel and verify that a single scroll | ||
tick animates to the next snap point, and a second scroll tick should not trigger snapping (due | ||
to the content being too tall)`); | ||
|
||
if (!window.testRunner) | ||
return; | ||
|
||
await UIHelper.statelessMouseWheelScrollAt(100, 100, 0, -1); | ||
await shouldBecomeEqual("pageYOffset", "600"); | ||
await UIHelper.statelessMouseWheelScrollAt(200, 200, 0, -1); | ||
await shouldBecomeEqual("pageYOffset > 600", "true"); | ||
shouldBeTrue("pageYOffset < 1500"); | ||
|
||
finishJSTest(); | ||
}); | ||
</script> | ||
</head> | ||
<body> | ||
<div class="snap" id="first-container" style="background: #80475E"></div> | ||
<div class="snap" id="extra-tall" style="background: #CC5A71"></div> | ||
<div class="snap" style="background: #32228B"></div> | ||
<div class="output"> | ||
<pre id="description"></pre> | ||
<pre id="console"></pre> | ||
</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters