OLD | NEW |
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 Loading... |
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 bool* ranOutOfSiblings) { |
313 DCHECK(limit == kTraverseAllSiblings || limit >= 0) << limit; | 314 DCHECK(limit == kTraverseAllSiblings || limit >= 0) << limit; |
| 315 DCHECK(!ranOutOfSiblings || limit >= 0) << limit; |
| 316 if (ranOutOfSiblings) |
| 317 *ranOutOfSiblings = false; |
| 318 |
314 if (LayoutObject* sibling = | 319 if (LayoutObject* sibling = |
315 previousSiblingLayoutObjectInternal(previousSibling(node), limit)) | 320 previousSiblingLayoutObjectInternal(previousSibling(node), limit)) { |
316 return sibling; | 321 return sibling; |
| 322 } |
317 | 323 |
318 Node* parent = LayoutTreeBuilderTraversal::parent(node); | 324 Node* parent = LayoutTreeBuilderTraversal::parent(node); |
319 while (limit && parent && hasDisplayContentsStyle(*parent)) { | 325 while (limit != -1 && parent && hasDisplayContentsStyle(*parent)) { |
320 if (LayoutObject* sibling = previousSiblingLayoutObjectInternal( | 326 if (LayoutObject* sibling = previousSiblingLayoutObjectInternal( |
321 previousSibling(*parent), limit)) | 327 previousSibling(*parent), limit)) |
322 return sibling; | 328 return sibling; |
323 parent = LayoutTreeBuilderTraversal::parent(*parent); | 329 parent = LayoutTreeBuilderTraversal::parent(*parent); |
324 } | 330 } |
325 | 331 |
| 332 if (ranOutOfSiblings) { |
| 333 DCHECK_GE(limit, -1); |
| 334 *ranOutOfSiblings = limit == -1; |
| 335 } |
| 336 |
326 return nullptr; | 337 return nullptr; |
327 } | 338 } |
328 | 339 |
329 LayoutObject* LayoutTreeBuilderTraversal::nextInTopLayer( | 340 LayoutObject* LayoutTreeBuilderTraversal::nextInTopLayer( |
330 const Element& element) { | 341 const Element& element) { |
331 if (!element.isInTopLayer()) | 342 if (!element.isInTopLayer()) |
332 return 0; | 343 return 0; |
333 const HeapVector<Member<Element>>& topLayerElements = | 344 const HeapVector<Member<Element>>& topLayerElements = |
334 element.document().topLayerElements(); | 345 element.document().topLayerElements(); |
335 size_t position = topLayerElements.find(&element); | 346 size_t position = topLayerElements.find(&element); |
336 DCHECK_NE(position, kNotFound); | 347 DCHECK_NE(position, kNotFound); |
337 for (size_t i = position + 1; i < topLayerElements.size(); ++i) { | 348 for (size_t i = position + 1; i < topLayerElements.size(); ++i) { |
338 if (LayoutObject* layoutObject = topLayerElements[i]->layoutObject()) | 349 if (LayoutObject* layoutObject = topLayerElements[i]->layoutObject()) |
339 return layoutObject; | 350 return layoutObject; |
340 } | 351 } |
341 return 0; | 352 return 0; |
342 } | 353 } |
343 | 354 |
344 } // namespace blink | 355 } // namespace blink |
OLD | NEW |