File: inert-retargeting.tentative.html

package info (click to toggle)
firefox-esr 91.13.0esr-1~deb11u1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 3,375,652 kB
  • sloc: cpp: 5,762,054; javascript: 5,481,714; ansic: 3,121,191; python: 851,492; asm: 331,172; xml: 178,949; java: 155,554; sh: 63,704; makefile: 20,127; perl: 12,825; yacc: 4,583; cs: 3,846; objc: 3,026; lex: 1,720; exp: 762; pascal: 635; php: 436; lisp: 260; awk: 231; ruby: 103; sed: 53; sql: 46; csh: 45
file content (290 lines) | stat: -rw-r--r-- 9,148 bytes parent folder | download | duplicates (8)
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
<!DOCTYPE html>
<html>
<head>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-actions.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<style>
button#foreground,
button#background {
  position: absolute;
  top: 75px;
  left: 50px;
  width: 100px;
  height: 20px;
}

button#background {
  left: 75px;
  width: 150px;
  height: 40px;
  top: 125px;
  line-height: 53px;
}

.clicked {
  background-color: red;
}

#ancestorContainer.clicked {
  background-color: green;
}

#ancestorContainer {
  position: relative;
  width: 300px;
  height: 300px;
  background-color: blue;
}

#displacedAncestor {
  position: absolute;
  top: 13px;
  left: 240px;
  width: 300px;
  height: 250px;
  background-color: #ff89;
}

#displacedAncestor.clicked {
  background-color: #f009;
}

#inertContainer {
  background-color: #fff9;
  position: absolute;
  top: 35px;
  left: -192px;
  width: 200px;
  height: 200px;
}

fieldset {
  margin: 0;
  padding: 0;
  border: 1px solid black;
}

legend {
  background-color: white;
  border: 1px solid black;
  margin-left: 5px;
}

button.clicked::after {
  content: " (clicked)";
}

.clicked > legend::after {
  content: " (clicked)";
}

</style>
</head>
<body>
  <p>Click on "foreground".</p>
  <ul>
    <li>The blue square ("Non-inert ancestor container") should turn green.</li>
    <li>The yellow, semi-transparent square ("Non-inert, displaced container") should not turn red.</li>
    <li>"Non-inert button" should not turn red.</li>
  </ul>
  <p>(The full test suite checks a range of events.)</p>
  <fieldset id="ancestorContainer">
    <legend>Non-inert ancestor container</legend>
    <button id="background">background</button>
    <fieldset id="displacedAncestor">
      <legend>Non-inert, displaced ancestor</legend>
      <fieldset id="inertContainer" inert>
        <legend>Inert container</legend>
        <button id="foreground">foreground</button>
      </fieldset>
    </fieldset>
  </fieldset>

  <script>
document.body.addEventListener('click', (e) => {
  e.target.classList.add('clicked');
});

function clickOn(element) {
  return new test_driver.Actions()
      .pointerMove(0, 0, {origin: element})
      .pointerDown({button: test_driver.Actions.prototype.ButtonType.LEFT})
      .pointerUp({button: test_driver.Actions.prototype.ButtonType.LEFT})
      .send();
}

function auxClickOn(element) {
  return new test_driver.Actions()
      .pointerMove(0, 0, {origin: element})
      .pointerDown({button: test_driver.Actions.prototype.ButtonType.RIGHT})
      .pointerUp({button: test_driver.Actions.prototype.ButtonType.RIGHT})
      .send();
}

function dblClickOn(element) {
  return new test_driver.Actions()
      .pointerMove(0, 0, {origin: element})
      .pointerDown({button: test_driver.Actions.prototype.ButtonType.LEFT})
      .pointerUp({button: test_driver.Actions.prototype.ButtonType.LEFT})
      .pointerDown({button: test_driver.Actions.prototype.ButtonType.LEFT})
      .pointerUp({button: test_driver.Actions.prototype.ButtonType.LEFT})
      .send();
}

function movePointerOver(element) {
  let rect = element.getBoundingClientRect();
  return new test_driver.Actions()
      .pointerMove(0, 0, { origin: element })
      .send();
}

function movePointerTo(x, y) {
  return new test_driver.Actions()
      .pointerMove(x, y, { origin: "viewport" })
      .send();
}

function expectEventsOn(events, element) {
  let promises = [];
  for (event of events) {
    ((event, element) => {
      var promise = new Promise((resolve, reject) => {
        let f = (e) => {
          assert_equals(e.type, event);
          assert_equals(e.target, element);
          resolve();
        }
        element.addEventListener(event, f, { capture: true, once: true });

        step_timeout(() => {
          element.removeEventListener(event, f, { capture: true });
          reject("did not get " + event + " on " + element.id);
        }, 1000);
      });
      promises.push(promise);
    })(event, element);
  }
  return promises;
}

