#ifndef NodeTraversal_h
#define NodeTraversal_h
#include "Element.h"
namespace WebCore {
namespace ElementTraversal {
Element* firstWithin(const Node*);
Element* firstWithin(const ContainerNode*);
Element* next(const Node*);
Element* next(const Node*, const Node* stayWithin);
Element* next(const ContainerNode*);
Element* next(const ContainerNode*, const Node* stayWithin);
Element* nextSkippingChildren(const Node*);
Element* nextSkippingChildren(const Node*, const Node* stayWithin);
Element* nextSkippingChildren(const ContainerNode*);
Element* nextSkippingChildren(const ContainerNode*, const Node* stayWithin);
Element* previousIncludingPseudo(const Node*, const Node* = 0);
Element* nextIncludingPseudo(const Node*, const Node* = 0);
Element* nextIncludingPseudoSkippingChildren(const Node*, const Node* = 0);
Element* pseudoAwarePreviousSibling(const Node*);
}
namespace NodeTraversal {
Node* next(const Node*);
Node* next(const Node*, const Node* stayWithin);
Node* next(const ContainerNode*);
Node* next(const ContainerNode*, const Node* stayWithin);
Node* nextSkippingChildren(const Node*);
Node* nextSkippingChildren(const Node*, const Node* stayWithin);
Node* nextSkippingChildren(const ContainerNode*);
Node* nextSkippingChildren(const ContainerNode*, const Node* stayWithin);
Node* previous(const Node*, const Node* stayWithin = 0);
Node* previousSkippingChildren(const Node*, const Node* stayWithin = 0);
Node* nextPostOrder(const Node*, const Node* stayWithin = 0);
Node* previousPostOrder(const Node*, const Node* stayWithin = 0);
Node* previousSkippingChildrenPostOrder(const Node*, const Node* stayWithin = 0);
Node* previousIncludingPseudo(const Node*, const Node* = 0);
Node* nextIncludingPseudo(const Node*, const Node* = 0);
Node* nextIncludingPseudoSkippingChildren(const Node*, const Node* = 0);
}
namespace ElementTraversal {
template <class NodeType>
inline Element* firstElementWithinTemplate(NodeType* current)
{
Node* node = current->firstChild();
while (node && !node->isElementNode())
node = node->nextSibling();
return toElement(node);
}
inline Element* firstWithin(const ContainerNode* current) { return firstElementWithinTemplate(current); }
inline Element* firstWithin(const Node* current) { return firstElementWithinTemplate(current); }
template <class NodeType>
inline Element* traverseNextElementTemplate(NodeType* current)
{
Node* node = NodeTraversal::next(current);
while (node && !node->isElementNode())
node = NodeTraversal::nextSkippingChildren(node);
return toElement(node);
}
inline Element* next(const ContainerNode* current) { return traverseNextElementTemplate(current); }
inline Element* next(const Node* current) { return traverseNextElementTemplate(current); }
template <class NodeType>
inline Element* traverseNextElementTemplate(NodeType* current, const Node* stayWithin)
{
Node* node = NodeTraversal::next(current, stayWithin);
while (node && !node->isElementNode())
node = NodeTraversal::nextSkippingChildren(node, stayWithin);
return toElement(node);
}
inline Element* next(const ContainerNode* current, const Node* stayWithin) { return traverseNextElementTemplate(current, stayWithin); }
inline Element* next(const Node* current, const Node* stayWithin) { return traverseNextElementTemplate(current, stayWithin); }
template <class NodeType>
inline Element* traverseNextElementSkippingChildrenTemplate(NodeType* current)
{
Node* node = NodeTraversal::nextSkippingChildren(current);
while (node && !node->isElementNode())
node = NodeTraversal::nextSkippingChildren(node);
return toElement(node);
}
inline Element* nextSkippingChildren(const ContainerNode* current) { return traverseNextElementSkippingChildrenTemplate(current); }
inline Element* nextSkippingChildren(const Node* current) { return traverseNextElementSkippingChildrenTemplate(current); }
template <class NodeType>
inline Element* traverseNextElementSkippingChildrenTemplate(NodeType* current, const Node* stayWithin)
{
Node* node = NodeTraversal::nextSkippingChildren(current, stayWithin);
while (node && !node->isElementNode())
node = NodeTraversal::nextSkippingChildren(node, stayWithin);
return toElement(node);
}
inline Element* nextSkippingChildren(const ContainerNode* current, const Node* stayWithin) { return traverseNextElementSkippingChildrenTemplate(current, stayWithin); }
inline Element* nextSkippingChildren(const Node* current, const Node* stayWithin) { return traverseNextElementSkippingChildrenTemplate(current, stayWithin); }
inline Element* previousIncludingPseudo(const Node* current, const Node* stayWithin)
{
Node* node = NodeTraversal::previousIncludingPseudo(current, stayWithin);
while (node && !node->isElementNode())
node = NodeTraversal::previousIncludingPseudo(node, stayWithin);
return toElement(node);
}
inline Element* nextIncludingPseudo(const Node* current, const Node* stayWithin)
{
Node* node = NodeTraversal::nextIncludingPseudo(current, stayWithin);
while (node && !node->isElementNode())
node = NodeTraversal::nextIncludingPseudo(node, stayWithin);
return toElement(node);
}
inline Element* nextIncludingPseudoSkippingChildren(const Node* current, const Node* stayWithin)
{
Node* node = NodeTraversal::nextIncludingPseudoSkippingChildren(current, stayWithin);
while (node && !node->isElementNode())
node = NodeTraversal::nextIncludingPseudoSkippingChildren(node, stayWithin);
return toElement(node);
}
inline Element* pseudoAwarePreviousSibling(const Node* current)
{
Node* node = current->pseudoAwarePreviousSibling();
while (node && !node->isElementNode())
node = node->pseudoAwarePreviousSibling();
return toElement(node);
}
}
namespace NodeTraversal {
Node* nextAncestorSibling(const Node*);
Node* nextAncestorSibling(const Node*, const Node* stayWithin);
template <class NodeType>
inline Node* traverseNextTemplate(NodeType* current)
{
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); }
template <class NodeType>
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();
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); }
template <class NodeType>
inline Node* traverseNextSkippingChildrenTemplate(NodeType* current)
{
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)
{
if (current == stayWithin)
return 0;
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); }
}
}
#endif