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

Unified Diff: tools/dom/templates/html/impl/impl_Event.darttemplate

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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/dom/src/EventStreamProvider.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/dom/templates/html/impl/impl_Event.darttemplate
diff --git a/tools/dom/templates/html/impl/impl_Event.darttemplate b/tools/dom/templates/html/impl/impl_Event.darttemplate
index a3fc47f660dd5faa429cd19a30bde06f4fc51673..ef07e13c1cdca386238aa5b5f3202f5500e8ac03 100644
--- a/tools/dom/templates/html/impl/impl_Event.darttemplate
+++ b/tools/dom/templates/html/impl/impl_Event.darttemplate
@@ -33,7 +33,30 @@ $(ANNOTATIONS)$(CLASS_MODIFIERS)class $CLASSNAME$EXTENDS$IMPLEMENTS$NATIVESPEC {
e._initEvent(name, canBubble, cancelable);
return e;
}
+
+ /** The CSS selector involved with event delegation. */
+ String _selector;
- $CLASSNAME._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;
+ }
$!MEMBERS
}
« no previous file with comments | « tools/dom/src/EventStreamProvider.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698