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

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

Issue 2725953002: Refactor LayoutTreeBuilderTraversal to expose a cleaner interface to layout sibling nodes. (Closed)
Patch Set: Refactor LayoutTreeBuilderTraversal to expose a cleaner interface to layout sibling nodes. 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
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 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 return nextAncestorSibling(node, stayWithin); 227 return nextAncestorSibling(node, stayWithin);
228 } 228 }
229 229
230 Node* LayoutTreeBuilderTraversal::next(const Node& node, 230 Node* LayoutTreeBuilderTraversal::next(const Node& node,
231 const Node* stayWithin) { 231 const Node* stayWithin) {
232 if (Node* child = pseudoAwareFirstChild(node)) 232 if (Node* child = pseudoAwareFirstChild(node))
233 return child; 233 return child;
234 return nextSkippingChildren(node, stayWithin); 234 return nextSkippingChildren(node, stayWithin);
235 } 235 }
236 236
237 static LayoutObject* nextSiblingLayoutObjectInternal(Node* node, 237 static Node* nextLayoutSiblingInternal(Node* node, int32_t& limit) {
238 int32_t& limit) {
239 for (Node* sibling = node; sibling && limit-- != 0; 238 for (Node* sibling = node; sibling && limit-- != 0;
240 sibling = LayoutTreeBuilderTraversal::nextSibling(*sibling)) { 239 sibling = LayoutTreeBuilderTraversal::nextSibling(*sibling)) {
241 LayoutObject* layoutObject = sibling->layoutObject();
242
243 #if DCHECK_IS_ON() 240 #if DCHECK_IS_ON()
244 if (hasDisplayContentsStyle(*sibling)) 241 if (hasDisplayContentsStyle(*sibling))
245 DCHECK(!layoutObject); 242 DCHECK(!sibling->layoutObject());
246 #endif 243 #endif
247 244
248 if (!layoutObject && hasDisplayContentsStyle(*sibling)) { 245 if (!hasDisplayContentsStyle(*sibling))
249 layoutObject = nextSiblingLayoutObjectInternal( 246 return sibling;
250 pseudoAwareFirstChild(*sibling), limit);
251 if (layoutObject)
252 return layoutObject;
253 if (limit == -1)
254 return nullptr;
255 }
256 247
257 if (layoutObject && !isLayoutObjectReparented(layoutObject)) 248 if (Node* inner =
258 return layoutObject; 249 nextLayoutSiblingInternal(pseudoAwareFirstChild(*sibling), limit))
250 return inner;
251
252 if (limit == -1)
253 return nullptr;
259 } 254 }
260 255
261 return nullptr; 256 return nullptr;
262 } 257 }
263 258
264 LayoutObject* LayoutTreeBuilderTraversal::nextSiblingLayoutObject( 259 Node* LayoutTreeBuilderTraversal::nextLayoutSibling(const Node& node,
265 const Node& node, 260 int32_t& limit) {
266 int32_t limit) { 261 DCHECK_NE(limit, -1);
267 DCHECK(limit == kTraverseAllSiblings || limit >= 0) << limit; 262 if (Node* sibling = nextLayoutSiblingInternal(nextSibling(node), limit))
268 if (LayoutObject* sibling =
269 nextSiblingLayoutObjectInternal(nextSibling(node), limit))
270 return sibling; 263 return sibling;
271 264
272 Node* parent = LayoutTreeBuilderTraversal::parent(node); 265 Node* parent = LayoutTreeBuilderTraversal::parent(node);
273 while (limit != -1 && parent && hasDisplayContentsStyle(*parent)) { 266 while (limit != -1 && parent && hasDisplayContentsStyle(*parent)) {
274 if (LayoutObject* sibling = 267 if (Node* sibling = nextLayoutSiblingInternal(nextSibling(*parent), limit))
275 nextSiblingLayoutObjectInternal(nextSibling(*parent), limit))
276 return sibling; 268 return sibling;
277 parent = LayoutTreeBuilderTraversal::parent(*parent); 269 parent = LayoutTreeBuilderTraversal::parent(*parent);
278 } 270 }
279 271
280 return nullptr; 272 return nullptr;
281 } 273 }
282 274
283 static LayoutObject* previousSiblingLayoutObjectInternal(Node* node, 275 static Node* previousLayoutSiblingInternal(Node* node, int32_t& limit) {
284 int32_t& limit) {
285 for (Node* sibling = node; sibling && limit-- != 0; 276 for (Node* sibling = node; sibling && limit-- != 0;
286 sibling = LayoutTreeBuilderTraversal::previousSibling(*sibling)) { 277 sibling = LayoutTreeBuilderTraversal::previousSibling(*sibling)) {
287 LayoutObject* layoutObject = sibling->layoutObject();
288
289 #if DCHECK_IS_ON() 278 #if DCHECK_IS_ON()
290 if (hasDisplayContentsStyle(*sibling)) 279 if (hasDisplayContentsStyle(*sibling))
291 DCHECK(!layoutObject); 280 DCHECK(!sibling->layoutObject());
292 #endif 281 #endif
293 282
294 if (!layoutObject && hasDisplayContentsStyle(*sibling)) { 283 if (!hasDisplayContentsStyle(*sibling))
295 layoutObject = previousSiblingLayoutObjectInternal( 284 return sibling;
296 pseudoAwareLastChild(*sibling), limit);
297 if (layoutObject)
298 return layoutObject;
299 if (limit == -1)
300 return nullptr;
301 }
302 285
303 if (layoutObject && !isLayoutObjectReparented(layoutObject)) 286 if (Node* inner = previousLayoutSiblingInternal(
304 return layoutObject; 287 pseudoAwareLastChild(*sibling), limit))
288 return inner;
289
290 if (limit == -1)
291 return nullptr;
305 } 292 }
306 293
307 return nullptr; 294 return nullptr;
308 } 295 }
309 296
310 LayoutObject* LayoutTreeBuilderTraversal::previousSiblingLayoutObject( 297 Node* LayoutTreeBuilderTraversal::previousLayoutSibling(const Node& node,
311 const Node& node, 298 int32_t& limit) {
312 int32_t limit) { 299 DCHECK_NE(limit, -1);
313 DCHECK(limit == kTraverseAllSiblings || limit >= 0) << limit; 300 if (Node* sibling =
314 if (LayoutObject* sibling = 301 previousLayoutSiblingInternal(previousSibling(node), limit))
315 previousSiblingLayoutObjectInternal(previousSibling(node), limit))
316 return sibling; 302 return sibling;
317 303
318 Node* parent = LayoutTreeBuilderTraversal::parent(node); 304 Node* parent = LayoutTreeBuilderTraversal::parent(node);
319 while (limit != -1 && parent && hasDisplayContentsStyle(*parent)) { 305 while (limit != -1 && parent && hasDisplayContentsStyle(*parent)) {
320 if (LayoutObject* sibling = previousSiblingLayoutObjectInternal( 306 if (Node* sibling =
321 previousSibling(*parent), limit)) 307 previousLayoutSiblingInternal(previousSibling(*parent), limit))
322 return sibling; 308 return sibling;
323 parent = LayoutTreeBuilderTraversal::parent(*parent); 309 parent = LayoutTreeBuilderTraversal::parent(*parent);
324 } 310 }
325 311
326 return nullptr; 312 return nullptr;
327 } 313 }
328 314
315 LayoutObject* LayoutTreeBuilderTraversal::nextSiblingLayoutObject(
316 const Node& node,
317 int32_t limit) {
318 DCHECK(limit == kTraverseAllSiblings || limit >= 0) << limit;
319 for (Node* sibling = nextLayoutSibling(node, limit); sibling && limit != -1;
320 sibling = nextLayoutSibling(*sibling, limit)) {
321 LayoutObject* layoutObject = sibling->layoutObject();
322 if (layoutObject && !isLayoutObjectReparented(layoutObject))
323 return layoutObject;
324 }
325 return nullptr;
326 }
327
328 LayoutObject* LayoutTreeBuilderTraversal::previousSiblingLayoutObject(
329 const Node& node,
330 int32_t limit) {
331 DCHECK(limit == kTraverseAllSiblings || limit >= 0) << limit;
332 for (Node* sibling = previousLayoutSibling(node, limit);
333 sibling && limit != -1;
334 sibling = previousLayoutSibling(*sibling, limit)) {
335 LayoutObject* layoutObject = sibling->layoutObject();
336 if (layoutObject && !isLayoutObjectReparented(layoutObject))
337 return layoutObject;
338 }
339 return nullptr;
340 }
341
329 LayoutObject* LayoutTreeBuilderTraversal::nextInTopLayer( 342 LayoutObject* LayoutTreeBuilderTraversal::nextInTopLayer(
330 const Element& element) { 343 const Element& element) {
331 if (!element.isInTopLayer()) 344 if (!element.isInTopLayer())
332 return 0; 345 return 0;
333 const HeapVector<Member<Element>>& topLayerElements = 346 const HeapVector<Member<Element>>& topLayerElements =
334 element.document().topLayerElements(); 347 element.document().topLayerElements();
335 size_t position = topLayerElements.find(&element); 348 size_t position = topLayerElements.find(&element);
336 DCHECK_NE(position, kNotFound); 349 DCHECK_NE(position, kNotFound);
337 for (size_t i = position + 1; i < topLayerElements.size(); ++i) { 350 for (size_t i = position + 1; i < topLayerElements.size(); ++i) {
338 if (LayoutObject* layoutObject = topLayerElements[i]->layoutObject()) 351 if (LayoutObject* layoutObject = topLayerElements[i]->layoutObject())
339 return layoutObject; 352 return layoutObject;
340 } 353 }
341 return 0; 354 return 0;
342 } 355 }
343 356
344 } // namespace blink 357 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698