Skip to content

Commit

Permalink
Bug 1861541 [wpt PR 42796] - Improve scroller loop for intersection o…
Browse files Browse the repository at this point in the history
…bserver scroll margin, a=testonly

Automatic update from web-platform-tests
Improve scroller loop for intersection observer scroll margin

Now if there are scroll margins, collect the intermediate scrollers
into a vector in RootAndTarget when walking the containing block
chain in RootAndTarget::ComputeRelationship() instead of walk the
containing block chain again in ClipToRoot(). For scroll margin,
ClipToRoot() now calls ApplyClip() in a loop instead of calling
itself recursively.

Bug: 1485750
Change-Id: I0be9ff83df91969c9253235e11387dbe48042a82
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4977999
Reviewed-by: Traian Captan <[email protected]>
Commit-Queue: Xianzhu Wang <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1218947}

--

wpt-commits: 8ffb3d9a7243e4d115f38b631dd87c50957e8115
wpt-pr: 42796
  • Loading branch information
wangxianzhu authored and moz-wptsync-bot committed Nov 19, 2023
1 parent a970a37 commit 2ec732a
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<!DOCTYPE html>
<meta name="viewport" content="width=device-width,initial-scale=1">
<link rel="help" href="https://www.w3.org/TR/intersection-observer/#dom-intersectionobserver-scrollmargin">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="./resources/intersection-observer-test-utils.js"></script>

<style>
#scroller { width: 100px; height: 100px; overflow: hidden; background-color: gray; position: absolute; }
#target { width: 50px; height: 50px; background-color: green; }
</style>

<div id=root>
<div id=scroller>
<div id=target></div>
</div>
</div>

<script>
let entries = [];

window.onload = function() {
runTestCycle(testIntersection, "Test scroll margin intersection");

const observer = new IntersectionObserver(
es => entries = entries.concat(es),
{
root: document.querySelector("#root"),
scrollMargin: "10px"
}
);
observer.observe(target);
};

function testIntersection() {
assert_equals(entries.length, 1, "IntersectionObserverEntryCount");
// Not insecting because root is not in the containing block chain of target.
assert_false(entries[0].isIntersecting, "isIntersecting");
}
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<!DOCTYPE html>
<meta name="viewport" content="width=device-width,initial-scale=1">
<link rel="help" href="https://www.w3.org/TR/intersection-observer/#dom-intersectionobserver-scrollmargin">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="./resources/intersection-observer-test-utils.js"></script>

<style>
#scroller { width: 100px; height: 100px; overflow: hidden; background-color: gray; border: 10px solid black; outline: 10px solid blue; }
#spacer { width: 50px; height: 100px; }
#target { width: 50px; height: 50px; background-color: green; }
</style>

<div id=scroller>
<div id=spacer></div>
<div id=target></div>
</div>

<script>
let entries = [];

window.onload = function() {
runTestCycle(testIntersection, "Test scroll margin intersection");

const observer = new IntersectionObserver(
es => entries = entries.concat(es),
{
scrollMargin: "10px"
}
);
observer.observe(target);
};

function testIntersection() {
assert_equals(entries.length, 1, "IntersectionObserverEntryCount");
assert_true(entries[0].isIntersecting, "isIntersecting");
assert_approx_equals(entries[0].intersectionRatio, 0.2, 0.001, "intersectionRatio");
}
</script>

0 comments on commit 2ec732a

Please sign in to comment.