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 isInSVGUseShadowTree(Node& node) |
80 { | 81 { |
81 return node.isPseudoElement() && !node.parentElement(); | 82 if (ShadowRoot* root = node.containingShadowRoot()) |
83 return root->type() == ShadowRootType::UserAgent && isSVGUseElement(root ->host()); | |
84 return false; | |
85 } | |
86 | |
87 static inline bool eventPathShouldBeEmptyFor(Node& node, Event* event) | |
88 { | |
89 return (node.isPseudoElement() && !node.parentElement()) || (isInSVGUseShado wTree(node) && event && !event->composed()); | |
pdr.
2016/07/30 04:02:42
WDYT of breaking these two complex cases apart as
hayato
2016/08/01 03:44:10
Sounds nice. Done
| |
82 } | 90 } |
83 | 91 |
84 void EventPath::initialize() | 92 void EventPath::initialize() |
85 { | 93 { |
86 if (eventPathShouldBeEmptyFor(*m_node)) | 94 if (eventPathShouldBeEmptyFor(*m_node, m_event)) |
87 return; | 95 return; |
96 | |
88 calculatePath(); | 97 calculatePath(); |
89 calculateAdjustedTargets(); | 98 calculateAdjustedTargets(); |
90 calculateTreeOrderAndSetNearestAncestorClosedTree(); | 99 calculateTreeOrderAndSetNearestAncestorClosedTree(); |
91 } | 100 } |
92 | 101 |
93 void EventPath::calculatePath() | 102 void EventPath::calculatePath() |
pdr.
2016/07/30 04:02:42
I'm not very familiar with the event apis. Can you
| |
94 { | 103 { |
95 ASSERT(m_node); | 104 ASSERT(m_node); |
96 ASSERT(m_nodeEventContexts.isEmpty()); | 105 ASSERT(m_nodeEventContexts.isEmpty()); |
97 m_node->updateDistribution(); | 106 m_node->updateDistribution(); |
98 | 107 |
99 // For performance and memory usage reasons we want to store the | 108 // For performance and memory usage reasons we want to store the |
100 // path using as few bytes as possible and with as few allocations | 109 // 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 | 110 // as possible which is why we gather the data on the stack before |
102 // storing it in a perfectly sized m_nodeEventContexts Vector. | 111 // storing it in a perfectly sized m_nodeEventContexts Vector. |
103 HeapVector<Member<Node>, 64> nodesInPath; | 112 HeapVector<Member<Node>, 64> nodesInPath; |
104 Node* current = m_node; | 113 Node* current = m_node; |
114 | |
115 // Exclude nodes in SVG <use>'s shadow tree from event path. | |
116 // See crbug.com/630870 | |
117 while (isInSVGUseShadowTree(*current)) | |
pdr.
2016/07/30 04:02:42
I think this can be rewritten using existing apis
hayato
2016/08/01 03:44:10
Thanks! Done.
| |
118 current = ¤t->containingShadowRoot()->host(); | |
119 | |
105 nodesInPath.append(current); | 120 nodesInPath.append(current); |
106 while (current) { | 121 while (current) { |
107 if (m_event && current->keepEventInNode(m_event)) | 122 if (m_event && current->keepEventInNode(m_event)) |
108 break; | 123 break; |
109 HeapVector<Member<InsertionPoint>, 8> insertionPoints; | 124 HeapVector<Member<InsertionPoint>, 8> insertionPoints; |
110 collectDestinationInsertionPoints(*current, insertionPoints); | 125 collectDestinationInsertionPoints(*current, insertionPoints); |
111 if (!insertionPoints.isEmpty()) { | 126 if (!insertionPoints.isEmpty()) { |
112 for (const auto& insertionPoint : insertionPoints) { | 127 for (const auto& insertionPoint : insertionPoints) { |
113 if (insertionPoint->isShadowInsertionPoint()) { | 128 if (insertionPoint->isShadowInsertionPoint()) { |
114 ShadowRoot* containingShadowRoot = insertionPoint->containin gShadowRoot(); | 129 ShadowRoot* containingShadowRoot = insertionPoint->containin gShadowRoot(); |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
362 DEFINE_TRACE(EventPath) | 377 DEFINE_TRACE(EventPath) |
363 { | 378 { |
364 visitor->trace(m_nodeEventContexts); | 379 visitor->trace(m_nodeEventContexts); |
365 visitor->trace(m_node); | 380 visitor->trace(m_node); |
366 visitor->trace(m_event); | 381 visitor->trace(m_event); |
367 visitor->trace(m_treeScopeEventContexts); | 382 visitor->trace(m_treeScopeEventContexts); |
368 visitor->trace(m_windowEventContext); | 383 visitor->trace(m_windowEventContext); |
369 } | 384 } |
370 | 385 |
371 } // namespace blink | 386 } // namespace blink |
OLD | NEW |