]> git.saurik.com Git - iphone-api.git/blob - WebCore/NamedAttrMap.h
Adding the WebCore headers (for Cydget).
[iphone-api.git] / WebCore / NamedAttrMap.h
1 /*
2 * This file is part of the DOM implementation for KDE.
3 *
4 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
5 * (C) 1999 Antti Koivisto (koivisto@kde.org)
6 * (C) 2001 Peter Kelly (pmk@post.com)
7 * (C) 2001 Dirk Mueller (mueller@kde.org)
8 * Copyright (C) 2003, 2004, 2005, 2006 Apple Computer, Inc.
9 *
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Library General Public
12 * License as published by the Free Software Foundation; either
13 * version 2 of the License, or (at your option) any later version.
14 *
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Library General Public License for more details.
19 *
20 * You should have received a copy of the GNU Library General Public License
21 * along with this library; see the file COPYING.LIB. If not, write to
22 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
23 * Boston, MA 02110-1301, USA.
24 *
25 */
26
27 #ifndef NamedAttrMap_h
28 #define NamedAttrMap_h
29
30 #include "Attribute.h"
31 #include "NamedNodeMap.h"
32 #include <wtf/RefPtr.h>
33 #include <wtf/Vector.h>
34
35 #ifdef __OBJC__
36 #define id id_AVOID_KEYWORD
37 #endif
38
39 namespace WebCore {
40
41 // the map of attributes of an element
42 class NamedAttrMap : public NamedNodeMap {
43 friend class Element;
44 protected:
45 NamedAttrMap(Element* element) : m_element(element) { }
46 public:
47 static PassRefPtr<NamedAttrMap> create(Element* element) { return adoptRef(new NamedAttrMap(element)); }
48
49 virtual ~NamedAttrMap();
50
51 void setAttributes(const NamedAttrMap&);
52
53 // DOM methods & attributes for NamedNodeMap
54
55 virtual PassRefPtr<Node> getNamedItem(const String& name) const;
56 virtual PassRefPtr<Node> removeNamedItem(const String& name, ExceptionCode&);
57
58 virtual PassRefPtr<Node> getNamedItemNS(const String& namespaceURI, const String& localName) const;
59 virtual PassRefPtr<Node> removeNamedItemNS(const String& namespaceURI, const String& localName, ExceptionCode&);
60
61 virtual PassRefPtr<Node> getNamedItem(const QualifiedName& name) const;
62 virtual PassRefPtr<Node> removeNamedItem(const QualifiedName& name, ExceptionCode&);
63 virtual PassRefPtr<Node> setNamedItem(Node* arg, ExceptionCode&);
64
65 virtual PassRefPtr<Node> item(unsigned index) const;
66 size_t length() const { return m_attributes.size(); }
67
68 // Other methods (not part of DOM)
69 Attribute* attributeItem(unsigned index) const { return m_attributes[index].get(); }
70 Attribute* getAttributeItem(const QualifiedName& name) const;
71 Attribute* getAttributeItem(const String& name, bool shouldIgnoreAttributeCase) const;
72
73 void shrinkToLength() { m_attributes.shrinkCapacity(length()); }
74 void reserveInitialCapacity(unsigned capacity) { m_attributes.reserveInitialCapacity(capacity); }
75
76 // used during parsing: only inserts if not already there
77 // no error checking!
78 void insertAttribute(PassRefPtr<Attribute> newAttribute, bool allowDuplicates)
79 {
80 ASSERT(!m_element);
81 if (allowDuplicates || !getAttributeItem(newAttribute->name()))
82 addAttribute(newAttribute);
83 }
84
85 virtual bool isMappedAttributeMap() const;
86
87 const AtomicString& id() const { return m_id; }
88 void setID(const AtomicString& _id) { m_id = _id; }
89
90 bool mapsEquivalent(const NamedAttrMap* otherMap) const;
91
92 // These functions are internal, and do no error checking.
93 void addAttribute(PassRefPtr<Attribute>);
94 void removeAttribute(const QualifiedName& name);
95
96 protected:
97 virtual void clearAttributes();
98
99 void detachFromElement();
100
101 Element* m_element;
102 Vector<RefPtr<Attribute> > m_attributes;
103 AtomicString m_id;
104 };
105
106 } //namespace
107
108 #undef id
109
110 #endif