#ifndef ChildNodeList_h
#define ChildNodeList_h
#include "CollectionIndexCache.h"
#include "NodeList.h"
#include <wtf/Ref.h>
#include <wtf/RefPtr.h>
namespace WebCore {
class ContainerNode;
class EmptyNodeList final : public NodeList {
public:
static PassRef<EmptyNodeList> create(Node& owner)
{
return adoptRef(*new EmptyNodeList(owner));
}
virtual ~EmptyNodeList();
Node& ownerNode() { return m_owner.get(); }
private:
explicit EmptyNodeList(Node& owner) : m_owner(owner) { }
virtual unsigned length() const override { return 0; }
virtual Node* item(unsigned) const override { return nullptr; }
virtual Node* namedItem(const AtomicString&) const override { return nullptr; }
virtual size_t memoryCost() const override { return 0; }
virtual bool isEmptyNodeList() const override { return true; }
Ref<Node> m_owner;
};
class ChildNodeList final : public NodeList {
public:
static PassRef<ChildNodeList> create(ContainerNode& parent)
{
return adoptRef(*new ChildNodeList(parent));
}
virtual ~ChildNodeList();
ContainerNode& ownerNode() { return m_parent.get(); }
void invalidateCache();
Node* collectionBegin() const;
Node* collectionLast() const;
Node* collectionEnd() const { return nullptr; }
void collectionTraverseForward(Node*&, unsigned count, unsigned& traversedCount) const;
void collectionTraverseBackward(Node*&, unsigned count) const;
bool collectionCanTraverseBackward() const { return true; }
void willValidateIndexCache() const { }
private:
explicit ChildNodeList(ContainerNode& parent);
virtual unsigned length() const override;
virtual Node* item(unsigned index) const override;
virtual Node* namedItem(const AtomicString&) const override;
virtual size_t memoryCost() const override { return m_indexCache.memoryCost(); }
virtual bool isChildNodeList() const override { return true; }
Ref<ContainerNode> m_parent;
mutable CollectionIndexCache<ChildNodeList, Node*> m_indexCache;
};
}
#endif // ChildNodeList_h