2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Peter Kelly (pmk@post.com)
5 * (C) 2001 Dirk Mueller (mueller@kde.org)
6 * Copyright (C) 2003, 2004, 2005, 2006, 2008 Apple Inc. All rights reserved.
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.
28 #include "CSSMappedAttributeDeclaration.h"
29 #include "QualifiedName.h"
34 class CSSStyleDeclaration;
38 // This has no counterpart in DOM.
39 // It is an internal representation of the node value of an Attr.
40 // The actual Attr with its value as a Text child is allocated only if needed.
41 class Attribute : public RefCounted<Attribute> {
43 friend class NamedNodeMap;
45 static PassRefPtr<Attribute> create(const QualifiedName& name, const AtomicString& value)
47 return adoptRef(new Attribute(name, value, false, 0));
49 static PassRefPtr<Attribute> createMapped(const QualifiedName& name, const AtomicString& value)
51 return adoptRef(new Attribute(name, value, true, 0));
53 static PassRefPtr<Attribute> createMapped(const AtomicString& name, const AtomicString& value)
55 return adoptRef(new Attribute(name, value, true, 0));
58 const AtomicString& value() const { return m_value; }
59 const AtomicString& prefix() const { return m_name.prefix(); }
60 const AtomicString& localName() const { return m_name.localName(); }
61 const AtomicString& namespaceURI() const { return m_name.namespaceURI(); }
63 const QualifiedName& name() const { return m_name; }
66 PassRefPtr<Attr> createAttrIfNeeded(Element*);
68 bool isNull() const { return m_value.isNull(); }
69 bool isEmpty() const { return m_value.isEmpty(); }
71 PassRefPtr<Attribute> clone() const;
73 // An extension to get the style information for presentational attributes.
74 CSSStyleDeclaration* style() const { return m_styleDecl.get(); }
75 CSSMappedAttributeDeclaration* decl() const { return m_styleDecl.get(); }
76 void setDecl(PassRefPtr<CSSMappedAttributeDeclaration> decl) { m_styleDecl = decl; }
78 void setValue(const AtomicString& value) { m_value = value; }
79 void setPrefix(const AtomicString& prefix) { m_name.setPrefix(prefix); }
81 // Note: This API is only for HTMLTreeBuilder. It is not safe to change the
82 // name of an attribute once parseMappedAttribute has been called as DOM
83 // elements may have placed the Attribute in a hash by name.
84 void parserSetName(const QualifiedName& name) { m_name = name; }
86 bool isMappedAttribute() { return m_isMappedAttribute; }
89 Attribute(const QualifiedName& name, const AtomicString& value, bool isMappedAttribute, CSSMappedAttributeDeclaration* styleDecl)
90 : m_isMappedAttribute(isMappedAttribute)
94 , m_styleDecl(styleDecl)
98 Attribute(const AtomicString& name, const AtomicString& value, bool isMappedAttribute, CSSMappedAttributeDeclaration* styleDecl)
99 : m_isMappedAttribute(isMappedAttribute)
101 , m_name(nullAtom, name, nullAtom)
103 , m_styleDecl(styleDecl)
107 void bindAttr(Attr*);
108 void unbindAttr(Attr*);
110 // These booleans will go into the spare 32-bits of padding from RefCounted in 64-bit.
111 bool m_isMappedAttribute;
114 QualifiedName m_name;
115 AtomicString m_value;
116 RefPtr<CSSMappedAttributeDeclaration> m_styleDecl;
119 } // namespace WebCore
121 #endif // Attribute_h