2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Dirk Mueller (mueller@kde.org)
5 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
6 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public License
19 * along with this library; see the file COPYING.LIB. If not, write to
20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
24 #ifndef TagCollection_h
25 #define TagCollection_h
27 #include "core/dom/Element.h"
28 #include "core/html/HTMLCollection.h"
29 #include "wtf/text/AtomicString.h"
33 // Collection that limits to a particular tag.
34 class TagCollection : public HTMLCollection {
36 static PassRefPtr<TagCollection> create(ContainerNode* rootNode, const AtomicString& namespaceURI, const AtomicString& localName)
38 ASSERT(namespaceURI != starAtom);
39 return adoptRef(new TagCollection(rootNode, TagCollectionType, namespaceURI, localName));
42 static PassRefPtr<TagCollection> create(ContainerNode* rootNode, CollectionType type, const AtomicString& localName)
44 ASSERT_UNUSED(type, type == TagCollectionType);
45 return adoptRef(new TagCollection(rootNode, TagCollectionType, starAtom, localName));
48 virtual ~TagCollection();
50 bool elementMatches(const Element&) const;
53 TagCollection(ContainerNode* rootNode, CollectionType, const AtomicString& namespaceURI, const AtomicString& localName);
55 AtomicString m_namespaceURI;
56 AtomicString m_localName;
59 class HTMLTagCollection FINAL : public TagCollection {
61 static PassRefPtr<HTMLTagCollection> create(ContainerNode* rootNode, CollectionType type, const AtomicString& localName)
63 ASSERT_UNUSED(type, type == HTMLTagCollectionType);
64 return adoptRef(new HTMLTagCollection(rootNode, localName));
67 bool elementMatches(const Element&) const;
70 HTMLTagCollection(ContainerNode* rootNode, const AtomicString& localName);
72 AtomicString m_loweredLocalName;
75 inline bool HTMLTagCollection::elementMatches(const Element& testElement) const
77 // Implements http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-getelementsbytagname
78 if (m_localName != starAtom) {
79 const AtomicString& localName = testElement.isHTMLElement() ? m_loweredLocalName : m_localName;
80 if (localName != testElement.localName())
83 ASSERT(m_namespaceURI == starAtom);
87 } // namespace WebCore
89 #endif // TagCollection_h