| 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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 initialize(); | 81 initialize(); |
| 82 } | 82 } |
| 83 | 83 |
| 84 void EventPath::initialize() | 84 void EventPath::initialize() |
| 85 { | 85 { |
| 86 calculatePath(); | 86 calculatePath(); |
| 87 calculateAdjustedTargets(); | 87 calculateAdjustedTargets(); |
| 88 calculateTreeScopePrePostOrderNumbers(); | 88 calculateTreeScopePrePostOrderNumbers(); |
| 89 } | 89 } |
| 90 | 90 |
| 91 void EventPath::addNodeEventContext(Node& node) | |
| 92 { | |
| 93 m_nodeEventContexts.append(NodeEventContext(&node, eventTargetRespectingTarg
etRules(node))); | |
| 94 } | |
| 95 | |
| 96 void EventPath::calculatePath() | 91 void EventPath::calculatePath() |
| 97 { | 92 { |
| 98 ASSERT(m_node); | 93 ASSERT(m_node); |
| 99 ASSERT(m_nodeEventContexts.isEmpty()); | 94 ASSERT(m_nodeEventContexts.isEmpty()); |
| 100 m_node->updateDistribution(); | 95 m_node->updateDistribution(); |
| 101 | 96 |
| 97 // For performance and memory usage reasons we want to store the |
| 98 // path using as few bytes as possible and with as few allocations |
| 99 // as possible which is why we gather the data on the stack before |
| 100 // storing it in a perfectly sized m_nodeEventContexts Vector. |
| 101 WillBeHeapVector<RawPtrWillBeMember<Node>, 64> nodesInPath; |
| 102 Node* current = m_node; | 102 Node* current = m_node; |
| 103 addNodeEventContext(*current); | 103 nodesInPath.append(current); |
| 104 if (!m_node->inDocument()) | 104 if (!m_node->inDocument()) |
| 105 return; | 105 current = nullptr; |
| 106 while (current) { | 106 while (current) { |
| 107 if (m_event && current->keepEventInNode(m_event)) | 107 if (m_event && current->keepEventInNode(m_event)) |
| 108 break; | 108 break; |
| 109 WillBeHeapVector<RawPtrWillBeMember<InsertionPoint>, 8> insertionPoints; | 109 WillBeHeapVector<RawPtrWillBeMember<InsertionPoint>, 8> insertionPoints; |
| 110 collectDestinationInsertionPoints(*current, insertionPoints); | 110 collectDestinationInsertionPoints(*current, insertionPoints); |
| 111 if (!insertionPoints.isEmpty()) { | 111 if (!insertionPoints.isEmpty()) { |
| 112 for (const auto& insertionPoint : insertionPoints) { | 112 for (const auto& insertionPoint : insertionPoints) { |
| 113 if (insertionPoint->isShadowInsertionPoint()) { | 113 if (insertionPoint->isShadowInsertionPoint()) { |
| 114 ShadowRoot* containingShadowRoot = insertionPoint->containin
gShadowRoot(); | 114 ShadowRoot* containingShadowRoot = insertionPoint->containin
gShadowRoot(); |
| 115 ASSERT(containingShadowRoot); | 115 ASSERT(containingShadowRoot); |
| 116 if (!containingShadowRoot->isOldest()) | 116 if (!containingShadowRoot->isOldest()) |
| 117 addNodeEventContext(*containingShadowRoot->olderShadowRo
ot()); | 117 nodesInPath.append(containingShadowRoot->olderShadowRoot
()); |
| 118 } | 118 } |
| 119 addNodeEventContext(*insertionPoint); | 119 nodesInPath.append(insertionPoint); |
| 120 } | 120 } |
| 121 current = insertionPoints.last(); | 121 current = insertionPoints.last(); |
| 122 continue; | 122 continue; |
| 123 } | 123 } |
| 124 if (current->isShadowRoot()) { | 124 if (current->isShadowRoot()) { |
| 125 if (m_event && shouldStopAtShadowRoot(*m_event, *toShadowRoot(curren
t), *m_node)) | 125 if (m_event && shouldStopAtShadowRoot(*m_event, *toShadowRoot(curren
t), *m_node)) |
| 126 break; | 126 break; |
| 127 current = current->shadowHost(); | 127 current = current->shadowHost(); |
| 128 addNodeEventContext(*current); | 128 nodesInPath.append(current); |
| 129 } else { | 129 } else { |
| 130 current = current->parentNode(); | 130 current = current->parentNode(); |
| 131 if (current) | 131 if (current) |
| 132 addNodeEventContext(*current); | 132 nodesInPath.append(current); |
| 133 } | 133 } |
| 134 } | 134 } |
| 135 |
| 136 m_nodeEventContexts.reserveCapacity(nodesInPath.size()); |
| 137 for (Node* nodeInPath : nodesInPath) { |
| 138 m_nodeEventContexts.append(NodeEventContext(nodeInPath, eventTargetRespe
ctingTargetRules(*nodeInPath))); |
| 139 } |
| 135 } | 140 } |
| 136 | 141 |
| 137 void EventPath::calculateTreeScopePrePostOrderNumbers() | 142 void EventPath::calculateTreeScopePrePostOrderNumbers() |
| 138 { | 143 { |
| 139 // Precondition: | 144 // Precondition: |
| 140 // - TreeScopes in m_treeScopeEventContexts must be *connected* in the sam
e tree of trees. | 145 // - TreeScopes in m_treeScopeEventContexts must be *connected* in the sam
e tree of trees. |
| 141 // - The root tree must be included. | 146 // - The root tree must be included. |
| 142 WillBeHeapHashMap<RawPtrWillBeMember<const TreeScope>, RawPtrWillBeMember<Tr
eeScopeEventContext>> treeScopeEventContextMap; | 147 WillBeHeapHashMap<RawPtrWillBeMember<const TreeScope>, RawPtrWillBeMember<Tr
eeScopeEventContext>> treeScopeEventContextMap; |
| 143 for (const auto& treeScopeEventContext : m_treeScopeEventContexts) | 148 for (const auto& treeScopeEventContext : m_treeScopeEventContexts) |
| 144 treeScopeEventContextMap.add(&treeScopeEventContext->treeScope(), treeSc
opeEventContext.get()); | 149 treeScopeEventContextMap.add(&treeScopeEventContext->treeScope(), treeSc
opeEventContext.get()); |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 #if ENABLE(OILPAN) | 355 #if ENABLE(OILPAN) |
| 351 visitor->trace(m_nodeEventContexts); | 356 visitor->trace(m_nodeEventContexts); |
| 352 visitor->trace(m_node); | 357 visitor->trace(m_node); |
| 353 visitor->trace(m_event); | 358 visitor->trace(m_event); |
| 354 visitor->trace(m_treeScopeEventContexts); | 359 visitor->trace(m_treeScopeEventContexts); |
| 355 visitor->trace(m_windowEventContext); | 360 visitor->trace(m_windowEventContext); |
| 356 #endif | 361 #endif |
| 357 } | 362 } |
| 358 | 363 |
| 359 } // namespace | 364 } // namespace |
| OLD | NEW |