blob: fea92d1da5700ee0b1888941737cec9fbf9e98be [file] [log] [blame] [edit]
<!DOCTYPE html>
<title>CSSOM View - scrollIntoView considers direction:rtl</title>
<meta charset="utf-8">
<link rel="author" title="Cathie Chen" href="mailto:cathiechen@igalia.com">
<link rel="help" href="https://drafts.csswg.org/cssom-view/#dom-element-scrollintoview">
<link rel="help" href="https://drafts.csswg.org/cssom-view/#scroll-an-element">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<style>
.box {
float: left;
width: 200px;
height: 200px;
}
#scroller {
direction: rtl;
overflow-x: scroll;
width: 300px;
height: 215px;
}
#container{
width: 600px;
height: 200px;
}
#target {
background-color: #ff0;
}
</style>
<body>
<div id="scroller">
<div id="container">
<div class="row">
<div class="box"></div>
<div class="box" id="target"></div>
<div class="box"></div>
</div>
</div>
</div>
<script>
// This page is direction: rtl and scroller is direction: rtl.
// So the the overflow direction is leftward, downward. The beginning edges are the top and right edges.
// And the ending edges are the bottom and left edges.
// Acording to the spec, x is min(0, max(x, element padding edge width - element scrolling area width)).
// So x is nonpositive and decreases leftward.
var target = document.getElementById("target");
var scroller = document.getElementById("scroller");
var box_width = target.offsetWidth;
var scroller_width = scroller.offsetWidth;
var leftEdge = -2*box_width + scroller_width;
var center = -(3*box_width - scroller_width)/2;
var rightEdge = - box_width;
test(() => {
scroller.scrollTo(0, 0);
target.scrollIntoView({inline: "start"});
assert_approx_equals(scroller.scrollLeft, rightEdge, 0.5, "start should be the right edge");
}, `scrollIntoView({inline: "start"}), direction: rtl`);
test(() => {
scroller.scrollTo(0, 0);
target.scrollIntoView({inline: "center"});
assert_approx_equals(scroller.scrollLeft, center, 0.5, "should center the target");
}, `scrollIntoView({inline: "center"}), direction: rtl`);
test(() => {
scroller.scrollTo(0, 0);
target.scrollIntoView({inline: "end"});
assert_approx_equals(scroller.scrollLeft, leftEdge, 0.5, "end should be the left edge");
}, `scrollIntoView({inline: "end"}), direction: rtl`);
</script>
</body>
</html>