• 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, 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 WebCore {
32 
33 class CSSStyleDeclaration;
34 class ExceptionState;
35 class MutableStylePropertySet;
36 
37 // Attr can have Text children
38 // therefore it has to be a fullblown Node. The plan
39 // is to dynamically allocate a textchild and store the
40 // resulting nodevalue in the attribute upon
41 // destruction. however, this is not yet implemented.
42 
43 class Attr FINAL : public ContainerNode {
44 public:
45     static PassRefPtr<Attr> create(Element&, const QualifiedName&);
46     static PassRefPtr<Attr> create(Document&, const QualifiedName&, const AtomicString& value);
47     virtual ~Attr();
48 
name()49     String name() const { return qualifiedName().toString(); }
specified()50     bool specified() const { return true; }
ownerElement()51     Element* ownerElement() const { return m_element; }
52 
53     const AtomicString& value() const;
54     void setValue(const AtomicString&, ExceptionState&);
55     void setValue(const AtomicString&);
56 
qualifiedName()57     const QualifiedName& qualifiedName() const { return m_name; }
58 
59     bool isId() const;
60 
61     void attachToElement(Element*);
62     void detachFromElementWithValue(const AtomicString&);
63 
localName()64     virtual const AtomicString& localName() const OVERRIDE { return m_name.localName(); }
namespaceURI()65     virtual const AtomicString& namespaceURI() const OVERRIDE { return m_name.namespaceURI(); }
prefix()66     virtual const AtomicString& prefix() const OVERRIDE { return m_name.prefix(); }
67 
68     virtual void setPrefix(const AtomicString&, ExceptionState&) OVERRIDE;
69 
70 private:
71     Attr(Element&, const QualifiedName&);
72     Attr(Document&, const QualifiedName&, const AtomicString& value);
73 
74     void createTextChild();
75 
nodeName()76     virtual String nodeName() const OVERRIDE { return name(); }
nodeType()77     virtual NodeType nodeType() const OVERRIDE { return ATTRIBUTE_NODE; }
78 
nodeValue()79     virtual String nodeValue() const OVERRIDE { return value(); }
80     virtual void setNodeValue(const String&);
81     virtual PassRefPtr<Node> cloneNode(bool deep = true);
82 
isAttributeNode()83     virtual bool isAttributeNode() const { return true; }
84     virtual bool childTypeAllowed(NodeType) const;
85 
86     virtual void childrenChanged(bool changedByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0);
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     Element* m_element;
93     QualifiedName m_name;
94     AtomicString m_standaloneValue;
95     unsigned m_ignoreChildrenChanged;
96 };
97 
98 DEFINE_NODE_TYPE_CASTS(Attr, isAttributeNode());
99 
100 } // namespace WebCore
101 
102 #endif // Attr_h
103