diff options
author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
---|---|---|
committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
commit | 1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch) | |
tree | 46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/WebCore/dom/NodeTraversal.h | |
parent | 32761a6cee1d0dee366b885b7b9c777e67885688 (diff) | |
download | WebKitGtk-tarball-master.tar.gz |
webkitgtk-2.16.5HEADwebkitgtk-2.16.5master
Diffstat (limited to 'Source/WebCore/dom/NodeTraversal.h')
-rw-r--r-- | Source/WebCore/dom/NodeTraversal.h | 115 |
1 files changed, 52 insertions, 63 deletions
diff --git a/Source/WebCore/dom/NodeTraversal.h b/Source/WebCore/dom/NodeTraversal.h index 41870646b..8ab9846dc 100644 --- a/Source/WebCore/dom/NodeTraversal.h +++ b/Source/WebCore/dom/NodeTraversal.h @@ -22,8 +22,7 @@ * */ -#ifndef NodeTraversal_h -#define NodeTraversal_h +#pragma once #include "ContainerNode.h" #include "Text.h" @@ -35,107 +34,97 @@ namespace NodeTraversal { // This uses the same order that tags appear in the source file. If the stayWithin // argument is non-null, the traversal will stop once the specified node is reached. // This can be used to restrict traversal to a particular sub-tree. -Node* next(const Node*); -Node* next(const Node*, const Node* stayWithin); -Node* next(const ContainerNode*); -Node* next(const ContainerNode*, const Node* stayWithin); -Node* next(const Text*); -Node* next(const Text*, const Node* stayWithin); +Node* next(const Node&); +Node* next(const Node&, const Node* stayWithin); +Node* next(const ContainerNode&); +Node* next(const ContainerNode&, const Node* stayWithin); +Node* next(const Text&); +Node* next(const Text&, const Node* stayWithin); // Like next, but skips children and starts with the next sibling. -Node* nextSkippingChildren(const Node*); -Node* nextSkippingChildren(const Node*, const Node* stayWithin); -Node* nextSkippingChildren(const ContainerNode*); -Node* nextSkippingChildren(const ContainerNode*, const Node* stayWithin); +Node* nextSkippingChildren(const Node&); +Node* nextSkippingChildren(const Node&, const Node* stayWithin); // Does a reverse pre-order traversal to find the node that comes before the current one in document order -Node* last(const ContainerNode*); -Node* previous(const Node*, const Node* stayWithin = 0); +WEBCORE_EXPORT Node* last(const ContainerNode&); +Node* previous(const Node&, const Node* stayWithin = nullptr); // Like previous, but skips children and starts with the next sibling. -Node* previousSkippingChildren(const Node*, const Node* stayWithin = 0); +Node* previousSkippingChildren(const Node&, const Node* stayWithin = nullptr); // Like next, but visits parents after their children. -Node* nextPostOrder(const Node*, const Node* stayWithin = 0); +Node* nextPostOrder(const Node&, const Node* stayWithin = nullptr); // Like previous/previousSkippingChildren, but visits parents before their children. -Node* previousPostOrder(const Node*, const Node* stayWithin = 0); -Node* previousSkippingChildrenPostOrder(const Node*, const Node* stayWithin = 0); +Node* previousPostOrder(const Node&, const Node* stayWithin = nullptr); +Node* previousSkippingChildrenPostOrder(const Node&, const Node* stayWithin = nullptr); // Pre-order traversal including the pseudo-elements. -Node* previousIncludingPseudo(const Node*, const Node* = 0); -Node* nextIncludingPseudo(const Node*, const Node* = 0); -Node* nextIncludingPseudoSkippingChildren(const Node*, const Node* = 0); +Node* previousIncludingPseudo(const Node&, const Node* = nullptr); +Node* nextIncludingPseudo(const Node&, const Node* = nullptr); +Node* nextIncludingPseudoSkippingChildren(const Node&, const Node* = nullptr); } namespace NodeTraversal { -Node* nextAncestorSibling(const Node*); -Node* nextAncestorSibling(const Node*, const Node* stayWithin); -Node* deepLastChild(Node*); +WEBCORE_EXPORT Node* nextAncestorSibling(const Node&); +WEBCORE_EXPORT Node* nextAncestorSibling(const Node&, const Node* stayWithin); +WEBCORE_EXPORT Node* deepLastChild(Node&); template <class NodeType> -inline Node* traverseNextTemplate(NodeType* current) +inline Node* traverseNextTemplate(NodeType& current) { - if (current->firstChild()) - return current->firstChild(); - if (current->nextSibling()) - return current->nextSibling(); + if (current.firstChild()) + return current.firstChild(); + if (current.nextSibling()) + return current.nextSibling(); return nextAncestorSibling(current); } -inline Node* next(const Node* current) { return traverseNextTemplate(current); } -inline Node* next(const ContainerNode* current) { return traverseNextTemplate(current); } +inline Node* next(const Node& current) { return traverseNextTemplate(current); } +inline Node* next(const ContainerNode& current) { return traverseNextTemplate(current); } template <class NodeType> -inline Node* traverseNextTemplate(NodeType* current, const Node* stayWithin) +inline Node* traverseNextTemplate(NodeType& current, const Node* stayWithin) { - if (current->firstChild()) - return current->firstChild(); - if (current == stayWithin) - return 0; - if (current->nextSibling()) - return current->nextSibling(); + if (current.firstChild()) + return current.firstChild(); + if (¤t == stayWithin) + return nullptr; + if (current.nextSibling()) + return current.nextSibling(); return nextAncestorSibling(current, stayWithin); } -inline Node* next(const Node* current, const Node* stayWithin) { return traverseNextTemplate(current, stayWithin); } -inline Node* next(const ContainerNode* current, const Node* stayWithin) { return traverseNextTemplate(current, stayWithin); } +inline Node* next(const Node& current, const Node* stayWithin) { return traverseNextTemplate(current, stayWithin); } +inline Node* next(const ContainerNode& current, const Node* stayWithin) { return traverseNextTemplate(current, stayWithin); } -template <class NodeType> -inline Node* traverseNextSkippingChildrenTemplate(NodeType* current) +inline Node* nextSkippingChildren(const Node& current) { - if (current->nextSibling()) - return current->nextSibling(); + if (current.nextSibling()) + return current.nextSibling(); return nextAncestorSibling(current); } -inline Node* nextSkippingChildren(const Node* current) { return traverseNextSkippingChildrenTemplate(current); } -inline Node* nextSkippingChildren(const ContainerNode* current) { return traverseNextSkippingChildrenTemplate(current); } -template <class NodeType> -inline Node* traverseNextSkippingChildrenTemplate(NodeType* current, const Node* stayWithin) +inline Node* nextSkippingChildren(const Node& current, const Node* stayWithin) { - if (current == stayWithin) - return 0; - if (current->nextSibling()) - return current->nextSibling(); + if (¤t == stayWithin) + return nullptr; + if (current.nextSibling()) + return current.nextSibling(); return nextAncestorSibling(current, stayWithin); } -inline Node* nextSkippingChildren(const Node* current, const Node* stayWithin) { return traverseNextSkippingChildrenTemplate(current, stayWithin); } -inline Node* nextSkippingChildren(const ContainerNode* current, const Node* stayWithin) { return traverseNextSkippingChildrenTemplate(current, stayWithin); } -inline Node* next(const Text* current) { return traverseNextSkippingChildrenTemplate(current); } -inline Node* next(const Text* current, const Node* stayWithin) { return traverseNextSkippingChildrenTemplate(current, stayWithin); } +inline Node* next(const Text& current) { return nextSkippingChildren(current); } +inline Node* next(const Text& current, const Node* stayWithin) { return nextSkippingChildren(current, stayWithin); } -inline Node* previous(const Node* current, const Node* stayWithin) +inline Node* previous(const Node& current, const Node* stayWithin) { - if (Node* previous = current->previousSibling()) - return deepLastChild(previous); - if (current->parentNode() == stayWithin) + if (Node* previous = current.previousSibling()) + return deepLastChild(*previous); + if (current.parentNode() == stayWithin) return nullptr; - return current->parentNode(); + return current.parentNode(); } } } - -#endif |