Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(177)

Side by Side Diff: third_party/WebKit/Source/core/dom/shadow/FlatTreeTraversal.cpp

Issue 1854423002: ASSERT -> {DCHECK|DCHECK_XX}, ENABLE(ASSERT) -> DCHECK_IS_ON() in dom (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: mark svg/as-image/svg-nested.html crash on win Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 } 66 }
67 if (node->isInV0ShadowTree()) 67 if (node->isInV0ShadowTree())
68 return v0ResolveDistributionStartingAt(*sibling, direction); 68 return v0ResolveDistributionStartingAt(*sibling, direction);
69 return const_cast<Node*>(sibling); 69 return const_cast<Node*>(sibling);
70 } 70 }
71 return nullptr; 71 return nullptr;
72 } 72 }
73 73
74 Node* FlatTreeTraversal::v0ResolveDistributionStartingAt(const Node& node, Trave rsalDirection direction) 74 Node* FlatTreeTraversal::v0ResolveDistributionStartingAt(const Node& node, Trave rsalDirection direction)
75 { 75 {
76 ASSERT(!isHTMLSlotElement(node)); 76 DCHECK(!isHTMLSlotElement(node));
77 for (const Node* sibling = &node; sibling; sibling = (direction == Traversal DirectionForward ? sibling->nextSibling() : sibling->previousSibling())) { 77 for (const Node* sibling = &node; sibling; sibling = (direction == Traversal DirectionForward ? sibling->nextSibling() : sibling->previousSibling())) {
78 if (!isActiveInsertionPoint(*sibling)) 78 if (!isActiveInsertionPoint(*sibling))
79 return const_cast<Node*>(sibling); 79 return const_cast<Node*>(sibling);
80 const InsertionPoint& insertionPoint = toInsertionPoint(*sibling); 80 const InsertionPoint& insertionPoint = toInsertionPoint(*sibling);
81 if (Node* found = (direction == TraversalDirectionForward ? insertionPoi nt.firstDistributedNode() : insertionPoint.lastDistributedNode())) 81 if (Node* found = (direction == TraversalDirectionForward ? insertionPoi nt.firstDistributedNode() : insertionPoint.lastDistributedNode()))
82 return found; 82 return found;
83 ASSERT(isHTMLShadowElement(insertionPoint) || (isHTMLContentElement(inse rtionPoint) && !insertionPoint.hasChildren())); 83 DCHECK(isHTMLShadowElement(insertionPoint) || (isHTMLContentElement(inse rtionPoint) && !insertionPoint.hasChildren()));
84 } 84 }
85 return nullptr; 85 return nullptr;
86 } 86 }
87 87
88 static HTMLSlotElement* finalDestinationSlotFor(const Node& node) 88 static HTMLSlotElement* finalDestinationSlotFor(const Node& node)
89 { 89 {
90 HTMLSlotElement* slot = node.assignedSlot(); 90 HTMLSlotElement* slot = node.assignedSlot();
91 if (!slot) 91 if (!slot)
92 return nullptr; 92 return nullptr;
93 for (HTMLSlotElement* next = slot->assignedSlot(); next; next = next->assign edSlot()) { 93 for (HTMLSlotElement* next = slot->assignedSlot(); next; next = next->assign edSlot()) {
(...skipping 16 matching lines...) Expand all
110 return found; 110 return found;
111 111
112 if (!node.isInV0ShadowTree()) 112 if (!node.isInV0ShadowTree())
113 return nullptr; 113 return nullptr;
114 114
115 // For v0 older shadow tree 115 // For v0 older shadow tree
116 if (node.parentNode() && node.parentNode()->isShadowRoot()) { 116 if (node.parentNode() && node.parentNode()->isShadowRoot()) {
117 ShadowRoot* parentShadowRoot = toShadowRoot(node.parentNode()); 117 ShadowRoot* parentShadowRoot = toShadowRoot(node.parentNode());
118 if (!parentShadowRoot->isYoungest()) { 118 if (!parentShadowRoot->isYoungest()) {
119 HTMLShadowElement* assignedInsertionPoint = parentShadowRoot->shadow InsertionPointOfYoungerShadowRoot(); 119 HTMLShadowElement* assignedInsertionPoint = parentShadowRoot->shadow InsertionPointOfYoungerShadowRoot();
120 ASSERT(assignedInsertionPoint); 120 DCHECK(assignedInsertionPoint);
121 return traverseSiblings(*assignedInsertionPoint, direction); 121 return traverseSiblings(*assignedInsertionPoint, direction);
122 } 122 }
123 } 123 }
124 return nullptr; 124 return nullptr;
125 } 125 }
126 126
127 Node* FlatTreeTraversal::traverseSiblingsForV1HostChild(const Node& node, Traver salDirection direction) 127 Node* FlatTreeTraversal::traverseSiblingsForV1HostChild(const Node& node, Traver salDirection direction)
128 { 128 {
129 HTMLSlotElement* slot = finalDestinationSlotFor(node); 129 HTMLSlotElement* slot = finalDestinationSlotFor(node);
130 if (!slot) 130 if (!slot)
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 if (parent && isHTMLSlotElement(parent)) { 162 if (parent && isHTMLSlotElement(parent)) {
163 HTMLSlotElement& slot = toHTMLSlotElement(*parent); 163 HTMLSlotElement& slot = toHTMLSlotElement(*parent);
164 if (!slot.getAssignedNodes().isEmpty()) 164 if (!slot.getAssignedNodes().isEmpty())
165 return nullptr; 165 return nullptr;
166 return traverseParent(slot, details); 166 return traverseParent(slot, details);
167 } 167 }
168 168
169 if (canBeDistributedToInsertionPoint(node)) 169 if (canBeDistributedToInsertionPoint(node))
170 return traverseParentForV0(node, details); 170 return traverseParentForV0(node, details);
171 171
172 ASSERT(!shadowWhereNodeCanBeDistributed(node)); 172 DCHECK(!shadowWhereNodeCanBeDistributed(node));
173 return traverseParentOrHost(node); 173 return traverseParentOrHost(node);
174 } 174 }
175 175
176 ContainerNode* FlatTreeTraversal::traverseParentForV0(const Node& node, ParentTr aversalDetails* details) 176 ContainerNode* FlatTreeTraversal::traverseParentForV0(const Node& node, ParentTr aversalDetails* details)
177 { 177 {
178 if (shadowWhereNodeCanBeDistributed(node)) { 178 if (shadowWhereNodeCanBeDistributed(node)) {
179 if (const InsertionPoint* insertionPoint = resolveReprojection(&node)) { 179 if (const InsertionPoint* insertionPoint = resolveReprojection(&node)) {
180 if (details) 180 if (details)
181 details->didTraverseInsertionPoint(insertionPoint); 181 details->didTraverseInsertionPoint(insertionPoint);
182 // The node is distributed. But the distribution was stopped at this insertion point. 182 // The node is distributed. But the distribution was stopped at this insertion point.
(...skipping 10 matching lines...) Expand all
193 } 193 }
194 194
195 ContainerNode* FlatTreeTraversal::traverseParentOrHost(const Node& node) 195 ContainerNode* FlatTreeTraversal::traverseParentOrHost(const Node& node)
196 { 196 {
197 ContainerNode* parent = node.parentNode(); 197 ContainerNode* parent = node.parentNode();
198 if (!parent) 198 if (!parent)
199 return nullptr; 199 return nullptr;
200 if (!parent->isShadowRoot()) 200 if (!parent->isShadowRoot())
201 return parent; 201 return parent;
202 ShadowRoot* shadowRoot = toShadowRoot(parent); 202 ShadowRoot* shadowRoot = toShadowRoot(parent);
203 ASSERT(!shadowRoot->shadowInsertionPointOfYoungerShadowRoot()); 203 DCHECK(!shadowRoot->shadowInsertionPointOfYoungerShadowRoot());
204 if (!shadowRoot->isYoungest()) 204 if (!shadowRoot->isYoungest())
205 return nullptr; 205 return nullptr;
206 return shadowRoot->host(); 206 return shadowRoot->host();
207 } 207 }
208 208
209 Node* FlatTreeTraversal::childAt(const Node& node, unsigned index) 209 Node* FlatTreeTraversal::childAt(const Node& node, unsigned index)
210 { 210 {
211 assertPrecondition(node); 211 assertPrecondition(node);
212 Node* child = traverseFirstChild(node); 212 Node* child = traverseFirstChild(node);
213 while (child && index--) 213 while (child && index--)
(...skipping 24 matching lines...) Expand all
238 238
239 Node* FlatTreeTraversal::previousSkippingChildren(const Node& node) 239 Node* FlatTreeTraversal::previousSkippingChildren(const Node& node)
240 { 240 {
241 if (Node* previousSibling = traversePreviousSibling(node)) 241 if (Node* previousSibling = traversePreviousSibling(node))
242 return previousSibling; 242 return previousSibling;
243 return traversePreviousAncestorSibling(node); 243 return traversePreviousAncestorSibling(node);
244 } 244 }
245 245
246 static Node* previousAncestorSiblingPostOrder(const Node& current, const Node* s tayWithin) 246 static Node* previousAncestorSiblingPostOrder(const Node& current, const Node* s tayWithin)
247 { 247 {
248 ASSERT(!FlatTreeTraversal::previousSibling(current)); 248 DCHECK(!FlatTreeTraversal::previousSibling(current));
249 for (Node* parent = FlatTreeTraversal::parent(current); parent; parent = Fla tTreeTraversal::parent(*parent)) { 249 for (Node* parent = FlatTreeTraversal::parent(current); parent; parent = Fla tTreeTraversal::parent(*parent)) {
250 if (parent == stayWithin) 250 if (parent == stayWithin)
251 return nullptr; 251 return nullptr;
252 if (Node* previousSibling = FlatTreeTraversal::previousSibling(*parent)) 252 if (Node* previousSibling = FlatTreeTraversal::previousSibling(*parent))
253 return previousSibling; 253 return previousSibling;
254 } 254 }
255 return nullptr; 255 return nullptr;
256 } 256 }
257 257
258 // TODO(yosin) We should consider introducing template class to share code 258 // TODO(yosin) We should consider introducing template class to share code
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 [](const Node& node) 296 [](const Node& node)
297 { 297 {
298 return FlatTreeTraversal::parent(node); 298 return FlatTreeTraversal::parent(node);
299 }); 299 });
300 assertPostcondition(result); 300 assertPostcondition(result);
301 return result; 301 return result;
302 } 302 }
303 303
304 Node* FlatTreeTraversal::traverseNextAncestorSibling(const Node& node) 304 Node* FlatTreeTraversal::traverseNextAncestorSibling(const Node& node)
305 { 305 {
306 ASSERT(!traverseNextSibling(node)); 306 DCHECK(!traverseNextSibling(node));
307 for (Node* parent = traverseParent(node); parent; parent = traverseParent(*p arent)) { 307 for (Node* parent = traverseParent(node); parent; parent = traverseParent(*p arent)) {
308 if (Node* nextSibling = traverseNextSibling(*parent)) 308 if (Node* nextSibling = traverseNextSibling(*parent))
309 return nextSibling; 309 return nextSibling;
310 } 310 }
311 return nullptr; 311 return nullptr;
312 } 312 }
313 313
314 Node* FlatTreeTraversal::traversePreviousAncestorSibling(const Node& node) 314 Node* FlatTreeTraversal::traversePreviousAncestorSibling(const Node& node)
315 { 315 {
316 ASSERT(!traversePreviousSibling(node)); 316 DCHECK(!traversePreviousSibling(node));
317 for (Node* parent = traverseParent(node); parent; parent = traverseParent(*p arent)) { 317 for (Node* parent = traverseParent(node); parent; parent = traverseParent(*p arent)) {
318 if (Node* previousSibling = traversePreviousSibling(*parent)) 318 if (Node* previousSibling = traversePreviousSibling(*parent))
319 return previousSibling; 319 return previousSibling;
320 } 320 }
321 return nullptr; 321 return nullptr;
322 } 322 }
323 323
324 unsigned FlatTreeTraversal::index(const Node& node) 324 unsigned FlatTreeTraversal::index(const Node& node)
325 { 325 {
326 assertPrecondition(node); 326 assertPrecondition(node);
(...skipping 25 matching lines...) Expand all
352 Node& FlatTreeTraversal::lastWithinOrSelf(const Node& node) 352 Node& FlatTreeTraversal::lastWithinOrSelf(const Node& node)
353 { 353 {
354 assertPrecondition(node); 354 assertPrecondition(node);
355 Node* lastDescendant = lastWithin(node); 355 Node* lastDescendant = lastWithin(node);
356 Node& result = lastDescendant ? *lastDescendant : const_cast<Node&>(node); 356 Node& result = lastDescendant ? *lastDescendant : const_cast<Node&>(node);
357 assertPostcondition(&result); 357 assertPostcondition(&result);
358 return result; 358 return result;
359 } 359 }
360 360
361 } // namespace blink 361 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698