Changeset 155287 in webkit
- Timestamp:
- Sep 8, 2013, 12:02:42 AM (12 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r155283 r155287 1 2013-09-07 Antti Koivisto <antti@apple.com> 2 3 Separate forward and backward paths in ComposedShadowTreeWalker 4 https://bugs.webkit.org/show_bug.cgi?id=120979 5 6 Reviewed by Andreas Kling. 7 8 Have separate first/last and next/previous paths instead of using a direction enum. 9 10 Reduce the number of helper functions and give them more understandable names. 11 12 * dom/ComposedShadowTreeWalker.cpp: 13 (WebCore::findFirstSiblingEnteringInsertionPoints): 14 (WebCore::findFirstEnteringInsertionPoints): 15 (WebCore::findFirstFromDistributedNode): 16 (WebCore::findLastSiblingEnteringInsertionPoints): 17 (WebCore::findLastEnteringInsertionPoints): 18 (WebCore::findLastFromDistributedNode): 19 (WebCore::ComposedShadowTreeWalker::firstChild): 20 (WebCore::ComposedShadowTreeWalker::traverseFirstChild): 21 (WebCore::ComposedShadowTreeWalker::lastChild): 22 (WebCore::ComposedShadowTreeWalker::traverseLastChild): 23 (WebCore::ComposedShadowTreeWalker::nextSibling): 24 (WebCore::ComposedShadowTreeWalker::previousSibling): 25 (WebCore::ComposedShadowTreeWalker::traverseNextSibling): 26 (WebCore::ComposedShadowTreeWalker::traversePreviousSibling): 27 * dom/ComposedShadowTreeWalker.h: 28 1 29 2013-09-07 Andreas Kling <akling@apple.com> 2 30 -
trunk/Source/WebCore/dom/ComposedShadowTreeWalker.cpp
r155264 r155287 2 2 /* 3 3 * Copyright (C) 2012 Google Inc. All rights reserved. 4 * Copyright (C) 2013 Apple Inc. All rights reserved. 4 5 * 5 6 * Redistribution and use in source and binary forms, with or without … … 53 54 } 54 55 55 void ComposedShadowTreeWalker::firstChild() 56 { 57 assertPrecondition(); 58 m_node = traverseChild(m_node, TraversalDirectionForward); 59 assertPostcondition(); 60 } 61 62 Node* ComposedShadowTreeWalker::traverseFirstChild(const Node* node) const 63 { 64 ASSERT(node); 65 return traverseChild(node, TraversalDirectionForward); 66 } 67 68 void ComposedShadowTreeWalker::lastChild() 69 { 70 assertPrecondition(); 71 m_node = traverseLastChild(m_node); 72 assertPostcondition(); 73 } 74 75 Node* ComposedShadowTreeWalker::traverseLastChild(const Node* node) const 76 { 77 ASSERT(node); 78 return traverseChild(node, TraversalDirectionBackward); 79 } 80 81 Node* ComposedShadowTreeWalker::traverseChild(const Node* node, TraversalDirection direction) const 82 { 83 ASSERT(node); 84 if (canCrossUpperBoundary()) { 85 return node->shadowRoot() ? traverseLightChildren(node->shadowRoot(), direction) 86 : traverseLightChildren(node, direction); 87 } 88 if (isShadowHost(node)) 89 return 0; 90 return traverseLightChildren(node, direction); 91 } 92 93 Node* ComposedShadowTreeWalker::traverseLightChildren(const Node* node, TraversalDirection direction) 94 { 95 ASSERT(node); 96 return traverseSiblings(direction == TraversalDirectionForward ? node->firstChild() : node->lastChild(), direction); 97 } 98 99 Node* ComposedShadowTreeWalker::traverseSiblings(const Node* node, TraversalDirection direction) 100 { 101 for (const Node* sibling = node; sibling; sibling = (direction == TraversalDirectionForward ? sibling->nextSibling() : sibling->previousSibling())) { 102 if (Node* found = traverseNode(sibling, direction)) 103 return found; 104 } 105 return 0; 106 } 107 108 Node* ComposedShadowTreeWalker::traverseNode(const Node* node, TraversalDirection direction) 56 static Node* findFirstSiblingEnteringInsertionPoints(const Node*); 57 static Node* findFirstEnteringInsertionPoints(const Node*); 58 static Node* findFirstFromDistributedNode(const Node*, const InsertionPoint*); 59 static Node* findLastSiblingEnteringInsertionPoints(const Node*); 60 static Node* findLastEnteringInsertionPoints(const Node*); 61 static Node* findLastFromDistributedNode(const Node*, const InsertionPoint*); 62 63 static Node* findFirstSiblingEnteringInsertionPoints(const Node* node) 64 { 65 for (const Node* sibling = node; sibling; sibling = sibling->nextSibling()) { 66 if (Node* found = findFirstEnteringInsertionPoints(sibling)) 67 return found; 68 } 69 return nullptr; 70 } 71 72 static Node* findFirstEnteringInsertionPoints(const Node* node) 109 73 { 110 74 ASSERT(node); … … 112 76 return const_cast<Node*>(node); 113 77 const InsertionPoint* insertionPoint = toInsertionPoint(node); 114 if (Node* found = traverseDistributedNodes(direction == TraversalDirectionForward ? insertionPoint->firstDistributed() : insertionPoint->lastDistributed(), insertionPoint, direction))78 if (Node* found = findFirstFromDistributedNode(insertionPoint->firstDistributed(), insertionPoint)) 115 79 return found; 116 return traverseLightChildren(node, direction); 80 return findFirstSiblingEnteringInsertionPoints(node->firstChild()); 81 } 82 83 static Node* findFirstFromDistributedNode(const Node* node, const InsertionPoint* insertionPoint) 84 { 85 for (const Node* next = node; next; next = insertionPoint->nextDistributedTo(next)) { 86 if (Node* found = findFirstEnteringInsertionPoints(next)) 87 return found; 88 } 89 return nullptr; 90 } 91 92 static Node* findLastSiblingEnteringInsertionPoints(const Node* node) 93 { 94 for (const Node* sibling = node; sibling; sibling = sibling->previousSibling()) { 95 if (Node* found = findLastEnteringInsertionPoints(sibling)) 96 return found; 97 } 98 return nullptr; 99 } 100 101 static Node* findLastEnteringInsertionPoints(const Node* node) 102 { 103 ASSERT(node); 104 if (!isActiveInsertionPoint(node)) 105 return const_cast<Node*>(node); 106 const InsertionPoint* insertionPoint = toInsertionPoint(node); 107 if (Node* found = findLastFromDistributedNode(insertionPoint->lastDistributed(), insertionPoint)) 108 return found; 109 return findLastSiblingEnteringInsertionPoints(node->lastChild()); 110 } 111 112 static Node* findLastFromDistributedNode(const Node* node, const InsertionPoint* insertionPoint) 113 { 114 for (const Node* next = node; next; next = insertionPoint->previousDistributedTo(next)) { 115 if (Node* found = findLastEnteringInsertionPoints(next)) 116 return found; 117 } 118 return nullptr; 119 } 120 121 void ComposedShadowTreeWalker::firstChild() 122 { 123 assertPrecondition(); 124 m_node = traverseFirstChild(m_node); 125 assertPostcondition(); 126 } 127 128 Node* ComposedShadowTreeWalker::traverseFirstChild(const Node* node) const 129 { 130 ASSERT(node); 131 if (node->shadowRoot()) { 132 if (!canCrossUpperBoundary()) 133 return nullptr; 134 node = node->shadowRoot(); 135 } 136 return findFirstSiblingEnteringInsertionPoints(node->firstChild()); 137 } 138 139 void ComposedShadowTreeWalker::lastChild() 140 { 141 assertPrecondition(); 142 m_node = traverseLastChild(m_node); 143 assertPostcondition(); 144 } 145 146 Node* ComposedShadowTreeWalker::traverseLastChild(const Node* node) const 147 { 148 ASSERT(node); 149 if (node->shadowRoot()) { 150 if (!canCrossUpperBoundary()) 151 return nullptr; 152 node = node->shadowRoot(); 153 } 154 return findLastSiblingEnteringInsertionPoints(node->lastChild()); 117 155 } 118 156 … … 120 158 { 121 159 assertPrecondition(); 122 m_node = traverse SiblingOrBackToInsertionPoint(m_node, TraversalDirectionForward);160 m_node = traverseNextSibling(m_node); 123 161 assertPostcondition(); 124 162 } … … 127 165 { 128 166 assertPrecondition(); 129 m_node = traverseSiblingOrBackToInsertionPoint(m_node, TraversalDirectionBackward); 130 assertPostcondition(); 131 } 132 133 Node* ComposedShadowTreeWalker::traverseDistributedNodes(const Node* node, const InsertionPoint* insertionPoint, TraversalDirection direction) 134 { 135 for (const Node* next = node; next; next = (direction == TraversalDirectionForward ? insertionPoint->nextDistributedTo(next) : insertionPoint->previousDistributedTo(next))) { 136 if (Node* found = traverseNode(next, direction)) 137 return found; 138 } 139 return 0; 140 } 141 142 Node* ComposedShadowTreeWalker::traverseSiblingOrBackToInsertionPoint(const Node* node, TraversalDirection direction) 143 { 144 ASSERT(node); 145 146 if (!nodeCanBeDistributed(node)) 147 return traverseSiblingInCurrentTree(node, direction); 148 149 InsertionPoint* insertionPoint = findInsertionPointOf(node); 150 if (!insertionPoint) 151 return traverseSiblingInCurrentTree(node, direction); 152 153 if (Node* found = traverseDistributedNodes(direction == TraversalDirectionForward ? insertionPoint->nextDistributedTo(node) : insertionPoint->previousDistributedTo(node), insertionPoint, direction)) 154 return found; 155 return traverseSiblingOrBackToInsertionPoint(insertionPoint, direction); 156 } 157 158 Node* ComposedShadowTreeWalker::traverseSiblingInCurrentTree(const Node* node, TraversalDirection direction) 159 { 160 ASSERT(node); 161 if (Node* found = traverseSiblings(direction == TraversalDirectionForward ? node->nextSibling() : node->previousSibling(), direction)) 162 return found; 163 return escapeFallbackContentElement(node, direction); 164 } 165 166 inline Node* ComposedShadowTreeWalker::escapeFallbackContentElement(const Node* node, TraversalDirection direction) 167 { 168 ASSERT(node); 169 if (node->parentNode() && isActiveInsertionPoint(node->parentNode())) 170 return traverseSiblingOrBackToInsertionPoint(node->parentNode(), direction); 171 return 0; 167 m_node = traversePreviousSibling(m_node); 168 assertPostcondition(); 172 169 } 173 170 … … 212 209 { 213 210 ASSERT(node); 214 return traverseSiblingOrBackToInsertionPoint(node, TraversalDirectionForward); 211 212 InsertionPoint* insertionPoint; 213 if (nodeCanBeDistributed(node) && (insertionPoint = findInsertionPointOf(node))) { 214 Node* found = findFirstFromDistributedNode(insertionPoint->nextDistributedTo(node), insertionPoint); 215 if (found) 216 return found; 217 return traverseNextSibling(insertionPoint); 218 } 219 220 for (const Node* sibling = node->nextSibling(); sibling; sibling = sibling->nextSibling()) { 221 if (Node* found = findFirstEnteringInsertionPoints(sibling)) 222 return found; 223 } 224 if (node->parentNode() && isActiveInsertionPoint(node->parentNode())) 225 return traverseNextSibling(node->parentNode()); 226 227 return nullptr; 215 228 } 216 229 … … 218 231 { 219 232 ASSERT(node); 220 return traverseSiblingOrBackToInsertionPoint(node, TraversalDirectionBackward); 233 234 InsertionPoint* insertionPoint; 235 if (nodeCanBeDistributed(node) && (insertionPoint = findInsertionPointOf(node))) { 236 Node* found = findLastFromDistributedNode(insertionPoint->previousDistributedTo(node), insertionPoint); 237 if (found) 238 return found; 239 return traversePreviousSibling(insertionPoint); 240 } 241 242 for (const Node* sibling = node->previousSibling(); sibling; sibling = sibling->previousSibling()) { 243 if (Node* found = findLastEnteringInsertionPoints(sibling)) 244 return found; 245 } 246 if (node->parentNode() && isActiveInsertionPoint(node->parentNode())) 247 return traversePreviousSibling(node->parentNode()); 248 249 return nullptr; 221 250 } 222 251 -
trunk/Source/WebCore/dom/ComposedShadowTreeWalker.h
r155264 r155287 69 69 70 70 private: 71 enum TraversalDirection {72 TraversalDirectionForward,73 TraversalDirectionBackward74 };75 76 71 bool canCrossUpperBoundary() const { return m_policy == CrossUpperBoundary; } 77 72 … … 94 89 } 95 90 96 static Node* traverseNode(const Node*, TraversalDirection);97 static Node* traverseLightChildren(const Node*, TraversalDirection);98 99 91 Node* traverseFirstChild(const Node*) const; 100 92 Node* traverseLastChild(const Node*) const; 101 Node* traverseChild(const Node*, TraversalDirection) const;102 93 103 94 static Node* traverseNextSibling(const Node*); 104 95 static Node* traversePreviousSibling(const Node*); 105 106 static Node* traverseSiblingOrBackToInsertionPoint(const Node*, TraversalDirection);107 static Node* traverseSiblingInCurrentTree(const Node*, TraversalDirection);108 109 static Node* traverseSiblings(const Node*, TraversalDirection);110 static Node* traverseDistributedNodes(const Node*, const InsertionPoint*, TraversalDirection);111 112 static Node* escapeFallbackContentElement(const Node*, TraversalDirection);113 96 114 97 const Node* m_node;
Note:
See TracChangeset
for help on using the changeset viewer.