Skip to content

Commit

Permalink
Bug 1780701 - Skip returning the snap target if the snap position is …
Browse files Browse the repository at this point in the history
…same as the scroll destination. r=botond

Depends on D152617

Differential Revision: https://phabricator.services.mozilla.com/D152618
  • Loading branch information
hiikezoe committed Jul 26, 2022
1 parent 287d08b commit 6cd2d7b
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 2 deletions.
70 changes: 70 additions & 0 deletions gfx/layers/apz/test/mochitest/helper_bug1780701.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Test that scroll snap wont't happen on zoomed content</title>
<script src="apz_test_utils.js"></script>
<script src="apz_test_native_event_utils.js"></script>
<script src="/tests/SimpleTest/paint_listener.js"></script>
<style>
body {
margin: 0;
}
html {
overflow-y: scroll;
scroll-snap-type: y proximity;
}
.snap {
width: 100vw;
height: 100vh;
background-color: blue;
position: absolute;
top: 200px;
scroll-snap-align: start;
}
</style>
</head>
<body>
<div class="snap"></div>
<div style="width: 100%; height: 500vh;"></div>
<script type="application/javascript">
async function test() {
let transformEndPromise = promiseTransformEnd();

// Use scrollToVisual() to scroll visual viewport.
SpecialPowers.DOMWindowUtils.scrollToVisual(
100, 400,
SpecialPowers.DOMWindowUtils.UPDATE_TYPE_MAIN_THREAD,
SpecialPowers.DOMWindowUtils.SCROLL_MODE_SMOOTH);

// Wait for the end of the scroll.
await transformEndPromise;
await waitToClearOutAnyPotentialScrolls();

const pageTop = visualViewport.pageTop;
const pageLeft = visualViewport.pageLeft;

let eventFired = false;
window.visualViewport.addEventListener("scroll", () => {
eventFired = true;
});

// Trigger a scroll snap, it should nothing.
SpecialPowers.wrap(document.documentElement).mozScrollSnap();

await waitToClearOutAnyPotentialScrolls();
ok(!eventFired, "No visual scroll should happen");

// Sanity checks to see whether the visual viewport hasn't been changed.
is(visualViewport.pageTop, pageTop);
is(visualViewport.pageLeft, pageLeft);
}

SpecialPowers.DOMWindowUtils.setResolutionAndScaleTo(10.0);
waitUntilApzStable()
.then(test)
.then(subtestDone, subtestFailed);
</script>
</body>
</html>
1 change: 1 addition & 0 deletions gfx/layers/apz/test/mochitest/test_group_scroll_snap.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
{"file": "helper_scroll_snap_not_resnap_during_scrollbar_dragging.html",
// Same as above helper_scroll_snap_not_resnap_during_scrollbar_dragging.html.
"prefs": [["layout.css.scroll-behavior.spring-constant", 1000]]},
{"file": "helper_bug1780701.html"}
];

if (isApzEnabled()) {
Expand Down
6 changes: 4 additions & 2 deletions layout/generic/ScrollSnap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,15 +366,17 @@ Maybe<SnapTarget> ScrollSnapUtils::GetSnapPointForDestination(
std::abs(aDestination.y - finalPos.mPosition.y) > proximityThreshold) {
finalPos.mPosition.y = aDestination.y;
} else if (aSnapInfo.mScrollSnapStrictnessY !=
StyleScrollSnapStrictness::None) {
StyleScrollSnapStrictness::None &&
aDestination.y != finalPos.mPosition.y) {
snapped = true;
}
if (aSnapInfo.mScrollSnapStrictnessX ==
StyleScrollSnapStrictness::Proximity &&
std::abs(aDestination.x - finalPos.mPosition.x) > proximityThreshold) {
finalPos.mPosition.x = aDestination.x;
} else if (aSnapInfo.mScrollSnapStrictnessX !=
StyleScrollSnapStrictness::None) {
StyleScrollSnapStrictness::None &&
aDestination.x != finalPos.mPosition.x) {
snapped = true;
}
return snapped ? Some(finalPos) : Nothing();
Expand Down

0 comments on commit 6cd2d7b

Please sign in to comment.