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