]> git.saurik.com Git - iphone-api.git/blob - WebCore/Element.h
Adding the WebCore headers (for Cydget).
[iphone-api.git] / WebCore / Element.h
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.
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 Element_h
26 #define Element_h
27
28 #include "ContainerNode.h"
29 #include "QualifiedName.h"
30 #include "ScrollTypes.h"
31
32 #include "RenderStyle.h"
33
34 namespace WebCore {
35
36 class Attr;
37 class Attribute;
38 class CSSStyleDeclaration;
39 class ElementRareData;
40 class IntSize;
41
42 class Element : public ContainerNode {
43 public:
44 Element(const QualifiedName&, Document*);
45 ~Element();
46
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&);
52
53 bool hasAttributes() const;
54
55 bool hasAttribute(const String& name) const;
56 bool hasAttributeNS(const String& namespaceURI, const String& localName) const;
57
58 const AtomicString& getAttribute(const String& name) const;
59 const AtomicString& getAttributeNS(const String& namespaceURI, const String& localName) const;
60
61 void setAttribute(const AtomicString& name, const AtomicString& value, ExceptionCode&);
62 void setAttributeNS(const AtomicString& namespaceURI, const AtomicString& qualifiedName, const AtomicString& value, ExceptionCode&);
63
64 void scrollIntoView (bool alignToTop = true);
65 void scrollIntoViewIfNeeded(bool centerIfNeeded = true);
66
67 void scrollByUnits(int units, ScrollGranularity);
68 void scrollByLines(int lines);
69 void scrollByPages(int pages);
70
71 int offsetLeft();
72 int offsetTop();
73 int offsetWidth();
74 int offsetHeight();
75 Element* offsetParent();
76 int clientLeft();
77 int clientTop();
78 int clientWidth();
79 int clientHeight();
80 int scrollLeft();
81 int scrollTop();
82 void setScrollLeft(int);
83 void setScrollTop(int);
84 int scrollWidth();
85 int scrollHeight();
86
87 void removeAttribute(const String& name, ExceptionCode&);
88 void removeAttributeNS(const String& namespaceURI, const String& localName, ExceptionCode&);
89
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&);
95
96 virtual CSSStyleDeclaration* style();
97
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); }
101
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(); }
105
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(); }
110
111 virtual KURL baseURI() const;
112
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);
120
121 PassRefPtr<Element> cloneElement();
122
123 void normalizeAttributes();
124
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; }
129
130 String nodeNamePreservingCase() const;
131
132 // convenience methods which ignore exceptions
133 void setAttribute(const QualifiedName&, const AtomicString& value);
134 void setBooleanAttribute(const QualifiedName& name, bool);
135
136 virtual NamedAttrMap* attributes() const;
137 NamedAttrMap* attributes(bool readonly) const;
138
139 // This method is called whenever an attribute is added, changed or removed.
140 virtual void attributeChanged(Attribute*, bool preserveDecls = false);
141
142 // not part of the DOM
143 void setAttributeMap(PassRefPtr<NamedAttrMap>);
144
145 virtual void copyNonAttributeProperties(const Element* /*source*/) { }
146
147 virtual void attach();
148 virtual void detach();
149 virtual RenderObject* createRenderer(RenderArena*, RenderStyle*);
150 virtual void recalcStyle(StyleChange = NoChange);
151
152 virtual RenderStyle* computedStyle();
153
154 virtual bool childTypeAllowed(NodeType);
155
156 virtual PassRefPtr<Attribute> createAttribute(const QualifiedName&, const AtomicString& value);
157
158 void dispatchAttrRemovalEvent(Attribute*);
159 void dispatchAttrAdditionEvent(Attribute*);
160
161 virtual void accessKeyAction(bool /*sendToAnyEvent*/) { }
162
163 virtual bool isURLAttribute(Attribute*) const;
164 virtual const QualifiedName& imageSourceAttributeName() const;
165 virtual String target() const { return String(); }
166
167 virtual void focus(bool restorePreviousSelection = true);
168 virtual void updateFocusAppearance(bool restorePreviousSelection);
169 void blur();
170
171 #ifndef NDEBUG
172 virtual void formatForDebugger(char* buffer, unsigned length) const;
173 #endif
174
175 String innerText() const;
176 String outerText() const;
177
178 virtual String title() const;
179
180 EVisibility implicitVisibility();
181
182 String openTagStartToString() const;
183
184 void updateId(const AtomicString& oldId, const AtomicString& newId);
185
186 IntSize minimumSizeForResizing() const;
187 void setMinimumSizeForResizing(const IntSize&);
188
189 // Use Document::registerForDocumentActivationCallbacks() to subscribe to these
190 virtual void documentWillBecomeInactive() { }
191 virtual void documentDidBecomeActive() { }
192
193 // Use Document::registerForMediaVolumeCallbacks() to subscribe to this
194 virtual void mediaVolumeDidChange() { }
195
196 bool isFinishedParsingChildren() const { return m_parsingChildrenFinished; }
197 virtual void finishParsingChildren();
198 virtual void beginParsingChildren() { m_parsingChildrenFinished = false; }
199
200 // ElementTraversal API
201 Element* firstElementChild() const;
202 Element* lastElementChild() const;
203 Element* previousElementSibling() const;
204 Element* nextElementSibling() const;
205 unsigned childElementCount() const;
206
207 private:
208 virtual void createAttributeMap() const;
209
210 virtual void updateStyleAttribute() const {}
211
212 #if ENABLE(SVG)
213 virtual void updateAnimatedSVGAttribute(const String&) const {}
214 #endif
215
216 void updateFocusAppearanceSoonAfterAttach();
217 void cancelFocusAppearanceUpdate();
218
219 virtual const AtomicString& virtualPrefix() const { return prefix(); }
220 virtual const AtomicString& virtualLocalName() const { return localName(); }
221 virtual const AtomicString& virtualNamespaceURI() const { return namespaceURI(); }
222
223 QualifiedName m_tagName;
224 virtual NodeRareData* createRareData();
225
226 protected:
227 ElementRareData* rareData() const;
228 ElementRareData* ensureRareData();
229
230 mutable RefPtr<NamedAttrMap> namedAttrMap;
231 };
232
233 inline bool Node::hasTagName(const QualifiedName& name) const
234 {
235 return isElementNode() && static_cast<const Element*>(this)->hasTagName(name);
236 }
237
238 inline bool Node::hasAttributes() const
239 {
240 return isElementNode() && static_cast<const Element*>(this)->hasAttributes();
241 }
242
243 inline NamedAttrMap* Node::attributes() const
244 {
245 return isElementNode() ? static_cast<const Element*>(this)->attributes() : 0;
246 }
247
248 inline Element* Node::parentElement() const
249 {
250 Node* parent = parentNode();
251 return parent && parent->isElementNode() ? static_cast<Element*>(parent) : 0;
252 }
253
254 } //namespace
255
256 #endif