2008-11-04 Anders Carlsson <andersca@apple.com>
[webkit/qt.git] / WebCore / dom / Element.h
blob59ce6a9545e2716b0768efc7984ec165bd524bda
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 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.
25 #ifndef Element_h
26 #define Element_h
28 #include "ContainerNode.h"
29 #include "QualifiedName.h"
30 #include "ScrollTypes.h"
32 namespace WebCore {
34 class Attr;
35 class Attribute;
36 class CSSStyleDeclaration;
37 class ElementRareData;
38 class IntSize;
40 class Element : public ContainerNode {
41 public:
42 Element(const QualifiedName&, Document*);
43 ~Element();
45 const AtomicString& getIDAttribute() const;
46 bool hasAttribute(const QualifiedName&) const;
47 const AtomicString& getAttribute(const QualifiedName&) const;
48 void setAttribute(const QualifiedName&, const AtomicString& value, ExceptionCode&);
49 void removeAttribute(const QualifiedName&, ExceptionCode&);
51 bool hasAttributes() const;
53 bool hasAttribute(const String& name) const;
54 bool hasAttributeNS(const String& namespaceURI, const String& localName) const;
56 const AtomicString& getAttribute(const String& name) const;
57 const AtomicString& getAttributeNS(const String& namespaceURI, const String& localName) const;
59 void setAttribute(const AtomicString& name, const AtomicString& value, ExceptionCode&);
60 void setAttributeNS(const AtomicString& namespaceURI, const AtomicString& qualifiedName, const AtomicString& value, ExceptionCode&);
62 void scrollIntoView (bool alignToTop = true);
63 void scrollIntoViewIfNeeded(bool centerIfNeeded = true);
65 void scrollByUnits(int units, ScrollGranularity);
66 void scrollByLines(int lines);
67 void scrollByPages(int pages);
69 int offsetLeft();
70 int offsetTop();
71 int offsetWidth();
72 int offsetHeight();
73 Element* offsetParent();
74 int clientLeft();
75 int clientTop();
76 int clientWidth();
77 int clientHeight();
78 int scrollLeft();
79 int scrollTop();
80 void setScrollLeft(int);
81 void setScrollTop(int);
82 int scrollWidth();
83 int scrollHeight();
85 void removeAttribute(const String& name, ExceptionCode&);
86 void removeAttributeNS(const String& namespaceURI, const String& localName, ExceptionCode&);
88 PassRefPtr<Attr> getAttributeNode(const String& name);
89 PassRefPtr<Attr> getAttributeNodeNS(const String& namespaceURI, const String& localName);
90 PassRefPtr<Attr> setAttributeNode(Attr*, ExceptionCode&);
91 PassRefPtr<Attr> setAttributeNodeNS(Attr*, ExceptionCode&);
92 PassRefPtr<Attr> removeAttributeNode(Attr*, ExceptionCode&);
94 virtual CSSStyleDeclaration* style();
96 const QualifiedName& tagQName() const { return m_tagName; }
97 String tagName() const { return nodeName(); }
98 bool hasTagName(const QualifiedName& tagName) const { return m_tagName.matches(tagName); }
100 // A fast function for checking the local name against another atomic string.
101 bool hasLocalName(const AtomicString& other) const { return m_tagName.localName() == other; }
102 bool hasLocalName(const QualifiedName& other) const { return m_tagName.localName() == other.localName(); }
104 const AtomicString& localName() const { return m_tagName.localName(); }
105 const AtomicString& prefix() const { return m_tagName.prefix(); }
106 virtual void setPrefix(const AtomicString&, ExceptionCode&);
107 const AtomicString& namespaceURI() const { return m_tagName.namespaceURI(); }
109 virtual KURL baseURI() const;
111 // DOM methods overridden from parent classes
112 virtual NodeType nodeType() const;
113 virtual PassRefPtr<Node> cloneNode(bool deep);
114 virtual String nodeName() const;
115 virtual void insertedIntoDocument();
116 virtual void removedFromDocument();
117 virtual void childrenChanged(bool changedByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0);
119 void normalizeAttributes();
121 virtual bool isInputTypeHidden() const { return false; }
122 virtual bool isPasswordField() const { return false; }
124 String nodeNamePreservingCase() const;
126 // convenience methods which ignore exceptions
127 void setAttribute(const QualifiedName&, const AtomicString& value);
128 void setBooleanAttribute(const QualifiedName& name, bool);
130 virtual NamedAttrMap* attributes() const;
131 NamedAttrMap* attributes(bool readonly) const;
133 // This method is called whenever an attribute is added, changed or removed.
134 virtual void attributeChanged(Attribute*, bool preserveDecls = false);
136 // not part of the DOM
137 void setAttributeMap(PassRefPtr<NamedAttrMap>);
139 virtual void copyNonAttributeProperties(const Element* source) {}
141 virtual void attach();
142 virtual void detach();
143 virtual RenderObject* createRenderer(RenderArena*, RenderStyle*);
144 virtual void recalcStyle(StyleChange = NoChange);
146 virtual RenderStyle* computedStyle();
148 virtual bool childTypeAllowed(NodeType);
150 virtual PassRefPtr<Attribute> createAttribute(const QualifiedName&, const AtomicString& value);
152 void dispatchAttrRemovalEvent(Attribute*);
153 void dispatchAttrAdditionEvent(Attribute*);
155 virtual void accessKeyAction(bool sendToAnyEvent) { }
157 virtual bool isURLAttribute(Attribute*) const;
158 virtual const QualifiedName& imageSourceAttributeName() const;
159 virtual String target() const { return String(); }
161 virtual void focus(bool restorePreviousSelection = true);
162 virtual void updateFocusAppearance(bool restorePreviousSelection);
163 void blur();
165 #ifndef NDEBUG
166 virtual void formatForDebugger(char* buffer, unsigned length) const;
167 #endif
169 bool contains(const Node*) const;
171 String innerText() const;
172 String outerText() const;
174 virtual String title() const;
176 String openTagStartToString() const;
178 void updateId(const AtomicString& oldId, const AtomicString& newId);
180 IntSize minimumSizeForResizing() const;
181 void setMinimumSizeForResizing(const IntSize&);
183 // Use Document::registerForDocumentActivationCallbacks() to subscribe these
184 virtual void documentWillBecomeInactive() { }
185 virtual void documentDidBecomeActive() { }
187 bool isFinishedParsingChildren() const { return m_parsingChildrenFinished; }
188 virtual void finishParsingChildren();
189 virtual void beginParsingChildren() { m_parsingChildrenFinished = false; }
191 // ElementTraversal API
192 Element* firstElementChild() const;
193 Element* lastElementChild() const;
194 Element* previousElementSibling() const;
195 Element* nextElementSibling() const;
196 unsigned childElementCount() const;
198 private:
199 virtual void createAttributeMap() const;
201 virtual void updateStyleAttribute() const {}
203 #if ENABLE(SVG)
204 virtual void updateAnimatedSVGAttribute(const String&) const {}
205 #endif
207 void updateFocusAppearanceSoonAfterAttach();
208 void cancelFocusAppearanceUpdate();
210 virtual const AtomicString& virtualPrefix() const { return prefix(); }
211 virtual const AtomicString& virtualLocalName() const { return localName(); }
212 virtual const AtomicString& virtualNamespaceURI() const { return namespaceURI(); }
214 QualifiedName m_tagName;
215 virtual NodeRareData* createRareData();
217 protected:
218 ElementRareData* rareData() const;
219 ElementRareData* ensureRareData();
221 mutable RefPtr<NamedAttrMap> namedAttrMap;
223 // These two bits are really used by the StyledElement subclass, but they are pulled up here in order to be shared with other
224 // Element bits.
225 mutable bool m_isStyleAttributeValid : 1;
226 mutable bool m_synchronizingStyleAttribute : 1;
228 #if ENABLE(SVG)
229 // These bit is are used by SVGElement subclasses, and it lives here for the same reason as above.
230 mutable bool m_areSVGAttributesValid : 1;
231 mutable bool m_synchronizingSVGAttributes : 1;
232 #endif
234 private:
235 bool m_parsingChildrenFinished : 1;
238 inline bool Node::hasTagName(const QualifiedName& name) const
240 return isElementNode() && static_cast<const Element*>(this)->hasTagName(name);
243 inline bool Node::hasAttributes() const
245 return isElementNode() && static_cast<const Element*>(this)->hasAttributes();
248 inline NamedAttrMap* Node::attributes() const
250 return isElementNode() ? static_cast<const Element*>(this)->attributes() : 0;
253 } //namespace
255 #endif