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 |
12 _WrappedEvent(this.wrapped); | 16 _WrappedEvent(this.wrapped); |
13 | 17 |
14 bool get bubbles => wrapped.bubbles; | 18 bool get bubbles => wrapped.bubbles; |
15 | 19 |
16 bool get cancelable => wrapped.cancelable; | 20 bool get cancelable => wrapped.cancelable; |
17 | 21 |
18 DataTransfer get clipboardData => wrapped.clipboardData; | 22 DataTransfer get clipboardData => wrapped.clipboardData; |
19 | 23 |
20 EventTarget get currentTarget => wrapped.currentTarget; | 24 EventTarget get currentTarget => wrapped.currentTarget; |
21 | 25 |
(...skipping 17 matching lines...) Expand all Loading... |
39 wrapped.preventDefault(); | 43 wrapped.preventDefault(); |
40 } | 44 } |
41 | 45 |
42 void stopImmediatePropagation() { | 46 void stopImmediatePropagation() { |
43 wrapped.stopImmediatePropagation(); | 47 wrapped.stopImmediatePropagation(); |
44 } | 48 } |
45 | 49 |
46 void stopPropagation() { | 50 void stopPropagation() { |
47 wrapped.stopPropagation(); | 51 wrapped.stopPropagation(); |
48 } | 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 |
| 87 dynamic get _get_currentTarget => wrapped._get_currentTarget; |
| 88 |
| 89 dynamic get _get_target => wrapped._get_target; |
49 } | 90 } |
OLD | NEW |