#include "config.h"
#include "LiveNodeList.h"
#include "ClassNodeList.h"
#include "Element.h"
#include "ElementTraversal.h"
#include "HTMLCollection.h"
#include "TagNodeList.h"
namespace WebCore {
LiveNodeList::LiveNodeList(ContainerNode& ownerNode, NodeListInvalidationType invalidationType)
: m_ownerNode(ownerNode)
, m_invalidationType(invalidationType)
, m_isRegisteredForInvalidationAtDocument(false)
{
ASSERT(m_invalidationType == static_cast<unsigned>(invalidationType));
}
LiveNodeList::~LiveNodeList()
{
}
ContainerNode& LiveNodeList::rootNode() const
{
if (isRootedAtDocument() && ownerNode().inDocument())
return ownerNode().document();
return ownerNode();
}
Node* LiveNodeList::namedItem(const AtomicString& elementId) const
{
Node& rootNode = this->rootNode();
if (rootNode.inDocument()) {
Element* element = rootNode.treeScope().getElementById(elementId);
if (element && nodeMatches(element) && element->isDescendantOf(&rootNode))
return element;
if (!element)
return nullptr;
}
unsigned length = this->length();
for (unsigned i = 0; i < length; i++) {
Node* node = item(i);
if (!node->isElementNode())
continue;
Element* element = toElement(node);
if (element->hasID() && element->idForStyleResolution() == elementId)
return node;
}
return nullptr;
}
}