#include "config.h"
#include "ChildNodeList.h"
#include "ElementIterator.h"
#include "NodeRareData.h"
namespace WebCore {
EmptyNodeList::~EmptyNodeList()
{
m_owner.get().nodeLists()->removeEmptyChildNodeList(this);
}
ChildNodeList::ChildNodeList(ContainerNode& parent)
: m_parent(parent)
, m_indexCache(*this)
{
}
ChildNodeList::~ChildNodeList()
{
m_parent.get().nodeLists()->removeChildNodeList(this);
}
unsigned ChildNodeList::length() const
{
return m_indexCache.nodeCount(*this);
}
Node* ChildNodeList::item(unsigned index) const
{
return m_indexCache.nodeAt(*this, index);
}
Node* ChildNodeList::collectionBegin() const
{
return m_parent->firstChild();
}
Node* ChildNodeList::collectionLast() const
{
return m_parent->lastChild();
}
void ChildNodeList::collectionTraverseForward(Node*& current, unsigned count, unsigned& traversedCount) const
{
ASSERT(count);
for (traversedCount = 0; traversedCount < count; ++traversedCount) {
current = current->nextSibling();
if (!current)
return;
}
}
void ChildNodeList::collectionTraverseBackward(Node*& current, unsigned count) const
{
ASSERT(count);
for (; count && current ; --count)
current = current->previousSibling();
}
void ChildNodeList::invalidateCache()
{
m_indexCache.invalidate(*this);
}
}