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.
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 "core/CoreExport.h"
29 #include "core/dom/Node.h"
30 #include "core/dom/QualifiedName.h"
34 class CORE_EXPORT Attr final
: public Node
{
35 DEFINE_WRAPPERTYPEINFO();
37 static PassRefPtrWillBeRawPtr
<Attr
> create(Element
&, const QualifiedName
&);
38 static PassRefPtrWillBeRawPtr
<Attr
> create(Document
&, const QualifiedName
&, const AtomicString
& value
);
41 String
name() const { return m_name
.toString(); }
42 bool specified() const { return true; }
43 Element
* ownerElement() const { return m_element
; }
45 const AtomicString
& value() const;
46 void setValue(const AtomicString
&);
48 const AtomicString
& valueForBindings() const;
49 void setValueForBindings(const AtomicString
&);
51 const QualifiedName
qualifiedName() const;
53 void attachToElement(Element
*, const AtomicString
&);
54 void detachFromElementWithValue(const AtomicString
&);
56 const AtomicString
& localName() const { return m_name
.localName(); }
57 const AtomicString
& namespaceURI() const { return m_name
.namespaceURI(); }
58 const AtomicString
& prefix() const { return m_name
.prefix(); }
60 DECLARE_VIRTUAL_TRACE();
63 Attr(Element
&, const QualifiedName
&);
64 Attr(Document
&, const QualifiedName
&, const AtomicString
& value
);
66 bool isElementNode() const = delete; // This will catch anyone doing an unnecessary check.
68 String
nodeName() const override
{ return name(); }
69 NodeType
nodeType() const override
{ return ATTRIBUTE_NODE
; }
71 String
nodeValue() const override
{ return value(); }
72 void setNodeValue(const String
&) override
;
73 PassRefPtrWillBeRawPtr
<Node
> cloneNode(bool deep
= true) override
;
75 bool isAttributeNode() const override
{ return true; }
77 // Attr wraps either an element/name, or a name/value pair (when it's a standalone Node.)
78 // Note that m_name is always set, but m_element/m_standaloneValue may be null.
79 RawPtrWillBeMember
<Element
> m_element
;
81 // Holds the value if it is a standalone Node, or the local name of the
82 // attribute it is attached to on an Element. The latter may (letter case)
83 // differ from m_name's local name. As these two modes are non-overlapping,
84 // use a single field.
85 AtomicString m_standaloneValueOrAttachedLocalName
;
88 DEFINE_NODE_TYPE_CASTS(Attr
, isAttributeNode());