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 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 } | 123 } |
124 | 124 |
125 void EventPath::resetWith(Node* node) | 125 void EventPath::resetWith(Node* node) |
126 { | 126 { |
127 ASSERT(node); | 127 ASSERT(node); |
128 m_node = node; | 128 m_node = node; |
129 m_nodeEventContexts.clear(); | 129 m_nodeEventContexts.clear(); |
130 m_treeScopeEventContexts.clear(); | 130 m_treeScopeEventContexts.clear(); |
131 calculatePath(); | 131 calculatePath(); |
132 calculateAdjustedTargets(); | 132 calculateAdjustedTargets(); |
133 calculateAdjustedEventPath(); | 133 if (RuntimeEnabledFeatures::shadowDOMEnabled() && !node->isSVGElement()) |
| 134 calculateTreeScopePrePostOrderNumbers(); |
134 } | 135 } |
135 | 136 |
136 void EventPath::addNodeEventContext(Node* node) | 137 void EventPath::addNodeEventContext(Node* node) |
137 { | 138 { |
138 m_nodeEventContexts.append(NodeEventContext(node, eventTargetRespectingTarge
tRules(node))); | 139 m_nodeEventContexts.append(NodeEventContext(node, eventTargetRespectingTarge
tRules(node))); |
139 } | 140 } |
140 | 141 |
141 void EventPath::calculatePath() | 142 void EventPath::calculatePath() |
142 { | 143 { |
143 ASSERT(m_node); | 144 ASSERT(m_node); |
(...skipping 27 matching lines...) Expand all Loading... |
171 current = current->shadowHost(); | 172 current = current->shadowHost(); |
172 addNodeEventContext(current); | 173 addNodeEventContext(current); |
173 } else { | 174 } else { |
174 current = current->parentNode(); | 175 current = current->parentNode(); |
175 if (current) | 176 if (current) |
176 addNodeEventContext(current); | 177 addNodeEventContext(current); |
177 } | 178 } |
178 } | 179 } |
179 } | 180 } |
180 | 181 |
181 void EventPath::calculateAdjustedEventPath() | 182 void EventPath::calculateTreeScopePrePostOrderNumbers() |
182 { | 183 { |
183 if (!RuntimeEnabledFeatures::shadowDOMEnabled()) | 184 // Precondition: |
184 return; | 185 // - TreeScopes in m_treeScopeEventContexts must be *connected* in the sam
e tree of trees. |
| 186 // - The root tree must be included. |
| 187 HashMap<const TreeScope*, TreeScopeEventContext*> treeScopeEventContextMap; |
| 188 for (size_t i = 0; i < m_treeScopeEventContexts.size(); ++i) |
| 189 treeScopeEventContextMap.add(&m_treeScopeEventContexts[i]->treeScope(),
m_treeScopeEventContexts[i].get()); |
| 190 TreeScopeEventContext* rootTree = 0; |
185 for (size_t i = 0; i < m_treeScopeEventContexts.size(); ++i) { | 191 for (size_t i = 0; i < m_treeScopeEventContexts.size(); ++i) { |
186 TreeScopeEventContext* treeScopeEventContext = m_treeScopeEventContexts[
i].get(); | 192 TreeScopeEventContext* treeScopeEventContext = m_treeScopeEventContexts[
i].get(); |
187 Vector<RefPtr<Node> > nodes; | 193 // Use olderShadowRootOrParentTreeScope here for parent-child relationsh
ips. |
188 nodes.reserveInitialCapacity(size()); | 194 // See the definition of trees of trees in the Shado DOM spec: http://w3
c.github.io/webcomponents/spec/shadow/ |
189 for (size_t i = 0; i < size(); ++i) { | 195 TreeScope* parent = treeScopeEventContext->treeScope().olderShadowRootOr
ParentTreeScope(); |
190 if (at(i).node()->treeScope().isInclusiveOlderSiblingShadowRootOrAnc
estorTreeScopeOf(treeScopeEventContext->treeScope())) { | 196 if (!parent) { |
191 ASSERT(!at(i).node()->containingShadowRoot() | 197 ASSERT(!rootTree); |
192 || at(i).node()->treeScope() == treeScopeEventContext->treeS
cope() | 198 rootTree = treeScopeEventContext; |
193 || toShadowRoot(treeScopeEventContext->treeScope().rootNode(
)).type() == ShadowRoot::UserAgentShadowRoot | 199 continue; |
194 || at(i).node()->containingShadowRoot()->type() != ShadowRoo
t::UserAgentShadowRoot); | |
195 nodes.append(at(i).node()); | |
196 } | |
197 } | 200 } |
198 treeScopeEventContext->adoptEventPath(nodes); | 201 ASSERT(treeScopeEventContextMap.find(parent) != treeScopeEventContextMap
.end()); |
| 202 treeScopeEventContextMap.find(parent)->value->addChild(*treeScopeEventCo
ntext); |
199 } | 203 } |
| 204 ASSERT(rootTree); |
| 205 rootTree->calculatePrePostOrderNumber(0); |
200 } | 206 } |
201 | 207 |
202 TreeScopeEventContext* EventPath::ensureTreeScopeEventContext(Node* currentTarge
t, TreeScope* treeScope, TreeScopeEventContextMap& treeScopeEventContextMap) | 208 TreeScopeEventContext* EventPath::ensureTreeScopeEventContext(Node* currentTarge
t, TreeScope* treeScope, TreeScopeEventContextMap& treeScopeEventContextMap) |
203 { | 209 { |
204 if (!treeScope) | 210 if (!treeScope) |
205 return 0; | 211 return 0; |
206 TreeScopeEventContextMap::AddResult addResult = treeScopeEventContextMap.add
(treeScope, TreeScopeEventContext::create(*treeScope)); | 212 TreeScopeEventContextMap::AddResult addResult = treeScopeEventContextMap.add
(treeScope, TreeScopeEventContext::create(*treeScope)); |
207 TreeScopeEventContext* treeScopeEventContext = addResult.storedValue->value.
get(); | 213 TreeScopeEventContext* treeScopeEventContext = addResult.storedValue->value.
get(); |
208 if (addResult.isNewEntry) { | 214 if (addResult.isNewEntry) { |
209 TreeScopeEventContext* parentTreeScopeEventContext = ensureTreeScopeEven
tContext(0, treeScope->olderShadowRootOrParentTreeScope(), treeScopeEventContext
Map); | 215 TreeScopeEventContext* parentTreeScopeEventContext = ensureTreeScopeEven
tContext(0, treeScope->olderShadowRootOrParentTreeScope(), treeScopeEventContext
Map); |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
368 | 374 |
369 #ifndef NDEBUG | 375 #ifndef NDEBUG |
370 void EventPath::checkReachability(TreeScope& treeScope, TouchList& touchList) | 376 void EventPath::checkReachability(TreeScope& treeScope, TouchList& touchList) |
371 { | 377 { |
372 for (size_t i = 0; i < touchList.length(); ++i) | 378 for (size_t i = 0; i < touchList.length(); ++i) |
373 ASSERT(touchList.item(i)->target()->toNode()->treeScope().isInclusiveOld
erSiblingShadowRootOrAncestorTreeScopeOf(treeScope)); | 379 ASSERT(touchList.item(i)->target()->toNode()->treeScope().isInclusiveOld
erSiblingShadowRootOrAncestorTreeScopeOf(treeScope)); |
374 } | 380 } |
375 #endif | 381 #endif |
376 | 382 |
377 } // namespace | 383 } // namespace |
OLD | NEW |