-
Notifications
You must be signed in to change notification settings - Fork 9
/
pointerenterleave-continuous.html
294 lines (238 loc) · 8.58 KB
/
pointerenterleave-continuous.html
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
291
292
293
294
<!doctype html>
<html>
<!--
Test cases for Pointer Events v1 spec
This document references Test Assertions (abbrev TA below) written by Cathy Chan
-->
<head>
<title>Pointer Events pointer enter/leave Test for continuous pointer movement through a child element</title>
<meta name="viewport" content="width=device-width">
<link rel="author" href="mailto:[email protected]">
<link rel="help" href="http://www.w3.org/wiki/PointerEvents/TestAssertions">
<script src="http://w3c-test.org/resources/testharness.js"></script>
<!--<script src="./testharness.js"></script>-->
<!--<script src="./pointer-prefix.js"></script>-->
<script>
setup({ explicit_done: true });
var detected_pointertypes = {};
//add_completion_callback(showPointerTypes);
var target0OutCount = 0;
var target1OutCount = 0;
var target0LeaveCount = 0;
var target1LeaveCount = 0;
var target0OverCount = 0;
var target1OverCount = 0;
var target0EnterCount = 0;
var target1EnterCount = 0;
var debugLog = "";
function showPointerTypes() {
var complete_notice = document.getElementById("complete-notice");
var pointertype_log = document.getElementById("pointertype-log");
var pointertypes = Object.keys(detected_pointertypes);
pointertype_log.innerHTML =
"<p>pointerout events for cyan box: " + target1OutCount + "</p>" +
"<p>pointerout events for yellow box: " + target0OutCount + "</p>" +
"<p>pointerleave events for cyan box: " + target1LeaveCount + "</p>" +
"<p>pointerleave events for yellow box: " + target0LeaveCount + "</p>" +
"<p>pointerover events for cyan box: " + target1OverCount + "</p>" +
"<p>pointerover events for yellow box: " + target0OverCount + "</p>" +
"<p>pointerenter events for cyan box: " + target1EnterCount + "</p>" +
"<p>pointerenter events for yellow box: " + target0EnterCount + "</p>" +
"<p>order: " + debugLog + "</p>";
complete_notice.style.display = "block";
}
function run() {
var target0 = document.getElementById("target0");
var target1 = document.getElementById("target1");
var start = document.getElementById("startBox");
var end = document.getElementById("endBox");
var testStarted = false;
var testDone = false;
var test_pointerenterleave = async_test("pointerenterleave sequence.");
on_event(start, pointerPrefix["pointerover"], function(event) {
testStarted = true;
debugLog = "";
target0OutCount = 0;
target1OutCount = 0;
target0LeaveCount = 0;
target1LeaveCount = 0;
target0OverCount = 0;
target1OverCount = 0;
target0EnterCount = 0;
target1EnterCount = 0;
});
on_event(target0, pointerPrefix["pointerout"], function(event) {
detected_pointertypes[ event.pointerType ] = true;
target0OutCount++;
debugLog += " pointerout[yellow] ";
});
on_event(target1, pointerPrefix["pointerout"], function(event) {
detected_pointertypes[ event.pointerType ] = true;
target1OutCount++;
debugLog += " pointerout[cyan] ";
});
// XXX this is using mouseleave, should be pointerPrefix["pointerleave"] but not implemented
on_event(target0, "mouseleave", function(event) {
detected_pointertypes[ event.pointerType ] = true;
target0LeaveCount++;
debugLog += " mouseleave[yellow] ";
});
// XXX this is using mouseleave, should be pointerPrefix["pointerleave"] but not implemented
on_event(target1, "mouseleave", function(event) {
detected_pointertypes[ event.pointerType ] = true;
target1LeaveCount++;
debugLog += " mouseleave[cyan] ";
});
on_event(target0, pointerPrefix["pointerover"], function(event) {
detected_pointertypes[ event.pointerType ] = true;
target0OverCount++;
debugLog += " pointerover[yellow] ";
});
on_event(target1, pointerPrefix["pointerover"], function(event) {
detected_pointertypes[ event.pointerType ] = true;
target1OverCount++;
debugLog += " pointerover[cyan] ";
});
// XXX this is using mouseenter, should be pointerPrefix["pointerenter"] but not implemented
on_event(target0, "mouseenter", function(event) {
detected_pointertypes[ event.pointerType ] = true;
target0EnterCount++;
debugLog += " mouseenter[yellow] ";
});
// XXX this is using mouseenter, should be pointerPrefix["pointerenter"] but not implemented
on_event(target1, "mouseenter", function(event) {
detected_pointertypes[ event.pointerType ] = true;
target1EnterCount++;
debugLog += " mouseenter[cyan] ";
});
// there should be 3 target0 out events because:
// 1) moving from yellow to cyan
// 2) moving from cyan to yellow bubbles up to yellow
// 3) moving out of yellow to the end target
//
// but because leave events don't bubble and don't fire on entering a child
// there should only be one leave event for the yellow box
on_event(end, pointerPrefix["pointerover"], function(event) {
if(testStarted && !testDone) {
testDone = true;
test_pointerenterleave.step(function () {
assert_equals(target0OutCount, 3, "yellow box pointerout count");
assert_equals(target1OutCount, 1, "cyan box pointerout count");
assert_equals(target0LeaveCount, 1, "yellow box pointerleave count");
assert_equals(target1LeaveCount, 1, "cyan box pointerleave count");
assert_true(target0OutCount > target1OutCount, "child count should be > parent due to bubbling for out");
assert_true(target0LeaveCount == target1LeaveCount, "child count should be == parent as no bubbling for leave");
assert_equals(target0OverCount, 3, "yellow box pointerover count");
assert_equals(target1OverCount, 1, "cyan box pointerover count");
assert_equals(target0EnterCount, 1, "yellow box pointerenter count");
assert_equals(target1EnterCount, 1, "cyan box pointerenter count");
assert_true(target0OverCount > target1OverCount, "child count should be > parent due to bubbling for over");
assert_true(target0EnterCount == target1EnterCount, "child count should be == parent as no bubbling for enter");
} );
showPointerTypes();
test_pointerenterleave.done();
done();
}
});
}
</script>
<!-- difference between over/out and enter/leave
when you enter a sub-element, you go out but do not leave
e.g.
Element A, Element B, ^ is pointer moving horizontally across screen left-to-right.
______________
|A |
| _______ |
| |B | |
^| | | |
| _______ |
| |
______________
______________
|A |
| _______ | A: over, enter
| |B | |
|^ | | |
| _______ |
| |
______________
______________
|A |
| _______ | A: out
| |B | | B: over, enter
| | ^ | |
| _______ |
| |
______________
______________
|A |
| _______ |
| |B | | A: enter
| | |^ | B: out, leave
| _______ |
| |
______________
______________
|A |
| _______ |
| |B | | A: out, leave
| | | | ^ B:
| _______ |
| |
______________
We also have an explicit end element because we can't trigger on either out or leave because
it isn't defined what relative those are dispatched, so it might vary by user agent,
however both out and leave should be dispatched before over or enter on the end element
-->
<style>
div {
margin: 0em;
padding: 2em;
}
#startBox {
background: lightgreen;
border: 1px solid black;
}
#endBox {
background: pink;
border: 1px solid black;
}
#target0 {
background: yellow;
border: 1px solid orange;
}
#target1 {
background: cyan;
border: 1px solid orange;
}
#complete-notice {
background: #afa;
border: 1px solid #0a0;
display: none;
}
#pointertype-log {
font-weight: bold;
}
</style>
</head>
<body onload="run()">
<h1>Pointer Events pointer enter/leave Test for continuous pointer movement through a child element</h1>
<h2>TODO: this test currently uses mouse enter/leave events rather than pointer enter/leave because pointer enter/leave isn't implemented.</h2>
<div id="startBox">
Start with your pointer here.
</div>
<div id="target0">
Without lifting it, move your pointer into this yellow box.
<div id="target1">
Then into the cyan box.
</div>
</div>
<div id="endBox">
Then move your pointer out of both boxes and end here.
</div>
<div id="complete-notice">
<p>Data log: <span id="pointertype-log"></span>.</p>
</div>
<div id="log"></div>
</body>
</html>