Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(288)

Side by Side Diff: tools/dom/src/EventStreamProvider.dart

Issue 26722002: Add "matchingTarget" function to Event, which is the Element that matched the CSS value selector. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tests/html/element_test.dart ('k') | tools/dom/templates/html/impl/impl_Event.darttemplate » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 html; 5 part of html;
6 6
7 /** 7 /**
8 * Adapter for exposing DOM events as Dart streams. 8 * Adapter for exposing DOM events as Dart streams.
9 */ 9 */
10 class _EventStream<T extends Event> extends Stream<T> { 10 class _EventStream<T extends Event> extends Stream<T> {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 44
45 /** 45 /**
46 * Adapter for exposing DOM Element events as streams, while also allowing 46 * Adapter for exposing DOM Element events as streams, while also allowing
47 * event delegation. 47 * event delegation.
48 */ 48 */
49 class _ElementEventStreamImpl<T extends Event> extends _EventStream<T> 49 class _ElementEventStreamImpl<T extends Event> extends _EventStream<T>
50 implements ElementStream<T> { 50 implements ElementStream<T> {
51 _ElementEventStreamImpl(target, eventType, useCapture) : 51 _ElementEventStreamImpl(target, eventType, useCapture) :
52 super(target, eventType, useCapture); 52 super(target, eventType, useCapture);
53 53
54 Stream<T> matches(String selector) => 54 Stream<T> matches(String selector) => this.where(
55 this.where((event) => event.target.matchesWithAncestors(selector)); 55 (event) => event.target.matchesWithAncestors(selector)).map((e) {
56 e._selector = selector;
57 return e;
58 });
56 } 59 }
57 60
58 /** 61 /**
59 * Adapter for exposing events on a collection of DOM Elements as streams, 62 * Adapter for exposing events on a collection of DOM Elements as streams,
60 * while also allowing event delegation. 63 * while also allowing event delegation.
61 */ 64 */
62 class _ElementListEventStreamImpl<T extends Event> extends Stream<T> 65 class _ElementListEventStreamImpl<T extends Event> extends Stream<T>
63 implements ElementStream<T> { 66 implements ElementStream<T> {
64 final _StreamPool _pool; 67 final _StreamPool _pool;
65 Stream<T> _stream; 68 Stream<T> _stream;
66 69
67 _ElementListEventStreamImpl(targetList, eventType, useCapture) : 70 _ElementListEventStreamImpl(targetList, eventType, useCapture) :
68 _pool = new _StreamPool.broadcast() { 71 _pool = new _StreamPool.broadcast() {
69 for (Element target in targetList) { 72 for (Element target in targetList) {
70 var stream = new _EventStream(target, eventType, useCapture); 73 var stream = new _EventStream(target, eventType, useCapture);
71 _pool.add(stream); 74 _pool.add(stream);
72 } 75 }
73 _stream = _pool.stream; 76 _stream = _pool.stream;
74 } 77 }
75 78
76 Stream<T> matches(String selector) => 79 Stream<T> matches(String selector) => this.where(
77 this.where((event) => event.target.matchesWithAncestors(selector)); 80 (event) => event.target.matchesWithAncestors(selector)).map((e) {
81 e._selector = selector;
82 return e;
83 });
78 84
79 // Delegate all regular Stream behavor to our wrapped Stream. 85 // Delegate all regular Stream behavor to our wrapped Stream.
80 StreamSubscription<T> listen(void onData(T event), 86 StreamSubscription<T> listen(void onData(T event),
81 { void onError(error), 87 { void onError(error),
82 void onDone(), 88 void onDone(),
83 bool cancelOnError}) => 89 bool cancelOnError}) =>
84 _stream.listen(onData, onError: onError, onDone: onDone, 90 _stream.listen(onData, onError: onError, onDone: onDone,
85 cancelOnError: cancelOnError); 91 cancelOnError: cancelOnError);
86 Stream<T> asBroadcastStream({void onListen(StreamSubscription subscription), 92 Stream<T> asBroadcastStream({void onListen(StreamSubscription subscription),
87 void onCancel(StreamSubscription subscription)}) 93 void onCancel(StreamSubscription subscription)})
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 388
383 ElementStream<T> _forElementList(ElementList e, 389 ElementStream<T> _forElementList(ElementList e,
384 {bool useCapture: false}) { 390 {bool useCapture: false}) {
385 return new _ElementListEventStreamImpl(e, _eventTypeGetter(e), useCapture); 391 return new _ElementListEventStreamImpl(e, _eventTypeGetter(e), useCapture);
386 } 392 }
387 393
388 String getEventType(EventTarget target) { 394 String getEventType(EventTarget target) {
389 return _eventTypeGetter(target); 395 return _eventTypeGetter(target);
390 } 396 }
391 } 397 }
OLDNEW
« no previous file with comments | « tests/html/element_test.dart ('k') | tools/dom/templates/html/impl/impl_Event.darttemplate » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698