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

Unified Diff: third_party/WebKit/Source/core/dom/NodeTraversal.cpp

Issue 1932523003: Introduce NodeTraversal::ancestorsOf() and inclusiveAncestors() for range-based for loop (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 2016-04-28T18:38:12 Created 4 years, 8 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/NodeTraversal.h ('k') | third_party/WebKit/Source/core/dom/Range.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/dom/NodeTraversal.cpp
diff --git a/third_party/WebKit/Source/core/dom/NodeTraversal.cpp b/third_party/WebKit/Source/core/dom/NodeTraversal.cpp
index 25c00e0f69aaeb2e5d37a2ea3b7b5bdc54b72963..b074b63d86f911625e7aa9ef67d267ffa9252776 100644
--- a/third_party/WebKit/Source/core/dom/NodeTraversal.cpp
+++ b/third_party/WebKit/Source/core/dom/NodeTraversal.cpp
@@ -49,10 +49,10 @@ Node* NodeTraversal::nextIncludingPseudo(const Node& current, const Node* stayWi
return 0;
if (Node* next = current.pseudoAwareNextSibling())
return next;
- for (Node* parent = current.parentNode(); parent; parent = parent->parentNode()) {
+ for (Node& parent : ancestorsOf(current)) {
if (parent == stayWithin)
return 0;
- if (Node* next = parent->pseudoAwareNextSibling())
+ if (Node* next = parent.pseudoAwareNextSibling())
return next;
}
return 0;
@@ -64,10 +64,10 @@ Node* NodeTraversal::nextIncludingPseudoSkippingChildren(const Node& current, co
return 0;
if (Node* next = current.pseudoAwareNextSibling())
return next;
- for (Node* parent = current.parentNode(); parent; parent = parent->parentNode()) {
+ for (Node& parent : ancestorsOf(current)) {
if (parent == stayWithin)
return 0;
- if (Node* next = parent->pseudoAwareNextSibling())
+ if (Node* next = parent.pseudoAwareNextSibling())
return next;
}
return 0;
@@ -76,9 +76,9 @@ Node* NodeTraversal::nextIncludingPseudoSkippingChildren(const Node& current, co
Node* NodeTraversal::nextAncestorSibling(const Node& current)
{
DCHECK(!current.nextSibling());
- for (Node* parent = current.parentNode(); parent; parent = parent->parentNode()) {
- if (parent->nextSibling())
- return parent->nextSibling();
+ for (Node& parent : ancestorsOf(current)) {
+ if (parent.nextSibling())
+ return parent.nextSibling();
}
return 0;
}
@@ -87,11 +87,11 @@ Node* NodeTraversal::nextAncestorSibling(const Node& current, const Node* stayWi
{
DCHECK(!current.nextSibling());
DCHECK_NE(current, stayWithin);
- for (Node* parent = current.parentNode(); parent; parent = parent->parentNode()) {
+ for (Node& parent : ancestorsOf(current)) {
if (parent == stayWithin)
return 0;
- if (parent->nextSibling())
- return parent->nextSibling();
+ if (parent.nextSibling())
+ return parent.nextSibling();
}
return 0;
}
@@ -129,11 +129,11 @@ Node* NodeTraversal::previousSkippingChildren(const Node& current, const Node* s
return 0;
if (current.previousSibling())
return current.previousSibling();
- for (Node* parent = current.parentNode(); parent; parent = parent->parentNode()) {
+ for (Node& parent : ancestorsOf(current)) {
if (parent == stayWithin)
return 0;
- if (parent->previousSibling())
- return parent->previousSibling();
+ if (parent.previousSibling())
+ return parent.previousSibling();
}
return 0;
}
@@ -153,11 +153,11 @@ Node* NodeTraversal::nextPostOrder(const Node& current, const Node* stayWithin)
static Node* previousAncestorSiblingPostOrder(const Node& current, const Node* stayWithin)
{
DCHECK(!current.previousSibling());
- for (Node* parent = current.parentNode(); parent; parent = parent->parentNode()) {
+ for (Node& parent : NodeTraversal::ancestorsOf(current)) {
if (parent == stayWithin)
return 0;
- if (parent->previousSibling())
- return parent->previousSibling();
+ if (parent.previousSibling())
+ return parent.previousSibling();
}
return 0;
}
« no previous file with comments | « third_party/WebKit/Source/core/dom/NodeTraversal.h ('k') | third_party/WebKit/Source/core/dom/Range.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698