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

Unified Diff: sdk/lib/html/dart2js/html_dart2js.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:
Download patch
« no previous file with comments | « no previous file | sdk/lib/html/dartium/html_dartium.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/html/dart2js/html_dart2js.dart
diff --git a/sdk/lib/html/dart2js/html_dart2js.dart b/sdk/lib/html/dart2js/html_dart2js.dart
index 708bdb016ca2a9c401377247d8acbd598516f465..abfe227b1e1f58ffb2fee7b129767e612740eb3f 100644
--- a/sdk/lib/html/dart2js/html_dart2js.dart
+++ b/sdk/lib/html/dart2js/html_dart2js.dart
@@ -11062,8 +11062,31 @@ class Event extends Interceptor native "Event" {
e._initEvent(name, canBubble, cancelable);
return e;
}
+
+ /** The CSS selector involved with event delegation. */
+ String _selector;
- Event._private();
+ /**
+ * A pointer to the element whose CSS selector matched within which an event
+ * was fired. If this Event was not associated with any Event delegation,
+ * accessing this value will throw an [UnsupportedError].
+ */
+ Element get matchingTarget {
+ if (_selector == null) {
+ throw new UnsupportedError('Cannot call matchingTarget if this Event did'
+ ' not arise as a result of event delegation.');
+ }
+ var currentTarget = this.currentTarget;
+ var target = this.target;
+ var matchedTarget;
+ while (matchedTarget == null && target != currentTarget && target != null) {
+ if (target.matches(_selector)) {
+ matchedTarget = target;
+ }
+ target = target.parent;
+ }
+ return matchedTarget;
+ }
@DomName('Event.AT_TARGET')
@DocsEditable()
@@ -29072,8 +29095,11 @@ class _ElementEventStreamImpl<T extends Event> extends _EventStream<T>
_ElementEventStreamImpl(target, eventType, useCapture) :
super(target, eventType, useCapture);
- Stream<T> matches(String selector) =>
- this.where((event) => event.target.matchesWithAncestors(selector));
+ Stream<T> matches(String selector) => this.where(
+ (event) => event.target.matchesWithAncestors(selector)).map((e) {
+ e._selector = selector;
+ return e;
+ });
}
/**
@@ -29094,8 +29120,11 @@ class _ElementListEventStreamImpl<T extends Event> extends Stream<T>
_stream = _pool.stream;
}
- Stream<T> matches(String selector) =>
- this.where((event) => event.target.matchesWithAncestors(selector));
+ Stream<T> matches(String selector) => this.where(
+ (event) => event.target.matchesWithAncestors(selector)).map((e) {
+ e._selector = selector;
+ return e;
+ });
// Delegate all regular Stream behavor to our wrapped Stream.
StreamSubscription<T> listen(void onData(T event),
« no previous file with comments | « no previous file | sdk/lib/html/dartium/html_dartium.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698