• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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.
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 
25 #ifndef Attribute_h
26 #define Attribute_h
27 
28 #include "CSSMappedAttributeDeclaration.h"
29 #include "QualifiedName.h"
30 
31 namespace WebCore {
32 
33 class Attr;
34 class CSSStyleDeclaration;
35 class Element;
36 class NamedNodeMap;
37 
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> {
42     friend class Attr;
43     friend class NamedNodeMap;
44 public:
create(const QualifiedName & name,const AtomicString & value)45     static PassRefPtr<Attribute> create(const QualifiedName& name, const AtomicString& value)
46     {
47         return adoptRef(new Attribute(name, value, false, 0));
48     }
createMapped(const QualifiedName & name,const AtomicString & value)49     static PassRefPtr<Attribute> createMapped(const QualifiedName& name, const AtomicString& value)
50     {
51         return adoptRef(new Attribute(name, value, true, 0));
52     }
createMapped(const AtomicString & name,const AtomicString & value)53     static PassRefPtr<Attribute> createMapped(const AtomicString& name, const AtomicString& value)
54     {
55         return adoptRef(new Attribute(name, value, true, 0));
56     }
57 
value()58     const AtomicString& value() const { return m_value; }
prefix()59     const AtomicString& prefix() const { return m_name.prefix(); }
localName()60     const AtomicString& localName() const { return m_name.localName(); }
namespaceURI()61     const AtomicString& namespaceURI() const { return m_name.namespaceURI(); }
62 
name()63     const QualifiedName& name() const { return m_name; }
64 
65     Attr* attr() const;
66     PassRefPtr<Attr> createAttrIfNeeded(Element*);
67 
isNull()68     bool isNull() const { return m_value.isNull(); }
isEmpty()69     bool isEmpty() const { return m_value.isEmpty(); }
70 
71     PassRefPtr<Attribute> clone() const;
72 
73     // An extension to get the style information for presentational attributes.
style()74     CSSStyleDeclaration* style() const { return m_styleDecl.get(); }
decl()75     CSSMappedAttributeDeclaration* decl() const { return m_styleDecl.get(); }
setDecl(PassRefPtr<CSSMappedAttributeDeclaration> decl)76     void setDecl(PassRefPtr<CSSMappedAttributeDeclaration> decl) { m_styleDecl = decl; }
77 
setValue(const AtomicString & value)78     void setValue(const AtomicString& value) { m_value = value; }
setPrefix(const AtomicString & prefix)79     void setPrefix(const AtomicString& prefix) { m_name.setPrefix(prefix); }
80 
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.
parserSetName(const QualifiedName & name)84     void parserSetName(const QualifiedName& name) { m_name = name; }
85 
isMappedAttribute()86     bool isMappedAttribute() { return m_isMappedAttribute; }
87 
88 private:
Attribute(const QualifiedName & name,const AtomicString & value,bool isMappedAttribute,CSSMappedAttributeDeclaration * styleDecl)89     Attribute(const QualifiedName& name, const AtomicString& value, bool isMappedAttribute, CSSMappedAttributeDeclaration* styleDecl)
90         : m_isMappedAttribute(isMappedAttribute)
91         , m_hasAttr(false)
92         , m_name(name)
93         , m_value(value)
94         , m_styleDecl(styleDecl)
95     {
96     }
97 
Attribute(const AtomicString & name,const AtomicString & value,bool isMappedAttribute,CSSMappedAttributeDeclaration * styleDecl)98     Attribute(const AtomicString& name, const AtomicString& value, bool isMappedAttribute, CSSMappedAttributeDeclaration* styleDecl)
99         : m_isMappedAttribute(isMappedAttribute)
100         , m_hasAttr(false)
101         , m_name(nullAtom, name, nullAtom)
102         , m_value(value)
103         , m_styleDecl(styleDecl)
104     {
105     }
106 
107     void bindAttr(Attr*);
108     void unbindAttr(Attr*);
109 
110     // These booleans will go into the spare 32-bits of padding from RefCounted in 64-bit.
111     bool m_isMappedAttribute;
112     bool m_hasAttr;
113 
114     QualifiedName m_name;
115     AtomicString m_value;
116     RefPtr<CSSMappedAttributeDeclaration> m_styleDecl;
117 };
118 
119 } // namespace WebCore
120 
121 #endif // Attribute_h
122