OLD | NEW |
---|---|
(Empty) | |
1 <!DOCTYPE HTML> | |
Rick Byers
2015/06/11 04:14:56
Ultimately we're going to want to try to bring tes
mustaq
2015/06/12 16:05:23
Done: moved to "pointerevents", at least preservin
Rick Byers
2015/06/16 17:25:38
I'm fine considering the eventSender question as o
| |
2 <script src="../../../resources/js-test.js"></script> | |
3 <style> | |
4 div { | |
5 margin: 10px; | |
6 padding: 50px; | |
7 float: left; | |
8 } | |
9 #console { | |
10 padding: 0px; | |
11 float: none; | |
12 } | |
13 </style> | |
14 | |
15 <div id="grey" style="background-color:grey"> | |
16 <div id="lightgreen" style="background-color:lightgreen"> | |
17 <div id="green" style="background-color:green;"> | |
18 </div> | |
19 </div> | |
20 </div> | |
21 | |
22 <div id="console"></div> | |
23 | |
24 <script> | |
25 description("Verifies that tapping on an element fires appropriate pointer event s."); | |
26 | |
27 var preventDefault = false; | |
28 | |
29 function getPhaseString(event) { | |
30 return event.eventPhase == 0 ? "none" : | |
Rick Byers
2015/06/11 04:14:56
nit: rather than hard-coding the constants you sho
mustaq
2015/06/12 16:05:23
Done.
| |
31 event.eventPhase == 1 ? "capturing" : | |
32 event.eventPhase == 2 ? "target" : | |
33 event.eventPhase == 3 ? "bubbling" : | |
34 "error"; | |
35 } | |
36 | |
37 function init() { | |
38 var eventNames = ["touchstart", "touchend", "touchmove", "pointerdown", "point erup", "pointermove"]; | |
39 | |
40 ["grey", "lightgreen", "green"].forEach(function(id) { | |
41 var targetDiv = document.getElementById(id); | |
42 | |
43 eventNames.forEach(function(eventName) { | |
44 targetDiv.addEventListener(eventName, function(event) { | |
45 debug(id + " received " + event.type + " at phase=" + getPhaseString(eve nt)); | |
46 if (preventDefault) | |
47 event.preventDefault(); | |
48 }); | |
49 }) | |
50 }); | |
51 } | |
52 | |
53 function sendTouch(id) { | |
54 var rect = document.getElementById(id).getBoundingClientRect(); | |
55 var x = rect.left + 10; | |
56 var y = rect.top + 10; | |
57 | |
58 debug("-- sending touch to " + id + " --"); | |
59 | |
60 eventSender.clearTouchPoints(); | |
61 eventSender.addTouchPoint(x, y); | |
62 eventSender.touchStart(); | |
63 eventSender.updateTouchPoint(0, x+20, y+20); | |
64 eventSender.touchEnd(); | |
Rick Byers
2015/06/11 04:14:56
I think you need to pass the ID (0) here to get th
mustaq
2015/06/12 16:05:23
Done, missed the "release" calls.
| |
65 } | |
66 | |
67 init(); | |
68 if (window.eventSender) { | |
69 preventDefault = false; | |
70 debug("--- with preventDefault=false ---"); | |
71 sendTouch("green"); | |
72 | |
73 preventDefault = true; | |
74 debug("--- with preventDefault=true ---"); | |
75 sendTouch("green"); | |
76 } else { | |
77 debug("This test requires eventSender"); | |
78 } | |
79 </script> | |
OLD | NEW |