summaryrefslogtreecommitdiff
path: root/Source/WebCore/html/HTMLNameCollection.h
diff options
context:
space:
mode:
Diffstat (limited to 'Source/WebCore/html/HTMLNameCollection.h')
-rw-r--r--Source/WebCore/html/HTMLNameCollection.h65
1 files changed, 42 insertions, 23 deletions
diff --git a/Source/WebCore/html/HTMLNameCollection.h b/Source/WebCore/html/HTMLNameCollection.h
index 94a808d27..e70748abb 100644
--- a/Source/WebCore/html/HTMLNameCollection.h
+++ b/Source/WebCore/html/HTMLNameCollection.h
@@ -20,22 +20,22 @@
*
*/
-#ifndef HTMLNameCollection_h
-#define HTMLNameCollection_h
-
-#include "HTMLCollection.h"
+#pragma once
+#include "CachedHTMLCollection.h"
+#include "NodeRareData.h"
#include <wtf/text/AtomicString.h>
namespace WebCore {
class Document;
-class HTMLNameCollection : public HTMLCollection {
+template <typename HTMLCollectionClass, CollectionTraversalType traversalType>
+class HTMLNameCollection : public CachedHTMLCollection<HTMLCollectionClass, traversalType> {
public:
- ~HTMLNameCollection();
+ virtual ~HTMLNameCollection();
- Document& document() { return toDocument(ownerNode()); }
+ Document& document() { return downcast<Document>(this->ownerNode()); }
protected:
HTMLNameCollection(Document&, CollectionType, const AtomicString& name);
@@ -43,48 +43,67 @@ protected:
AtomicString m_name;
};
-class WindowNameCollection final : public HTMLNameCollection {
+template <typename HTMLCollectionClass, CollectionTraversalType traversalType>
+HTMLNameCollection<HTMLCollectionClass, traversalType>::HTMLNameCollection(Document& document, CollectionType type, const AtomicString& name)
+ : CachedHTMLCollection<HTMLCollectionClass, traversalType>(document, type)
+ , m_name(name)
+{
+}
+
+template <typename HTMLCollectionClass, CollectionTraversalType traversalType>
+HTMLNameCollection<HTMLCollectionClass, traversalType>::~HTMLNameCollection()
+{
+ ASSERT(this->type() == WindowNamedItems || this->type() == DocumentNamedItems);
+
+ document().nodeLists()->removeCachedCollection(this, m_name);
+}
+
+class WindowNameCollection final : public HTMLNameCollection<WindowNameCollection, CollectionTraversalType::Descendants> {
public:
- static PassRef<WindowNameCollection> create(Document& document, CollectionType type, const AtomicString& name)
+ static Ref<WindowNameCollection> create(Document& document, CollectionType type, const AtomicString& name)
{
return adoptRef(*new WindowNameCollection(document, type, name));
}
- bool nodeMatches(Element* element) const { return nodeMatches(element, m_name.impl()); }
+ // For CachedHTMLCollection.
+ bool elementMatches(const Element& element) const { return elementMatches(element, m_name.impl()); }
- static bool nodeMatchesIfIdAttributeMatch(Element*) { return true; }
- static bool nodeMatchesIfNameAttributeMatch(Element*);
- static bool nodeMatches(Element*, const AtomicStringImpl*);
+ static bool elementMatchesIfIdAttributeMatch(const Element&) { return true; }
+ static bool elementMatchesIfNameAttributeMatch(const Element&);
+ static bool elementMatches(const Element&, const AtomicStringImpl*);
private:
WindowNameCollection(Document& document, CollectionType type, const AtomicString& name)
- : HTMLNameCollection(document, type, name)
+ : HTMLNameCollection<WindowNameCollection, CollectionTraversalType::Descendants>(document, type, name)
{
ASSERT(type == WindowNamedItems);
}
};
-class DocumentNameCollection final : public HTMLNameCollection {
+class DocumentNameCollection final : public HTMLNameCollection<DocumentNameCollection, CollectionTraversalType::Descendants> {
public:
- static PassRef<DocumentNameCollection> create(Document& document, CollectionType type, const AtomicString& name)
+ static Ref<DocumentNameCollection> create(Document& document, CollectionType type, const AtomicString& name)
{
return adoptRef(*new DocumentNameCollection(document, type, name));
}
- static bool nodeMatchesIfIdAttributeMatch(Element*);
- static bool nodeMatchesIfNameAttributeMatch(Element*);
- bool nodeMatches(Element* element) const { return nodeMatches(element, m_name.impl()); }
+ static bool elementMatchesIfIdAttributeMatch(const Element&);
+ static bool elementMatchesIfNameAttributeMatch(const Element&);
- static bool nodeMatches(Element*, const AtomicStringImpl*);
+ // For CachedHTMLCollection.
+ bool elementMatches(const Element& element) const { return elementMatches(element, m_name.impl()); }
+
+ static bool elementMatches(const Element&, const AtomicStringImpl*);
private:
DocumentNameCollection(Document& document, CollectionType type, const AtomicString& name)
- : HTMLNameCollection(document, type, name)
+ : HTMLNameCollection<DocumentNameCollection, CollectionTraversalType::Descendants>(document, type, name)
{
ASSERT(type == DocumentNamedItems);
}
};
-}
+} // namespace WebCore
-#endif
+SPECIALIZE_TYPE_TRAITS_HTMLCOLLECTION(WindowNameCollection, WindowNamedItems)
+SPECIALIZE_TYPE_TRAITS_HTMLCOLLECTION(DocumentNameCollection, DocumentNamedItems)