Skip to content

Commit cb60c18

Browse files
hiikezoemoz-wptsync-bot
authored andcommitted
Scroll visually to position:fixed element in ScrollFrameIntoView if necessary.
In the case of position:fixed frame, walking up the frame tree doesn't reach to the root scroll container, thus we need to invoke ScrollToVisual outside the walking up the tree loop. This commit has two independent tests, a web platform test and a mochitest. Unfortunately the web platform test doesn't work on Firefox, since WebDriver (GeckoDriver) doesn't support touch action yet. It works on Chrome. What the mochitest does is mostly equivalent with the web platform test, but with nsIDOMWindowUtils.setResolutionAndScaleTo and zoomToFocusedInput. Differential Revision: https://phabricator.services.mozilla.com/D236061 bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1943865 gecko-commit: 2249a06891096a52bef8c581f2181d933f21b4b3 gecko-reviewers: dlrobertson
1 parent bd0bfff commit cb60c18

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<meta name="viewport" content="width=device-width,initial-scale=1">
4+
<script src="/resources/testharness.js"></script>
5+
<script src="/resources/testharnessreport.js"></script>
6+
<script src="/resources/testdriver.js"></script>
7+
<script src="/resources/testdriver-actions.js"></script>
8+
<script src="/resources/testdriver-vendor.js"></script>
9+
<link rel="help" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1943865">
10+
<link rel="help" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1943053">
11+
<link rel="help" href="https://drafts.csswg.org/cssom-view/#perform-a-scroll">
12+
<style>
13+
body {
14+
margin: 0px;
15+
padding: 0px;
16+
}
17+
</style>
18+
<div id="anchor"></div>
19+
<div style="position: fixed; bottom: 0;">
20+
<div style="position: absolute; bottom: 0;">
21+
<input type="text" id="name" />
22+
</div>
23+
</div>
24+
<script>
25+
promise_test(async t => {
26+
assert_equals(window.scrollY, 0);
27+
assert_equals(visualViewport.scale, 1.0);
28+
assert_equals(visualViewport.pageTop, 0);
29+
30+
// Pinch zoom in this document.
31+
await new test_driver.Actions()
32+
.addPointer("finger1", "touch")
33+
.addPointer("finger2", "touch")
34+
.pointerMove(parseInt(window.innerWidth / 2),
35+
parseInt(window.innerHeight / 2),
36+
{origin: "viewport", sourceName: "finger1"})
37+
.pointerMove(parseInt(window.innerWidth / 2),
38+
parseInt(window.innerHeight / 2),
39+
{origin: "viewport", sourceName: "finger2"})
40+
.pointerDown({sourceName: "finger1"})
41+
.pointerDown({sourceName: "finger2"})
42+
.pointerMove(parseInt(window.innerWidth / 3),
43+
parseInt(window.innerHeight / 3),
44+
{origin: "viewport", sourceName: "finger1"})
45+
.pointerMove(parseInt(window.innerWidth / 3 * 2),
46+
parseInt(window.innerHeight / 3 * 2),
47+
{origin: "viewport", sourceName: "finger2"})
48+
.pointerUp({sourceName: "finger1"})
49+
.pointerUp({sourceName: "finger2"})
50+
.send();
51+
52+
assert_greater_than(visualViewport.scale, 1.0);
53+
54+
// Suppose that the pinch zoom-in gesture at the center of the document did
55+
// move the visual viewport offset.
56+
assert_greater_than(visualViewport.pageTop, 0);
57+
58+
// Move to zero offset of the visual viewport.
59+
let scrollPromise =
60+
new Promise(resolve => visualViewport.addEventListener("scroll", resolve));
61+
document.querySelector('#anchor').scrollIntoView({ behavior: "instant" });
62+
await scrollPromise;
63+
64+
assert_equals(visualViewport.pageTop, 0);
65+
66+
// Now trigger a scrollIntoView call to an element inside a position:fixed element.
67+
scrollPromise =
68+
new Promise(resolve => visualViewport.addEventListener("scroll", resolve));
69+
document.querySelector('#name').scrollIntoView({ behavior: "instant" });
70+
await scrollPromise;
71+
72+
assert_greater_than(visualViewport.pageTop, 0);
73+
}, "Element.scrollIntoView scrolls visually");
74+
</script>

0 commit comments

Comments
 (0)