- Revision
- 120945
- Author
- [email protected]
- Date
- 2012-06-21 11:05:26 -0700 (Thu, 21 Jun 2012)
Log Message
Modify event re-targeting algorithm so that we can tell which distributed node is clicked.
https://bugs.webkit.org/show_bug.cgi?id=89073
Reviewed by Dimitri Glazkov.
Source/WebCore:
Adopt a new event re-targeting algorithm in the latest Shadow DOM spec.
The corresponding bug in the shadow DOM spec is:
https://www.w3.org/Bugs/Public/show_bug.cgi?id=17090
This change is introduced to handle the following use case:
1. There is an insertion point, with zero or more nodes distributed into it.
2. User clicks on one of the items.
3. The event handler in shadow DOM subtree wants to know which item was clicked on.
The new re-targeting algorithm sets an event's target to a
distributed node where an event was originally fired, instead of
an insertion point to where the node is distributed.
The similar re-targeting algorithm also applies to an event's
relatedTarget.
Test: fast/dom/shadow/shadow-dom-event-dispatching.html
* dom/EventDispatcher.cpp:
(WebCore::EventRelatedTargetAdjuster::adjust):
(WebCore::EventDispatcher::ensureEventAncestors):
LayoutTests:
* fast/dom/shadow/shadow-dom-event-dispatching-expected.txt:
Modified Paths
Diff
Modified: trunk/LayoutTests/ChangeLog (120944 => 120945)
--- trunk/LayoutTests/ChangeLog 2012-06-21 18:01:58 UTC (rev 120944)
+++ trunk/LayoutTests/ChangeLog 2012-06-21 18:05:26 UTC (rev 120945)
@@ -1,3 +1,12 @@
+2012-06-21 Hayato Ito <[email protected]>
+
+ Modify event re-targeting algorithm so that we can tell which distributed node is clicked.
+ https://bugs.webkit.org/show_bug.cgi?id=89073
+
+ Reviewed by Dimitri Glazkov.
+
+ * fast/dom/shadow/shadow-dom-event-dispatching-expected.txt:
+
2012-06-21 Andrei Onea <[email protected]>
[CSSRegions]Change WEBKIT_REGION_RULE value to 16
Modified: trunk/LayoutTests/fast/dom/shadow/shadow-dom-event-dispatching-expected.txt (120944 => 120945)
--- trunk/LayoutTests/fast/dom/shadow/shadow-dom-event-dispatching-expected.txt 2012-06-21 18:01:58 UTC (rev 120944)
+++ trunk/LayoutTests/fast/dom/shadow/shadow-dom-event-dispatching-expected.txt 2012-06-21 18:05:26 UTC (rev 120945)
@@ -37,8 +37,8 @@
mouseover
@distributed-light-child (target: distributed-light-child) (related: shadow-host)
- @content (target: content) (related: shadow-host)
- @shadow-root (target: content) (related: shadow-host)
+ @content (target: distributed-light-child) (related: shadow-host)
+ @shadow-root (target: distributed-light-child) (related: shadow-host)
@shadow-host (target: distributed-light-child) (related: shadow-host)
@top (target: distributed-light-child) (related: shadow-host)
@@ -46,8 +46,8 @@
mouseout
@distributed-light-child (target: distributed-light-child) (related: shadow-host)
- @content (target: content) (related: shadow-host)
- @shadow-root (target: content) (related: shadow-host)
+ @content (target: distributed-light-child) (related: shadow-host)
+ @shadow-root (target: distributed-light-child) (related: shadow-host)
@shadow-host (target: distributed-light-child) (related: shadow-host)
@top (target: distributed-light-child) (related: shadow-host)
@@ -58,15 +58,15 @@
Moving mouse from shadow-host/shadow-root-child to distributed-light-child
mouseout
- @shadow-root-child (target: shadow-root-child) (related: content)
- @shadow-root (target: shadow-root-child) (related: content)
+ @shadow-root-child (target: shadow-root-child) (related: distributed-light-child)
+ @shadow-root (target: shadow-root-child) (related: distributed-light-child)
@shadow-host (target: shadow-host) (related: distributed-light-child)
@top (target: shadow-host) (related: distributed-light-child)
mouseover
@distributed-light-child (target: distributed-light-child) (related: shadow-host)
- @content (target: content) (related: shadow-root-child)
- @shadow-root (target: content) (related: shadow-root-child)
+ @content (target: distributed-light-child) (related: shadow-root-child)
+ @shadow-root (target: distributed-light-child) (related: shadow-root-child)
@shadow-host (target: distributed-light-child) (related: shadow-host)
@top (target: distributed-light-child) (related: shadow-host)
@@ -74,14 +74,14 @@
mouseout
@distributed-light-child (target: distributed-light-child) (related: shadow-host)
- @content (target: content) (related: shadow-root-child)
- @shadow-root (target: content) (related: shadow-root-child)
+ @content (target: distributed-light-child) (related: shadow-root-child)
+ @shadow-root (target: distributed-light-child) (related: shadow-root-child)
@shadow-host (target: distributed-light-child) (related: shadow-host)
@top (target: distributed-light-child) (related: shadow-host)
mouseover
- @shadow-root-child (target: shadow-root-child) (related: content)
- @shadow-root (target: shadow-root-child) (related: content)
+ @shadow-root-child (target: shadow-root-child) (related: distributed-light-child)
+ @shadow-root (target: shadow-root-child) (related: distributed-light-child)
@shadow-host (target: shadow-host) (related: distributed-light-child)
@top (target: shadow-host) (related: distributed-light-child)
@@ -136,14 +136,14 @@
mouseout
@F (target: F) (related: D)
@E (target: F) (related: D)
- @I (target: I) (related: H)
- @M (target: M) (related: K)
- @O (target: O) (related: K)
- @shadow-root-L (target: O) (related: K)
- @L (target: M) (related: K)
- @shadow-root-G (target: M) (related: K)
- @G (target: I) (related: H)
- @shadow-root-B (target: I) (related: H)
+ @I (target: F) (related: D)
+ @M (target: F) (related: D)
+ @O (target: F) (related: D)
+ @shadow-root-L (target: F) (related: D)
+ @L (target: F) (related: D)
+ @shadow-root-G (target: F) (related: D)
+ @G (target: F) (related: D)
+ @shadow-root-B (target: F) (related: D)
@B (target: F) (related: D)
@A (target: F) (related: D)
@top (target: F) (related: D)
@@ -151,14 +151,14 @@
mouseover
@D (target: D) (related: F)
@C (target: D) (related: F)
- @H (target: H) (related: I)
- @K (target: K) (related: M)
- @N (target: N) (related: M)
- @shadow-root-J (target: N) (related: M)
- @J (target: K) (related: M)
- @shadow-root-G (target: K) (related: M)
- @G (target: H) (related: I)
- @shadow-root-B (target: H) (related: I)
+ @H (target: D) (related: F)
+ @K (target: D) (related: F)
+ @N (target: D) (related: F)
+ @shadow-root-J (target: D) (related: F)
+ @J (target: D) (related: F)
+ @shadow-root-G (target: D) (related: F)
+ @G (target: D) (related: F)
+ @shadow-root-B (target: D) (related: F)
@B (target: D) (related: F)
@A (target: D) (related: F)
@top (target: D) (related: F)
@@ -166,10 +166,10 @@
Moving mouse from B/G/L to D
mouseout
- @L (target: L) (related: K)
- @shadow-root-G (target: L) (related: K)
- @G (target: G) (related: H)
- @shadow-root-B (target: G) (related: H)
+ @L (target: L) (related: D)
+ @shadow-root-G (target: L) (related: D)
+ @G (target: G) (related: D)
+ @shadow-root-B (target: G) (related: D)
@B (target: B) (related: D)
@A (target: B) (related: D)
@top (target: B) (related: D)
@@ -177,14 +177,14 @@
mouseover
@D (target: D) (related: B)
@C (target: D) (related: B)
- @H (target: H) (related: G)
- @K (target: K) (related: L)
- @N (target: N) (related: L)
- @shadow-root-J (target: N) (related: L)
- @J (target: K) (related: L)
- @shadow-root-G (target: K) (related: L)
- @G (target: H) (related: G)
- @shadow-root-B (target: H) (related: G)
+ @H (target: D) (related: G)
+ @K (target: D) (related: L)
+ @N (target: D) (related: L)
+ @shadow-root-J (target: D) (related: L)
+ @J (target: D) (related: L)
+ @shadow-root-G (target: D) (related: L)
+ @G (target: D) (related: G)
+ @shadow-root-B (target: D) (related: G)
@B (target: D) (related: B)
@A (target: D) (related: B)
@top (target: D) (related: B)
@@ -208,14 +208,14 @@
mouseover
@D (target: D) (related: A)
@C (target: D) (related: A)
- @H (target: H) (related: A)
- @K (target: K) (related: A)
- @N (target: N) (related: A)
- @shadow-root-J (target: N) (related: A)
- @J (target: K) (related: A)
- @shadow-root-G (target: K) (related: A)
- @G (target: H) (related: A)
- @shadow-root-B (target: H) (related: A)
+ @H (target: D) (related: A)
+ @K (target: D) (related: A)
+ @N (target: D) (related: A)
+ @shadow-root-J (target: D) (related: A)
+ @J (target: D) (related: A)
+ @shadow-root-G (target: D) (related: A)
+ @G (target: D) (related: A)
+ @shadow-root-B (target: D) (related: A)
@B (target: D) (related: A)
@A (target: D) (related: A)
@top (target: D) (related: A)
@@ -225,14 +225,14 @@
mouseout
@D (target: D) (related: A)
@C (target: D) (related: A)
- @H (target: H) (related: A)
- @K (target: K) (related: A)
- @N (target: N) (related: A)
- @shadow-root-J (target: N) (related: A)
- @J (target: K) (related: A)
- @shadow-root-G (target: K) (related: A)
- @G (target: H) (related: A)
- @shadow-root-B (target: H) (related: A)
+ @H (target: D) (related: A)
+ @K (target: D) (related: A)
+ @N (target: D) (related: A)
+ @shadow-root-J (target: D) (related: A)
+ @J (target: D) (related: A)
+ @shadow-root-G (target: D) (related: A)
+ @G (target: D) (related: A)
+ @shadow-root-B (target: D) (related: A)
@B (target: D) (related: A)
@A (target: D) (related: A)
@top (target: D) (related: A)
@@ -317,8 +317,8 @@
@child-of-inactive-content (target: child-of-inactive-content) (related: A)
@inactive-content (target: child-of-inactive-content) (related: A)
@parent-of-inactive-content (target: child-of-inactive-content) (related: A)
- @active-content (target: active-content) (related: A)
- @shadow-root-B (target: active-content) (related: A)
+ @active-content (target: child-of-inactive-content) (related: A)
+ @shadow-root-B (target: child-of-inactive-content) (related: A)
@B (target: child-of-inactive-content) (related: A)
@top (target: child-of-inactive-content) (related: A)
@@ -336,10 +336,10 @@
mouseout
@B (target: B) (related: A)
- @C (target: C) (related: A)
- @older-shadow-root (target: C) (related: A)
- @E (target: E) (related: A)
- @younger-shadow-root (target: E) (related: A)
+ @C (target: B) (related: A)
+ @older-shadow-root (target: B) (related: A)
+ @E (target: B) (related: A)
+ @younger-shadow-root (target: B) (related: A)
@A (target: B) (related: A)
@top (target: B) (related: A)
@@ -363,16 +363,16 @@
mouseout
@B (target: B) (related: A)
- @C (target: C) (related: A)
- @older-shadow-root (target: C) (related: A)
- @E (target: E) (related: F)
- @younger-shadow-root (target: E) (related: F)
+ @C (target: B) (related: A)
+ @older-shadow-root (target: B) (related: A)
+ @E (target: B) (related: F)
+ @younger-shadow-root (target: B) (related: F)
@A (target: B) (related: A)
@top (target: B) (related: A)
mouseover
- @F (target: F) (related: E)
- @younger-shadow-root (target: F) (related: E)
+ @F (target: F) (related: B)
+ @younger-shadow-root (target: F) (related: B)
@A (target: A) (related: B)
@top (target: A) (related: B)
Modified: trunk/Source/WebCore/ChangeLog (120944 => 120945)
--- trunk/Source/WebCore/ChangeLog 2012-06-21 18:01:58 UTC (rev 120944)
+++ trunk/Source/WebCore/ChangeLog 2012-06-21 18:05:26 UTC (rev 120945)
@@ -1,3 +1,32 @@
+2012-06-21 Hayato Ito <[email protected]>
+
+ Modify event re-targeting algorithm so that we can tell which distributed node is clicked.
+ https://bugs.webkit.org/show_bug.cgi?id=89073
+
+ Reviewed by Dimitri Glazkov.
+
+ Adopt a new event re-targeting algorithm in the latest Shadow DOM spec.
+ The corresponding bug in the shadow DOM spec is:
+ https://www.w3.org/Bugs/Public/show_bug.cgi?id=17090
+
+ This change is introduced to handle the following use case:
+ 1. There is an insertion point, with zero or more nodes distributed into it.
+ 2. User clicks on one of the items.
+ 3. The event handler in shadow DOM subtree wants to know which item was clicked on.
+
+ The new re-targeting algorithm sets an event's target to a
+ distributed node where an event was originally fired, instead of
+ an insertion point to where the node is distributed.
+
+ The similar re-targeting algorithm also applies to an event's
+ relatedTarget.
+
+ Test: fast/dom/shadow/shadow-dom-event-dispatching.html
+
+ * dom/EventDispatcher.cpp:
+ (WebCore::EventRelatedTargetAdjuster::adjust):
+ (WebCore::EventDispatcher::ensureEventAncestors):
+
2012-06-21 Andrei Onea <[email protected]>
[CSSRegions]Change WEBKIT_REGION_RULE value to 16
Modified: trunk/Source/WebCore/dom/EventDispatcher.cpp (120944 => 120945)
--- trunk/Source/WebCore/dom/EventDispatcher.cpp 2012-06-21 18:01:58 UTC (rev 120944)
+++ trunk/Source/WebCore/dom/EventDispatcher.cpp 2012-06-21 18:05:26 UTC (rev 120945)
@@ -67,13 +67,25 @@
void EventRelatedTargetAdjuster::adjust(Vector<EventContext>& ancestors)
{
+ Vector<EventTarget*> relatedTargetStack;
TreeScope* lastTreeScope = 0;
+ Node* lastNode = 0;
for (ComposedShadowTreeParentWalker walker(m_relatedTarget.get()); walker.get(); walker.parentIncludingInsertionPointAndShadowRoot()) {
- TreeScope* scope = walker.get()->treeScope();
- // Skips adding a node to the map if treeScope does not change.
+ Node* node = walker.get();
+ if (relatedTargetStack.isEmpty())
+ relatedTargetStack.append(node);
+ else if (isInsertionPoint(node) && isAssignedTo(lastNode, toInsertionPoint(node)))
+ relatedTargetStack.append(relatedTargetStack.last());
+ TreeScope* scope = node->treeScope();
+ // Skips adding a node to the map if treeScope does not change. Just for the performance optimization.
if (scope != lastTreeScope)
- m_relatedTargetMap.add(scope, walker.get());
+ m_relatedTargetMap.add(scope, relatedTargetStack.last());
lastTreeScope = scope;
+ lastNode = node;
+ if (node->isShadowRoot()) {
+ ASSERT(!relatedTargetStack.isEmpty());
+ relatedTargetStack.removeLast();
+ }
}
lastTreeScope = 0;
@@ -81,7 +93,7 @@
for (Vector<EventContext>::iterator iter = ancestors.begin(); iter < ancestors.end(); ++iter) {
TreeScope* scope = iter->node()->treeScope();
if (scope == lastTreeScope) {
- // Re-use the previous adjustedRelatedTarget if treeScope does not change.
+ // Re-use the previous adjustedRelatedTarget if treeScope does not change. Just for the performance optimization.
iter->setRelatedTarget(adjustedRelatedTarget);
} else {
adjustedRelatedTarget = findRelatedTarget(scope);
@@ -212,8 +224,10 @@
Node* last = 0;
for (ComposedShadowTreeParentWalker walker(m_node.get()); walker.get(); walker.parentIncludingInsertionPointAndShadowRoot()) {
Node* node = walker.get();
- if ((isInsertionPoint(node) && isAssignedTo(last, toInsertionPoint(node))) || targetStack.isEmpty())
+ if (targetStack.isEmpty())
targetStack.append(eventTargetRespectingSVGTargetRules(node));
+ else if (isInsertionPoint(node) && isAssignedTo(last, toInsertionPoint(node)))
+ targetStack.append(targetStack.last());
m_ancestors.append(EventContext(node, eventTargetRespectingSVGTargetRules(node), targetStack.last()));
if (!inDocument)
return;
@@ -222,8 +236,10 @@
continue;
if (determineDispatchBehavior(event, toShadowRoot(node)) == StayInsideShadowDOM)
return;
- if (!isSVGElement && !targetStack.isEmpty())
+ if (!isSVGElement) {
+ ASSERT(!targetStack.isEmpty());
targetStack.removeLast();
+ }
}
}