#pragma once
#include "ExceptionOr.h"
#include "NodeFilter.h"
#include "ScriptWrappable.h"
#include "Traversal.h"
#include <wtf/RefCounted.h>
namespace WebCore {
class TreeWalker : public ScriptWrappable, public RefCounted<TreeWalker>, public NodeIteratorBase {
public:
static Ref<TreeWalker> create(Node& rootNode, unsigned long whatToShow, RefPtr<NodeFilter>&& filter)
{
return adoptRef(*new TreeWalker(rootNode, whatToShow, WTFMove(filter)));
}
Node& currentNode() { return m_current.get(); }
const Node& currentNode() const { return m_current.get(); }
WEBCORE_EXPORT void setCurrentNode(Node&);
WEBCORE_EXPORT ExceptionOr<Node*> parentNode();
WEBCORE_EXPORT ExceptionOr<Node*> firstChild();
WEBCORE_EXPORT ExceptionOr<Node*> lastChild();
WEBCORE_EXPORT ExceptionOr<Node*> previousSibling();
WEBCORE_EXPORT ExceptionOr<Node*> nextSibling();
WEBCORE_EXPORT ExceptionOr<Node*> previousNode();
WEBCORE_EXPORT ExceptionOr<Node*> nextNode();
private:
TreeWalker(Node&, unsigned long whatToShow, RefPtr<NodeFilter>&&);
enum class SiblingTraversalType { Previous, Next };
template<SiblingTraversalType> ExceptionOr<Node*> traverseSiblings();
Node* setCurrent(Ref<Node>&&);
Ref<Node> m_current;
};
}