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
Scroll snap sometimes jumps back to the wrong place on stevejobsarchi…
…ve.com https://bugs.webkit.org/show_bug.cgi?id=255492 rdar://107885376 Reviewed by Wenson Hsieh. 259696@main added some logic that attempts to re-snap after layout when multiple boxes were snapped, adding a `m_currentlySnappedBoxes` member to `ScrollSnapAnimatorState`. However, `m_currentlySnappedBoxes` was only updated in the `resnapAfterLayout` code path, not when scrolling moved you to a new snap point. That resulted in `resnapAfterLayout` sometimes returning you to a stale location if you'd scrolled to a new snap point since the last time `resnapAfterLayout` was run, especially when hitting the "multiple boxes were snapped" clause. It's troublesome to have both `m_currentlySnappedBoxes` and a `snapTargetID` in each SnapOffset (a future patch will clean this up). But for now, ensure that `m_currentlySnappedBoxes` is updated on each scroll-related snap as well as resnapping after layout. * LayoutTests/css3/scroll-snap/resnap-after-layout-expected.txt: Added. * LayoutTests/css3/scroll-snap/resnap-after-layout.html: Added. * LayoutTests/platform/gtk/TestExpectations: * LayoutTests/platform/ios-wk2/TestExpectations: * LayoutTests/platform/wpe/TestExpectations: * Source/WebCore/platform/ScrollSnapAnimatorState.cpp: (WebCore::ScrollSnapAnimatorState::setActiveSnapIndexForAxis): (WebCore::ScrollSnapAnimatorState::updateCurrentlySnappedBoxes): (WebCore::chooseBoxToResnapTo): (WebCore::ScrollSnapAnimatorState::resnapAfterLayout): (WebCore::ScrollSnapAnimatorState::setNearestScrollSnapIndexForAxisAndOffsetInternal): (WebCore::ScrollSnapAnimatorState::setNearestScrollSnapIndexForOffset): (WebCore::ScrollSnapAnimatorState::chooseBoxToResnapTo const): Deleted. (WebCore::ScrollSnapAnimatorState::setNearestScrollSnapIndexForAxisAndOffset): Deleted. * Source/WebCore/platform/ScrollSnapAnimatorState.h: Some functions can be private. (WebCore::ScrollSnapAnimatorState::setActiveSnapIndexForAxisInternal): The "internal" implies that it doesn't update m_currentlySnappedBoxes. (WebCore::ScrollSnapAnimatorState::setActiveSnapIndexForAxis): Deleted. * Source/WebCore/platform/ScrollableArea.cpp: (WebCore::ScrollableArea::resnapAfterLayout): Improved logging. (WebCore::ScrollableArea::doPostThumbMoveSnapping): Improved logging. Canonical link: https://commits.webkit.org/263097@main
- Loading branch information
Showing
8 changed files
with
163 additions
and
41 deletions.
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
LayoutTests/css3/scroll-snap/resnap-after-layout-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,6 @@ | ||
layout trigger | ||
PASS window.scrollY is 1200 | ||
PASS successfullyParsed is true | ||
|
||
TEST COMPLETE | ||
|
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,90 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<style> | ||
:root { | ||
scroll-snap-type: block mandatory; | ||
font-size: 24pt; | ||
} | ||
|
||
* { | ||
box-sizing: border-box; | ||
} | ||
|
||
html, body { | ||
width: 100%; | ||
height: 100%; | ||
} | ||
|
||
body { | ||
margin: 0; | ||
background-image: repeating-linear-gradient(transparent, silver 400px); | ||
} | ||
|
||
.target { | ||
scroll-snap-align: start; | ||
border: 1px solid black; | ||
} | ||
|
||
body > div { | ||
padding: 100px; | ||
text-align: center; | ||
color: white; | ||
width: 80%; | ||
height: 100%; | ||
} | ||
|
||
.multiple > div { | ||
height: 100%; | ||
width: 50%; | ||
float: left; | ||
} | ||
|
||
body.changed .layout-trigger { | ||
height: 20px; | ||
} | ||
</style> | ||
<script src="../../resources/js-test-pre.js"></script> | ||
<script src="../../resources/ui-helper.js"></script> | ||
<script> | ||
jsTestIsAsync = true; | ||
|
||
async function startTest() | ||
{ | ||
// Scroll to first "multiple" snap point at 700. | ||
await UIHelper.mouseWheelScrollAt(100, 100, 0, -10, 0, -40); | ||
forceLayout(); | ||
|
||
// Scroll to second "single" snap point at 1200. | ||
await UIHelper.mouseWheelScrollAt(100, 100, 0, -10, 0, -40); | ||
forceLayout(); | ||
|
||
await UIHelper.renderingUpdate(); | ||
shouldBe('window.scrollY', '1200'); | ||
|
||
finishJSTest(); | ||
} | ||
|
||
function forceLayout() | ||
{ | ||
document.body.classList.toggle('changed'); | ||
document.body.offsetHeight; | ||
} | ||
|
||
window.addEventListener('load', () => { | ||
setTimeout(startTest, 0); | ||
}, false); | ||
</script> | ||
</head> | ||
<body> | ||
<div class="target" style='background-color: red'></div> | ||
<div class="multiple" style='background-color: orange'> | ||
<div class="target" style='background-color: yellow'></div> | ||
<div class="target" style='background-color: fuchsia'></div> | ||
</div> | ||
<div class="target" style='background-color: green'></div> | ||
<div class="layout-trigger">layout trigger</div> | ||
<div id="console"></div> | ||
<script src="../../resources/js-test-post.js"></script> | ||
</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