summaryrefslogtreecommitdiff
path: root/Source/WebCore/html/HTMLNameCollection.cpp
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@lorry>2016-04-10 09:28:39 +0000
committerLorry Tar Creator <lorry-tar-importer@lorry>2016-04-10 09:28:39 +0000
commit32761a6cee1d0dee366b885b7b9c777e67885688 (patch)
treed6bec92bebfb216f4126356e55518842c2f476a1 /Source/WebCore/html/HTMLNameCollection.cpp
parenta4e969f4965059196ca948db781e52f7cfebf19e (diff)
downloadWebKitGtk-tarball-32761a6cee1d0dee366b885b7b9c777e67885688.tar.gz
webkitgtk-2.4.11webkitgtk-2.4.11
Diffstat (limited to 'Source/WebCore/html/HTMLNameCollection.cpp')
-rw-r--r--Source/WebCore/html/HTMLNameCollection.cpp57
1 files changed, 35 insertions, 22 deletions
diff --git a/Source/WebCore/html/HTMLNameCollection.cpp b/Source/WebCore/html/HTMLNameCollection.cpp
index 329749bbb..50eda4826 100644
--- a/Source/WebCore/html/HTMLNameCollection.cpp
+++ b/Source/WebCore/html/HTMLNameCollection.cpp
@@ -36,46 +36,59 @@ namespace WebCore {
using namespace HTMLNames;
-bool WindowNameCollection::elementMatchesIfNameAttributeMatch(const Element& element)
+HTMLNameCollection::HTMLNameCollection(Document& document, CollectionType type, const AtomicString& name)
+ : HTMLCollection(document, type)
+ , m_name(name)
{
- 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)
+HTMLNameCollection::~HTMLNameCollection()
+{
+ ASSERT(type() == WindowNamedItems || type() == DocumentNamedItems);
+
+ document().nodeLists()->removeCachedCollection(this, m_name);
+}
+
+bool WindowNameCollection::nodeMatchesIfNameAttributeMatch(Element* element)
+{
+ return isHTMLImageElement(element) || isHTMLFormElement(element) || element->hasTagName(appletTag)
+ || element->hasTagName(embedTag) || element->hasTagName(objectTag);
+}
+
+bool WindowNameCollection::nodeMatches(Element* element, const AtomicStringImpl* name)
{
// Find only images, forms, applets, embeds and objects by name, but anything by id
- if (elementMatchesIfNameAttributeMatch(element) && element.getNameAttribute().impl() == name)
+ if (nodeMatchesIfNameAttributeMatch(element) && element->getNameAttribute().impl() == name)
return true;
- return element.getIdAttribute().impl() == name;
+ return element->getIdAttribute().impl() == name;
}
-bool DocumentNameCollection::elementMatchesIfIdAttributeMatch(const Element& element)
+bool DocumentNameCollection::nodeMatchesIfIdAttributeMatch(Element* element)
{
// FIXME: we need to fix HTMLImageElement to update the hash map for us when name attribute has been removed.
- return is<HTMLAppletElement>(element) || (is<HTMLObjectElement>(element) && downcast<HTMLObjectElement>(element).isDocNamedItem())
- || (is<HTMLImageElement>(element) && element.hasName());
+ return element->hasTagName(appletTag) || (element->hasTagName(objectTag) && toHTMLObjectElement(element)->isDocNamedItem())
+ || (isHTMLImageElement(element) && element->hasName());
}
-bool DocumentNameCollection::elementMatchesIfNameAttributeMatch(const Element& element)
+bool DocumentNameCollection::nodeMatchesIfNameAttributeMatch(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);
+ return isHTMLFormElement(element) || element->hasTagName(embedTag) || element->hasTagName(iframeTag)
+ || element->hasTagName(appletTag) || (element->hasTagName(objectTag) && toHTMLObjectElement(element)->isDocNamedItem())
+ || isHTMLImageElement(element);
}
-bool DocumentNameCollection::elementMatches(const Element& element, const AtomicStringImpl* name)
+bool DocumentNameCollection::nodeMatches(Element* element, const AtomicStringImpl* name)
{
// Find images, forms, applets, embeds, objects and iframes by name, applets and object by id, and images by id
// but only if they have a name attribute (this very strange rule matches IE)
- 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());
+ if (isHTMLFormElement(element) || element->hasTagName(embedTag) || element->hasTagName(iframeTag))
+ return element->getNameAttribute().impl() == name;
+ if (element->hasTagName(appletTag))
+ return element->getNameAttribute().impl() == name || element->getIdAttribute().impl() == name;
+ if (element->hasTagName(objectTag))
+ return (element->getNameAttribute().impl() == name || element->getIdAttribute().impl() == name) && toHTMLObjectElement(element)->isDocNamedItem();
+ if (isHTMLImageElement(element))
+ return element->getNameAttribute().impl() == name || (element->getIdAttribute().impl() == name && element->hasName());
return false;
}