| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 part of touch; | 5 part of touch; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * Wraps a callback with translations of mouse events to touch events. Use | 8 * Wraps a callback with translations of mouse events to touch events. Use |
| 9 * this function to invoke your callback that expects touch events after | 9 * this function to invoke your callback that expects touch events after |
| 10 * touch events are created from the actual mouse events. | 10 * touch events are created from the actual mouse events. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 targetTouches = mockTouchList; | 23 targetTouches = mockTouchList; |
| 24 } | 24 } |
| 25 callback(new MockTouchEvent(e, touches, targetTouches, changedTouches)); | 25 callback(new MockTouchEvent(e, touches, targetTouches, changedTouches)); |
| 26 // Required to prevent spurious selection changes while tracking touches | 26 // Required to prevent spurious selection changes while tracking touches |
| 27 // on devices that don't support touch events. | 27 // on devices that don't support touch events. |
| 28 e.preventDefault(); | 28 e.preventDefault(); |
| 29 }; | 29 }; |
| 30 } | 30 } |
| 31 | 31 |
| 32 /** Helper method to attach event listeners to a [node]. */ | 32 /** Helper method to attach event listeners to a [node]. */ |
| 33 void _addEventListeners(Element node, | 33 void _addEventListeners(Element node, EventListener onStart, |
| 34 EventListener onStart, EventListener onMove, EventListener onEnd, | 34 EventListener onMove, EventListener onEnd, EventListener onCancel, |
| 35 EventListener onCancel, [bool capture = false]) { | 35 [bool capture = false]) { |
| 36 | |
| 37 Function removeListeners; | 36 Function removeListeners; |
| 38 | 37 |
| 39 onEndWrapper(e) { | 38 onEndWrapper(e) { |
| 40 removeListeners(); | 39 removeListeners(); |
| 41 return onEnd(e); | 40 return onEnd(e); |
| 42 } | 41 } |
| 43 | 42 |
| 44 onLeaveWrapper(e) { | 43 onLeaveWrapper(e) { |
| 45 removeListeners(); | 44 removeListeners(); |
| 46 return onEnd(e); | 45 return onEnd(e); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 58 var touchCancelSub; | 57 var touchCancelSub; |
| 59 | 58 |
| 60 removeListeners = () { | 59 removeListeners = () { |
| 61 touchMoveSub.cancel(); | 60 touchMoveSub.cancel(); |
| 62 touchEndSub.cancel(); | 61 touchEndSub.cancel(); |
| 63 touchLeaveSub.cancel(); | 62 touchLeaveSub.cancel(); |
| 64 touchCancelSub.cancel(); | 63 touchCancelSub.cancel(); |
| 65 }; | 64 }; |
| 66 | 65 |
| 67 Element.touchStartEvent.forTarget(node, useCapture: capture).listen((e) { | 66 Element.touchStartEvent.forTarget(node, useCapture: capture).listen((e) { |
| 68 touchMoveSub = Element.touchMoveEvent.forTarget( | 67 touchMoveSub = Element.touchMoveEvent |
| 69 document, useCapture: capture).listen(onMove); | 68 .forTarget(document, useCapture: capture) |
| 70 touchEndSub = Element.touchEndEvent.forTarget( | 69 .listen(onMove); |
| 71 document, useCapture: capture).listen(onEndWrapper); | 70 touchEndSub = Element.touchEndEvent |
| 72 touchLeaveSub = Element.touchLeaveEvent.forTarget( | 71 .forTarget(document, useCapture: capture) |
| 73 document, useCapture: capture).listen(onLeaveWrapper); | 72 .listen(onEndWrapper); |
| 74 touchCancelSub = Element.touchCancelEvent.forTarget( | 73 touchLeaveSub = Element.touchLeaveEvent |
| 75 document, useCapture: capture).listen(onCancelWrapper); | 74 .forTarget(document, useCapture: capture) |
| 75 .listen(onLeaveWrapper); |
| 76 touchCancelSub = Element.touchCancelEvent |
| 77 .forTarget(document, useCapture: capture) |
| 78 .listen(onCancelWrapper); |
| 76 return onStart(e); | 79 return onStart(e); |
| 77 }); | 80 }); |
| 78 } else { | 81 } else { |
| 79 onStart = mouseToTouchCallback(onStart); | 82 onStart = mouseToTouchCallback(onStart); |
| 80 onMove = mouseToTouchCallback(onMove); | 83 onMove = mouseToTouchCallback(onMove); |
| 81 onEnd = mouseToTouchCallback(onEnd); | 84 onEnd = mouseToTouchCallback(onEnd); |
| 82 // onLeave will never be called if the device does not support touches. | 85 // onLeave will never be called if the device does not support touches. |
| 83 | 86 |
| 84 var mouseMoveSub; | 87 var mouseMoveSub; |
| 85 var mouseUpSub; | 88 var mouseUpSub; |
| 86 var touchCancelSub; | 89 var touchCancelSub; |
| 87 | 90 |
| 88 removeListeners = () { | 91 removeListeners = () { |
| 89 mouseMoveSub.cancel(); | 92 mouseMoveSub.cancel(); |
| 90 mouseUpSub.cancel(); | 93 mouseUpSub.cancel(); |
| 91 touchCancelSub.cancel(); | 94 touchCancelSub.cancel(); |
| 92 }; | 95 }; |
| 93 | 96 |
| 94 Element.mouseDownEvent.forTarget(node, useCapture: capture).listen((e) { | 97 Element.mouseDownEvent.forTarget(node, useCapture: capture).listen((e) { |
| 95 mouseMoveSub = Element.mouseMoveEvent.forTarget( | 98 mouseMoveSub = Element.mouseMoveEvent |
| 96 document, useCapture: capture).listen(onMove); | 99 .forTarget(document, useCapture: capture) |
| 97 mouseUpSub = Element.mouseUpEvent.forTarget( | 100 .listen(onMove); |
| 98 document, useCapture: capture).listen(onEndWrapper); | 101 mouseUpSub = Element.mouseUpEvent |
| 99 touchCancelSub = Element.touchCancelEvent.forTarget( | 102 .forTarget(document, useCapture: capture) |
| 100 document, useCapture: capture).listen(onCancelWrapper); | 103 .listen(onEndWrapper); |
| 104 touchCancelSub = Element.touchCancelEvent |
| 105 .forTarget(document, useCapture: capture) |
| 106 .listen(onCancelWrapper); |
| 101 return onStart(e); | 107 return onStart(e); |
| 102 }); | 108 }); |
| 103 } | 109 } |
| 104 } | 110 } |
| 105 | 111 |
| 106 /** | 112 /** |
| 107 * Gets whether the given touch event targets the node, or one of the node's | 113 * Gets whether the given touch event targets the node, or one of the node's |
| 108 * children. | 114 * children. |
| 109 */ | 115 */ |
| 110 bool _touchEventTargetsNode(event, Node node) { | 116 bool _touchEventTargetsNode(event, Node node) { |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 get client => wrapped.client; | 181 get client => wrapped.client; |
| 176 | 182 |
| 177 int get identifier => 0; | 183 int get identifier => 0; |
| 178 | 184 |
| 179 int get pageX => wrapped.page.x; | 185 int get pageX => wrapped.page.x; |
| 180 | 186 |
| 181 int get pageY => wrapped.page.y; | 187 int get pageY => wrapped.page.y; |
| 182 | 188 |
| 183 int get screenX => wrapped.screen.x; | 189 int get screenX => wrapped.screen.x; |
| 184 | 190 |
| 185 int get screenY {return wrapped.screen.y; } | 191 int get screenY { |
| 192 return wrapped.screen.y; |
| 193 } |
| 186 | 194 |
| 187 EventTarget get target => wrapped.target; | 195 EventTarget get target => wrapped.target; |
| 188 | 196 |
| 189 double get force { throw new UnimplementedError(); } | 197 double get force { |
| 190 Point get page { throw new UnimplementedError(); } | 198 throw new UnimplementedError(); |
| 191 int get radiusX { throw new UnimplementedError(); } | 199 } |
| 192 int get radiusY { throw new UnimplementedError(); } | 200 |
| 193 num get rotationAngle { throw new UnimplementedError(); } | 201 Point get page { |
| 194 Point get screen { throw new UnimplementedError(); } | 202 throw new UnimplementedError(); |
| 195 num get webkitForce { throw new UnimplementedError(); } | 203 } |
| 196 int get webkitRadiusX { throw new UnimplementedError(); } | 204 |
| 197 int get webkitRadiusY { throw new UnimplementedError(); } | 205 int get radiusX { |
| 198 num get webkitRotationAngle { throw new UnimplementedError(); } | 206 throw new UnimplementedError(); |
| 207 } |
| 208 |
| 209 int get radiusY { |
| 210 throw new UnimplementedError(); |
| 211 } |
| 212 |
| 213 num get rotationAngle { |
| 214 throw new UnimplementedError(); |
| 215 } |
| 216 |
| 217 Point get screen { |
| 218 throw new UnimplementedError(); |
| 219 } |
| 220 |
| 221 num get webkitForce { |
| 222 throw new UnimplementedError(); |
| 223 } |
| 224 |
| 225 int get webkitRadiusX { |
| 226 throw new UnimplementedError(); |
| 227 } |
| 228 |
| 229 int get webkitRadiusY { |
| 230 throw new UnimplementedError(); |
| 231 } |
| 232 |
| 233 num get webkitRotationAngle { |
| 234 throw new UnimplementedError(); |
| 235 } |
| 199 } | 236 } |
| 200 | 237 |
| 201 class MockTouchEvent implements TouchEvent { | 238 class MockTouchEvent implements TouchEvent { |
| 202 MouseEvent wrapped; | 239 MouseEvent wrapped; |
| 203 // TODO(jacobr): these are currently Lists instead of a TouchList. | 240 // TODO(jacobr): these are currently Lists instead of a TouchList. |
| 204 final List<Touch> touches; | 241 final List<Touch> touches; |
| 205 final List<Touch> targetTouches; | 242 final List<Touch> targetTouches; |
| 206 final List<Touch> changedTouches; | 243 final List<Touch> changedTouches; |
| 207 MockTouchEvent(MouseEvent this.wrapped, List<Touch> this.touches, | 244 MockTouchEvent(MouseEvent this.wrapped, List<Touch> this.touches, |
| 208 List<Touch> this.targetTouches, | 245 List<Touch> this.targetTouches, List<Touch> this.changedTouches) {} |
| 209 List<Touch> this.changedTouches) {} | |
| 210 | 246 |
| 211 bool get bubbles => wrapped.bubbles; | 247 bool get bubbles => wrapped.bubbles; |
| 212 | 248 |
| 213 bool get cancelBubble => wrapped.cancelBubble; | 249 bool get cancelBubble => wrapped.cancelBubble; |
| 214 | 250 |
| 215 void set cancelBubble(bool value) { wrapped.cancelBubble = value; } | 251 void set cancelBubble(bool value) { |
| 252 wrapped.cancelBubble = value; |
| 253 } |
| 216 | 254 |
| 217 bool get cancelable => wrapped.cancelable; | 255 bool get cancelable => wrapped.cancelable; |
| 218 | 256 |
| 219 EventTarget get currentTarget => wrapped.currentTarget; | 257 EventTarget get currentTarget => wrapped.currentTarget; |
| 220 | 258 |
| 221 bool get defaultPrevented => wrapped.defaultPrevented; | 259 bool get defaultPrevented => wrapped.defaultPrevented; |
| 222 | 260 |
| 223 int get eventPhase => wrapped.eventPhase; | 261 int get eventPhase => wrapped.eventPhase; |
| 224 | 262 |
| 225 void set returnValue(bool value) { wrapped.returnValue = value; } | 263 void set returnValue(bool value) { |
| 264 wrapped.returnValue = value; |
| 265 } |
| 226 | 266 |
| 227 bool get returnValue => wrapped.returnValue; | 267 bool get returnValue => wrapped.returnValue; |
| 228 | 268 |
| 229 EventTarget get target => wrapped.target; | 269 EventTarget get target => wrapped.target; |
| 230 | 270 |
| 231 int get timeStamp => wrapped.timeStamp; | 271 int get timeStamp => wrapped.timeStamp; |
| 232 | 272 |
| 233 String get type => wrapped.type; | 273 String get type => wrapped.type; |
| 234 | 274 |
| 235 void preventDefault() { wrapped.preventDefault(); } | 275 void preventDefault() { |
| 276 wrapped.preventDefault(); |
| 277 } |
| 236 | 278 |
| 237 void stopImmediatePropagation() { wrapped.stopImmediatePropagation(); } | 279 void stopImmediatePropagation() { |
| 280 wrapped.stopImmediatePropagation(); |
| 281 } |
| 238 | 282 |
| 239 void stopPropagation() { wrapped.stopPropagation(); } | 283 void stopPropagation() { |
| 284 wrapped.stopPropagation(); |
| 285 } |
| 240 | 286 |
| 241 int get charCode => wrapped.charCode; | 287 int get charCode => wrapped.charCode; |
| 242 | 288 |
| 243 int get detail => wrapped.detail; | 289 int get detail => wrapped.detail; |
| 244 | 290 |
| 245 // TODO(sra): keyCode is not on MouseEvent. | 291 // TODO(sra): keyCode is not on MouseEvent. |
| 246 //int get keyCode => (wrapped as KeyboardEvent).keyCode; | 292 //int get keyCode => (wrapped as KeyboardEvent).keyCode; |
| 247 | 293 |
| 248 int get layerX => wrapped.layer.x; | 294 int get layerX => wrapped.layer.x; |
| 249 | 295 |
| 250 int get layerY => wrapped.layer.y; | 296 int get layerY => wrapped.layer.y; |
| 251 | 297 |
| 252 int get pageX => wrapped.page.x; | 298 int get pageX => wrapped.page.x; |
| 253 | 299 |
| 254 int get pageY => wrapped.page.y; | 300 int get pageY => wrapped.page.y; |
| 255 | 301 |
| 256 Window get view => wrapped.view; | 302 Window get view => wrapped.view; |
| 257 | 303 |
| 258 int get which => wrapped.which; | 304 int get which => wrapped.which; |
| 259 | 305 |
| 260 bool get altKey => wrapped.altKey; | 306 bool get altKey => wrapped.altKey; |
| 261 | 307 |
| 262 bool get ctrlKey => wrapped.ctrlKey; | 308 bool get ctrlKey => wrapped.ctrlKey; |
| 263 | 309 |
| 264 bool get metaKey => wrapped.metaKey; | 310 bool get metaKey => wrapped.metaKey; |
| 265 | 311 |
| 266 bool get shiftKey => wrapped.shiftKey; | 312 bool get shiftKey => wrapped.shiftKey; |
| 267 | 313 |
| 268 DataTransfer get clipboardData { throw new UnimplementedError(); } | 314 DataTransfer get clipboardData { |
| 269 Point get layer { throw new UnimplementedError(); } | 315 throw new UnimplementedError(); |
| 270 Element get matchingTarget { throw new UnimplementedError(); } | 316 } |
| 271 Point get page { throw new UnimplementedError(); } | 317 |
| 272 List get path { throw new UnimplementedError(); } | 318 Point get layer { |
| 273 Point get screen { throw new UnimplementedError(); } | 319 throw new UnimplementedError(); |
| 274 /*InputDevice*/ get sourceDevice { throw new UnimplementedError(); } | 320 } |
| 321 |
| 322 Element get matchingTarget { |
| 323 throw new UnimplementedError(); |
| 324 } |
| 325 |
| 326 Point get page { |
| 327 throw new UnimplementedError(); |
| 328 } |
| 329 |
| 330 List get path { |
| 331 throw new UnimplementedError(); |
| 332 } |
| 333 |
| 334 Point get screen { |
| 335 throw new UnimplementedError(); |
| 336 } |
| 337 |
| 338 /*InputDevice*/ get sourceDevice { |
| 339 throw new UnimplementedError(); |
| 340 } |
| 275 } | 341 } |
| OLD | NEW |