ComposedShadowTreeWalker.h [plain text]
#ifndef ComposedShadowTreeWalker_h
#define ComposedShadowTreeWalker_h
#include "ShadowRoot.h"
namespace WebCore {
class Node;
class ShadowRoot;
class ComposedShadowTreeWalker {
public:
enum Policy {
CrossUpperBoundary,
DoNotCrossUpperBoundary,
};
ComposedShadowTreeWalker(const Node*, Policy = CrossUpperBoundary);
static ComposedShadowTreeWalker fromFirstChild(const Node*, Policy = CrossUpperBoundary);
Node* get() const { return const_cast<Node*>(m_node); }
void firstChild();
void lastChild();
void nextSibling();
void previousSibling();
void parent();
void next();
void previous();
private:
enum TraversalDirection {
TraversalDirectionForward,
TraversalDirectionBackward
};
bool canCrossUpperBoundary() const { return m_policy == CrossUpperBoundary; }
void assertPrecondition() const
{
#ifndef NDEBUG
ASSERT(m_node);
if (canCrossUpperBoundary())
ASSERT(!m_node->isShadowRoot());
else
ASSERT(!m_node->isShadowRoot() || toShadowRoot(m_node)->isYoungest());
#endif
}
void assertPostcondition() const
{
#ifndef NDEBUG
if (m_node)
assertPrecondition();
#endif
}
static Node* traverseNode(const Node*, TraversalDirection);
static Node* traverseLightChildren(const Node*, TraversalDirection);
Node* traverseFirstChild(const Node*) const;
Node* traverseLastChild(const Node*) const;
Node* traverseChild(const Node*, TraversalDirection) const;
Node* traverseParent(const Node*) const;
static Node* traverseNextSibling(const Node*);
static Node* traversePreviousSibling(const Node*);
static Node* traverseSiblingOrBackToInsertionPoint(const Node*, TraversalDirection);
static Node* traverseSiblingInCurrentTree(const Node*, TraversalDirection);
static Node* traverseSiblingOrBackToYoungerShadowRoot(const Node*, TraversalDirection);
static Node* escapeFallbackContentElement(const Node*, TraversalDirection);
Node* traverseNodeEscapingFallbackContents(const Node*) const;
Node* traverseParentInCurrentTree(const Node*) const;
Node* traverseParentBackToYoungerShadowRootOrHost(const ShadowRoot*) const;
const Node* m_node;
Policy m_policy;
};
}
#endif