#pragma once
#include "CachedHTMLCollection.h"
#include <wtf/text/AtomString.h>
namespace WebCore {
class TagCollection final : public CachedHTMLCollection<TagCollection, CollectionTypeTraits<ByTag>::traversalType> {
WTF_MAKE_ISO_ALLOCATED(TagCollection);
public:
static Ref<TagCollection> create(ContainerNode& rootNode, CollectionType type, const AtomString& qualifiedName)
{
ASSERT_UNUSED(type, type == ByTag);
return adoptRef(*new TagCollection(rootNode, qualifiedName));
}
virtual ~TagCollection();
bool elementMatches(Element&) const;
private:
TagCollection(ContainerNode& rootNode, const AtomString& qualifiedName);
AtomString m_qualifiedName;
};
class TagCollectionNS final : public CachedHTMLCollection<TagCollectionNS, CollectionTypeTraits<ByTag>::traversalType> {
WTF_MAKE_ISO_ALLOCATED(TagCollectionNS);
public:
static Ref<TagCollectionNS> create(ContainerNode& rootNode, const AtomString& namespaceURI, const AtomString& localName)
{
return adoptRef(*new TagCollectionNS(rootNode, namespaceURI, localName));
}
virtual ~TagCollectionNS();
bool elementMatches(Element&) const;
private:
TagCollectionNS(ContainerNode& rootNode, const AtomString& namespaceURI, const AtomString& localName);
AtomString m_namespaceURI;
AtomString m_localName;
};
class HTMLTagCollection final : public CachedHTMLCollection<HTMLTagCollection, CollectionTypeTraits<ByHTMLTag>::traversalType> {
WTF_MAKE_ISO_ALLOCATED(HTMLTagCollection);
public:
static Ref<HTMLTagCollection> create(ContainerNode& rootNode, CollectionType type, const AtomString& qualifiedName)
{
ASSERT_UNUSED(type, type == ByHTMLTag);
return adoptRef(*new HTMLTagCollection(rootNode, qualifiedName));
}
virtual ~HTMLTagCollection();
bool elementMatches(Element&) const;
private:
HTMLTagCollection(ContainerNode& rootNode, const AtomString& qualifiedName);
AtomString m_qualifiedName;
AtomString 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();
}
}