| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | |
| 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. | |
| 4 | |
| 5 part of dart.html; | |
| 6 | |
| 7 /** | |
| 8 * Helper class to implement custom events which wrap DOM events. | |
| 9 */ | |
| 10 class _WrappedEvent implements Event { | |
| 11 final Event wrapped; | |
| 12 | |
| 13 /** The CSS selector involved with event delegation. */ | |
| 14 String _selector; | |
| 15 | |
| 16 _WrappedEvent(this.wrapped); | |
| 17 | |
| 18 bool get bubbles => wrapped.bubbles; | |
| 19 | |
| 20 bool get cancelable => wrapped.cancelable; | |
| 21 | |
| 22 DataTransfer get clipboardData => wrapped.clipboardData; | |
| 23 | |
| 24 EventTarget get currentTarget => wrapped.currentTarget; | |
| 25 | |
| 26 bool get defaultPrevented => wrapped.defaultPrevented; | |
| 27 | |
| 28 int get eventPhase => wrapped.eventPhase; | |
| 29 | |
| 30 EventTarget get target => wrapped.target; | |
| 31 | |
| 32 int get timeStamp => wrapped.timeStamp; | |
| 33 | |
| 34 String get type => wrapped.type; | |
| 35 | |
| 36 void _initEvent(String eventTypeArg, bool canBubbleArg, | |
| 37 bool cancelableArg) { | |
| 38 throw new UnsupportedError( | |
| 39 'Cannot initialize this Event.'); | |
| 40 } | |
| 41 | |
| 42 void preventDefault() { | |
| 43 wrapped.preventDefault(); | |
| 44 } | |
| 45 | |
| 46 void stopImmediatePropagation() { | |
| 47 wrapped.stopImmediatePropagation(); | |
| 48 } | |
| 49 | |
| 50 void stopPropagation() { | |
| 51 wrapped.stopPropagation(); | |
| 52 } | |
| 53 | |
| 54 /** | |
| 55 * A pointer to the element whose CSS selector matched within which an event | |
| 56 * was fired. If this Event was not associated with any Event delegation, | |
| 57 * accessing this value will throw an [UnsupportedError]. | |
| 58 */ | |
| 59 Element get matchingTarget { | |
| 60 if (_selector == null) { | |
| 61 throw new UnsupportedError('Cannot call matchingTarget if this Event did' | |
| 62 ' not arise as a result of event delegation.'); | |
| 63 } | |
| 64 var currentTarget = this.currentTarget; | |
| 65 var target = this.target; | |
| 66 var matchedTarget; | |
| 67 do { | |
| 68 if (target.matches(_selector)) return target; | |
| 69 target = target.parent; | |
| 70 } while (target != null && target != currentTarget.parent); | |
| 71 throw new StateError('No selector matched for populating matchedTarget.'); | |
| 72 } | |
| 73 | |
| 74 /** | |
| 75 * This event's path, taking into account shadow DOM. | |
| 76 * | |
| 77 * ## Other resources | |
| 78 * | |
| 79 * * [Shadow DOM extensions to Event] | |
| 80 * (http://w3c.github.io/webcomponents/spec/shadow/#extensions-to-event) from | |
| 81 * W3C. | |
| 82 */ | |
| 83 // https://dvcs.w3.org/hg/webcomponents/raw-file/tip/spec/shadow/index.html#ex
tensions-to-event | |
| 84 @Experimental() | |
| 85 List<Node> get path => wrapped.path; | |
| 86 } | |
| OLD | NEW |