Skip to content

Commit 0af816b

Browse files
mrobinsonservo-wpt-sync
authored andcommitted
script: Prevent "scroll to fragment" from scrolling offscreen
Previously, the "scroll to fragment" operation could scroll past the end of the screen, because the scroll position was not clamped to viewport boundaries. Correct this by using the `Window::scroll()` method which handles this case. In addition, ensure that `Window`'s `current_viewport` member is initialized properly when it is created.
1 parent 0a75a01 commit 0af816b

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<!DOCTYPE html>
2+
<html style="writing-mode: vertical-lr;">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Fragment Navigation: inline start position should not scroll out of content range</title>
6+
<link rel="help" href="https://html.spec.whatwg.org/multipage/#scroll-to-the-fragment-identifier">
7+
<link rel="author" href="mailto:[email protected]" title="Martin Robinson">
8+
<script src="/resources/testharness.js"></script>
9+
<script src="/resources/testharnessreport.js"></script>
10+
</head>
11+
<body>
12+
<!-- When scrolling to this fragment the viewport inline position should not
13+
change because, it is already fully enclosed by the viewport and page width. -->
14+
<div id="test1" style="position: absolute; top: 5000px; left: 100px; height: 100px; width: 100px;"></div>
15+
<script>
16+
17+
var t = async_test("ScrollToFragment");
18+
t.step(() => {
19+
location.hash = "test1";
20+
setTimeout(t.step_func(() => {
21+
assert_true(window.scrollY > 0);
22+
assert_true(window.scrollY < 5000);
23+
assert_equals(window.scrollX, 0);
24+
t.done();
25+
}));
26+
});
27+
28+
</script>
29+
</body>
30+
</html>

0 commit comments

Comments
 (0)