1 | /* |
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-2008, 2014-2016 Apple Inc. All rights reserved. |
6 | * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) |
7 | * |
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. |
12 | * |
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. |
17 | * |
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. |
22 | */ |
23 | |
24 | #pragma once |
25 | |
26 | #include "CachedHTMLCollection.h" |
27 | #include <wtf/text/AtomicString.h> |
28 | |
29 | namespace WebCore { |
30 | |
31 | // HTMLCollection that limits to a particular tag. |
32 | class TagCollection final : public CachedHTMLCollection<TagCollection, CollectionTypeTraits<ByTag>::traversalType> { |
33 | WTF_MAKE_ISO_ALLOCATED(TagCollection); |
34 | public: |
35 | static Ref<TagCollection> create(ContainerNode& rootNode, CollectionType type, const AtomicString& qualifiedName) |
36 | { |
37 | ASSERT_UNUSED(type, type == ByTag); |
38 | return adoptRef(*new TagCollection(rootNode, qualifiedName)); |
39 | } |
40 | |
41 | virtual ~TagCollection(); |
42 | bool elementMatches(Element&) const; |
43 | |
44 | private: |
45 | TagCollection(ContainerNode& rootNode, const AtomicString& qualifiedName); |
46 | |
47 | AtomicString m_qualifiedName; |
48 | }; |
49 | |
50 | class TagCollectionNS final : public CachedHTMLCollection<TagCollectionNS, CollectionTypeTraits<ByTag>::traversalType> { |
51 | WTF_MAKE_ISO_ALLOCATED(TagCollectionNS); |
52 | public: |
53 | static Ref<TagCollectionNS> create(ContainerNode& rootNode, const AtomicString& namespaceURI, const AtomicString& localName) |
54 | { |
55 | return adoptRef(*new TagCollectionNS(rootNode, namespaceURI, localName)); |
56 | } |
57 | |
58 | virtual ~TagCollectionNS(); |
59 | bool elementMatches(Element&) const; |
60 | |
61 | private: |
62 | TagCollectionNS(ContainerNode& rootNode, const AtomicString& namespaceURI, const AtomicString& localName); |
63 | |
64 | AtomicString m_namespaceURI; |
65 | AtomicString m_localName; |
66 | }; |
67 | |
68 | class HTMLTagCollection final : public CachedHTMLCollection<HTMLTagCollection, CollectionTypeTraits<ByHTMLTag>::traversalType> { |
69 | WTF_MAKE_ISO_ALLOCATED(HTMLTagCollection); |
70 | public: |
71 | static Ref<HTMLTagCollection> create(ContainerNode& rootNode, CollectionType type, const AtomicString& qualifiedName) |
72 | { |
73 | ASSERT_UNUSED(type, type == ByHTMLTag); |
74 | return adoptRef(*new HTMLTagCollection(rootNode, qualifiedName)); |
75 | } |
76 | |
77 | virtual ~HTMLTagCollection(); |
78 | bool elementMatches(Element&) const; |
79 | |
80 | private: |
81 | HTMLTagCollection(ContainerNode& rootNode, const AtomicString& qualifiedName); |
82 | |
83 | AtomicString m_qualifiedName; |
84 | AtomicString m_loweredQualifiedName; |
85 | }; |
86 | |
87 | inline bool TagCollection::elementMatches(Element& element) const |
88 | { |
89 | return m_qualifiedName == element.tagQName().toString(); |
90 | } |
91 | |
92 | inline bool TagCollectionNS::elementMatches(Element& element) const |
93 | { |
94 | if (m_localName != starAtom() && m_localName != element.localName()) |
95 | return false; |
96 | return m_namespaceURI == starAtom() || m_namespaceURI == element.namespaceURI(); |
97 | } |
98 | |
99 | inline bool HTMLTagCollection::elementMatches(Element& element) const |
100 | { |
101 | if (element.isHTMLElement()) |
102 | return m_loweredQualifiedName == element.tagQName().toString(); |
103 | return m_qualifiedName == element.tagQName().toString(); |
104 | } |
105 | |
106 | } // namespace WebCore |
107 | |