QtWebKit/qwebelement.h Source File

qwebelement.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies)
3 
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.
8 
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.
13 
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.
18 */
19 
20 #ifndef QWEBELEMENT_H
21 #define QWEBELEMENT_H
22 
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>
28 
29 #include "qwebkitglobal.h"
30 namespace WebCore {
31  class Element;
32  class Node;
33 }
34 
35 
36 #if defined(WTF_USE_V8) && WTF_USE_V8
37 namespace V8 {
38  namespace Bindings {
39  class QtWebElementRuntime;
40  }
41 }
42 #else
43 namespace JSC {
44  namespace Bindings {
45  class QtWebElementRuntime;
46  }
47 }
48 #endif
49 
51 class QPainter;
53 
54 class QWebFrame;
56 class QWebElementPrivate;
57 
59 public:
60  QWebElement();
61  QWebElement(const QWebElement&);
62  QWebElement &operator=(const QWebElement&);
63  ~QWebElement();
64 
65  bool operator==(const QWebElement& o) const;
66  bool operator!=(const QWebElement& o) const;
67 
68  bool isNull() const;
69 
70  QWebElementCollection findAll(const QString &selectorQuery) const;
71  QWebElement findFirst(const QString &selectorQuery) const;
72 
73  void setPlainText(const QString& text);
74  QString toPlainText() const;
75 
76  void setOuterXml(const QString& markup);
77  QString toOuterXml() const;
78 
79  void setInnerXml(const QString& markup);
80  QString toInnerXml() const;
81 
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;
92 
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);
98 
99  bool hasFocus() const;
100  void setFocus();
101 
102  QRect geometry() const;
103 
104  QString tagName() const;
105  QString prefix() const;
106  QString localName() const;
107  QString namespaceUri() const;
108 
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;
116 
117  // TODO: Add QWebElementCollection overloads
118  // docs need example snippet
119  void appendInside(const QString& markup);
120  void appendInside(const QWebElement& element);
121 
122  // docs need example snippet
123  void prependInside(const QString& markup);
124  void prependInside(const QWebElement& element);
125 
126  // docs need example snippet
127  void appendOutside(const QString& markup);
128  void appendOutside(const QWebElement& element);
129 
130  // docs need example snippet
131  void prependOutside(const QString& markup);
132  void prependOutside(const QWebElement& element);
133 
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);
139 
140  void replace(const QString& markup);
141  void replace(const QWebElement& element);
142 
143  QWebElement clone() const;
144  QWebElement& takeFromDocument();
145  void removeFromDocument();
146  void removeAllChildren();
147 
148  QVariant evaluateJavaScript(const QString& scriptSource);
149 
154  };
155  QString styleProperty(const QString& name, StyleResolveStrategy strategy) const;
156  void setStyleProperty(const QString& name, const QString& value);
157 
158  void render(QPainter* painter);
159  void render(QPainter* painter, const QRect& clipRect);
160 
161 private:
162  explicit QWebElement(WebCore::Element*);
163  explicit QWebElement(WebCore::Node*);
164 
165  static QWebElement enclosingElement(WebCore::Node*);
166 
167  friend class DumpRenderTreeSupportQt;
168  friend class QWebFrame;
169  friend class QWebElementCollection;
170  friend class QWebHitTestResult;
171  friend class QWebHitTestResultPrivate;
172  friend class QWebPage;
173 
174 #if defined(WTF_USE_V8) && WTF_USE_V8
175  friend class V8::Bindings::QtWebElementRuntime;
176 #else
177  friend class JSC::Bindings::QtWebElementRuntime;
178 #endif
179 
180  QWebElementPrivate* d;
181  WebCore::Element* m_element;
182 };
183 
184 class QWebElementCollectionPrivate;
185 
187 {
188 public:
190  QWebElementCollection(const QWebElement &contextElement, const QString &query);
192  QWebElementCollection &operator=(const QWebElementCollection &);
194 
197  {
198  append(other); return *this;
199  }
200 
201  void append(const QWebElementCollection &collection);
202 
203  int count() const;
204  QWebElement at(int i) const;
205  inline QWebElement operator[](int i) const { return at(i); }
206 
207  inline QWebElement first() const { return at(0); }
208  inline QWebElement last() const { return at(count() - 1); }
209 
210  QList<QWebElement> toList() const;
211 
213  public:
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) {}
216 
217  inline const QWebElement operator*() const { return collection->at(i); }
218 
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; }
225 
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; }
235  private:
236  int i;
237  const QWebElementCollection* const collection;
238  };
239  friend class const_iterator;
240 
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()); };
245 
246  class iterator {
247  public:
248  inline iterator(const QWebElementCollection* collection, int index) : i(index), collection(collection) {}
249  inline iterator(const iterator& o) : i(o.i), collection(o.collection) {}
250 
251  inline QWebElement operator*() const { return collection->at(i); }
252 
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; }
259 
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; }
269  private:
270  int i;
271  const QWebElementCollection* const collection;
272  };
273  friend class iterator;
274 
275  inline iterator begin() { return iterator(this, 0); }
276  inline iterator end() { return iterator(this, count()); }
277 private:
279 };
280 
282 
283 #endif // QWEBELEMENT_H
#define QT_END_NAMESPACE
Definition: qglobal.h:128
bool operator==(const iterator &o) const
Definition: qwebelement.h:253
int operator-(iterator j) const
Definition: qwebelement.h:268
QWebElement first() const
Definition: qwebelement.h:207
iterator(const QWebElementCollection *collection, int index)
Definition: qwebelement.h:248
iterator & operator-=(int j)
Definition: qwebelement.h:265
int operator-(const_iterator j) const
Definition: qwebelement.h:234
const_iterator constEnd() const
Definition: qwebelement.h:244
iterator operator-(int j) const
Definition: qwebelement.h:267
bool operator>(const const_iterator &o) const
Definition: qwebelement.h:223
iterator operator+(int j) const
Definition: qwebelement.h:266
#define Q_DECLARE_METATYPE(TYPE)
Definition: qmetatype.h:265
QWebElement operator*() const
Definition: qwebelement.h:251
bool operator<=(const iterator &o) const
Definition: qwebelement.h:256
const_iterator(const const_iterator &o)
Definition: qwebelement.h:215
bool operator==(const Attribute &cA, const AttributeInstance< type > &cB)
This operator compares the two attributes and NOT their values.
Definition: node.h:577
iterator(const iterator &o)
Definition: qwebelement.h:249
#define QT_BEGIN_NAMESPACE
Definition: qglobal.h:127
bool operator!=(const iterator &o) const
Definition: qwebelement.h:254
const_iterator end() const
Definition: qwebelement.h:242
const QByteArray operator+(const QByteArray &a1, const QByteArray &a2)
Definition: qbytearray.h:564
GLuint GLuint GLsizei count
Definition: GLee.h:872
const_iterator operator+(int j) const
Definition: qwebelement.h:232
GLenum GLsizei n
Definition: GLee.h:3432
const_iterator & operator+=(int j)
Definition: qwebelement.h:230
bool operator!=(const QByteArray &a1, const QByteArray &a2)
Definition: qbytearray.h:533
QWebElement last() const
Definition: qwebelement.h:208
bool operator==(const const_iterator &o) const
Definition: qwebelement.h:219
const_iterator constBegin() const
Definition: qwebelement.h:243
iterator & operator+=(int j)
Definition: qwebelement.h:264
GLsizei const GLfloat * value
Definition: GLee.h:1742
Definition: qrect.h:58
GLuint const GLchar * name
Definition: GLee.h:1704
const_iterator begin() const
Definition: qwebelement.h:241
bool operator<(const iterator &o) const
Definition: qwebelement.h:255
GLXFBConfig int attribute
Definition: GLee.h:10233
const QWebElement operator*() const
Definition: qwebelement.h:217
bool operator<(const const_iterator &o) const
Definition: qwebelement.h:221
bool operator>(const iterator &o) const
Definition: qwebelement.h:257
bool operator!=(const const_iterator &o) const
Definition: qwebelement.h:220
bool operator<=(const const_iterator &o) const
Definition: qwebelement.h:222
QWebElementCollection & operator+=(const QWebElementCollection &other)
Definition: qwebelement.h:196
bool operator>=(const iterator &o) const
Definition: qwebelement.h:258
bool operator>=(const const_iterator &o) const
Definition: qwebelement.h:224
const_iterator(const QWebElementCollection *collection, int index)
Definition: qwebelement.h:214
QWebElement operator[](int i) const
Definition: qwebelement.h:205
const_iterator operator-(int j) const
Definition: qwebelement.h:233
const_iterator & operator-=(int j)
Definition: qwebelement.h:231
GLuint index
Definition: GLee.h:1704
#define QWEBKIT_EXPORT
Definition: qwebkitglobal.h:45