#ifndef NodeTraversal_h
#define NodeTraversal_h
#include "core/dom/Node.h"
namespace WebCore {
class NodeTraversal {
public:
static Node* next(const Node& current) { return traverseNextTemplate(current); }
static Node* next(const ContainerNode& current) { return traverseNextTemplate(current); }
static Node* next(const Node& current, const Node* stayWithin) { return traverseNextTemplate(current, stayWithin); }
static Node* next(const ContainerNode& current, const Node* stayWithin) { return traverseNextTemplate(current, stayWithin); }
static Node* nextSkippingChildren(const Node& current) { return traverseNextSkippingChildrenTemplate(current); }
static Node* nextSkippingChildren(const ContainerNode& current) { return traverseNextSkippingChildrenTemplate(current); }
static Node* nextSkippingChildren(const Node& current, const Node* stayWithin) { return traverseNextSkippingChildrenTemplate(current, stayWithin); }
static Node* nextSkippingChildren(const ContainerNode& current, const Node* stayWithin) { return traverseNextSkippingChildrenTemplate(current, stayWithin); }
static Node* previous(const Node&, const Node* stayWithin = 0);
static Node* previousSkippingChildren(const Node&, const Node* stayWithin = 0);
static Node* nextPostOrder(const Node&, const Node* stayWithin = 0);
static Node* previousPostOrder(const Node&, const Node* stayWithin = 0);
static Node* previousIncludingPseudo(const Node&, const Node* stayWithin = 0);
static Node* nextIncludingPseudo(const Node&, const Node* stayWithin = 0);
static Node* nextIncludingPseudoSkippingChildren(const Node&, const Node* stayWithin = 0);
static Node* nextAncestorSibling(const Node&);
static Node* nextAncestorSibling(const Node&, const Node* stayWithin);
private:
template <class NodeType>
static Node* traverseNextTemplate(NodeType&);
template <class NodeType>
static Node* traverseNextTemplate(NodeType&, const Node* stayWithin);
template <class NodeType>
static Node* traverseNextSkippingChildrenTemplate(NodeType&);
template <class NodeType>
static Node* traverseNextSkippingChildrenTemplate(NodeType&, const Node* stayWithin);
};
template <class NodeType>
inline Node* NodeTraversal::traverseNextTemplate(NodeType& current)
{
if (current.firstChild())
return current.firstChild();
if (current.nextSibling())
return current.nextSibling();
return nextAncestorSibling(current);
}
template <class NodeType>
inline Node* NodeTraversal::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);
}
template <class NodeType>
inline Node* NodeTraversal::traverseNextSkippingChildrenTemplate(NodeType& current)
{
if (current.nextSibling())
return current.nextSibling();
return nextAncestorSibling(current);
}
template <class NodeType>
inline Node* NodeTraversal::traverseNextSkippingChildrenTemplate(NodeType& current, const Node* stayWithin)
{
if (current == stayWithin)
return 0;
if (current.nextSibling())
return current.nextSibling();
return nextAncestorSibling(current, stayWithin);
}
}
#endif