OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 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 | 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 dart.html; | 5 part of dart.html; |
6 | 6 |
7 /** | 7 /** |
8 * Helper class to implement custom events which wrap DOM events. | 8 * Helper class to implement custom events which wrap DOM events. |
9 */ | 9 */ |
10 class _WrappedEvent implements Event { | 10 class _WrappedEvent implements Event { |
11 final Event wrapped; | 11 final Event wrapped; |
12 | |
13 /** The CSS selector involved with event delegation. */ | |
14 String _selector; | |
15 | |
16 _WrappedEvent(this.wrapped); | 12 _WrappedEvent(this.wrapped); |
17 | 13 |
18 bool get bubbles => wrapped.bubbles; | 14 bool get bubbles => wrapped.bubbles; |
19 | 15 |
20 bool get cancelable => wrapped.cancelable; | 16 bool get cancelable => wrapped.cancelable; |
21 | 17 |
22 DataTransfer get clipboardData => wrapped.clipboardData; | 18 DataTransfer get clipboardData => wrapped.clipboardData; |
23 | 19 |
24 EventTarget get currentTarget => wrapped.currentTarget; | 20 EventTarget get currentTarget => wrapped.currentTarget; |
25 | 21 |
(...skipping 17 matching lines...) Expand all Loading... |
43 wrapped.preventDefault(); | 39 wrapped.preventDefault(); |
44 } | 40 } |
45 | 41 |
46 void stopImmediatePropagation() { | 42 void stopImmediatePropagation() { |
47 wrapped.stopImmediatePropagation(); | 43 wrapped.stopImmediatePropagation(); |
48 } | 44 } |
49 | 45 |
50 void stopPropagation() { | 46 void stopPropagation() { |
51 wrapped.stopPropagation(); | 47 wrapped.stopPropagation(); |
52 } | 48 } |
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 | |
87 dynamic get _get_currentTarget => wrapped._get_currentTarget; | |
88 | |
89 dynamic get _get_target => wrapped._get_target; | |
90 } | 49 } |
OLD | NEW |