Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 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; |
Ben Murdoch | df95704 | 2013-08-06 11:01:27 +0100 | [diff] [blame] | 34 | class ExceptionState; |
Torne (Richard Coles) | 93ac45c | 2013-05-29 14:40:20 +0100 | [diff] [blame] | 35 | class MutableStylePropertySet; |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 36 | |
Torne (Richard Coles) | 81a5157 | 2013-05-13 16:52:28 +0100 | [diff] [blame] | 37 | // Attr can have Text children |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 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 | |
| 49 | String name() const { return qualifiedName().toString(); } |
| 50 | bool specified() const { return m_specified; } |
| 51 | Element* ownerElement() const { return m_element; } |
| 52 | |
| 53 | const AtomicString& value() const; |
Ben Murdoch | df95704 | 2013-08-06 11:01:27 +0100 | [diff] [blame] | 54 | void setValue(const AtomicString&, ExceptionState&); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 55 | void setValue(const AtomicString&); |
| 56 | |
| 57 | const QualifiedName& qualifiedName() const { return m_name; } |
| 58 | |
| 59 | bool isId() const; |
| 60 | |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 61 | void setSpecified(bool specified) { m_specified = specified; } |
| 62 | |
| 63 | void attachToElement(Element*); |
| 64 | void detachFromElementWithValue(const AtomicString&); |
| 65 | |
| 66 | private: |
| 67 | Attr(Element*, const QualifiedName&); |
| 68 | Attr(Document*, const QualifiedName&, const AtomicString& value); |
| 69 | |
| 70 | void createTextChild(); |
| 71 | |
| 72 | virtual String nodeName() const OVERRIDE { return name(); } |
| 73 | virtual NodeType nodeType() const OVERRIDE { return ATTRIBUTE_NODE; } |
| 74 | |
Torne (Richard Coles) | 93ac45c | 2013-05-29 14:40:20 +0100 | [diff] [blame] | 75 | virtual const AtomicString& localName() const OVERRIDE { return m_name.localName(); } |
| 76 | virtual const AtomicString& namespaceURI() const OVERRIDE { return m_name.namespaceURI(); } |
| 77 | virtual const AtomicString& prefix() const OVERRIDE { return m_name.prefix(); } |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 78 | |
Ben Murdoch | df95704 | 2013-08-06 11:01:27 +0100 | [diff] [blame] | 79 | virtual void setPrefix(const AtomicString&, ExceptionState&); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 80 | |
| 81 | virtual String nodeValue() const OVERRIDE { return value(); } |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 82 | virtual void setNodeValue(const String&); |
| 83 | virtual PassRefPtr<Node> cloneNode(bool deep = true); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 84 | |
| 85 | virtual bool isAttributeNode() const { return true; } |
| 86 | virtual bool childTypeAllowed(NodeType) const; |
| 87 | |
| 88 | virtual void childrenChanged(bool changedByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0); |
| 89 | |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 90 | Attribute& elementAttribute(); |
| 91 | |
| 92 | // Attr wraps either an element/name, or a name/value pair (when it's a standalone Node.) |
| 93 | // Note that m_name is always set, but m_element/m_standaloneValue may be null. |
| 94 | Element* m_element; |
| 95 | QualifiedName m_name; |
| 96 | AtomicString m_standaloneValue; |
| 97 | |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 98 | unsigned m_ignoreChildrenChanged : 31; |
| 99 | bool m_specified : 1; |
| 100 | }; |
| 101 | |
Ben Murdoch | 591b958 | 2013-07-10 11:41:44 +0100 | [diff] [blame] | 102 | inline Attr* toAttr(Node* node) |
| 103 | { |
| 104 | ASSERT_WITH_SECURITY_IMPLICATION(!node || node->isAttributeNode()); |
| 105 | return static_cast<Attr*>(node); |
| 106 | } |
| 107 | |
| 108 | inline const Attr* toAttr(const Node* node) |
| 109 | { |
| 110 | ASSERT_WITH_SECURITY_IMPLICATION(!node || node->isAttributeNode()); |
| 111 | return static_cast<const Attr*>(node); |
| 112 | } |
| 113 | |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 114 | } // namespace WebCore |
| 115 | |
| 116 | #endif // Attr_h |