#pragma once
#include "CachedHTMLCollection.h"
#include <wtf/text/AtomicString.h>
namespace WebCore {
class TagCollection final : public CachedHTMLCollection<TagCollection, CollectionTypeTraits<ByTag>::traversalType> {
public:
static Ref<TagCollection> create(ContainerNode& rootNode, CollectionType type, const AtomicString& qualifiedName)
{
ASSERT_UNUSED(type, type == ByTag);
return adoptRef(*new TagCollection(rootNode, qualifiedName));
}
virtual ~TagCollection();
bool elementMatches(Element&) const;
private:
TagCollection(ContainerNode& rootNode, const AtomicString& qualifiedName);
AtomicString m_qualifiedName;
};
class TagCollectionNS final : public CachedHTMLCollection<TagCollectionNS, CollectionTypeTraits<ByTag>::traversalType> {
public:
static Ref<TagCollectionNS> create(ContainerNode& rootNode, const AtomicString& namespaceURI, const AtomicString& localName)
{
return adoptRef(*new TagCollectionNS(rootNode, namespaceURI, localName));
}
virtual ~TagCollectionNS();
bool elementMatches(Element&) const;
private:
TagCollectionNS(ContainerNode& rootNode, const AtomicString& namespaceURI, const AtomicString& localName);
AtomicString m_namespaceURI;
AtomicString m_localName;
};
class HTMLTagCollection final : public CachedHTMLCollection<HTMLTagCollection, CollectionTypeTraits<ByHTMLTag>::traversalType> {
public:
static Ref<HTMLTagCollection> create(ContainerNode& rootNode, CollectionType type, const AtomicString& qualifiedName)
{
ASSERT_UNUSED(type, type == ByHTMLTag);
return adoptRef(*new HTMLTagCollection(rootNode, qualifiedName));
}
virtual ~HTMLTagCollection();
bool elementMatches(Element&) const;
private:
HTMLTagCollection(ContainerNode& rootNode, const AtomicString& qualifiedName);
AtomicString m_qualifiedName;
AtomicString m_loweredQualifiedName;
};
inline bool TagCollection::elementMatches(Element& element) const
{
return m_qualifiedName == element.tagQName().toString();
}
inline bool TagCollectionNS::elementMatches(Element& element) const
{
if (m_localName != starAtom() && m_localName != element.localName())
return false;
return m_namespaceURI == starAtom() || m_namespaceURI == element.namespaceURI();
}
inline bool HTMLTagCollection::elementMatches(Element& element) const
{
if (element.isHTMLElement())
return m_loweredQualifiedName == element.tagQName().toString();
return m_qualifiedName == element.tagQName().toString();
}
}