HTMLNameCollection.cpp [plain text]
#include "config.h"
#include "HTMLNameCollection.h"
#include "Element.h"
#include "HTMLDocument.h"
#include "HTMLFormElement.h"
#include "HTMLImageElement.h"
#include "HTMLNames.h"
#include "HTMLObjectElement.h"
#include "NodeRareData.h"
#include "NodeTraversal.h"
namespace WebCore {
using namespace HTMLNames;
HTMLNameCollection::HTMLNameCollection(Document& document, CollectionType type, const AtomicString& name)
: HTMLCollection(document, type)
, m_name(name)
{
}
HTMLNameCollection::~HTMLNameCollection()
{
ASSERT(type() == WindowNamedItems || type() == DocumentNamedItems);
document().nodeLists()->removeCachedCollection(this, m_name);
}
bool WindowNameCollection::elementMatchesIfNameAttributeMatch(const Element& element)
{
return is<HTMLImageElement>(element) || is<HTMLFormElement>(element) || is<HTMLAppletElement>(element)
|| is<HTMLEmbedElement>(element) || is<HTMLObjectElement>(element);
}
bool WindowNameCollection::elementMatches(const Element& element, const AtomicStringImpl* name)
{
if (elementMatchesIfNameAttributeMatch(element) && element.getNameAttribute().impl() == name)
return true;
return element.getIdAttribute().impl() == name;
}
bool DocumentNameCollection::elementMatchesIfIdAttributeMatch(const Element& element)
{
return is<HTMLAppletElement>(element) || (is<HTMLObjectElement>(element) && downcast<HTMLObjectElement>(element).isDocNamedItem())
|| (is<HTMLImageElement>(element) && element.hasName());
}
bool DocumentNameCollection::elementMatchesIfNameAttributeMatch(const Element& element)
{
return is<HTMLFormElement>(element) || is<HTMLEmbedElement>(element) || is<HTMLIFrameElement>(element)
|| is<HTMLAppletElement>(element) || (is<HTMLObjectElement>(element) && downcast<HTMLObjectElement>(element).isDocNamedItem())
|| is<HTMLImageElement>(element);
}
bool DocumentNameCollection::elementMatches(const Element& element, const AtomicStringImpl* name)
{
if (is<HTMLFormElement>(element) || is<HTMLEmbedElement>(element) || is<HTMLIFrameElement>(element))
return element.getNameAttribute().impl() == name;
if (is<HTMLAppletElement>(element))
return element.getNameAttribute().impl() == name || element.getIdAttribute().impl() == name;
if (is<HTMLObjectElement>(element))
return (element.getNameAttribute().impl() == name || element.getIdAttribute().impl() == name) && downcast<HTMLObjectElement>(element).isDocNamedItem();
if (is<HTMLImageElement>(element))
return element.getNameAttribute().impl() == name || (element.getIdAttribute().impl() == name && element.hasName());
return false;
}
}