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#pragma once
26
27#include "Node.h"
28#include "QualifiedName.h"
29
30namespace WebCore {
31
32class Attribute;
33class CSSStyleDeclaration;
34class MutableStyleProperties;
35
36class Attr final : public Node {
37 WTF_MAKE_ISO_ALLOCATED(Attr);
38public:
39 static Ref<Attr> create(Element&, const QualifiedName&);
40 static Ref<Attr> create(Document&, const QualifiedName&, const AtomString& value);
41 virtual ~Attr();
42
43 String name() const { return qualifiedName().toString(); }
44 bool specified() const { return true; }
45 Element* ownerElement() const { return m_element; }
46
47 WEBCORE_EXPORT const AtomString& value() const;
48 WEBCORE_EXPORT void setValue(const AtomString&);
49
50 const QualifiedName& qualifiedName() const { return m_name; }
51
52 WEBCORE_EXPORT CSSStyleDeclaration* style();
53
54 void attachToElement(Element&);
55 void detachFromElementWithValue(const AtomString&);
56
57 const AtomString& namespaceURI() const final { return m_name.namespaceURI(); }
58 const AtomString& localName() const final { return m_name.localName(); }
59 const AtomString& prefix() const final { return m_name.prefix(); }
60
61private:
62 Attr(Element&, const QualifiedName&);
63 Attr(Document&, const QualifiedName&, const AtomString& value);
64
65 String nodeName() const final { return name(); }
66 NodeType nodeType() const final { return ATTRIBUTE_NODE; }
67
68 String nodeValue() const final { return value(); }
69 ExceptionOr<void> setNodeValue(const String&) final;
70
71 ExceptionOr<void> setPrefix(const AtomString&) final;
72
73 Ref<Node> cloneNodeInternal(Document&, CloningOperation) final;
74
75 bool isAttributeNode() const final { return true; }
76
77 Attribute& elementAttribute();
78
79 // Attr wraps either an element/name, or a name/value pair (when it's a standalone Node.)
80 // Note that m_name is always set, but m_element/m_standaloneValue may be null.
81 Element* m_element { nullptr };
82 QualifiedName m_name;
83 AtomString m_standaloneValue;
84
85 RefPtr<MutableStyleProperties> m_style;
86};
87
88} // namespace WebCore
89
90SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::Attr)
91 static bool isType(const WebCore::Node& node) { return node.isAttributeNode(); }
92SPECIALIZE_TYPE_TRAITS_END()
93