summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/css/cssom-view/scrollIntoView-vertical-rl-writing-mode.html
blob: dc5f3e2cdb2fa6c4b0c59ded80b7e19df2db274c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<!DOCTYPE html>
<title>CSSOM View - scrollIntoView considers vertical-rl writing mode</title>
<meta charset="utf-8">
<link rel="author" title="Suneel Kota" href="mailto:suneel.kota@samsung.com">
<link rel="help" href="https://drafts.csswg.org/cssom-view/#dom-element-scrollintoview">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<style>
.box {
  float: left;
  width: 200px;
  height: 200px;
}
#scroller {
  writing-mode: vertical-rl;
  overflow: scroll;
  width: 300px;
  height: 300px;
}
#container{
  width: 600px;
  height: 600px;
}
#target {
  background-color: #ff0;
}
</style>
<body>
<div id="scroller">
  <div id="container">
    <!-- ROW-1 -->
    <div class="row">
      <div class="box"></div>
      <div class="box"></div>
      <div class="box"></div>
    </div>

    <!-- ROW-2 -->
    <div class="row">
      <div class="box"></div>
      <div class="box" id="target"></div>
      <div class="box"></div>
    </div>

    <!-- ROW-3 -->
    <div class="row">
      <div class="box"></div>
      <div class="box"></div>
      <div class="box"></div>
    </div>
  </div>
</div>

<script>
// In vertical-rl mode, X corresponds to the block axis and is oriented
// leftward. Y corresponds to the inline axis and is oriented downward.
// So the beginning edges are the top and right edges and the ending
// edges are the bottom and left edges.

// This assumes that the horizontal scrollbar is on the bottom side.

var target = document.getElementById("target");
var scroller = document.getElementById("scroller");
var scrollbar_width = scroller.offsetWidth - scroller.clientWidth;

var scroller_width = scroller.offsetWidth;
var scroller_height = scroller.offsetHeight;
var box_width = target.offsetWidth;
var box_height = target.offsetHeight;

var expectedX;
// If scroll bar is on the left side, scroller.scrollLeft won't get bigger than 0,
scroller.scrollLeft = scrollbar_width;
if (scroller.scrollLeft == 0) {
  expectedX = {
    blockStart: -box_width,
    blockCenter: -(((3*box_width - scroller_width)/2) + (scrollbar_width/2)),
    blockEnd: -(((2*box_width) - scroller_width) + scrollbar_width),
  };
} else {
  expectedX = {
    blockStart: -(box_width - scrollbar_width),
    blockCenter: -(((3*box_width - scroller_width)/2) + (scrollbar_width/2) - scrollbar_width),
    blockEnd: -((2*box_width) - scroller_width),
  };
}

var expectedY = {
  inlineStart: box_height,
  inlineCenter: ((3*box_height - scroller_height)/2) + (scrollbar_width/2),
  inlineEnd: ((2*box_height) - scroller_height) + scrollbar_width,
};

[
  [{block: "start", inline: "start"}, expectedX.blockStart, expectedY.inlineStart],
  [{block: "start", inline: "center"}, expectedX.blockStart, expectedY.inlineCenter],
  [{block: "start", inline: "end"}, expectedX.blockStart, expectedY.inlineEnd],
  [{block: "center", inline: "start"}, expectedX.blockCenter, expectedY.inlineStart],
  [{block: "center", inline: "center"}, expectedX.blockCenter, expectedY.inlineCenter],
  [{block: "center", inline: "end"}, expectedX.blockCenter, expectedY.inlineEnd],
  [{block: "end", inline: "start"}, expectedX.blockEnd, expectedY.inlineStart],
  [{block: "end", inline: "center"}, expectedX.blockEnd, expectedY.inlineCenter],
  [{block: "end", inline: "end"}, expectedX.blockEnd, expectedY.inlineEnd],
].forEach(([input, expectedX, expectedY]) => {
  test(() => {
    scroller.scrollTo(0, 0);
    target.scrollIntoView(input);
    assert_approx_equals(scroller.scrollLeft, expectedX, 0.5, "scrollX");
    assert_approx_equals(scroller.scrollTop, expectedY, 0.5, "scrollY");
  }, `scrollIntoView(${JSON.stringify(input)})`);
})

</script>

</body>
</html>