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 * TODO(jacobr): consider using dart JsNative.$setInstanceInterceptor | |
10 * instead of using wrappers as that would allow passing these wrappers | |
11 * back through dispatchEvent unlike the current implementation. | |
12 * See https://github.com/dart-lang/sdk/issues/16869 | |
13 */ | |
14 class _WrappedEvent implements Event { | |
15 /** Needed because KeyboardEvent is implements. | |
16 */ | |
17 final Event wrapped; | |
18 | |
19 /** The CSS selector involved with event delegation. */ | |
20 String _selector; | |
21 | |
22 _WrappedEvent(this.wrapped); | |
23 | |
24 bool get bubbles => wrapped.bubbles; | |
25 | |
26 bool get cancelable => wrapped.cancelable; | |
27 | |
28 EventTarget get currentTarget => wrapped.currentTarget; | |
29 | |
30 List<EventTarget> deepPath() { | |
31 return wrapped.deepPath(); | |
32 } | |
33 | |
34 bool get defaultPrevented => wrapped.defaultPrevented; | |
35 | |
36 int get eventPhase => wrapped.eventPhase; | |
37 | |
38 bool get isTrusted => wrapped.isTrusted; | |
39 | |
40 bool get scoped => wrapped.scoped; | |
41 | |
42 EventTarget get target => wrapped.target; | |
43 | |
44 double get timeStamp => wrapped.timeStamp; | |
45 | |
46 String get type => wrapped.type; | |
47 | |
48 void _initEvent(String eventTypeArg, bool canBubbleArg, bool cancelableArg) { | |
49 throw new UnsupportedError('Cannot initialize this Event.'); | |
50 } | |
51 | |
52 void preventDefault() { | |
53 wrapped.preventDefault(); | |
54 } | |
55 | |
56 void stopImmediatePropagation() { | |
57 wrapped.stopImmediatePropagation(); | |
58 } | |
59 | |
60 void stopPropagation() { | |
61 wrapped.stopPropagation(); | |
62 } | |
63 | |
64 /** | |
65 * A pointer to the element whose CSS selector matched within which an event | |
66 * was fired. If this Event was not associated with any Event delegation, | |
67 * accessing this value will throw an [UnsupportedError]. | |
68 */ | |
69 Element get matchingTarget { | |
70 if (_selector == null) { | |
71 throw new UnsupportedError('Cannot call matchingTarget if this Event did' | |
72 ' not arise as a result of event delegation.'); | |
73 } | |
74 var currentTarget = this.currentTarget; | |
75 var target = this.target; | |
76 var matchedTarget; | |
77 do { | |
78 if (target.matches(_selector)) return target; | |
79 target = target.parent; | |
80 } while (target != null && target != currentTarget.parent); | |
81 throw new StateError('No selector matched for populating matchedTarget.'); | |
82 } | |
83 | |
84 /** | |
85 * This event's path, taking into account shadow DOM. | |
86 * | |
87 * ## Other resources | |
88 * | |
89 * * [Shadow DOM extensions to | |
90 * Event](http://w3c.github.io/webcomponents/spec/shadow/#extensions-to-even
t) | |
91 * from W3C. | |
92 */ | |
93 // https://dvcs.w3.org/hg/webcomponents/raw-file/tip/spec/shadow/index.html#ex
tensions-to-event | |
94 @Experimental() | |
95 List<Node> get path => wrapped.path; | |
96 } | |
OLD | NEW |