2 Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies)
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
23 #include <QtCore/qstring.h>
24 #include <QtCore/qstringlist.h>
25 #include <QtCore/qrect.h>
26 #include <QtCore/qvariant.h>
27 #include <QtCore/qshareddata.h>
29 #include "qwebkitglobal.h"
36 #if defined(WTF_USE_V8) && WTF_USE_V8
39 class QtWebElementRuntime;
45 class QtWebElementRuntime;
55 class QWebElementCollection;
56 class QWebElementPrivate;
58 class QWEBKIT_EXPORT QWebElement {
61 QWebElement(const QWebElement&);
62 QWebElement &operator=(const QWebElement&);
65 bool operator==(const QWebElement& o) const;
66 bool operator!=(const QWebElement& o) const;
70 QWebElementCollection findAll(const QString &selectorQuery) const;
71 QWebElement findFirst(const QString &selectorQuery) const;
73 void setPlainText(const QString& text);
74 QString toPlainText() const;
76 void setOuterXml(const QString& markup);
77 QString toOuterXml() const;
79 void setInnerXml(const QString& markup);
80 QString toInnerXml() const;
82 void setAttribute(const QString& name, const QString& value);
83 void setAttributeNS(const QString& namespaceUri, const QString& name, const QString& value);
84 QString attribute(const QString& name, const QString& defaultValue = QString()) const;
85 QString attributeNS(const QString& namespaceUri, const QString& name, const QString& defaultValue = QString()) const;
86 bool hasAttribute(const QString& name) const;
87 bool hasAttributeNS(const QString& namespaceUri, const QString& name) const;
88 void removeAttribute(const QString& name);
89 void removeAttributeNS(const QString& namespaceUri, const QString& name);
90 bool hasAttributes() const;
91 QStringList attributeNames(const QString& namespaceUri = QString()) const;
93 QStringList classes() const;
94 bool hasClass(const QString& name) const;
95 void addClass(const QString& name);
96 void removeClass(const QString& name);
97 void toggleClass(const QString& name);
99 bool hasFocus() const;
102 QRect geometry() const;
104 QString tagName() const;
105 QString prefix() const;
106 QString localName() const;
107 QString namespaceUri() const;
109 QWebElement parent() const;
110 QWebElement firstChild() const;
111 QWebElement lastChild() const;
112 QWebElement nextSibling() const;
113 QWebElement previousSibling() const;
114 QWebElement document() const;
115 QWebFrame *webFrame() const;
117 // TODO: Add QWebElementCollection overloads
118 // docs need example snippet
119 void appendInside(const QString& markup);
120 void appendInside(const QWebElement& element);
122 // docs need example snippet
123 void prependInside(const QString& markup);
124 void prependInside(const QWebElement& element);
126 // docs need example snippet
127 void appendOutside(const QString& markup);
128 void appendOutside(const QWebElement& element);
130 // docs need example snippet
131 void prependOutside(const QString& markup);
132 void prependOutside(const QWebElement& element);
134 // docs need example snippet
135 void encloseContentsWith(const QWebElement& element);
136 void encloseContentsWith(const QString& markup);
137 void encloseWith(const QString& markup);
138 void encloseWith(const QWebElement& element);
140 void replace(const QString& markup);
141 void replace(const QWebElement& element);
143 QWebElement clone() const;
144 QWebElement& takeFromDocument();
145 void removeFromDocument();
146 void removeAllChildren();
148 QVariant evaluateJavaScript(const QString& scriptSource);
150 enum StyleResolveStrategy {
155 QString styleProperty(const QString& name, StyleResolveStrategy strategy) const;
156 void setStyleProperty(const QString& name, const QString& value);
158 void render(QPainter* painter);
159 void render(QPainter* painter, const QRect& clipRect);
162 explicit QWebElement(WebCore::Element*);
163 explicit QWebElement(WebCore::Node*);
165 static QWebElement enclosingElement(WebCore::Node*);
167 friend class DumpRenderTreeSupportQt;
168 friend class QWebFrame;
169 friend class QWebElementCollection;
170 friend class QWebHitTestResult;
171 friend class QWebHitTestResultPrivate;
172 friend class QWebPage;
174 #if defined(WTF_USE_V8) && WTF_USE_V8
175 friend class V8::Bindings::QtWebElementRuntime;
177 friend class JSC::Bindings::QtWebElementRuntime;
180 QWebElementPrivate* d;
181 WebCore::Element* m_element;
184 class QWebElementCollectionPrivate;
186 class QWEBKIT_EXPORT QWebElementCollection
189 QWebElementCollection();
190 QWebElementCollection(const QWebElement &contextElement, const QString &query);
191 QWebElementCollection(const QWebElementCollection &);
192 QWebElementCollection &operator=(const QWebElementCollection &);
193 ~QWebElementCollection();
195 QWebElementCollection operator+(const QWebElementCollection &other) const;
196 inline QWebElementCollection &operator+=(const QWebElementCollection &other)
198 append(other); return *this;
201 void append(const QWebElementCollection &collection);
204 QWebElement at(int i) const;
205 inline QWebElement operator[](int i) const { return at(i); }
207 inline QWebElement first() const { return at(0); }
208 inline QWebElement last() const { return at(count() - 1); }
210 QList<QWebElement> toList() const;
212 class const_iterator {
214 inline const_iterator(const QWebElementCollection* collection, int index) : i(index), collection(collection) {}
215 inline const_iterator(const const_iterator& o) : i(o.i), collection(o.collection) {}
217 inline const QWebElement operator*() const { return collection->at(i); }
219 inline bool operator==(const const_iterator& o) const { return i == o.i && collection == o.collection; }
220 inline bool operator!=(const const_iterator& o) const { return i != o.i || collection != o.collection; }
221 inline bool operator<(const const_iterator& o) const { return i < o.i; }
222 inline bool operator<=(const const_iterator& o) const { return i <= o.i; }
223 inline bool operator>(const const_iterator& o) const { return i > o.i; }
224 inline bool operator>=(const const_iterator& o) const { return i >= o.i; }
226 inline const_iterator& operator++() { ++i; return *this; }
227 inline const_iterator operator++(int) { const_iterator n(collection, i); ++i; return n; }
228 inline const_iterator& operator--() { i--; return *this; }
229 inline const_iterator operator--(int) { const_iterator n(collection, i); i--; return n; }
230 inline const_iterator& operator+=(int j) { i += j; return *this; }
231 inline const_iterator& operator-=(int j) { i -= j; return *this; }
232 inline const_iterator operator+(int j) const { return const_iterator(collection, i + j); }
233 inline const_iterator operator-(int j) const { return const_iterator(collection, i - j); }
234 inline int operator-(const_iterator j) const { return i - j.i; }
237 const QWebElementCollection* const collection;
239 friend class const_iterator;
241 inline const_iterator begin() const { return constBegin(); }
242 inline const_iterator end() const { return constEnd(); }
243 inline const_iterator constBegin() const { return const_iterator(this, 0); }
244 inline const_iterator constEnd() const { return const_iterator(this, count()); };
248 inline iterator(const QWebElementCollection* collection, int index) : i(index), collection(collection) {}
249 inline iterator(const iterator& o) : i(o.i), collection(o.collection) {}
251 inline QWebElement operator*() const { return collection->at(i); }
253 inline bool operator==(const iterator& o) const { return i == o.i && collection == o.collection; }
254 inline bool operator!=(const iterator& o) const { return i != o.i || collection != o.collection; }
255 inline bool operator<(const iterator& o) const { return i < o.i; }
256 inline bool operator<=(const iterator& o) const { return i <= o.i; }
257 inline bool operator>(const iterator& o) const { return i > o.i; }
258 inline bool operator>=(const iterator& o) const { return i >= o.i; }
260 inline iterator& operator++() { ++i; return *this; }
261 inline iterator operator++(int) { iterator n(collection, i); ++i; return n; }
262 inline iterator& operator--() { i--; return *this; }
263 inline iterator operator--(int) { iterator n(collection, i); i--; return n; }
264 inline iterator& operator+=(int j) { i += j; return *this; }
265 inline iterator& operator-=(int j) { i -= j; return *this; }
266 inline iterator operator+(int j) const { return iterator(collection, i + j); }
267 inline iterator operator-(int j) const { return iterator(collection, i - j); }
268 inline int operator-(iterator j) const { return i - j.i; }
271 const QWebElementCollection* const collection;
273 friend class iterator;
275 inline iterator begin() { return iterator(this, 0); }
276 inline iterator end() { return iterator(this, count()); }
278 QExplicitlySharedDataPointer<QWebElementCollectionPrivate> d;
281 Q_DECLARE_METATYPE(QWebElement)
283 #endif // QWEBELEMENT_H