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

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

Issue 2715353002: Fix LayoutTreeBuilderTraversal limit checks when recursing. (Closed)
Patch Set: Created 3 years, 9 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
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/dom/LayoutTreeBuilderTraversalTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 #if DCHECK_IS_ON() 243 #if DCHECK_IS_ON()
244 if (hasDisplayContentsStyle(*sibling)) 244 if (hasDisplayContentsStyle(*sibling))
245 DCHECK(!layoutObject); 245 DCHECK(!layoutObject);
246 #endif 246 #endif
247 247
248 if (!layoutObject && hasDisplayContentsStyle(*sibling)) { 248 if (!layoutObject && hasDisplayContentsStyle(*sibling)) {
249 layoutObject = nextSiblingLayoutObjectInternal( 249 layoutObject = nextSiblingLayoutObjectInternal(
250 pseudoAwareFirstChild(*sibling), limit); 250 pseudoAwareFirstChild(*sibling), limit);
251 if (layoutObject) 251 if (layoutObject)
252 return layoutObject; 252 return layoutObject;
253 if (!limit) 253 if (limit == -1)
254 return nullptr; 254 return nullptr;
255 } 255 }
256 256
257 if (layoutObject && !isLayoutObjectReparented(layoutObject)) 257 if (layoutObject && !isLayoutObjectReparented(layoutObject))
258 return layoutObject; 258 return layoutObject;
259 } 259 }
260 260
261 return nullptr; 261 return nullptr;
262 } 262 }
263 263
264 LayoutObject* LayoutTreeBuilderTraversal::nextSiblingLayoutObject( 264 LayoutObject* LayoutTreeBuilderTraversal::nextSiblingLayoutObject(
265 const Node& node, 265 const Node& node,
266 int32_t limit) { 266 int32_t limit) {
267 DCHECK(limit == kTraverseAllSiblings || limit >= 0) << limit; 267 DCHECK(limit == kTraverseAllSiblings || limit >= 0) << limit;
268 if (LayoutObject* sibling = 268 if (LayoutObject* sibling =
269 nextSiblingLayoutObjectInternal(nextSibling(node), limit)) 269 nextSiblingLayoutObjectInternal(nextSibling(node), limit))
270 return sibling; 270 return sibling;
271 271
272 Node* parent = LayoutTreeBuilderTraversal::parent(node); 272 Node* parent = LayoutTreeBuilderTraversal::parent(node);
273 while (limit && parent && hasDisplayContentsStyle(*parent)) { 273 while (limit != -1 && parent && hasDisplayContentsStyle(*parent)) {
274 if (LayoutObject* sibling = 274 if (LayoutObject* sibling =
275 nextSiblingLayoutObjectInternal(nextSibling(*parent), limit)) 275 nextSiblingLayoutObjectInternal(nextSibling(*parent), limit))
276 return sibling; 276 return sibling;
277 parent = LayoutTreeBuilderTraversal::parent(*parent); 277 parent = LayoutTreeBuilderTraversal::parent(*parent);
278 } 278 }
279 279
280 return nullptr; 280 return nullptr;
281 } 281 }
282 282
283 static LayoutObject* previousSiblingLayoutObjectInternal(Node* node, 283 static LayoutObject* previousSiblingLayoutObjectInternal(Node* node,
284 int32_t& limit) { 284 int32_t& limit) {
285 for (Node* sibling = node; sibling && limit-- != 0; 285 for (Node* sibling = node; sibling && limit-- != 0;
286 sibling = LayoutTreeBuilderTraversal::previousSibling(*sibling)) { 286 sibling = LayoutTreeBuilderTraversal::previousSibling(*sibling)) {
287 LayoutObject* layoutObject = sibling->layoutObject(); 287 LayoutObject* layoutObject = sibling->layoutObject();
288 288
289 #if DCHECK_IS_ON() 289 #if DCHECK_IS_ON()
290 if (hasDisplayContentsStyle(*sibling)) 290 if (hasDisplayContentsStyle(*sibling))
291 DCHECK(!layoutObject); 291 DCHECK(!layoutObject);
292 #endif 292 #endif
293 293
294 if (!layoutObject && hasDisplayContentsStyle(*sibling)) { 294 if (!layoutObject && hasDisplayContentsStyle(*sibling)) {
295 layoutObject = previousSiblingLayoutObjectInternal( 295 layoutObject = previousSiblingLayoutObjectInternal(
296 pseudoAwareLastChild(*sibling), limit); 296 pseudoAwareLastChild(*sibling), limit);
297 if (layoutObject) 297 if (layoutObject)
298 return layoutObject; 298 return layoutObject;
299 if (!limit) 299 if (limit == -1)
300 return nullptr; 300 return nullptr;
301 } 301 }
302 302
303 if (layoutObject && !isLayoutObjectReparented(layoutObject)) 303 if (layoutObject && !isLayoutObjectReparented(layoutObject))
304 return layoutObject; 304 return layoutObject;
305 } 305 }
306 306
307 return nullptr; 307 return nullptr;
308 } 308 }
309 309
310 LayoutObject* LayoutTreeBuilderTraversal::previousSiblingLayoutObject( 310 LayoutObject* LayoutTreeBuilderTraversal::previousSiblingLayoutObject(
311 const Node& node, 311 const Node& node,
312 int32_t limit) { 312 int32_t limit) {
313 DCHECK(limit == kTraverseAllSiblings || limit >= 0) << limit; 313 DCHECK(limit == kTraverseAllSiblings || limit >= 0) << limit;
314 if (LayoutObject* sibling = 314 if (LayoutObject* sibling =
315 previousSiblingLayoutObjectInternal(previousSibling(node), limit)) 315 previousSiblingLayoutObjectInternal(previousSibling(node), limit))
316 return sibling; 316 return sibling;
317 317
318 Node* parent = LayoutTreeBuilderTraversal::parent(node); 318 Node* parent = LayoutTreeBuilderTraversal::parent(node);
319 while (limit && parent && hasDisplayContentsStyle(*parent)) { 319 while (limit != -1 && parent && hasDisplayContentsStyle(*parent)) {
320 if (LayoutObject* sibling = previousSiblingLayoutObjectInternal( 320 if (LayoutObject* sibling = previousSiblingLayoutObjectInternal(
321 previousSibling(*parent), limit)) 321 previousSibling(*parent), limit))
322 return sibling; 322 return sibling;
323 parent = LayoutTreeBuilderTraversal::parent(*parent); 323 parent = LayoutTreeBuilderTraversal::parent(*parent);
324 } 324 }
325 325
326 return nullptr; 326 return nullptr;
327 } 327 }
328 328
329 LayoutObject* LayoutTreeBuilderTraversal::nextInTopLayer( 329 LayoutObject* LayoutTreeBuilderTraversal::nextInTopLayer(
330 const Element& element) { 330 const Element& element) {
331 if (!element.isInTopLayer()) 331 if (!element.isInTopLayer())
332 return 0; 332 return 0;
333 const HeapVector<Member<Element>>& topLayerElements = 333 const HeapVector<Member<Element>>& topLayerElements =
334 element.document().topLayerElements(); 334 element.document().topLayerElements();
335 size_t position = topLayerElements.find(&element); 335 size_t position = topLayerElements.find(&element);
336 DCHECK_NE(position, kNotFound); 336 DCHECK_NE(position, kNotFound);
337 for (size_t i = position + 1; i < topLayerElements.size(); ++i) { 337 for (size_t i = position + 1; i < topLayerElements.size(); ++i) {
338 if (LayoutObject* layoutObject = topLayerElements[i]->layoutObject()) 338 if (LayoutObject* layoutObject = topLayerElements[i]->layoutObject())
339 return layoutObject; 339 return layoutObject;
340 } 340 }
341 return 0; 341 return 0;
342 } 342 }
343 343
344 } // namespace blink 344 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/dom/LayoutTreeBuilderTraversalTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698