| 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 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 } | 167 } |
| 168 | 168 |
| 169 void EventPath::calculateTreeOrderAndSetNearestAncestorClosedTree() { | 169 void EventPath::calculateTreeOrderAndSetNearestAncestorClosedTree() { |
| 170 // Precondition: | 170 // Precondition: |
| 171 // - TreeScopes in m_treeScopeEventContexts must be *connected* in the same | 171 // - TreeScopes in m_treeScopeEventContexts must be *connected* in the same |
| 172 // composed tree. | 172 // composed tree. |
| 173 // - The root tree must be included. | 173 // - The root tree must be included. |
| 174 HeapHashMap<Member<const TreeScope>, Member<TreeScopeEventContext>> | 174 HeapHashMap<Member<const TreeScope>, Member<TreeScopeEventContext>> |
| 175 treeScopeEventContextMap; | 175 treeScopeEventContextMap; |
| 176 for (const auto& treeScopeEventContext : m_treeScopeEventContexts) | 176 for (const auto& treeScopeEventContext : m_treeScopeEventContexts) |
| 177 treeScopeEventContextMap.add(&treeScopeEventContext->treeScope(), | 177 treeScopeEventContextMap.insert(&treeScopeEventContext->treeScope(), |
| 178 treeScopeEventContext.get()); | 178 treeScopeEventContext.get()); |
| 179 TreeScopeEventContext* rootTree = nullptr; | 179 TreeScopeEventContext* rootTree = nullptr; |
| 180 for (const auto& treeScopeEventContext : m_treeScopeEventContexts) { | 180 for (const auto& treeScopeEventContext : m_treeScopeEventContexts) { |
| 181 // Use olderShadowRootOrParentTreeScope here for parent-child relationships. | 181 // Use olderShadowRootOrParentTreeScope here for parent-child relationships. |
| 182 // See the definition of trees of trees in the Shadow DOM spec: | 182 // See the definition of trees of trees in the Shadow DOM spec: |
| 183 // http://w3c.github.io/webcomponents/spec/shadow/ | 183 // http://w3c.github.io/webcomponents/spec/shadow/ |
| 184 TreeScope* parent = treeScopeEventContext.get() | 184 TreeScope* parent = treeScopeEventContext.get() |
| 185 ->treeScope() | 185 ->treeScope() |
| 186 .olderShadowRootOrParentTreeScope(); | 186 .olderShadowRootOrParentTreeScope(); |
| 187 if (!parent) { | 187 if (!parent) { |
| 188 DCHECK(!rootTree); | 188 DCHECK(!rootTree); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 201 TreeScopeEventContext* EventPath::ensureTreeScopeEventContext( | 201 TreeScopeEventContext* EventPath::ensureTreeScopeEventContext( |
| 202 Node* currentTarget, | 202 Node* currentTarget, |
| 203 TreeScope* treeScope, | 203 TreeScope* treeScope, |
| 204 TreeScopeEventContextMap& treeScopeEventContextMap) { | 204 TreeScopeEventContextMap& treeScopeEventContextMap) { |
| 205 if (!treeScope) | 205 if (!treeScope) |
| 206 return nullptr; | 206 return nullptr; |
| 207 TreeScopeEventContext* treeScopeEventContext; | 207 TreeScopeEventContext* treeScopeEventContext; |
| 208 bool isNewEntry; | 208 bool isNewEntry; |
| 209 { | 209 { |
| 210 TreeScopeEventContextMap::AddResult addResult = | 210 TreeScopeEventContextMap::AddResult addResult = |
| 211 treeScopeEventContextMap.add(treeScope, nullptr); | 211 treeScopeEventContextMap.insert(treeScope, nullptr); |
| 212 isNewEntry = addResult.isNewEntry; | 212 isNewEntry = addResult.isNewEntry; |
| 213 if (isNewEntry) | 213 if (isNewEntry) |
| 214 addResult.storedValue->value = TreeScopeEventContext::create(*treeScope); | 214 addResult.storedValue->value = TreeScopeEventContext::create(*treeScope); |
| 215 treeScopeEventContext = addResult.storedValue->value.get(); | 215 treeScopeEventContext = addResult.storedValue->value.get(); |
| 216 } | 216 } |
| 217 if (isNewEntry) { | 217 if (isNewEntry) { |
| 218 TreeScopeEventContext* parentTreeScopeEventContext = | 218 TreeScopeEventContext* parentTreeScopeEventContext = |
| 219 ensureTreeScopeEventContext( | 219 ensureTreeScopeEventContext( |
| 220 0, treeScope->olderShadowRootOrParentTreeScope(), | 220 0, treeScope->olderShadowRootOrParentTreeScope(), |
| 221 treeScopeEventContextMap); | 221 treeScopeEventContextMap); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 treeScopeEventContextMap.values().begin(), | 253 treeScopeEventContextMap.values().begin(), |
| 254 treeScopeEventContextMap.values().end()); | 254 treeScopeEventContextMap.values().end()); |
| 255 } | 255 } |
| 256 | 256 |
| 257 void EventPath::buildRelatedNodeMap(const Node& relatedNode, | 257 void EventPath::buildRelatedNodeMap(const Node& relatedNode, |
| 258 RelatedTargetMap& relatedTargetMap) { | 258 RelatedTargetMap& relatedTargetMap) { |
| 259 EventPath* relatedTargetEventPath = | 259 EventPath* relatedTargetEventPath = |
| 260 new EventPath(const_cast<Node&>(relatedNode)); | 260 new EventPath(const_cast<Node&>(relatedNode)); |
| 261 for (const auto& treeScopeEventContext : | 261 for (const auto& treeScopeEventContext : |
| 262 relatedTargetEventPath->m_treeScopeEventContexts) { | 262 relatedTargetEventPath->m_treeScopeEventContexts) { |
| 263 relatedTargetMap.add(&treeScopeEventContext->treeScope(), | 263 relatedTargetMap.insert(&treeScopeEventContext->treeScope(), |
| 264 treeScopeEventContext->target()); | 264 treeScopeEventContext->target()); |
| 265 } | 265 } |
| 266 // Oilpan: It is important to explicitly clear the vectors to reuse | 266 // Oilpan: It is important to explicitly clear the vectors to reuse |
| 267 // the memory in subsequent event dispatchings. | 267 // the memory in subsequent event dispatchings. |
| 268 relatedTargetEventPath->clear(); | 268 relatedTargetEventPath->clear(); |
| 269 } | 269 } |
| 270 | 270 |
| 271 EventTarget* EventPath::findRelatedNode(TreeScope& scope, | 271 EventTarget* EventPath::findRelatedNode(TreeScope& scope, |
| 272 RelatedTargetMap& relatedTargetMap) { | 272 RelatedTargetMap& relatedTargetMap) { |
| 273 HeapVector<Member<TreeScope>, 32> parentTreeScopes; | 273 HeapVector<Member<TreeScope>, 32> parentTreeScopes; |
| 274 EventTarget* relatedNode = nullptr; | 274 EventTarget* relatedNode = nullptr; |
| 275 for (TreeScope* current = &scope; current; | 275 for (TreeScope* current = &scope; current; |
| 276 current = current->olderShadowRootOrParentTreeScope()) { | 276 current = current->olderShadowRootOrParentTreeScope()) { |
| 277 parentTreeScopes.push_back(current); | 277 parentTreeScopes.push_back(current); |
| 278 RelatedTargetMap::const_iterator iter = relatedTargetMap.find(current); | 278 RelatedTargetMap::const_iterator iter = relatedTargetMap.find(current); |
| 279 if (iter != relatedTargetMap.end() && iter->value) { | 279 if (iter != relatedTargetMap.end() && iter->value) { |
| 280 relatedNode = iter->value; | 280 relatedNode = iter->value; |
| 281 break; | 281 break; |
| 282 } | 282 } |
| 283 } | 283 } |
| 284 DCHECK(relatedNode); | 284 DCHECK(relatedNode); |
| 285 for (const auto& entry : parentTreeScopes) | 285 for (const auto& entry : parentTreeScopes) |
| 286 relatedTargetMap.add(entry, relatedNode); | 286 relatedTargetMap.insert(entry, relatedNode); |
| 287 | 287 |
| 288 return relatedNode; | 288 return relatedNode; |
| 289 } | 289 } |
| 290 | 290 |
| 291 void EventPath::adjustForRelatedTarget(Node& target, | 291 void EventPath::adjustForRelatedTarget(Node& target, |
| 292 EventTarget* relatedTarget) { | 292 EventTarget* relatedTarget) { |
| 293 if (!relatedTarget) | 293 if (!relatedTarget) |
| 294 return; | 294 return; |
| 295 Node* relatedNode = relatedTarget->toNode(); | 295 Node* relatedNode = relatedTarget->toNode(); |
| 296 if (!relatedNode) | 296 if (!relatedNode) |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 418 | 418 |
| 419 DEFINE_TRACE(EventPath) { | 419 DEFINE_TRACE(EventPath) { |
| 420 visitor->trace(m_nodeEventContexts); | 420 visitor->trace(m_nodeEventContexts); |
| 421 visitor->trace(m_node); | 421 visitor->trace(m_node); |
| 422 visitor->trace(m_event); | 422 visitor->trace(m_event); |
| 423 visitor->trace(m_treeScopeEventContexts); | 423 visitor->trace(m_treeScopeEventContexts); |
| 424 visitor->trace(m_windowEventContext); | 424 visitor->trace(m_windowEventContext); |
| 425 } | 425 } |
| 426 | 426 |
| 427 } // namespace blink | 427 } // namespace blink |
| OLD | NEW |