summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/css/css-anchor-position/inset-area-wm-dir.html
blob: 7e740b4aceb85aab2455c5ee5b4f65e25e5f9352 (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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<!DOCTYPE html>
<title>CSS Anchor Positioning: inset-area with writing-mode and direction</title>
<link rel="help" href="https://drafts.csswg.org/css-anchor-position/#inset-area">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<!-- The grid:

          100      150      150
      +--------+--------+--------+
      |        |        |        |
  150 |        |        |        |
      |        |        |        |
      +--------+--------+--------+
      |        |        |        |
   75 |        |        |        |
      |        |        |        |
      +--------+--------+--------+
      |        |        |        |
  175 |        |        |        |
      |        |        |        |
      +--------+--------+--------+

  -->
<style>
  #container {
    position: absolute;
    width: 400px;
    height: 400px;
  }
  #anchored {
    position: absolute;
    align-self: stretch;
    justify-self: stretch;
    position-anchor: --anchor;
  }
  #anchor {
    margin-top: 150px;
    margin-bottom: 175px;
    margin-left: 100px;
    margin-right: 150px;
    width: 150px;
    height: 75px;
    anchor-name: --anchor;
  }
</style>
<div id="container">
  <div id="anchored"></div>
  <div id="anchor"></div>
</div>
<script>
  function test_inset_area(writing_direction, inset_area, expected_offsets) {
    anchored.style.insetArea = inset_area;
    test(() => {
      assert_equals(anchored.offsetLeft, expected_offsets.left, "Checking offsetLeft");
      assert_equals(anchored.offsetTop, expected_offsets.top, "Checking offsetTop");
      assert_equals(anchored.offsetWidth, expected_offsets.width, "Checking offsetWidth");
      assert_equals(anchored.offsetHeight, expected_offsets.height, "Checking offsetHeight");
    }, "Offsets for: " + inset_area + " with writing-mode / direction: " + writing_direction);
  }

  const top_left = {left:0, top:0, width:100, height:150};
  const top_right = {left:250, top:0, width:150, height:150};
  const bottom_left = {left:0, top:225, width:100, height:175};
  const bottom_right = {left:250, top:225, width:150, height:175};

  anchored.style.writingMode = "horizontal-tb";
  anchored.style.direction = "ltr";

  // Writing-mode and direction on container
  let writing_direction = "containing-block: horizontal-tb / rtl";
  container.style.writingMode = "horizontal-tb";
  container.style.direction = "rtl";
  test_inset_area(writing_direction, "start start", top_right);
  test_inset_area(writing_direction, "self-start self-start", top_left);
  test_inset_area(writing_direction, "x-start y-start", top_right);
  test_inset_area(writing_direction, "x-self-start y-self-start", top_left);
  test_inset_area(writing_direction, "inline-start block-end", bottom_right);
  test_inset_area(writing_direction, "self-inline-start self-block-end", bottom_left);

  // containing-block: vertical-lr / ltr
  // self: horizontal-tb / ltr
  writing_direction = "containing-block: vertical-lr / ltr";
  container.style.writingMode = "vertical-lr";
  container.style.direction = "ltr";
  test_inset_area(writing_direction, "start start", top_left);
  test_inset_area(writing_direction, "self-start self-start", top_left);
  test_inset_area(writing_direction, "x-start y-start", top_left);
  test_inset_area(writing_direction, "x-self-start y-self-start", top_left);
  test_inset_area(writing_direction, "inline-start block-end", top_right);
  test_inset_area(writing_direction, "self-inline-start self-block-end", bottom_left);

  // containing-block: vertical-lr / rtl
  // self: horizontal-tb / ltr
  writing_direction = "containing-block: vertical-lr / rtl";
  container.style.writingMode = "vertical-lr";
  container.style.direction = "rtl";
  test_inset_area(writing_direction, "start start", bottom_left);
  test_inset_area(writing_direction, "self-start self-start", top_left);
  test_inset_area(writing_direction, "x-start y-start", bottom_left);
  test_inset_area(writing_direction, "x-self-start y-self-start", top_left);

  // containing-block: vertical-rl / ltr
  // self: horizontal-tb / ltr
  writing_direction = "containing-block: vertical-rl / ltr";
  container.style.writingMode = "vertical-rl";
  container.style.direction = "ltr";
  test_inset_area(writing_direction, "start start", top_right);
  test_inset_area(writing_direction, "self-start self-start", top_left);
  test_inset_area(writing_direction, "x-start y-start", top_right);
  test_inset_area(writing_direction, "x-self-start y-self-start", top_left);

  // containing-block: vertical-rl / rtl
  // self: horizontal-tb / ltr
  writing_direction = "containing-block: vertical-rl / rtl";
  container.style.writingMode = "vertical-rl";
  container.style.direction = "rtl";
  test_inset_area(writing_direction, "start start", bottom_right);
  test_inset_area(writing_direction, "self-start self-start", top_left);
  test_inset_area(writing_direction, "x-start y-start", bottom_right);
  test_inset_area(writing_direction, "x-self-start y-self-start", top_left);

  // Writing-mode and direction on self
  container.style.writingMode = "horizontal-tb";
  container.style.direction = "ltr";

  // containing-block: horizontal-tb / ltr
  // self: horizontal-tb / rtl
  writing_direction = "self: horizontal-tb / rtl";
  anchored.style.writingMode = "horizontal-tb";
  anchored.style.direction = "rtl";
  test_inset_area(writing_direction, "start start", top_left);
  test_inset_area(writing_direction, "self-start self-start", top_right);
  test_inset_area(writing_direction, "x-start y-start", top_left);
  test_inset_area(writing_direction, "x-self-start y-self-start", top_right);

  // containing-block: horizontal-tb / ltr
  // self: vertical-lr / ltr
  writing_direction = "self: vertical-lr / ltr";
  anchored.style.writingMode = "vertical-lr";
  anchored.style.direction = "ltr";
  test_inset_area(writing_direction, "start start", top_left);
  test_inset_area(writing_direction, "self-start self-start", top_left);
  test_inset_area(writing_direction, "x-start y-start", top_left);
  test_inset_area(writing_direction, "x-self-start y-self-start", top_left);

  // containing-block: horizontal-tb / ltr
  // self: vertical-lr / rtl
  writing_direction = "self: vertical-lr / rtl";
  anchored.style.writingMode = "vertical-lr";
  anchored.style.direction = "rtl";
  test_inset_area(writing_direction, "start start", top_left);
  test_inset_area(writing_direction, "self-start self-start", bottom_left);
  test_inset_area(writing_direction, "x-start y-start", top_left);
  test_inset_area(writing_direction, "x-self-start y-self-start", bottom_left);

  // containing-block: horizontal-tb / ltr
  // self: vertical-rl / ltr
  writing_direction = "self: vertical-rl / ltr";
  anchored.style.writingMode = "vertical-rl";
  anchored.style.direction = "ltr";
  test_inset_area(writing_direction, "start start", top_left);
  test_inset_area(writing_direction, "self-start self-start", top_right);
  test_inset_area(writing_direction, "x-start y-start", top_left);
  test_inset_area(writing_direction, "x-self-start y-self-start", top_right);

  // containing-block: horizontal-tb / ltr
  // self: vertical-rl / rtl
  writing_direction = "self: vertical-rl / rtl";
  anchored.style.writingMode = "vertical-rl";
  anchored.style.direction = "rtl";
  test_inset_area(writing_direction, "start start", top_left);
  test_inset_area(writing_direction, "self-start self-start", bottom_right);
  test_inset_area(writing_direction, "x-start y-start", top_left);
  test_inset_area(writing_direction, "x-self-start y-self-start", bottom_right);

</script>