HTMLNameCollection.cpp [plain text]
#include "config.h"
#include "HTMLNameCollection.h"
#include "Element.h"
#include "HTMLDocument.h"
#include "HTMLNames.h"
#include "HTMLObjectElement.h"
namespace WebCore {
using namespace HTMLNames;
HTMLNameCollection::HTMLNameCollection(Document* document, CollectionType type, const AtomicString& name)
: HTMLCollection(document, type)
, m_name(name)
{
}
Element* HTMLNameCollection::itemAfter(Element* previous) const
{
ASSERT(previous != base());
Node* current;
if (!previous)
current = base()->firstChild();
else
current = previous->traverseNextNode(base());
for (; current; current = current->traverseNextNode(base())) {
if (!current->isElementNode())
continue;
Element* e = static_cast<Element*>(current);
switch (type()) {
case WindowNamedItems:
if (e->hasTagName(imgTag) ||
e->hasTagName(formTag) ||
e->hasTagName(appletTag) ||
e->hasTagName(embedTag) ||
e->hasTagName(objectTag))
if (e->getNameAttribute() == m_name)
return e;
if (e->getIdAttribute() == m_name)
return e;
break;
case DocumentNamedItems:
if (e->hasTagName(formTag) || e->hasTagName(embedTag) || e->hasTagName(iframeTag)) {
if (e->getNameAttribute() == m_name)
return e;
} else if (e->hasTagName(appletTag)) {
if (e->getNameAttribute() == m_name || e->getIdAttribute() == m_name)
return e;
} else if (e->hasTagName(objectTag)) {
if ((e->getNameAttribute() == m_name || e->getIdAttribute() == m_name)
&& static_cast<HTMLObjectElement*>(e)->isDocNamedItem())
return e;
} else if (e->hasTagName(imgTag)) {
if (e->getNameAttribute() == m_name || (e->getIdAttribute() == m_name && e->hasName()))
return e;
}
break;
default:
ASSERT_NOT_REACHED();
}
}
return 0;
}
}