#ifndef TagCollection_h
#define TagCollection_h
#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, const AtomicString& namespaceURI, const AtomicString& localName)
{
ASSERT(namespaceURI != starAtom);
return adoptRef(*new TagCollection(rootNode, namespaceURI, localName));
}
static Ref<TagCollection> create(ContainerNode& rootNode, CollectionType type, const AtomicString& localName)
{
ASSERT_UNUSED(type, type == ByTag);
return adoptRef(*new TagCollection(rootNode, starAtom, localName));
}
virtual ~TagCollection();
bool elementMatches(Element&) const;
protected:
TagCollection(ContainerNode& rootNode, const AtomicString& namespaceURI, const AtomicString& localName);
AtomicString m_namespaceURI;
AtomicString m_localName;
};
inline bool TagCollection::elementMatches(Element& element) const
{
if (m_localName != starAtom && m_localName != element.localName())
return false;
return m_namespaceURI == starAtom || m_namespaceURI == element.namespaceURI();
}
class HTMLTagCollection final : public CachedHTMLCollection<HTMLTagCollection, CollectionTypeTraits<ByHTMLTag>::traversalType> {
public:
static Ref<HTMLTagCollection> create(ContainerNode& rootNode, CollectionType type, const AtomicString& localName)
{
ASSERT_UNUSED(type, type == ByHTMLTag);
return adoptRef(*new HTMLTagCollection(rootNode, localName));
}
virtual ~HTMLTagCollection();
bool elementMatches(Element&) const;
private:
HTMLTagCollection(ContainerNode& rootNode, const AtomicString& localName);
AtomicString m_localName;
AtomicString m_loweredLocalName;
};
inline bool HTMLTagCollection::elementMatches(Element& element) const
{
if (m_localName == starAtom)
return true;
const AtomicString& localName = element.isHTMLElement() ? m_loweredLocalName : m_localName;
return localName == element.localName();
}
}
#endif // TagCollection_h