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