OLD | NEW |
1 /** | 1 /** |
2 * @license | 2 * @license |
3 * Copyright (c) 2014 The Polymer Project Authors. All rights reserved. | 3 * Copyright (c) 2014 The Polymer Project Authors. All rights reserved. |
4 * This code may only be used under the BSD style license found at http://polyme
r.github.io/LICENSE.txt | 4 * This code may only be used under the BSD style license found at http://polyme
r.github.io/LICENSE.txt |
5 * The complete set of authors may be found at http://polymer.github.io/AUTHORS.
txt | 5 * The complete set of authors may be found at http://polymer.github.io/AUTHORS.
txt |
6 * The complete set of contributors may be found at http://polymer.github.io/CON
TRIBUTORS.txt | 6 * The complete set of contributors may be found at http://polymer.github.io/CON
TRIBUTORS.txt |
7 * Code distributed by Google as part of the polymer project is also | 7 * Code distributed by Google as part of the polymer project is also |
8 * subject to an additional IP rights grant found at http://polymer.github.io/PA
TENTS.txt | 8 * subject to an additional IP rights grant found at http://polymer.github.io/PA
TENTS.txt |
9 */ | 9 */ |
10 | 10 |
(...skipping 22 matching lines...) Expand all Loading... |
33 y: bcr.top, | 33 y: bcr.top, |
34 x: bcr.left | 34 x: bcr.left |
35 }; | 35 }; |
36 } | 36 } |
37 | 37 |
38 function makeEvent(type, xy, node) { | 38 function makeEvent(type, xy, node) { |
39 var props = { | 39 var props = { |
40 bubbles: true, | 40 bubbles: true, |
41 cancelable: true, | 41 cancelable: true, |
42 clientX: xy.x, | 42 clientX: xy.x, |
43 clientY: xy.y | 43 clientY: xy.y, |
| 44 // Make this a primary input. |
| 45 buttons: 1 // http://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/b
uttons |
44 }; | 46 }; |
45 var e; | 47 var e; |
46 var mousetype = type === 'tap' ? 'click' : 'mouse' + type; | 48 var mousetype = type === 'tap' ? 'click' : 'mouse' + type; |
47 if (HAS_NEW_MOUSE) { | 49 if (HAS_NEW_MOUSE) { |
48 e = new MouseEvent(mousetype, props); | 50 e = new MouseEvent(mousetype, props); |
49 } else { | 51 } else { |
50 e = document.createEvent('MouseEvent'); | 52 e = document.createEvent('MouseEvent'); |
51 e.initMouseEvent(mousetype, props.bubbles, props.cancelable, null, null, 0
, 0, | 53 e.initMouseEvent( |
52 props.clientX, props.clientY, false, false, false, false, 0, null); | 54 mousetype, props.bubbles, props.cancelable, |
| 55 null, /* view */ |
| 56 null, /* detail */ |
| 57 0, /* screenX */ |
| 58 0, /* screenY */ |
| 59 props.clientX, props.clientY, |
| 60 false, /*ctrlKey */ |
| 61 false, /*altKey */ |
| 62 false, /*shiftKey */ |
| 63 false, /*metaKey */ |
| 64 0, /*button */ |
| 65 null /*relatedTarget*/); |
53 } | 66 } |
54 node.dispatchEvent(e); | 67 node.dispatchEvent(e); |
55 } | 68 } |
56 | 69 |
57 function down(node, xy) { | 70 function down(node, xy) { |
58 xy = xy || middleOfNode(node); | 71 xy = xy || middleOfNode(node); |
59 makeEvent('down', xy, node); | 72 makeEvent('down', xy, node); |
60 } | 73 } |
61 | 74 |
62 function move(node, fromXY, toXY, steps) { | 75 function move(node, fromXY, toXY, steps) { |
(...skipping 14 matching lines...) Expand all Loading... |
77 y: toXY.y | 90 y: toXY.y |
78 }, node); | 91 }, node); |
79 } | 92 } |
80 | 93 |
81 function up(node, xy) { | 94 function up(node, xy) { |
82 xy = xy || middleOfNode(node); | 95 xy = xy || middleOfNode(node); |
83 makeEvent('up', xy, node); | 96 makeEvent('up', xy, node); |
84 } | 97 } |
85 | 98 |
86 function tap(node) { | 99 function tap(node) { |
| 100 // Respect nodes that are disabled in the UI. |
| 101 if (window.getComputedStyle(node)['pointer-events'] === 'none') |
| 102 return; |
87 var xy = middleOfNode(node); | 103 var xy = middleOfNode(node); |
88 down(node, xy); | 104 down(node, xy); |
89 up(node, xy); | 105 up(node, xy); |
90 makeEvent('tap', xy, node); | 106 makeEvent('tap', xy, node); |
91 } | 107 } |
92 | 108 |
93 function focus(target) { | 109 function focus(target) { |
94 Polymer.Base.fire.call(target, 'focus'); | 110 Polymer.Base.fire('focus', {}, { |
| 111 bubbles: false, |
| 112 node: target |
| 113 }); |
95 } | 114 } |
96 | 115 |
97 function blur(target) { | 116 function blur(target) { |
98 Polymer.Base.fire.call(target, 'blur'); | 117 Polymer.Base.fire('blur', {}, { |
| 118 bubbles: false, |
| 119 node: target |
| 120 }); |
99 } | 121 } |
100 | 122 |
101 function downAndUp(target, callback) { | 123 function downAndUp(target, callback) { |
102 down(target); | 124 down(target); |
103 Polymer.Base.async(function() { | 125 Polymer.Base.async(function() { |
104 up(target); | 126 up(target); |
105 tap(target); | 127 tap(target); |
106 | 128 |
107 callback && callback(); | 129 callback && callback(); |
108 }); | 130 }); |
109 } | 131 } |
110 | 132 |
111 function track(target, dx, dy, steps) { | 133 function track(target, dx, dy, steps) { |
112 dx = dx | 0; | 134 dx = dx | 0; |
113 dy = dy | 0; | 135 dy = dy | 0; |
114 steps = steps || 5; | 136 steps = steps || 5; |
115 down(target); | 137 down(target); |
116 var xy = middleOfNode(target); | 138 var xy = middleOfNode(target); |
117 var xy2 = { | 139 var xy2 = { |
118 x: xy.x + dx, | 140 x: xy.x + dx, |
119 y: xy.y + dy | 141 y: xy.y + dy |
120 }; | 142 }; |
121 move(target, xy, xy2, steps); | 143 move(target, xy, xy2, steps); |
122 up(target, xy2); | 144 up(target, xy2); |
123 } | 145 } |
124 | 146 |
125 function keyboardEventFor(type, keyCode) { | 147 function keyboardEventFor(type, keyCode) { |
126 var event = new CustomEvent(type); | 148 var event = new CustomEvent(type, { |
| 149 bubbles: true, |
| 150 cancelable: true |
| 151 }); |
127 | 152 |
128 event.keyCode = keyCode; | 153 event.keyCode = keyCode; |
129 event.code = keyCode; | 154 event.code = keyCode; |
130 | 155 |
131 return event; | 156 return event; |
132 } | 157 } |
133 | 158 |
134 function keyEventOn(target, type, keyCode) { | 159 function keyEventOn(target, type, keyCode) { |
135 target.dispatchEvent(keyboardEventFor(type, keyCode)); | 160 target.dispatchEvent(keyboardEventFor(type, keyCode)); |
136 } | 161 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 track: track, | 193 track: track, |
169 pressAndReleaseKeyOn: pressAndReleaseKeyOn, | 194 pressAndReleaseKeyOn: pressAndReleaseKeyOn, |
170 pressEnter: pressEnter, | 195 pressEnter: pressEnter, |
171 pressSpace: pressSpace, | 196 pressSpace: pressSpace, |
172 keyDownOn: keyDownOn, | 197 keyDownOn: keyDownOn, |
173 keyUpOn: keyUpOn, | 198 keyUpOn: keyUpOn, |
174 middleOfNode: middleOfNode, | 199 middleOfNode: middleOfNode, |
175 topLeftOfNode: topLeftOfNode | 200 topLeftOfNode: topLeftOfNode |
176 }; | 201 }; |
177 })(this); | 202 })(this); |
OLD | NEW |