Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / dom / Attr.h
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, 2007, 2008, 2009 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 Attr_h
26 #define Attr_h
27
28 #include "core/dom/ContainerNode.h"
29 #include "core/dom/QualifiedName.h"
30
31 namespace blink {
32
33 // Attr can have Text children
34 // therefore it has to be a fullblown Node. The plan
35 // is to dynamically allocate a textchild and store the
36 // resulting nodevalue in the attribute upon
37 // destruction. however, this is not yet implemented.
38
39 class Attr FINAL : public ContainerNode {
40 public:
41     static PassRefPtrWillBeRawPtr<Attr> create(Element&, const QualifiedName&);
42     static PassRefPtrWillBeRawPtr<Attr> create(Document&, const QualifiedName&, const AtomicString& value);
43     virtual ~Attr();
44
45     String name() const { return m_name.toString(); }
46     bool specified() const { return true; }
47     Element* ownerElement() const { return m_element; }
48
49     const AtomicString& value() const;
50     void setValue(const AtomicString&);
51
52     const AtomicString& valueForBindings() const;
53     void setValueForBindings(const AtomicString&);
54
55     const QualifiedName qualifiedName() const;
56
57     void attachToElement(Element*, const AtomicString&);
58     void detachFromElementWithValue(const AtomicString&);
59
60     virtual const AtomicString& localName() const OVERRIDE { return m_name.localName(); }
61     virtual const AtomicString& namespaceURI() const OVERRIDE { return m_name.namespaceURI(); }
62     const AtomicString& prefix() const { return m_name.prefix(); }
63
64     virtual void trace(Visitor*) OVERRIDE;
65
66 private:
67     Attr(Element&, const QualifiedName&);
68     Attr(Document&, const QualifiedName&, const AtomicString& value);
69
70     bool isElementNode() const WTF_DELETED_FUNCTION; // This will catch anyone doing an unnecessary check.
71
72     void createTextChild();
73
74     void setValueInternal(const AtomicString&);
75
76     virtual String nodeName() const OVERRIDE { return name(); }
77     virtual NodeType nodeType() const OVERRIDE { return ATTRIBUTE_NODE; }
78
79     virtual String nodeValue() const OVERRIDE { return value(); }
80     virtual void setNodeValue(const String&) OVERRIDE;
81     virtual PassRefPtrWillBeRawPtr<Node> cloneNode(bool deep = true) OVERRIDE;
82
83     virtual bool isAttributeNode() const OVERRIDE { return true; }
84     virtual bool childTypeAllowed(NodeType) const OVERRIDE;
85
86     virtual void childrenChanged(const ChildrenChange&) OVERRIDE;
87
88     Attribute& elementAttribute();
89
90     // Attr wraps either an element/name, or a name/value pair (when it's a standalone Node.)
91     // Note that m_name is always set, but m_element/m_standaloneValue may be null.
92     RawPtrWillBeMember<Element> m_element;
93     QualifiedName m_name;
94     // Holds the value if it is a standalone Node, or the local name of the
95     // attribute it is attached to on an Element. The latter may (letter case)
96     // differ from m_name's local name. As these two modes are non-overlapping,
97     // use a single field.
98     AtomicString m_standaloneValueOrAttachedLocalName;
99     unsigned m_ignoreChildrenChanged;
100 };
101
102 DEFINE_NODE_TYPE_CASTS(Attr, isAttributeNode());
103
104 } // namespace blink
105
106 #endif // Attr_h