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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/core/dom/LayoutTreeBuilderTraversal.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/dom/LayoutTreeBuilderTraversal.cpp
diff --git a/third_party/WebKit/Source/core/dom/LayoutTreeBuilderTraversal.cpp b/third_party/WebKit/Source/core/dom/LayoutTreeBuilderTraversal.cpp
index a502a25952b6965290486d37a9b59ef866ced8bc..1fbcd95490067677982190a038e87e00e395861a 100644
--- a/third_party/WebKit/Source/core/dom/LayoutTreeBuilderTraversal.cpp
+++ b/third_party/WebKit/Source/core/dom/LayoutTreeBuilderTraversal.cpp
@@ -234,45 +234,32 @@ Node* LayoutTreeBuilderTraversal::next(const Node& node,
return nextSkippingChildren(node, stayWithin);
}
-static LayoutObject* nextSiblingLayoutObjectInternal(Node* node,
- int32_t& limit) {
+static Node* nextLayoutSiblingInternal(Node* node, int32_t& limit) {
for (Node* sibling = node; sibling && limit-- != 0;
sibling = LayoutTreeBuilderTraversal::nextSibling(*sibling)) {
- LayoutObject* layoutObject = sibling->layoutObject();
+ if (!hasDisplayContentsStyle(*sibling))
+ return sibling;
-#if DCHECK_IS_ON()
- if (hasDisplayContentsStyle(*sibling))
- DCHECK(!layoutObject);
-#endif
-
- if (!layoutObject && hasDisplayContentsStyle(*sibling)) {
- layoutObject = nextSiblingLayoutObjectInternal(
- pseudoAwareFirstChild(*sibling), limit);
- if (layoutObject)
- return layoutObject;
- if (limit == -1)
- return nullptr;
- }
+ if (Node* inner =
+ nextLayoutSiblingInternal(pseudoAwareFirstChild(*sibling), limit))
+ return inner;
- if (layoutObject && !isLayoutObjectReparented(layoutObject))
- return layoutObject;
+ if (limit == -1)
+ return nullptr;
}
return nullptr;
}
-LayoutObject* LayoutTreeBuilderTraversal::nextSiblingLayoutObject(
- const Node& node,
- int32_t limit) {
- DCHECK(limit == kTraverseAllSiblings || limit >= 0) << limit;
- if (LayoutObject* sibling =
- nextSiblingLayoutObjectInternal(nextSibling(node), limit))
+Node* LayoutTreeBuilderTraversal::nextLayoutSibling(const Node& node,
+ int32_t& limit) {
+ DCHECK_NE(limit, -1);
+ if (Node* sibling = nextLayoutSiblingInternal(nextSibling(node), limit))
return sibling;
Node* parent = LayoutTreeBuilderTraversal::parent(node);
while (limit != -1 && parent && hasDisplayContentsStyle(*parent)) {
- if (LayoutObject* sibling =
- nextSiblingLayoutObjectInternal(nextSibling(*parent), limit))
+ if (Node* sibling = nextLayoutSiblingInternal(nextSibling(*parent), limit))
return sibling;
parent = LayoutTreeBuilderTraversal::parent(*parent);
}
@@ -280,45 +267,34 @@ LayoutObject* LayoutTreeBuilderTraversal::nextSiblingLayoutObject(
return nullptr;
}
-static LayoutObject* previousSiblingLayoutObjectInternal(Node* node,
- int32_t& limit) {
+static Node* previousLayoutSiblingInternal(Node* node, int32_t& limit) {
for (Node* sibling = node; sibling && limit-- != 0;
sibling = LayoutTreeBuilderTraversal::previousSibling(*sibling)) {
- LayoutObject* layoutObject = sibling->layoutObject();
+ if (!hasDisplayContentsStyle(*sibling))
+ return sibling;
-#if DCHECK_IS_ON()
- if (hasDisplayContentsStyle(*sibling))
- DCHECK(!layoutObject);
-#endif
-
- if (!layoutObject && hasDisplayContentsStyle(*sibling)) {
- layoutObject = previousSiblingLayoutObjectInternal(
- pseudoAwareLastChild(*sibling), limit);
- if (layoutObject)
- return layoutObject;
- if (limit == -1)
- return nullptr;
- }
+ if (Node* inner = previousLayoutSiblingInternal(
+ pseudoAwareLastChild(*sibling), limit))
+ return inner;
- if (layoutObject && !isLayoutObjectReparented(layoutObject))
- return layoutObject;
+ if (limit == -1)
+ return nullptr;
}
return nullptr;
}
-LayoutObject* LayoutTreeBuilderTraversal::previousSiblingLayoutObject(
- const Node& node,
- int32_t limit) {
- DCHECK(limit == kTraverseAllSiblings || limit >= 0) << limit;
- if (LayoutObject* sibling =
- previousSiblingLayoutObjectInternal(previousSibling(node), limit))
+Node* LayoutTreeBuilderTraversal::previousLayoutSibling(const Node& node,
+ int32_t& limit) {
+ DCHECK_NE(limit, -1);
+ if (Node* sibling =
+ previousLayoutSiblingInternal(previousSibling(node), limit))
return sibling;
Node* parent = LayoutTreeBuilderTraversal::parent(node);
while (limit != -1 && parent && hasDisplayContentsStyle(*parent)) {
- if (LayoutObject* sibling = previousSiblingLayoutObjectInternal(
- previousSibling(*parent), limit))
+ if (Node* sibling =
+ previousLayoutSiblingInternal(previousSibling(*parent), limit))
return sibling;
parent = LayoutTreeBuilderTraversal::parent(*parent);
}
@@ -326,6 +302,33 @@ LayoutObject* LayoutTreeBuilderTraversal::previousSiblingLayoutObject(
return nullptr;
}
+LayoutObject* LayoutTreeBuilderTraversal::nextSiblingLayoutObject(
+ const Node& node,
+ int32_t limit) {
+ DCHECK(limit == kTraverseAllSiblings || limit >= 0) << limit;
+ for (Node* sibling = nextLayoutSibling(node, limit); sibling && limit != -1;
+ sibling = nextLayoutSibling(*sibling, limit)) {
+ LayoutObject* layoutObject = sibling->layoutObject();
+ if (layoutObject && !isLayoutObjectReparented(layoutObject))
+ return layoutObject;
+ }
+ return nullptr;
+}
+
+LayoutObject* LayoutTreeBuilderTraversal::previousSiblingLayoutObject(
+ const Node& node,
+ int32_t limit) {
+ DCHECK(limit == kTraverseAllSiblings || limit >= 0) << limit;
+ for (Node* sibling = previousLayoutSibling(node, limit);
+ sibling && limit != -1;
+ sibling = previousLayoutSibling(*sibling, limit)) {
+ LayoutObject* layoutObject = sibling->layoutObject();
+ if (layoutObject && !isLayoutObjectReparented(layoutObject))
+ return layoutObject;
+ }
+ return nullptr;
+}
+
LayoutObject* LayoutTreeBuilderTraversal::nextInTopLayer(
const Element& element) {
if (!element.isInTopLayer())
« no previous file with comments | « third_party/WebKit/Source/core/dom/LayoutTreeBuilderTraversal.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698