#ifndef ChildNodeList_h
#define ChildNodeList_h
#include "core/dom/NodeList.h"
#include "core/html/CollectionIndexCache.h"
#include "wtf/PassRefPtr.h"
namespace WebCore {
class ChildNodeList FINAL : public NodeList {
public:
static PassRefPtr<ChildNodeList> create(ContainerNode& rootNode)
{
return adoptRef(new ChildNodeList(rootNode));
}
virtual ~ChildNodeList();
virtual unsigned length() const OVERRIDE { return m_collectionIndexCache.nodeCount(*this); }
virtual Node* item(unsigned index) const OVERRIDE { return m_collectionIndexCache.nodeAt(*this, index); }
void invalidateCache() { m_collectionIndexCache.invalidate(); }
ContainerNode& ownerNode() const { return *m_parent; }
ContainerNode& rootNode() const { return ownerNode(); }
bool canTraverseBackward() const { return true; }
Node* itemBefore(const Node* previousItem) const;
Node* traverseToFirstElement() const { return rootNode().firstChild(); }
Node* traverseForwardToOffset(unsigned offset, Node& currentNode, unsigned& currentOffset) const;
private:
explicit ChildNodeList(ContainerNode& rootNode);
virtual bool isChildNodeList() const OVERRIDE { return true; }
virtual Node* virtualOwnerNode() const OVERRIDE;
RefPtr<ContainerNode> m_parent;
mutable CollectionIndexCache<ChildNodeList, Node> m_collectionIndexCache;
};
DEFINE_TYPE_CASTS(ChildNodeList, NodeList, nodeList, nodeList->isChildNodeList(), nodeList.isChildNodeList());
}
#endif