Skip to content

Commit

Permalink
Set mApzScrollPos in the case of ScrollOrigin::AnchorAdjustment.
Browse files Browse the repository at this point in the history
Differential Revision: https://phabricator.services.mozilla.com/D198512

bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1874551
gecko-commit: 875fd9f694c9829bc4480a38e4d6bdd7b8e44a7c
gecko-reviewers: botond
  • Loading branch information
hiikezoe authored and moz-wptsync-bot committed Jan 18, 2024
1 parent 76f2630 commit 0c7542f
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions css/css-scroll-anchoring/adjustment-followed-by-scrollBy.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<!DOCTYPE html>
<html>
<meta name="viewport" content="width=device-width">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<link rel="author" title="Mozilla" href="https://mozilla.org">
<link rel="help" href="https://drafts.csswg.org/css-scroll-anchoring/">
<link rel="help" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1874551">
<style>
div {
height: round(20vh, 1px);
}
</style>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div id="center" style="height: 100px; background-color: blue;"></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<script>
promise_test(async t => {
assert_equals(window.scrollY, 0);

// Center an element.
center.scrollIntoView({ block: "center" }, { behavior: "instant" });
await new Promise(resolve => window.addEventListener("scroll", resolve));

const originalPosition = center.getBoundingClientRect().top;

// Given that now the element is centered, one of div elements above the
// centered element is used as the scroll anchor node. Hide two div elements,
// the first div and the div element just above the centered one to move the
// anchor node, thus it will trigger scroll anchoring adjustment.
center.previousElementSibling.style.display = "none";
document.querySelectorAll("div")[0].style.display = "none";

// And adjust the scroll position where the centered element is still
// positioned at the center of the scroll container.
window.scrollBy(0, center.getBoundingClientRect().top - originalPosition);
await new Promise(resolve => window.addEventListener("scroll", resolve));

const centeredPosition = center.getBoundingClientRect().top;

// Now try to scrollIntoView({ block: "center" }) and make sure the position
// is unchanged.
center.scrollIntoView({ block: "center" }, { behavior: "instant" });

// Wait two frames to be able to scroll if it's possible.
await new Promise(resolve => requestAnimationFrame(resolve));
await new Promise(resolve => requestAnimationFrame(resolve));

assert_equals(centeredPosition, center.getBoundingClientRect().top);
}, "Scroll anchoring followed by scrollBy call");
</script>
</html>

0 comments on commit 0c7542f

Please sign in to comment.