summaryrefslogtreecommitdiff
path: root/Source/WebCore/dom/NodeTraversal.cpp
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@lorry>2017-06-27 06:07:23 +0000
committerLorry Tar Creator <lorry-tar-importer@lorry>2017-06-27 06:07:23 +0000
commit1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch)
tree46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/WebCore/dom/NodeTraversal.cpp
parent32761a6cee1d0dee366b885b7b9c777e67885688 (diff)
downloadWebKitGtk-tarball-master.tar.gz
Diffstat (limited to 'Source/WebCore/dom/NodeTraversal.cpp')
-rw-r--r--Source/WebCore/dom/NodeTraversal.cpp169
1 files changed, 85 insertions, 84 deletions
diff --git a/Source/WebCore/dom/NodeTraversal.cpp b/Source/WebCore/dom/NodeTraversal.cpp
index 7ad11307c..8301e4a36 100644
--- a/Source/WebCore/dom/NodeTraversal.cpp
+++ b/Source/WebCore/dom/NodeTraversal.cpp
@@ -31,81 +31,81 @@ namespace WebCore {
namespace NodeTraversal {
-Node* previousIncludingPseudo(const Node* current, const Node* stayWithin)
+Node* previousIncludingPseudo(const Node& current, const Node* stayWithin)
{
Node* previous;
- if (current == stayWithin)
- return 0;
- if ((previous = current->pseudoAwarePreviousSibling())) {
+ if (&current == stayWithin)
+ return nullptr;
+ if ((previous = current.pseudoAwarePreviousSibling())) {
while (previous->pseudoAwareLastChild())
previous = previous->pseudoAwareLastChild();
return previous;
}
- return current->isPseudoElement() ? toPseudoElement(current)->hostElement() : current->parentNode();
+ return is<PseudoElement>(current) ? downcast<PseudoElement>(current).hostElement() : current.parentNode();
}
-Node* nextIncludingPseudo(const Node* current, const Node* stayWithin)
+Node* nextIncludingPseudo(const Node& current, const Node* stayWithin)
{
Node* next;
- if ((next = current->pseudoAwareFirstChild()))
+ if ((next = current.pseudoAwareFirstChild()))
return next;
- if (current == stayWithin)
- return 0;
- if ((next = current->pseudoAwareNextSibling()))
+ if (&current == stayWithin)
+ return nullptr;
+ if ((next = current.pseudoAwareNextSibling()))
return next;
- current = current->isPseudoElement() ? toPseudoElement(current)->hostElement() : current->parentNode();
- for (; current; current = current->parentNode()) {
- if (current == stayWithin)
- return 0;
- if ((next = current->pseudoAwareNextSibling()))
+ const Node* ancestor = is<PseudoElement>(current) ? downcast<PseudoElement>(current).hostElement() : current.parentNode();
+ for (; ancestor; ancestor = ancestor->parentNode()) {
+ if (ancestor == stayWithin)
+ return nullptr;
+ if ((next = ancestor->pseudoAwareNextSibling()))
return next;
}
- return 0;
+ return nullptr;
}
-Node* nextIncludingPseudoSkippingChildren(const Node* current, const Node* stayWithin)
+Node* nextIncludingPseudoSkippingChildren(const Node& current, const Node* stayWithin)
{
Node* next;
- if (current == stayWithin)
- return 0;
- if ((next = current->pseudoAwareNextSibling()))
+ if (&current == stayWithin)
+ return nullptr;
+ if ((next = current.pseudoAwareNextSibling()))
return next;
- current = current->isPseudoElement() ? toPseudoElement(current)->hostElement() : current->parentNode();
- for (; current; current = current->parentNode()) {
- if (current == stayWithin)
- return 0;
- if ((next = current->pseudoAwareNextSibling()))
+ const Node* ancestor = is<PseudoElement>(current) ? downcast<PseudoElement>(current).hostElement() : current.parentNode();
+ for (; ancestor; ancestor = ancestor->parentNode()) {
+ if (ancestor == stayWithin)
+ return nullptr;
+ if ((next = ancestor->pseudoAwareNextSibling()))
return next;
}
- return 0;
+ return nullptr;
}
-Node* nextAncestorSibling(const Node* current)
+Node* nextAncestorSibling(const Node& current)
{
- ASSERT(!current->nextSibling());
- for (current = current->parentNode(); current; current = current->parentNode()) {
- if (current->nextSibling())
- return current->nextSibling();
+ ASSERT(!current.nextSibling());
+ for (auto* ancestor = current.parentNode(); ancestor; ancestor = ancestor->parentNode()) {
+ if (ancestor->nextSibling())
+ return ancestor->nextSibling();
}
- return 0;
+ return nullptr;
}
-Node* nextAncestorSibling(const Node* current, const Node* stayWithin)
+Node* nextAncestorSibling(const Node& current, const Node* stayWithin)
{
- ASSERT(!current->nextSibling());
- ASSERT(current != stayWithin);
- for (current = current->parentNode(); current; current = current->parentNode()) {
- if (current == stayWithin)
- return 0;
- if (current->nextSibling())
- return current->nextSibling();
+ ASSERT(!current.nextSibling());
+ ASSERT(&current != stayWithin);
+ for (auto* ancestor = current.parentNode(); ancestor; ancestor = ancestor->parentNode()) {
+ if (ancestor == stayWithin)
+ return nullptr;
+ if (ancestor->nextSibling())
+ return ancestor->nextSibling();
}
- return 0;
+ return nullptr;
}
-Node* last(const ContainerNode* current)
+Node* last(const ContainerNode& current)
{
- Node* node = current->lastChild();
+ Node* node = current.lastChild();
if (!node)
return nullptr;
while (node->lastChild())
@@ -113,69 +113,70 @@ Node* last(const ContainerNode* current)
return node;
}
-Node* deepLastChild(Node* node)
+Node* deepLastChild(Node& node)
{
- while (node->lastChild())
- node = node->lastChild();
- return node;
+ Node* lastChild = &node;
+ while (lastChild->lastChild())
+ lastChild = lastChild->lastChild();
+ return lastChild;
}
-Node* previousSkippingChildren(const Node* current, const Node* stayWithin)
+Node* previousSkippingChildren(const Node& current, const Node* stayWithin)
{
- if (current == stayWithin)
- return 0;
- if (current->previousSibling())
- return current->previousSibling();
- for (current = current->parentNode(); current; current = current->parentNode()) {
- if (current == stayWithin)
- return 0;
- if (current->previousSibling())
- return current->previousSibling();
+ if (&current == stayWithin)
+ return nullptr;
+ if (current.previousSibling())
+ return current.previousSibling();
+ for (auto* ancestor = current.parentNode(); ancestor; ancestor = ancestor->parentNode()) {
+ if (ancestor == stayWithin)
+ return nullptr;
+ if (ancestor->previousSibling())
+ return ancestor->previousSibling();
}
- return 0;
+ return nullptr;
}
-Node* nextPostOrder(const Node* current, const Node* stayWithin)
+Node* nextPostOrder(const Node& current, const Node* stayWithin)
{
- if (current == stayWithin)
- return 0;
- if (!current->nextSibling())
- return current->parentNode();
- Node* next = current->nextSibling();
+ if (&current == stayWithin)
+ return nullptr;
+ if (!current.nextSibling())
+ return current.parentNode();
+ Node* next = current.nextSibling();
while (next->firstChild())
next = next->firstChild();
return next;
}
-static Node* previousAncestorSiblingPostOrder(const Node* current, const Node* stayWithin)
+static Node* previousAncestorSiblingPostOrder(const Node& current, const Node* stayWithin)
{
- ASSERT(!current->previousSibling());
- for (current = current->parentNode(); current; current = current->parentNode()) {
- if (current == stayWithin)
- return 0;
- if (current->previousSibling())
- return current->previousSibling();
+ ASSERT(!current.previousSibling());
+ for (auto* ancestor = current.parentNode(); ancestor; ancestor = ancestor->parentNode()) {
+ if (ancestor == stayWithin)
+ return nullptr;
+ if (ancestor->previousSibling())
+ return ancestor->previousSibling();
}
- return 0;
+ return nullptr;
}
-Node* previousPostOrder(const Node* current, const Node* stayWithin)
+Node* previousPostOrder(const Node& current, const Node* stayWithin)
{
- if (current->lastChild())
- return current->lastChild();
- if (current == stayWithin)
- return 0;
- if (current->previousSibling())
- return current->previousSibling();
+ if (current.lastChild())
+ return current.lastChild();
+ if (&current == stayWithin)
+ return nullptr;
+ if (current.previousSibling())
+ return current.previousSibling();
return previousAncestorSiblingPostOrder(current, stayWithin);
}
-Node* previousSkippingChildrenPostOrder(const Node* current, const Node* stayWithin)
+Node* previousSkippingChildrenPostOrder(const Node& current, const Node* stayWithin)
{
- if (current == stayWithin)
- return 0;
- if (current->previousSibling())
- return current->previousSibling();
+ if (&current == stayWithin)
+ return nullptr;
+ if (current.previousSibling())
+ return current.previousSibling();
return previousAncestorSiblingPostOrder(current, stayWithin);
}