1/*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 *           (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * Copyright (C) 2003, 2004, 2005, 2006, 2007 Apple Inc. All rights reserved.
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB.  If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20 *
21 */
22
23#ifndef HTMLNameCollection_h
24#define HTMLNameCollection_h
25
26#include "HTMLCollection.h"
27
28#include <wtf/text/AtomicString.h>
29
30namespace WebCore {
31
32class Document;
33
34class HTMLNameCollection : public HTMLCollection {
35public:
36    ~HTMLNameCollection();
37
38    Document& document() { return toDocument(ownerNode()); }
39
40protected:
41    HTMLNameCollection(Document&, CollectionType, const AtomicString& name);
42
43    AtomicString m_name;
44};
45
46class WindowNameCollection final : public HTMLNameCollection {
47public:
48    static PassRef<WindowNameCollection> create(Document& document, CollectionType type, const AtomicString& name)
49    {
50        return adoptRef(*new WindowNameCollection(document, type, name));
51    }
52
53    bool nodeMatches(Element* element) const { return nodeMatches(element, m_name.impl()); }
54
55    static bool nodeMatchesIfIdAttributeMatch(Element*) { return true; }
56    static bool nodeMatchesIfNameAttributeMatch(Element*);
57    static bool nodeMatches(Element*, const AtomicStringImpl*);
58
59private:
60    WindowNameCollection(Document& document, CollectionType type, const AtomicString& name)
61        : HTMLNameCollection(document, type, name)
62    {
63        ASSERT(type == WindowNamedItems);
64    }
65};
66
67class DocumentNameCollection final : public HTMLNameCollection {
68public:
69    static PassRef<DocumentNameCollection> create(Document& document, CollectionType type, const AtomicString& name)
70    {
71        return adoptRef(*new DocumentNameCollection(document, type, name));
72    }
73
74    static bool nodeMatchesIfIdAttributeMatch(Element*);
75    static bool nodeMatchesIfNameAttributeMatch(Element*);
76    bool nodeMatches(Element* element) const { return nodeMatches(element, m_name.impl()); }
77
78    static bool nodeMatches(Element*, const AtomicStringImpl*);
79
80private:
81    DocumentNameCollection(Document& document, CollectionType type, const AtomicString& name)
82        : HTMLNameCollection(document, type, name)
83    {
84        ASSERT(type == DocumentNamedItems);
85    }
86};
87
88}
89
90#endif
91