OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Neither the name of Google Inc. nor the names of its | 10 * * Neither the name of Google Inc. nor the names of its |
(...skipping 17 matching lines...) Expand all Loading... |
28 | 28 |
29 #include "core/EventNames.h" | 29 #include "core/EventNames.h" |
30 #include "core/dom/Document.h" | 30 #include "core/dom/Document.h" |
31 #include "core/dom/Touch.h" | 31 #include "core/dom/Touch.h" |
32 #include "core/dom/TouchList.h" | 32 #include "core/dom/TouchList.h" |
33 #include "core/dom/shadow/InsertionPoint.h" | 33 #include "core/dom/shadow/InsertionPoint.h" |
34 #include "core/dom/shadow/ShadowRoot.h" | 34 #include "core/dom/shadow/ShadowRoot.h" |
35 #include "core/events/TouchEvent.h" | 35 #include "core/events/TouchEvent.h" |
36 #include "core/events/TouchEventContext.h" | 36 #include "core/events/TouchEventContext.h" |
37 #include "core/html/HTMLSlotElement.h" | 37 #include "core/html/HTMLSlotElement.h" |
| 38 #include "core/svg/SVGUseElement.h" |
38 | 39 |
39 namespace blink { | 40 namespace blink { |
40 | 41 |
41 EventTarget* EventPath::eventTargetRespectingTargetRules(Node& referenceNode) | 42 EventTarget* EventPath::eventTargetRespectingTargetRules(Node& referenceNode) |
42 { | 43 { |
43 if (referenceNode.isPseudoElement()) { | 44 if (referenceNode.isPseudoElement()) { |
44 ASSERT(referenceNode.parentNode()); | 45 ASSERT(referenceNode.parentNode()); |
45 return referenceNode.parentNode(); | 46 return referenceNode.parentNode(); |
46 } | 47 } |
47 | 48 |
(...skipping 21 matching lines...) Expand all Loading... |
69 void EventPath::initializeWith(Node& node, Event* event) | 70 void EventPath::initializeWith(Node& node, Event* event) |
70 { | 71 { |
71 m_node = &node; | 72 m_node = &node; |
72 m_event = event; | 73 m_event = event; |
73 m_windowEventContext = nullptr; | 74 m_windowEventContext = nullptr; |
74 m_nodeEventContexts.clear(); | 75 m_nodeEventContexts.clear(); |
75 m_treeScopeEventContexts.clear(); | 76 m_treeScopeEventContexts.clear(); |
76 initialize(); | 77 initialize(); |
77 } | 78 } |
78 | 79 |
79 static inline bool eventPathShouldBeEmptyFor(Node& node) | 80 static inline bool eventPathShouldBeEmptyFor(Node& node, Event* event) |
80 { | 81 { |
81 return node.isPseudoElement() && !node.parentElement(); | 82 if (node.isPseudoElement() && !node.parentElement()) |
| 83 return true; |
| 84 |
| 85 // Do not dispatch non-composed events in SVG use trees. |
| 86 if (node.isSVGElement()) { |
| 87 if (toSVGElement(node).inUseShadowTree() && event && !event->composed()) |
| 88 return true; |
| 89 } |
| 90 |
| 91 return false; |
82 } | 92 } |
83 | 93 |
84 void EventPath::initialize() | 94 void EventPath::initialize() |
85 { | 95 { |
86 if (eventPathShouldBeEmptyFor(*m_node)) | 96 if (eventPathShouldBeEmptyFor(*m_node, m_event)) |
87 return; | 97 return; |
| 98 |
88 calculatePath(); | 99 calculatePath(); |
89 calculateAdjustedTargets(); | 100 calculateAdjustedTargets(); |
90 calculateTreeOrderAndSetNearestAncestorClosedTree(); | 101 calculateTreeOrderAndSetNearestAncestorClosedTree(); |
91 } | 102 } |
92 | 103 |
93 void EventPath::calculatePath() | 104 void EventPath::calculatePath() |
94 { | 105 { |
95 ASSERT(m_node); | 106 ASSERT(m_node); |
96 ASSERT(m_nodeEventContexts.isEmpty()); | 107 ASSERT(m_nodeEventContexts.isEmpty()); |
97 m_node->updateDistribution(); | 108 m_node->updateDistribution(); |
98 | 109 |
99 // For performance and memory usage reasons we want to store the | 110 // For performance and memory usage reasons we want to store the |
100 // path using as few bytes as possible and with as few allocations | 111 // path using as few bytes as possible and with as few allocations |
101 // as possible which is why we gather the data on the stack before | 112 // as possible which is why we gather the data on the stack before |
102 // storing it in a perfectly sized m_nodeEventContexts Vector. | 113 // storing it in a perfectly sized m_nodeEventContexts Vector. |
103 HeapVector<Member<Node>, 64> nodesInPath; | 114 HeapVector<Member<Node>, 64> nodesInPath; |
104 Node* current = m_node; | 115 Node* current = m_node; |
| 116 |
| 117 // Exclude nodes in SVG <use>'s shadow tree from event path. |
| 118 // See crbug.com/630870 |
| 119 while (current->isSVGElement()) { |
| 120 SVGUseElement* correspondingUseElement = toSVGElement(current)->correspo
ndingUseElement(); |
| 121 if (!correspondingUseElement) |
| 122 break; |
| 123 current = correspondingUseElement; |
| 124 } |
| 125 |
105 nodesInPath.append(current); | 126 nodesInPath.append(current); |
106 while (current) { | 127 while (current) { |
107 if (m_event && current->keepEventInNode(m_event)) | 128 if (m_event && current->keepEventInNode(m_event)) |
108 break; | 129 break; |
109 HeapVector<Member<InsertionPoint>, 8> insertionPoints; | 130 HeapVector<Member<InsertionPoint>, 8> insertionPoints; |
110 collectDestinationInsertionPoints(*current, insertionPoints); | 131 collectDestinationInsertionPoints(*current, insertionPoints); |
111 if (!insertionPoints.isEmpty()) { | 132 if (!insertionPoints.isEmpty()) { |
112 for (const auto& insertionPoint : insertionPoints) { | 133 for (const auto& insertionPoint : insertionPoints) { |
113 if (insertionPoint->isShadowInsertionPoint()) { | 134 if (insertionPoint->isShadowInsertionPoint()) { |
114 ShadowRoot* containingShadowRoot = insertionPoint->containin
gShadowRoot(); | 135 ShadowRoot* containingShadowRoot = insertionPoint->containin
gShadowRoot(); |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 DEFINE_TRACE(EventPath) | 383 DEFINE_TRACE(EventPath) |
363 { | 384 { |
364 visitor->trace(m_nodeEventContexts); | 385 visitor->trace(m_nodeEventContexts); |
365 visitor->trace(m_node); | 386 visitor->trace(m_node); |
366 visitor->trace(m_event); | 387 visitor->trace(m_event); |
367 visitor->trace(m_treeScopeEventContexts); | 388 visitor->trace(m_treeScopeEventContexts); |
368 visitor->trace(m_windowEventContext); | 389 visitor->trace(m_windowEventContext); |
369 } | 390 } |
370 | 391 |
371 } // namespace blink | 392 } // namespace blink |
OLD | NEW |