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 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 "ContainerNode.h"
29 #include "QualifiedName.h"
30 #include "ScrollTypes.h"
32 #include "RenderStyle.h"
38 class CSSStyleDeclaration
;
39 class ElementRareData
;
42 class Element
: public ContainerNode
{
44 Element(const QualifiedName
&, Document
*);
47 const AtomicString
& getIDAttribute() const;
48 bool hasAttribute(const QualifiedName
&) const;
49 const AtomicString
& getAttribute(const QualifiedName
&) const;
50 void setAttribute(const QualifiedName
&, const AtomicString
& value
, ExceptionCode
&);
51 void removeAttribute(const QualifiedName
&, ExceptionCode
&);
53 bool hasAttributes() const;
55 bool hasAttribute(const String
& name
) const;
56 bool hasAttributeNS(const String
& namespaceURI
, const String
& localName
) const;
58 const AtomicString
& getAttribute(const String
& name
) const;
59 const AtomicString
& getAttributeNS(const String
& namespaceURI
, const String
& localName
) const;
61 void setAttribute(const AtomicString
& name
, const AtomicString
& value
, ExceptionCode
&);
62 void setAttributeNS(const AtomicString
& namespaceURI
, const AtomicString
& qualifiedName
, const AtomicString
& value
, ExceptionCode
&);
64 void scrollIntoView (bool alignToTop
= true);
65 void scrollIntoViewIfNeeded(bool centerIfNeeded
= true);
67 void scrollByUnits(int units
, ScrollGranularity
);
68 void scrollByLines(int lines
);
69 void scrollByPages(int pages
);
75 Element
* offsetParent();
82 void setScrollLeft(int);
83 void setScrollTop(int);
87 void removeAttribute(const String
& name
, ExceptionCode
&);
88 void removeAttributeNS(const String
& namespaceURI
, const String
& localName
, ExceptionCode
&);
90 PassRefPtr
<Attr
> getAttributeNode(const String
& name
);
91 PassRefPtr
<Attr
> getAttributeNodeNS(const String
& namespaceURI
, const String
& localName
);
92 PassRefPtr
<Attr
> setAttributeNode(Attr
*, ExceptionCode
&);
93 PassRefPtr
<Attr
> setAttributeNodeNS(Attr
*, ExceptionCode
&);
94 PassRefPtr
<Attr
> removeAttributeNode(Attr
*, ExceptionCode
&);
96 virtual CSSStyleDeclaration
* style();
98 const QualifiedName
& tagQName() const { return m_tagName
; }
99 String
tagName() const { return nodeName(); }
100 bool hasTagName(const QualifiedName
& tagName
) const { return m_tagName
.matches(tagName
); }
102 // A fast function for checking the local name against another atomic string.
103 bool hasLocalName(const AtomicString
& other
) const { return m_tagName
.localName() == other
; }
104 bool hasLocalName(const QualifiedName
& other
) const { return m_tagName
.localName() == other
.localName(); }
106 const AtomicString
& localName() const { return m_tagName
.localName(); }
107 const AtomicString
& prefix() const { return m_tagName
.prefix(); }
108 virtual void setPrefix(const AtomicString
&, ExceptionCode
&);
109 const AtomicString
& namespaceURI() const { return m_tagName
.namespaceURI(); }
111 virtual KURL
baseURI() const;
113 // DOM methods overridden from parent classes
114 virtual NodeType
nodeType() const;
115 virtual PassRefPtr
<Node
> cloneNode(bool deep
);
116 virtual String
nodeName() const;
117 virtual void insertedIntoDocument();
118 virtual void removedFromDocument();
119 virtual void childrenChanged(bool changedByParser
= false, Node
* beforeChange
= 0, Node
* afterChange
= 0, int childCountDelta
= 0);
121 PassRefPtr
<Element
> cloneElement();
123 void normalizeAttributes();
125 virtual bool isFormControlElement() const { return false; }
126 virtual bool isFormControlElementWithState() const { return false; }
127 virtual bool isInputTypeHidden() const { return false; }
128 virtual bool isPasswordField() const { return false; }
130 String
nodeNamePreservingCase() const;
132 // convenience methods which ignore exceptions
133 void setAttribute(const QualifiedName
&, const AtomicString
& value
);
134 void setBooleanAttribute(const QualifiedName
& name
, bool);
136 virtual NamedAttrMap
* attributes() const;
137 NamedAttrMap
* attributes(bool readonly
) const;
139 // This method is called whenever an attribute is added, changed or removed.
140 virtual void attributeChanged(Attribute
*, bool preserveDecls
= false);
142 // not part of the DOM
143 void setAttributeMap(PassRefPtr
<NamedAttrMap
>);
145 virtual void copyNonAttributeProperties(const Element
* /*source*/) { }
147 virtual void attach();
148 virtual void detach();
149 virtual RenderObject
* createRenderer(RenderArena
*, RenderStyle
*);
150 virtual void recalcStyle(StyleChange
= NoChange
);
152 virtual RenderStyle
* computedStyle();
154 virtual bool childTypeAllowed(NodeType
);
156 virtual PassRefPtr
<Attribute
> createAttribute(const QualifiedName
&, const AtomicString
& value
);
158 void dispatchAttrRemovalEvent(Attribute
*);
159 void dispatchAttrAdditionEvent(Attribute
*);
161 virtual void accessKeyAction(bool /*sendToAnyEvent*/) { }
163 virtual bool isURLAttribute(Attribute
*) const;
164 virtual const QualifiedName
& imageSourceAttributeName() const;
165 virtual String
target() const { return String(); }
167 virtual void focus(bool restorePreviousSelection
= true);
168 virtual void updateFocusAppearance(bool restorePreviousSelection
);
172 virtual void formatForDebugger(char* buffer
, unsigned length
) const;
175 String
innerText() const;
176 String
outerText() const;
178 virtual String
title() const;
180 EVisibility
implicitVisibility();
182 String
openTagStartToString() const;
184 void updateId(const AtomicString
& oldId
, const AtomicString
& newId
);
186 IntSize
minimumSizeForResizing() const;
187 void setMinimumSizeForResizing(const IntSize
&);
189 // Use Document::registerForDocumentActivationCallbacks() to subscribe to these
190 virtual void documentWillBecomeInactive() { }
191 virtual void documentDidBecomeActive() { }
193 // Use Document::registerForMediaVolumeCallbacks() to subscribe to this
194 virtual void mediaVolumeDidChange() { }
196 bool isFinishedParsingChildren() const { return m_parsingChildrenFinished
; }
197 virtual void finishParsingChildren();
198 virtual void beginParsingChildren() { m_parsingChildrenFinished
= false; }
200 // ElementTraversal API
201 Element
* firstElementChild() const;
202 Element
* lastElementChild() const;
203 Element
* previousElementSibling() const;
204 Element
* nextElementSibling() const;
205 unsigned childElementCount() const;
208 virtual void createAttributeMap() const;
210 virtual void updateStyleAttribute() const {}
213 virtual void updateAnimatedSVGAttribute(const String
&) const {}
216 void updateFocusAppearanceSoonAfterAttach();
217 void cancelFocusAppearanceUpdate();
219 virtual const AtomicString
& virtualPrefix() const { return prefix(); }
220 virtual const AtomicString
& virtualLocalName() const { return localName(); }
221 virtual const AtomicString
& virtualNamespaceURI() const { return namespaceURI(); }
223 QualifiedName m_tagName
;
224 virtual NodeRareData
* createRareData();
227 ElementRareData
* rareData() const;
228 ElementRareData
* ensureRareData();
230 mutable RefPtr
<NamedAttrMap
> namedAttrMap
;
233 inline bool Node::hasTagName(const QualifiedName
& name
) const
235 return isElementNode() && static_cast<const Element
*>(this)->hasTagName(name
);
238 inline bool Node::hasAttributes() const
240 return isElementNode() && static_cast<const Element
*>(this)->hasAttributes();
243 inline NamedAttrMap
* Node::attributes() const
245 return isElementNode() ? static_cast<const Element
*>(this)->attributes() : 0;
248 inline Element
* Node::parentElement() const
250 Node
* parent
= parentNode();
251 return parent
&& parent
->isElementNode() ? static_cast<Element
*>(parent
) : 0;