function unexpectEventsOn(events, element) {
  let promises = [];
  for (event of events) {
    ((event, element) => {
      var promise = new Promise((resolve, reject) => {
        let f = (e) => {
          assert_equals(e.type, event);
          assert_equals(e.target, element);
          reject("got " + e.type + " on " + e.target.id);
        }
        element.addEventListener(event, f, { capture: true, once: true });

        step_timeout(() => {
          element.removeEventListener(event, f, { capture: true });
          resolve();
        }, 1000);
      });
      promises.push(promise);
    })(event, element);
  }
  return promises;
}

test(() => {
  let rect = foreground.getBoundingClientRect();
  let center_x = rect.left + (rect.width / 2);
  let center_y = rect.top + (rect.height / 2);
  assert_equals(document.elementsFromPoint(center_x, center_y)[0], foreground);
}, "elementsFromPoint returns inert element");

promise_test(async () => {
  // Test mouse events on non-inert element - events should go to "foreground"
  inertContainer.inert = false;
  await movePointerTo(0, 0);
  let promises = expectEventsOn(["mouseover", "mouseenter", "mousemove", "mousedown",
                                 "mouseup", "click", "auxclick", "mouseout",
                                 "mouseleave"],
                                foreground);
  await clickOn(foreground);
  await auxClickOn(foreground);
  await dblClickOn(foreground);
  let ancestorBox = ancestorContainer.getBoundingClientRect();
  let inertBox = inertContainer.getBoundingClientRect();
  let x = ancestorBox.left + (ancestorBox.width / 2);
  let y = inertBox.bottom + ((ancestorBox.bottom - inertBox.bottom) / 2);
  await movePointerTo(x, y);
  await Promise.all(promises);
}, "Tests that any mouse event on a non-inert element is correctly targeted to that element");

promise_test(async () => {
  // Make the containing element inert - now events should go to "container"
  // which is the non-inert ancestor at the same position
  inertContainer.inert = true;
  await movePointerTo(0, 0);

  let promises = expectEventsOn(["mouseover", "mouseenter", "mousemove", "mousedown",
                                 "mouseup", "click", "auxclick"],
                                ancestorContainer);

  // TODO(aboxhall): We are getting these unexpected events. Why?
  promises = promises.concat(unexpectEventsOn(["mouseout", "mouseleave"],
                                              ancestorContainer));

  await clickOn(foreground);
  await auxClickOn(foreground);
  await dblClickOn(foreground);
  let ancestorBox = ancestorContainer.getBoundingClientRect();
  let inertBox = inertContainer.getBoundingClientRect();
  let x = ancestorBox.left + (ancestorBox.width / 2);
  let y = inertBox.bottom + ((ancestorBox.bottom - inertBox.bottom) / 2);
  await movePointerTo(x, y);
  await Promise.all(promises);
}, 'Tests that any mouse event on an inert element is targeted to the nearest non-inert ancestor at the same coordinates');

promise_test(async () => {
  // Test pointer events on non-inert element - events should go to "foreground"
  inertContainer.inert = false;
  await movePointerTo(0, 0);

  let promises = expectEventsOn(["pointerover", "pointerenter", "pointermove",
                                 "pointerdown", "pointerup", "pointerout",
                                 "pointerleave"],
                                foreground);
  await clickOn(foreground);
  let ancestorBox = ancestorContainer.getBoundingClientRect();
  let inertBox = inertContainer.getBoundingClientRect();
  let x = ancestorBox.left + (ancestorBox.width / 2);
  let y = inertBox.bottom + ((ancestorBox.bottom - inertBox.bottom) / 2);
  await movePointerTo(x, y);
  await Promise.all(promises);
}, "Tests that any pointer event on a non-inert element is correctly targeted to that element");

promise_test(async () => {
  // Make the containing element inert - now events should go to "container"
  // which is the non-inert ancestor at the same position
  inertContainer.inert = true;
  await movePointerTo(0, 0);

  let promises = expectEventsOn(["pointerover", "pointerenter", "pointermove",
                                 "pointerdown", "pointerup" ],
                                ancestorContainer);

  // TODO(aboxhall): We are getting these unexpected events. Why?
  promises = promises.concat(unexpectEventsOn(["pointerout", "pointerleave"],
                                              ancestorContainer));

  await clickOn(foreground);
  let ancestorBox = ancestorContainer.getBoundingClientRect();
  let inertBox = inertContainer.getBoundingClientRect();
  let x = ancestorBox.left + (ancestorBox.width / 2);
  let y = inertBox.bottom + ((ancestorBox.bottom - inertBox.bottom) / 2);
  await movePointerTo(x, y);
  await Promise.all(promises);
}, 'Tests that any pointer event on an inert element is targeted to the nearest non-inert ancestor at the same coordinates');

</script>
</body>
</html>