| 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 | #include "config.h"
|
|---|
| 21 | #include "qwebelement.h"
|
|---|
| 22 |
|
|---|
| 23 | #include "CSSComputedStyleDeclaration.h"
|
|---|
| 24 | #include "CSSMutableStyleDeclaration.h"
|
|---|
| 25 | #include "CSSParser.h"
|
|---|
| 26 | #include "CSSRule.h"
|
|---|
| 27 | #include "CSSRuleList.h"
|
|---|
| 28 | #include "CSSStyleRule.h"
|
|---|
| 29 | #include "CString.h"
|
|---|
| 30 | #include "Document.h"
|
|---|
| 31 | #include "DocumentFragment.h"
|
|---|
| 32 | #include "FrameView.h"
|
|---|
| 33 | #include "GraphicsContext.h"
|
|---|
| 34 | #include "HTMLElement.h"
|
|---|
| 35 | #include "JSGlobalObject.h"
|
|---|
| 36 | #include "JSHTMLElement.h"
|
|---|
| 37 | #include "JSObject.h"
|
|---|
| 38 | #include "NodeList.h"
|
|---|
| 39 | #include "PropertyNameArray.h"
|
|---|
| 40 | #include "RenderImage.h"
|
|---|
| 41 | #include "StaticNodeList.h"
|
|---|
| 42 | #include "qt_runtime.h"
|
|---|
| 43 | #include "qwebframe.h"
|
|---|
| 44 | #include "qwebframe_p.h"
|
|---|
| 45 | #include "runtime_root.h"
|
|---|
| 46 | #include <parser/SourceCode.h>
|
|---|
| 47 | #include <wtf/Vector.h>
|
|---|
| 48 |
|
|---|
| 49 | #include <QPainter>
|
|---|
| 50 |
|
|---|
| 51 | using namespace WebCore;
|
|---|
| 52 |
|
|---|
| 53 | class QWebElementPrivate {
|
|---|
| 54 | public:
|
|---|
| 55 | };
|
|---|
| 56 |
|
|---|
| 57 | /*!
|
|---|
| 58 | \class QWebElement
|
|---|
| 59 | \since 4.6
|
|---|
| 60 | \brief The QWebElement class provides convenient access to DOM elements in
|
|---|
| 61 | a QWebFrame.
|
|---|
| 62 | \inmodule QtWebKit
|
|---|
| 63 |
|
|---|
| 64 | A QWebElement object allows easy access to the document model, represented
|
|---|
| 65 | by a tree-like structure of DOM elements. The root of the tree is called
|
|---|
| 66 | the document element and can be accessed using
|
|---|
| 67 | QWebFrame::documentElement().
|
|---|
| 68 |
|
|---|
| 69 | Specific elements can be accessed using findAll() and findFirst(). These
|
|---|
| 70 | elements are identified using CSS selectors. The code snippet below
|
|---|
| 71 | demonstrates the use of findAll().
|
|---|
| 72 |
|
|---|
| 73 | \snippet webkitsnippets/webelement/main.cpp FindAll
|
|---|
| 74 |
|
|---|
| 75 | The first list contains all \c span elements in the document. The second
|
|---|
| 76 | list contains \c span elements that are children of \c p, classified with
|
|---|
| 77 | \c intro.
|
|---|
| 78 |
|
|---|
| 79 | Using findFirst() is more efficient than calling findAll(), and extracting
|
|---|
| 80 | the first element only in the list returned.
|
|---|
| 81 |
|
|---|
| 82 | Alternatively you can traverse the document manually using firstChild() and
|
|---|
| 83 | nextSibling():
|
|---|
| 84 |
|
|---|
| 85 | \snippet webkitsnippets/webelement/main.cpp Traversing with QWebElement
|
|---|
| 86 |
|
|---|
| 87 | Individual elements can be inspected or changed using methods such as attribute()
|
|---|
| 88 | or setAttribute(). For examle, to capture the user's input in a text field for later
|
|---|
| 89 | use (auto-completion), a browser could do something like this:
|
|---|
| 90 |
|
|---|
| 91 | \snippet webkitsnippets/webelement/main.cpp autocomplete1
|
|---|
| 92 |
|
|---|
| 93 | When the same page is later revisited, the browser can fill in the text field automatically
|
|---|
| 94 | by modifying the value attribute of the input element:
|
|---|
| 95 |
|
|---|
| 96 | \snippet webkitsnippets/webelement/main.cpp autocomplete2
|
|---|
| 97 |
|
|---|
| 98 | Another use case is to emulate a click event on an element. The following
|
|---|
| 99 | code snippet demonstrates how to call the JavaScript DOM method click() of
|
|---|
| 100 | a submit button:
|
|---|
| 101 |
|
|---|
| 102 | \snippet webkitsnippets/webelement/main.cpp Calling a DOM element method
|
|---|
| 103 |
|
|---|
| 104 | The underlying content of QWebElement is explicitly shared. Creating a copy
|
|---|
| 105 | of a QWebElement does not create a copy of the content. Instead, both
|
|---|
| 106 | instances point to the same element.
|
|---|
| 107 |
|
|---|
| 108 | The contents of child elements can be converted to plain text with
|
|---|
| 109 | toPlainText(); to XHTML using toInnerXml(). To include the element's tag in
|
|---|
| 110 | the output, use toOuterXml().
|
|---|
| 111 |
|
|---|
| 112 | It is possible to replace the contents of child elements using
|
|---|
| 113 | setPlainText() and setInnerXml(). To replace the element itself and its
|
|---|
| 114 | contents, use setOuterXml().
|
|---|
| 115 |
|
|---|
| 116 | \section1 Examples
|
|---|
| 117 |
|
|---|
| 118 | The \l{DOM Traversal Example} shows one way to traverse documents in a running
|
|---|
| 119 | example.
|
|---|
| 120 |
|
|---|
| 121 | The \l{Simple Selector Example} can be used to experiment with the searching
|
|---|
| 122 | features of this class and provides sample code you can start working with.
|
|---|
| 123 | */
|
|---|
| 124 |
|
|---|
| 125 | /*!
|
|---|
| 126 | Constructs a null web element.
|
|---|
| 127 | */
|
|---|
| 128 | QWebElement::QWebElement()
|
|---|
| 129 | : d(0)
|
|---|
| 130 | , m_element(0)
|
|---|
| 131 | {
|
|---|
| 132 | }
|
|---|
| 133 |
|
|---|
| 134 | /*!
|
|---|
| 135 | \internal
|
|---|
| 136 | */
|
|---|
| 137 | QWebElement::QWebElement(WebCore::Element* domElement)
|
|---|
| 138 | : d(0)
|
|---|
| 139 | , m_element(domElement)
|
|---|
| 140 | {
|
|---|
| 141 | if (m_element)
|
|---|
| 142 | m_element->ref();
|
|---|
| 143 | }
|
|---|
| 144 |
|
|---|
| 145 | /*!
|
|---|
| 146 | \internal
|
|---|
| 147 | */
|
|---|
| 148 | QWebElement::QWebElement(WebCore::Node* node)
|
|---|
| 149 | : d(0)
|
|---|
| 150 | , m_element(0)
|
|---|
| 151 | {
|
|---|
| 152 | if (node && node->isHTMLElement()) {
|
|---|
| 153 | m_element = static_cast<HTMLElement*>(node);
|
|---|
| 154 | m_element->ref();
|
|---|
| 155 | }
|
|---|
| 156 | }
|
|---|
| 157 |
|
|---|
| 158 | /*!
|
|---|
| 159 | Constructs a copy of \a other.
|
|---|
| 160 | */
|
|---|
| 161 | QWebElement::QWebElement(const QWebElement &other)
|
|---|
| 162 | : d(0)
|
|---|
| 163 | , m_element(other.m_element)
|
|---|
| 164 | {
|
|---|
| 165 | if (m_element)
|
|---|
| 166 | m_element->ref();
|
|---|
| 167 | }
|
|---|
| 168 |
|
|---|
| 169 | /*!
|
|---|
| 170 | Assigns \a other to this element and returns a reference to this element.
|
|---|
| 171 | */
|
|---|
| 172 | QWebElement &QWebElement::operator=(const QWebElement &other)
|
|---|
| 173 | {
|
|---|
| 174 | // ### handle "d" assignment
|
|---|
| 175 | if (this != &other) {
|
|---|
| 176 | Element *otherElement = other.m_element;
|
|---|
| 177 | if (otherElement)
|
|---|
| 178 | otherElement->ref();
|
|---|
| 179 | if (m_element)
|
|---|
| 180 | m_element->deref();
|
|---|
| 181 | m_element = otherElement;
|
|---|
| 182 | }
|
|---|
| 183 | return *this;
|
|---|
| 184 | }
|
|---|
| 185 |
|
|---|
| 186 | /*!
|
|---|
| 187 | Destroys the element. However, the underlying DOM element is not destroyed.
|
|---|
| 188 | */
|
|---|
| 189 | QWebElement::~QWebElement()
|
|---|
| 190 | {
|
|---|
| 191 | delete d;
|
|---|
| 192 | if (m_element)
|
|---|
| 193 | m_element->deref();
|
|---|
| 194 | }
|
|---|
| 195 |
|
|---|
| 196 | bool QWebElement::operator==(const QWebElement& o) const
|
|---|
| 197 | {
|
|---|
| 198 | return m_element == o.m_element;
|
|---|
| 199 | }
|
|---|
| 200 |
|
|---|
| 201 | bool QWebElement::operator!=(const QWebElement& o) const
|
|---|
| 202 | {
|
|---|
| 203 | return m_element != o.m_element;
|
|---|
| 204 | }
|
|---|
| 205 |
|
|---|
| 206 | /*!
|
|---|
| 207 | Returns true if the element is a null element; otherwise returns false.
|
|---|
| 208 | */
|
|---|
| 209 | bool QWebElement::isNull() const
|
|---|
| 210 | {
|
|---|
| 211 | return !m_element;
|
|---|
| 212 | }
|
|---|
| 213 |
|
|---|
| 214 | /*!
|
|---|
| 215 | Returns a new list of child elements matching the given CSS selector
|
|---|
| 216 | \a selectorQuery. If there are no matching elements, an empty list is
|
|---|
| 217 | returned.
|
|---|
| 218 |
|
|---|
| 219 | \l{Standard CSS2 selector} syntax is used for the query.
|
|---|
| 220 |
|
|---|
| 221 | \note This search is performed recursively.
|
|---|
| 222 |
|
|---|
| 223 | \sa findFirst()
|
|---|
| 224 | */
|
|---|
| 225 | QWebElementCollection QWebElement::findAll(const QString &selectorQuery) const
|
|---|
| 226 | {
|
|---|
| 227 | return QWebElementCollection(*this, selectorQuery);
|
|---|
| 228 | }
|
|---|
| 229 |
|
|---|
| 230 | /*!
|
|---|
| 231 | Returns the first child element that matches the given CSS selector
|
|---|
| 232 | \a selectorQuery.
|
|---|
| 233 |
|
|---|
| 234 | \l{Standard CSS2 selector} syntax is used for the query.
|
|---|
| 235 |
|
|---|
| 236 | \note This search is performed recursively.
|
|---|
| 237 |
|
|---|
| 238 | \sa findAll()
|
|---|
| 239 | */
|
|---|
| 240 | QWebElement QWebElement::findFirst(const QString &selectorQuery) const
|
|---|
| 241 | {
|
|---|
| 242 | if (!m_element)
|
|---|
| 243 | return QWebElement();
|
|---|
| 244 | ExceptionCode exception = 0; // ###
|
|---|
| 245 | return QWebElement(m_element->querySelector(selectorQuery, exception).get());
|
|---|
| 246 | }
|
|---|
| 247 |
|
|---|
| 248 | /*!
|
|---|
| 249 | Replaces the existing content of this element with \a text.
|
|---|
| 250 |
|
|---|
| 251 | This is equivalent to setting the HTML innerText property.
|
|---|
| 252 |
|
|---|
| 253 | \sa toPlainText()
|
|---|
| 254 | */
|
|---|
| 255 | void QWebElement::setPlainText(const QString &text)
|
|---|
| 256 | {
|
|---|
| 257 | if (!m_element || !m_element->isHTMLElement())
|
|---|
| 258 | return;
|
|---|
| 259 | ExceptionCode exception = 0;
|
|---|
| 260 | static_cast<HTMLElement*>(m_element)->setInnerText(text, exception);
|
|---|
| 261 | }
|
|---|
| 262 |
|
|---|
| 263 | /*!
|
|---|
| 264 | Returns the text between the start and the end tag of this
|
|---|
| 265 | element.
|
|---|
| 266 |
|
|---|
| 267 | This is equivalent to reading the HTML innerText property.
|
|---|
| 268 |
|
|---|
| 269 | \sa setPlainText()
|
|---|
| 270 | */
|
|---|
| 271 | QString QWebElement::toPlainText() const
|
|---|
| 272 | {
|
|---|
| 273 | if (!m_element || !m_element->isHTMLElement())
|
|---|
| 274 | return QString();
|
|---|
| 275 | return static_cast<HTMLElement*>(m_element)->innerText();
|
|---|
| 276 | }
|
|---|
| 277 |
|
|---|
| 278 | /*!
|
|---|
| 279 | Replaces the contents of this element as well as its own tag with
|
|---|
| 280 | \a markup. The string may contain HTML or XML tags, which is parsed and
|
|---|
| 281 | formatted before insertion into the document.
|
|---|
| 282 |
|
|---|
| 283 | \note This is currently only implemented for (X)HTML elements.
|
|---|
| 284 |
|
|---|
| 285 | \sa toOuterXml(), toInnerXml(), setInnerXml()
|
|---|
| 286 | */
|
|---|
| 287 | void QWebElement::setOuterXml(const QString &markup)
|
|---|
| 288 | {
|
|---|
| 289 | if (!m_element || !m_element->isHTMLElement())
|
|---|
| 290 | return;
|
|---|
| 291 |
|
|---|
| 292 | ExceptionCode exception = 0;
|
|---|
| 293 |
|
|---|
| 294 | static_cast<HTMLElement*>(m_element)->setOuterHTML(markup, exception);
|
|---|
| 295 | }
|
|---|
| 296 |
|
|---|
| 297 | /*!
|
|---|
| 298 | Returns this element converted to XML, including the start and the end
|
|---|
| 299 | tags as well as its attributes.
|
|---|
| 300 |
|
|---|
| 301 | \note This is currently implemented for (X)HTML elements only.
|
|---|
| 302 |
|
|---|
| 303 | \sa setOuterXml(), setInnerXml(), toInnerXml()
|
|---|
| 304 | */
|
|---|
| 305 | QString QWebElement::toOuterXml() const
|
|---|
| 306 | {
|
|---|
| 307 | if (!m_element || !m_element->isHTMLElement())
|
|---|
| 308 | return QString();
|
|---|
| 309 |
|
|---|
| 310 | return static_cast<HTMLElement*>(m_element)->outerHTML();
|
|---|
| 311 | }
|
|---|
| 312 |
|
|---|
| 313 | /*!
|
|---|
| 314 | Replaces the contents of this element with \a markup. The string may
|
|---|
| 315 | contain HTML or XML tags, which is parsed and formatted before insertion
|
|---|
| 316 | into the document.
|
|---|
| 317 |
|
|---|
| 318 | \note This is currently implemented for (X)HTML elements only.
|
|---|
| 319 |
|
|---|
| 320 | \sa toInnerXml(), toOuterXml(), setOuterXml()
|
|---|
| 321 | */
|
|---|
| 322 | void QWebElement::setInnerXml(const QString &markup)
|
|---|
| 323 | {
|
|---|
| 324 | if (!m_element || !m_element->isHTMLElement())
|
|---|
| 325 | return;
|
|---|
| 326 |
|
|---|
| 327 | ExceptionCode exception = 0;
|
|---|
| 328 |
|
|---|
| 329 | static_cast<HTMLElement*>(m_element)->setInnerHTML(markup, exception);
|
|---|
| 330 | }
|
|---|
| 331 |
|
|---|
| 332 | /*!
|
|---|
| 333 | Returns the XML content between the element's start and end tags.
|
|---|
| 334 |
|
|---|
| 335 | \note This is currently implemented for (X)HTML elements only.
|
|---|
| 336 |
|
|---|
| 337 | \sa setInnerXml(), setOuterXml(), toOuterXml()
|
|---|
| 338 | */
|
|---|
| 339 | QString QWebElement::toInnerXml() const
|
|---|
| 340 | {
|
|---|
| 341 | if (!m_element || !m_element->isHTMLElement())
|
|---|
| 342 | return QString();
|
|---|
| 343 |
|
|---|
| 344 | return static_cast<HTMLElement*>(m_element)->innerHTML();
|
|---|
| 345 | }
|
|---|
| 346 |
|
|---|
| 347 | /*!
|
|---|
| 348 | Adds an attribute with the given \a name and \a value. If an attribute with
|
|---|
| 349 | the same name exists, its value is replaced by \a value.
|
|---|
| 350 |
|
|---|
| 351 | \sa attribute(), attributeNS(), setAttributeNS()
|
|---|
| 352 | */
|
|---|
| 353 | void QWebElement::setAttribute(const QString &name, const QString &value)
|
|---|
| 354 | {
|
|---|
| 355 | if (!m_element)
|
|---|
| 356 | return;
|
|---|
| 357 | ExceptionCode exception = 0;
|
|---|
| 358 | m_element->setAttribute(name, value, exception);
|
|---|
| 359 | }
|
|---|
| 360 |
|
|---|
| 361 | /*!
|
|---|
| 362 | Adds an attribute with the given \a name in \a namespaceUri with \a value.
|
|---|
| 363 | If an attribute with the same name exists, its value is replaced by
|
|---|
| 364 | \a value.
|
|---|
| 365 |
|
|---|
| 366 | \sa attributeNS(), attribute(), setAttribute()
|
|---|
| 367 | */
|
|---|
| 368 | void QWebElement::setAttributeNS(const QString &namespaceUri, const QString &name, const QString &value)
|
|---|
| 369 | {
|
|---|
| 370 | if (!m_element)
|
|---|
| 371 | return;
|
|---|
| 372 | WebCore::ExceptionCode exception = 0;
|
|---|
| 373 | m_element->setAttributeNS(namespaceUri, name, value, exception);
|
|---|
| 374 | }
|
|---|
| 375 |
|
|---|
| 376 | /*!
|
|---|
| 377 | Returns the attribute with the given \a name. If the attribute does not
|
|---|
| 378 | exist, \a defaultValue is returned.
|
|---|
| 379 |
|
|---|
| 380 | \sa setAttribute(), setAttributeNS(), attributeNS()
|
|---|
| 381 | */
|
|---|
| 382 | QString QWebElement::attribute(const QString &name, const QString &defaultValue) const
|
|---|
| 383 | {
|
|---|
| 384 | if (!m_element)
|
|---|
| 385 | return QString();
|
|---|
| 386 | if (m_element->hasAttribute(name))
|
|---|
| 387 | return m_element->getAttribute(name);
|
|---|
| 388 | else
|
|---|
| 389 | return defaultValue;
|
|---|
| 390 | }
|
|---|
| 391 |
|
|---|
| 392 | /*!
|
|---|
| 393 | Returns the attribute with the given \a name in \a namespaceUri. If the
|
|---|
| 394 | attribute does not exist, \a defaultValue is returned.
|
|---|
| 395 |
|
|---|
| 396 | \sa setAttributeNS(), setAttribute(), attribute()
|
|---|
| 397 | */
|
|---|
| 398 | QString QWebElement::attributeNS(const QString &namespaceUri, const QString &name, const QString &defaultValue) const
|
|---|
| 399 | {
|
|---|
| 400 | if (!m_element)
|
|---|
| 401 | return QString();
|
|---|
| 402 | if (m_element->hasAttributeNS(namespaceUri, name))
|
|---|
| 403 | return m_element->getAttributeNS(namespaceUri, name);
|
|---|
| 404 | else
|
|---|
| 405 | return defaultValue;
|
|---|
| 406 | }
|
|---|
| 407 |
|
|---|
| 408 | /*!
|
|---|
| 409 | Returns true if this element has an attribute with the given \a name;
|
|---|
| 410 | otherwise returns false.
|
|---|
| 411 |
|
|---|
| 412 | \sa attribute(), setAttribute()
|
|---|
| 413 | */
|
|---|
| 414 | bool QWebElement::hasAttribute(const QString &name) const
|
|---|
| 415 | {
|
|---|
| 416 | if (!m_element)
|
|---|
| 417 | return false;
|
|---|
| 418 | return m_element->hasAttribute(name);
|
|---|
| 419 | }
|
|---|
| 420 |
|
|---|
| 421 | /*!
|
|---|
| 422 | Returns true if this element has an attribute with the given \a name, in
|
|---|
| 423 | \a namespaceUri; otherwise returns false.
|
|---|
| 424 |
|
|---|
| 425 | \sa attributeNS(), setAttributeNS()
|
|---|
| 426 | */
|
|---|
| 427 | bool QWebElement::hasAttributeNS(const QString &namespaceUri, const QString &name) const
|
|---|
| 428 | {
|
|---|
| 429 | if (!m_element)
|
|---|
| 430 | return false;
|
|---|
| 431 | return m_element->hasAttributeNS(namespaceUri, name);
|
|---|
| 432 | }
|
|---|
| 433 |
|
|---|
| 434 | /*!
|
|---|
| 435 | Removes the attribute with the given \a name from this element.
|
|---|
| 436 |
|
|---|
| 437 | \sa attribute(), setAttribute(), hasAttribute()
|
|---|
| 438 | */
|
|---|
| 439 | void QWebElement::removeAttribute(const QString &name)
|
|---|
| 440 | {
|
|---|
| 441 | if (!m_element)
|
|---|
| 442 | return;
|
|---|
| 443 | ExceptionCode exception = 0;
|
|---|
| 444 | m_element->removeAttribute(name, exception);
|
|---|
| 445 | }
|
|---|
| 446 |
|
|---|
| 447 | /*!
|
|---|
| 448 | Removes the attribute with the given \a name, in \a namespaceUri, from this
|
|---|
| 449 | element.
|
|---|
| 450 |
|
|---|
| 451 | \sa attributeNS(), setAttributeNS(), hasAttributeNS()
|
|---|
| 452 | */
|
|---|
| 453 | void QWebElement::removeAttributeNS(const QString &namespaceUri, const QString &name)
|
|---|
| 454 | {
|
|---|
| 455 | if (!m_element)
|
|---|
| 456 | return;
|
|---|
| 457 | WebCore::ExceptionCode exception = 0;
|
|---|
| 458 | m_element->removeAttributeNS(namespaceUri, name, exception);
|
|---|
| 459 | }
|
|---|
| 460 |
|
|---|
| 461 | /*!
|
|---|
| 462 | Returns true if the element has any attributes defined; otherwise returns
|
|---|
| 463 | false;
|
|---|
| 464 |
|
|---|
| 465 | \sa attribute(), setAttribute()
|
|---|
| 466 | */
|
|---|
| 467 | bool QWebElement::hasAttributes() const
|
|---|
| 468 | {
|
|---|
| 469 | if (!m_element)
|
|---|
| 470 | return false;
|
|---|
| 471 | return m_element->hasAttributes();
|
|---|
| 472 | }
|
|---|
| 473 |
|
|---|
| 474 | /*!
|
|---|
| 475 | Return the list of attributes for the namespace given as \a namespaceUri.
|
|---|
| 476 |
|
|---|
| 477 | \sa attribute(), setAttribute()
|
|---|
| 478 | */
|
|---|
| 479 | QStringList QWebElement::attributeNames(const QString& namespaceUri) const
|
|---|
| 480 | {
|
|---|
| 481 | if (!m_element)
|
|---|
| 482 | return QStringList();
|
|---|
| 483 |
|
|---|
| 484 | QStringList attributeNameList;
|
|---|
| 485 | const NamedNodeMap* const attrs = m_element->attributes(/* read only = */ true);
|
|---|
| 486 | if (attrs) {
|
|---|
| 487 | const String namespaceUriString(namespaceUri); // convert QString -> String once
|
|---|
| 488 | const unsigned attrsCount = attrs->length();
|
|---|
| 489 | for (unsigned i = 0; i < attrsCount; ++i) {
|
|---|
| 490 | const Attribute* const attribute = attrs->attributeItem(i);
|
|---|
| 491 | if (namespaceUriString == attribute->namespaceURI())
|
|---|
| 492 | attributeNameList.append(attribute->localName());
|
|---|
| 493 | }
|
|---|
| 494 | }
|
|---|
| 495 | return attributeNameList;
|
|---|
| 496 | }
|
|---|
| 497 |
|
|---|
| 498 | /*!
|
|---|
| 499 | Returns true if the element has keyboard input focus; otherwise, returns false
|
|---|
| 500 |
|
|---|
| 501 | \sa setFocus()
|
|---|
| 502 | */
|
|---|
| 503 | bool QWebElement::hasFocus() const
|
|---|
| 504 | {
|
|---|
| 505 | if (!m_element)
|
|---|
| 506 | return false;
|
|---|
| 507 | if (m_element->document())
|
|---|
| 508 | return m_element == m_element->document()->focusedNode();
|
|---|
| 509 | return false;
|
|---|
| 510 | }
|
|---|
| 511 |
|
|---|
| 512 | /*!
|
|---|
| 513 | Gives keyboard input focus to this element
|
|---|
| 514 |
|
|---|
| 515 | \sa hasFocus()
|
|---|
| 516 | */
|
|---|
| 517 | void QWebElement::setFocus()
|
|---|
| 518 | {
|
|---|
| 519 | if (!m_element)
|
|---|
| 520 | return;
|
|---|
| 521 | if (m_element->document() && m_element->isFocusable())
|
|---|
| 522 | m_element->document()->setFocusedNode(m_element);
|
|---|
| 523 | }
|
|---|
| 524 |
|
|---|
| 525 | /*!
|
|---|
| 526 | Returns the geometry of this element, relative to its containing frame.
|
|---|
| 527 |
|
|---|
| 528 | \sa tagName()
|
|---|
| 529 | */
|
|---|
| 530 | QRect QWebElement::geometry() const
|
|---|
| 531 | {
|
|---|
| 532 | if (!m_element)
|
|---|
| 533 | return QRect();
|
|---|
| 534 | return m_element->getRect();
|
|---|
| 535 | }
|
|---|
| 536 |
|
|---|
| 537 | /*!
|
|---|
| 538 | Returns the tag name of this element.
|
|---|
| 539 |
|
|---|
| 540 | \sa geometry()
|
|---|
| 541 | */
|
|---|
| 542 | QString QWebElement::tagName() const
|
|---|
| 543 | {
|
|---|
| 544 | if (!m_element)
|
|---|
| 545 | return QString();
|
|---|
| 546 | return m_element->tagName();
|
|---|
| 547 | }
|
|---|
| 548 |
|
|---|
| 549 | /*!
|
|---|
| 550 | Returns the namespace prefix of the element. If the element has no\
|
|---|
| 551 | namespace prefix, empty string is returned.
|
|---|
| 552 | */
|
|---|
| 553 | QString QWebElement::prefix() const
|
|---|
| 554 | {
|
|---|
| 555 | if (!m_element)
|
|---|
| 556 | return QString();
|
|---|
| 557 | return m_element->prefix();
|
|---|
| 558 | }
|
|---|
| 559 |
|
|---|
| 560 | /*!
|
|---|
| 561 | Returns the local name of the element. If the element does not use
|
|---|
| 562 | namespaces, an empty string is returned.
|
|---|
| 563 | */
|
|---|
| 564 | QString QWebElement::localName() const
|
|---|
| 565 | {
|
|---|
| 566 | if (!m_element)
|
|---|
| 567 | return QString();
|
|---|
| 568 | return m_element->localName();
|
|---|
| 569 | }
|
|---|
| 570 |
|
|---|
| 571 | /*!
|
|---|
| 572 | Returns the namespace URI of this element. If the element has no namespace
|
|---|
| 573 | URI, an empty string is returned.
|
|---|
| 574 | */
|
|---|
| 575 | QString QWebElement::namespaceUri() const
|
|---|
| 576 | {
|
|---|
| 577 | if (!m_element)
|
|---|
| 578 | return QString();
|
|---|
| 579 | return m_element->namespaceURI();
|
|---|
| 580 | }
|
|---|
| 581 |
|
|---|
| 582 | /*!
|
|---|
| 583 | Returns the parent element of this elemen. If this element is the root
|
|---|
| 584 | document element, a null element is returned.
|
|---|
| 585 | */
|
|---|
| 586 | QWebElement QWebElement::parent() const
|
|---|
| 587 | {
|
|---|
| 588 | if (m_element)
|
|---|
| 589 | return QWebElement(m_element->parentElement());
|
|---|
| 590 | return QWebElement();
|
|---|
| 591 | }
|
|---|
| 592 |
|
|---|
| 593 | /*!
|
|---|
| 594 | Returns the element's first child.
|
|---|
| 595 |
|
|---|
| 596 | \sa lastChild(), previousSibling(), nextSibling()
|
|---|
| 597 | */
|
|---|
| 598 | QWebElement QWebElement::firstChild() const
|
|---|
| 599 | {
|
|---|
| 600 | if (!m_element)
|
|---|
| 601 | return QWebElement();
|
|---|
| 602 | for (Node* child = m_element->firstChild(); child; child = child->nextSibling()) {
|
|---|
| 603 | if (!child->isElementNode())
|
|---|
| 604 | continue;
|
|---|
| 605 | Element* e = static_cast<Element*>(child);
|
|---|
| 606 | return QWebElement(e);
|
|---|
| 607 | }
|
|---|
| 608 | return QWebElement();
|
|---|
| 609 | }
|
|---|
| 610 |
|
|---|
| 611 | /*!
|
|---|
| 612 | Returns the element's last child.
|
|---|
| 613 |
|
|---|
| 614 | \sa firstChild(), previousSibling(), nextSibling()
|
|---|
| 615 | */
|
|---|
| 616 | QWebElement QWebElement::lastChild() const
|
|---|
| 617 | {
|
|---|
| 618 | if (!m_element)
|
|---|
| 619 | return QWebElement();
|
|---|
| 620 | for (Node* child = m_element->lastChild(); child; child = child->previousSibling()) {
|
|---|
| 621 | if (!child->isElementNode())
|
|---|
| 622 | continue;
|
|---|
| 623 | Element* e = static_cast<Element*>(child);
|
|---|
| 624 | return QWebElement(e);
|
|---|
| 625 | }
|
|---|
| 626 | return QWebElement();
|
|---|
| 627 | }
|
|---|
| 628 |
|
|---|
| 629 | /*!
|
|---|
| 630 | Returns the element's next sibling.
|
|---|
| 631 |
|
|---|
| 632 | \sa firstChild(), previousSibling(), lastChild()
|
|---|
| 633 | */
|
|---|
| 634 | QWebElement QWebElement::nextSibling() const
|
|---|
| 635 | {
|
|---|
| 636 | if (!m_element)
|
|---|
| 637 | return QWebElement();
|
|---|
| 638 | for (Node* sib = m_element->nextSibling(); sib; sib = sib->nextSibling()) {
|
|---|
| 639 | if (!sib->isElementNode())
|
|---|
| 640 | continue;
|
|---|
| 641 | Element* e = static_cast<Element*>(sib);
|
|---|
| 642 | return QWebElement(e);
|
|---|
| 643 | }
|
|---|
| 644 | return QWebElement();
|
|---|
| 645 | }
|
|---|
| 646 |
|
|---|
| 647 | /*!
|
|---|
| 648 | Returns the element's previous sibling.
|
|---|
| 649 |
|
|---|
| 650 | \sa firstChild(), nextSibling(), lastChild()
|
|---|
| 651 | */
|
|---|
| 652 | QWebElement QWebElement::previousSibling() const
|
|---|
| 653 | {
|
|---|
| 654 | if (!m_element)
|
|---|
| 655 | return QWebElement();
|
|---|
| 656 | for (Node* sib = m_element->previousSibling(); sib; sib = sib->previousSibling()) {
|
|---|
| 657 | if (!sib->isElementNode())
|
|---|
| 658 | continue;
|
|---|
| 659 | Element* e = static_cast<Element*>(sib);
|
|---|
| 660 | return QWebElement(e);
|
|---|
| 661 | }
|
|---|
| 662 | return QWebElement();
|
|---|
| 663 | }
|
|---|
| 664 |
|
|---|
| 665 | /*!
|
|---|
| 666 | Returns the document which this element belongs to.
|
|---|
| 667 | */
|
|---|
| 668 | QWebElement QWebElement::document() const
|
|---|
| 669 | {
|
|---|
| 670 | if (!m_element)
|
|---|
| 671 | return QWebElement();
|
|---|
| 672 | Document* document = m_element->document();
|
|---|
| 673 | if (!document)
|
|---|
| 674 | return QWebElement();
|
|---|
| 675 | return QWebElement(document->documentElement());
|
|---|
| 676 | }
|
|---|
| 677 |
|
|---|
| 678 | /*!
|
|---|
| 679 | Returns the web frame which this element is a part of. If the element is a
|
|---|
| 680 | null element, null is returned.
|
|---|
| 681 | */
|
|---|
| 682 | QWebFrame *QWebElement::webFrame() const
|
|---|
| 683 | {
|
|---|
| 684 | if (!m_element)
|
|---|
| 685 | return 0;
|
|---|
| 686 |
|
|---|
| 687 | Document* document = m_element->document();
|
|---|
| 688 | if (!document)
|
|---|
| 689 | return 0;
|
|---|
| 690 |
|
|---|
| 691 | Frame* frame = document->frame();
|
|---|
| 692 | if (!frame)
|
|---|
| 693 | return 0;
|
|---|
| 694 | return QWebFramePrivate::kit(frame);
|
|---|
| 695 | }
|
|---|
| 696 |
|
|---|
| 697 | static bool setupScriptContext(WebCore::Element* element, JSC::JSValue& thisValue, ScriptState*& state, ScriptController*& scriptController)
|
|---|
| 698 | {
|
|---|
| 699 | if (!element)
|
|---|
| 700 | return false;
|
|---|
| 701 |
|
|---|
| 702 | Document* document = element->document();
|
|---|
| 703 | if (!document)
|
|---|
| 704 | return false;
|
|---|
| 705 |
|
|---|
| 706 | Frame* frame = document->frame();
|
|---|
| 707 | if (!frame)
|
|---|
| 708 | return false;
|
|---|
| 709 |
|
|---|
| 710 | scriptController = frame->script();
|
|---|
| 711 | if (!scriptController)
|
|---|
| 712 | return false;
|
|---|
| 713 |
|
|---|
| 714 | state = scriptController->globalObject(mainThreadNormalWorld())->globalExec();
|
|---|
| 715 | if (!state)
|
|---|
| 716 | return false;
|
|---|
| 717 |
|
|---|
| 718 | thisValue = toJS(state, element);
|
|---|
| 719 | if (!thisValue)
|
|---|
| 720 | return false;
|
|---|
| 721 |
|
|---|
| 722 | return true;
|
|---|
| 723 | }
|
|---|
| 724 |
|
|---|
| 725 |
|
|---|
| 726 | /*!
|
|---|
| 727 | Executes \a scriptSource with this element as \c this object.
|
|---|
| 728 | */
|
|---|
| 729 | QVariant QWebElement::evaluateJavaScript(const QString& scriptSource)
|
|---|
| 730 | {
|
|---|
| 731 | if (scriptSource.isEmpty())
|
|---|
| 732 | return QVariant();
|
|---|
| 733 |
|
|---|
| 734 | ScriptState* state = 0;
|
|---|
| 735 | JSC::JSValue thisValue;
|
|---|
| 736 | ScriptController* scriptController = 0;
|
|---|
| 737 |
|
|---|
| 738 | if (!setupScriptContext(m_element, thisValue, state, scriptController))
|
|---|
| 739 | return QVariant();
|
|---|
| 740 |
|
|---|
| 741 | JSC::ScopeChain& scopeChain = state->dynamicGlobalObject()->globalScopeChain();
|
|---|
| 742 | JSC::UString script((const UChar*)scriptSource.data(), scriptSource.length());
|
|---|
| 743 | JSC::Completion completion = JSC::evaluate(state, scopeChain, JSC::makeSource(script), thisValue);
|
|---|
| 744 | if ((completion.complType() != JSC::ReturnValue) && (completion.complType() != JSC::Normal))
|
|---|
| 745 | return QVariant();
|
|---|
| 746 |
|
|---|
| 747 | JSC::JSValue result = completion.value();
|
|---|
| 748 | if (!result)
|
|---|
| 749 | return QVariant();
|
|---|
| 750 |
|
|---|
| 751 | int distance = 0;
|
|---|
| 752 | return JSC::Bindings::convertValueToQVariant(state, result, QMetaType::Void, &distance);
|
|---|
| 753 | }
|
|---|
| 754 |
|
|---|
| 755 | /*!
|
|---|
| 756 | \enum QWebElement::StyleResolveStrategy
|
|---|
| 757 |
|
|---|
| 758 | This enum describes how QWebElement's styleProperty resolves the given
|
|---|
| 759 | property name.
|
|---|
| 760 |
|
|---|
| 761 | \value InlineStyle Return the property value as it is defined in
|
|---|
| 762 | the element, without respecting style inheritance and other CSS
|
|---|
| 763 | rules.
|
|---|
| 764 | \value CascadedStyle The property's value is determined using the
|
|---|
| 765 | inheritance and importance rules defined in the document's
|
|---|
| 766 | stylesheet.
|
|---|
| 767 | \value ComputedStyle The property's value is the absolute value
|
|---|
| 768 | of the style property resolved from the environment.
|
|---|
| 769 | */
|
|---|
| 770 |
|
|---|
| 771 | /*!
|
|---|
| 772 | Returns the value of the style with the given \a name using the specified
|
|---|
| 773 | \a strategy. If a style with \a name does not exist, an empty string is
|
|---|
| 774 | returned.
|
|---|
| 775 |
|
|---|
| 776 | In CSS, the cascading part depends on which CSS rule has priority and is
|
|---|
| 777 | thus applied. Generally, the last defined rule has priority. Thus, an
|
|---|
| 778 | inline style rule has priority over an embedded block style rule, which
|
|---|
| 779 | in return has priority over an external style rule.
|
|---|
| 780 |
|
|---|
| 781 | If the "!important" declaration is set on one of those, the declaration
|
|---|
| 782 | receives highest priority, unless other declarations also use the
|
|---|
| 783 | "!important" declaration. Then, the last "!important" declaration takes
|
|---|
| 784 | predecence.
|
|---|
| 785 |
|
|---|
| 786 | \sa setStyleProperty()
|
|---|
| 787 | */
|
|---|
| 788 |
|
|---|
| 789 | QString QWebElement::styleProperty(const QString &name, StyleResolveStrategy strategy) const
|
|---|
| 790 | {
|
|---|
| 791 | if (!m_element || !m_element->isStyledElement())
|
|---|
| 792 | return QString();
|
|---|
| 793 |
|
|---|
| 794 | int propID = cssPropertyID(name);
|
|---|
| 795 |
|
|---|
| 796 | if (!propID)
|
|---|
| 797 | return QString();
|
|---|
| 798 |
|
|---|
| 799 | CSSStyleDeclaration* style = static_cast<StyledElement*>(m_element)->style();
|
|---|
| 800 |
|
|---|
| 801 | if (strategy == InlineStyle)
|
|---|
| 802 | return style->getPropertyValue(propID);
|
|---|
| 803 |
|
|---|
| 804 | if (strategy == CascadedStyle) {
|
|---|
| 805 | if (style->getPropertyPriority(propID))
|
|---|
| 806 | return style->getPropertyValue(propID);
|
|---|
| 807 |
|
|---|
| 808 | // We are going to resolve the style property by walking through the
|
|---|
| 809 | // list of non-inline matched CSS rules for the element, looking for
|
|---|
| 810 | // the highest priority definition.
|
|---|
| 811 |
|
|---|
| 812 | // Get an array of matched CSS rules for the given element sorted
|
|---|
| 813 | // by importance and inheritance order. This include external CSS
|
|---|
| 814 | // declarations, as well as embedded and inline style declarations.
|
|---|
| 815 |
|
|---|
| 816 | DOMWindow* domWindow = m_element->document()->frame()->domWindow();
|
|---|
| 817 | if (RefPtr<CSSRuleList> rules = domWindow->getMatchedCSSRules(m_element, "")) {
|
|---|
| 818 | for (int i = rules->length(); i > 0; --i) {
|
|---|
| 819 | CSSStyleRule* rule = static_cast<CSSStyleRule*>(rules->item(i - 1));
|
|---|
| 820 |
|
|---|
| 821 | if (rule->style()->getPropertyPriority(propID))
|
|---|
| 822 | return rule->style()->getPropertyValue(propID);
|
|---|
| 823 |
|
|---|
| 824 | if (style->getPropertyValue(propID).isEmpty())
|
|---|
| 825 | style = rule->style();
|
|---|
| 826 | }
|
|---|
| 827 | }
|
|---|
| 828 |
|
|---|
| 829 | return style->getPropertyValue(propID);
|
|---|
| 830 | }
|
|---|
| 831 |
|
|---|
| 832 | if (strategy == ComputedStyle) {
|
|---|
| 833 | if (!m_element || !m_element->isStyledElement())
|
|---|
| 834 | return QString();
|
|---|
| 835 |
|
|---|
| 836 | int propID = cssPropertyID(name);
|
|---|
| 837 |
|
|---|
| 838 | RefPtr<CSSComputedStyleDeclaration> style = computedStyle(m_element);
|
|---|
| 839 | if (!propID || !style)
|
|---|
| 840 | return QString();
|
|---|
| 841 |
|
|---|
| 842 | return style->getPropertyValue(propID);
|
|---|
| 843 | }
|
|---|
| 844 |
|
|---|
| 845 | return QString();
|
|---|
| 846 | }
|
|---|
| 847 |
|
|---|
| 848 | /*!
|
|---|
| 849 | Sets the value of the inline style with the given \a name to \a value.
|
|---|
| 850 |
|
|---|
| 851 | Setting a value, does not necessarily mean that it will become the applied
|
|---|
| 852 | value, due to the fact that the style property's value might have been set
|
|---|
| 853 | earlier with a higher priority in external or embedded style declarations.
|
|---|
| 854 |
|
|---|
| 855 | In order to ensure that the value will be applied, you may have to append
|
|---|
| 856 | "!important" to the value.
|
|---|
| 857 | */
|
|---|
| 858 | void QWebElement::setStyleProperty(const QString &name, const QString &value)
|
|---|
| 859 | {
|
|---|
| 860 | if (!m_element || !m_element->isStyledElement())
|
|---|
| 861 | return;
|
|---|
| 862 |
|
|---|
| 863 | int propID = cssPropertyID(name);
|
|---|
| 864 | CSSStyleDeclaration* style = static_cast<StyledElement*>(m_element)->style();
|
|---|
| 865 | if (!propID || !style)
|
|---|
| 866 | return;
|
|---|
| 867 |
|
|---|
| 868 | ExceptionCode exception = 0;
|
|---|
| 869 | style->setProperty(name, value, exception);
|
|---|
| 870 | }
|
|---|
| 871 |
|
|---|
| 872 | /*!
|
|---|
| 873 | Returns the list of classes of this element.
|
|---|
| 874 | */
|
|---|
| 875 | QStringList QWebElement::classes() const
|
|---|
| 876 | {
|
|---|
| 877 | if (!hasAttribute(QLatin1String("class")))
|
|---|
| 878 | return QStringList();
|
|---|
| 879 |
|
|---|
| 880 | QStringList classes = attribute(QLatin1String("class")).simplified().split(QLatin1Char(' '), QString::SkipEmptyParts);
|
|---|
| 881 | classes.removeDuplicates();
|
|---|
| 882 | return classes;
|
|---|
| 883 | }
|
|---|
| 884 |
|
|---|
| 885 | /*!
|
|---|
| 886 | Returns true if this element has a class with the given \a name; otherwise
|
|---|
| 887 | returns false.
|
|---|
| 888 | */
|
|---|
| 889 | bool QWebElement::hasClass(const QString &name) const
|
|---|
| 890 | {
|
|---|
| 891 | QStringList list = classes();
|
|---|
| 892 | return list.contains(name);
|
|---|
| 893 | }
|
|---|
| 894 |
|
|---|
| 895 | /*!
|
|---|
| 896 | Adds the specified class with the given \a name to the element.
|
|---|
| 897 | */
|
|---|
| 898 | void QWebElement::addClass(const QString &name)
|
|---|
| 899 | {
|
|---|
| 900 | QStringList list = classes();
|
|---|
| 901 | if (!list.contains(name)) {
|
|---|
| 902 | list.append(name);
|
|---|
| 903 | QString value = list.join(QLatin1String(" "));
|
|---|
| 904 | setAttribute(QLatin1String("class"), value);
|
|---|
| 905 | }
|
|---|
| 906 | }
|
|---|
| 907 |
|
|---|
| 908 | /*!
|
|---|
| 909 | Removes the specified class with the given \a name from the element.
|
|---|
| 910 | */
|
|---|
| 911 | void QWebElement::removeClass(const QString &name)
|
|---|
| 912 | {
|
|---|
| 913 | QStringList list = classes();
|
|---|
| 914 | if (list.contains(name)) {
|
|---|
| 915 | list.removeAll(name);
|
|---|
| 916 | QString value = list.join(QLatin1String(" "));
|
|---|
| 917 | setAttribute(QLatin1String("class"), value);
|
|---|
| 918 | }
|
|---|
| 919 | }
|
|---|
| 920 |
|
|---|
| 921 | /*!
|
|---|
| 922 | Adds the specified class with the given \a name if it is not present. If
|
|---|
| 923 | the class is already present, it will be removed.
|
|---|
| 924 | */
|
|---|
| 925 | void QWebElement::toggleClass(const QString &name)
|
|---|
| 926 | {
|
|---|
| 927 | QStringList list = classes();
|
|---|
| 928 | if (list.contains(name))
|
|---|
| 929 | list.removeAll(name);
|
|---|
| 930 | else
|
|---|
| 931 | list.append(name);
|
|---|
| 932 |
|
|---|
| 933 | QString value = list.join(QLatin1String(" "));
|
|---|
| 934 | setAttribute(QLatin1String("class"), value);
|
|---|
| 935 | }
|
|---|
| 936 |
|
|---|
| 937 | /*!
|
|---|
| 938 | Appends the given \a element as the element's last child.
|
|---|
| 939 |
|
|---|
| 940 | If \a element is the child of another element, it is re-parented to this
|
|---|
| 941 | element. If \a element is a child of this element, then its position in
|
|---|
| 942 | the list of children is changed.
|
|---|
| 943 |
|
|---|
| 944 | Calling this function on a null element does nothing.
|
|---|
| 945 |
|
|---|
| 946 | \sa prependInside(), prependOutside(), appendOutside()
|
|---|
| 947 | */
|
|---|
| 948 | void QWebElement::appendInside(const QWebElement &element)
|
|---|
| 949 | {
|
|---|
| 950 | if (!m_element || element.isNull())
|
|---|
| 951 | return;
|
|---|
| 952 |
|
|---|
| 953 | ExceptionCode exception = 0;
|
|---|
| 954 | m_element->appendChild(element.m_element, exception);
|
|---|
| 955 | }
|
|---|
| 956 |
|
|---|
| 957 | /*!
|
|---|
| 958 | Appends the result of parsing \a markup as the element's last child.
|
|---|
| 959 |
|
|---|
| 960 | Calling this function on a null element does nothing.
|
|---|
| 961 |
|
|---|
| 962 | \sa prependInside(), prependOutside(), appendOutside()
|
|---|
| 963 | */
|
|---|
| 964 | void QWebElement::appendInside(const QString &markup)
|
|---|
| 965 | {
|
|---|
| 966 | if (!m_element)
|
|---|
| 967 | return;
|
|---|
| 968 |
|
|---|
| 969 | if (!m_element->isHTMLElement())
|
|---|
| 970 | return;
|
|---|
| 971 |
|
|---|
| 972 | HTMLElement* htmlElement = static_cast<HTMLElement*>(m_element);
|
|---|
| 973 | RefPtr<DocumentFragment> fragment = htmlElement->createContextualFragment(markup);
|
|---|
| 974 |
|
|---|
| 975 | ExceptionCode exception = 0;
|
|---|
| 976 | m_element->appendChild(fragment, exception);
|
|---|
| 977 | }
|
|---|
| 978 |
|
|---|
| 979 | /*!
|
|---|
| 980 | Prepends \a element as the element's first child.
|
|---|
| 981 |
|
|---|
| 982 | If \a element is the child of another element, it is re-parented to this
|
|---|
| 983 | element. If \a element is a child of this element, then its position in
|
|---|
| 984 | the list of children is changed.
|
|---|
| 985 |
|
|---|
| 986 | Calling this function on a null element does nothing.
|
|---|
| 987 |
|
|---|
| 988 | \sa appendInside(), prependOutside(), appendOutside()
|
|---|
| 989 | */
|
|---|
| 990 | void QWebElement::prependInside(const QWebElement &element)
|
|---|
| 991 | {
|
|---|
| 992 | if (!m_element || element.isNull())
|
|---|
| 993 | return;
|
|---|
| 994 |
|
|---|
| 995 | ExceptionCode exception = 0;
|
|---|
| 996 |
|
|---|
| 997 | if (m_element->hasChildNodes())
|
|---|
| 998 | m_element->insertBefore(element.m_element, m_element->firstChild(), exception);
|
|---|
| 999 | else
|
|---|
| 1000 | m_element->appendChild(element.m_element, exception);
|
|---|
| 1001 | }
|
|---|
| 1002 |
|
|---|
| 1003 | /*!
|
|---|
| 1004 | Prepends the result of parsing \a markup as the element's first child.
|
|---|
| 1005 |
|
|---|
| 1006 | Calling this function on a null element does nothing.
|
|---|
| 1007 |
|
|---|
| 1008 | \sa appendInside(), prependOutside(), appendOutside()
|
|---|
| 1009 | */
|
|---|
| 1010 | void QWebElement::prependInside(const QString &markup)
|
|---|
| 1011 | {
|
|---|
| 1012 | if (!m_element)
|
|---|
| 1013 | return;
|
|---|
| 1014 |
|
|---|
| 1015 | if (!m_element->isHTMLElement())
|
|---|
| 1016 | return;
|
|---|
| 1017 |
|
|---|
| 1018 | HTMLElement* htmlElement = static_cast<HTMLElement*>(m_element);
|
|---|
| 1019 | RefPtr<DocumentFragment> fragment = htmlElement->createContextualFragment(markup);
|
|---|
| 1020 |
|
|---|
| 1021 | ExceptionCode exception = 0;
|
|---|
| 1022 |
|
|---|
| 1023 | if (m_element->hasChildNodes())
|
|---|
| 1024 | m_element->insertBefore(fragment, m_element->firstChild(), exception);
|
|---|
| 1025 | else
|
|---|
| 1026 | m_element->appendChild(fragment, exception);
|
|---|
| 1027 | }
|
|---|
| 1028 |
|
|---|
| 1029 |
|
|---|
| 1030 | /*!
|
|---|
| 1031 | Inserts the given \a element before this element.
|
|---|
| 1032 |
|
|---|
| 1033 | If \a element is the child of another element, it is re-parented to the
|
|---|
| 1034 | parent of this element.
|
|---|
| 1035 |
|
|---|
| 1036 | Calling this function on a null element does nothing.
|
|---|
| 1037 |
|
|---|
| 1038 | \sa appendInside(), prependInside(), appendOutside()
|
|---|
| 1039 | */
|
|---|
| 1040 | void QWebElement::prependOutside(const QWebElement &element)
|
|---|
| 1041 | {
|
|---|
| 1042 | if (!m_element || element.isNull())
|
|---|
| 1043 | return;
|
|---|
| 1044 |
|
|---|
| 1045 | if (!m_element->parent())
|
|---|
| 1046 | return;
|
|---|
| 1047 |
|
|---|
| 1048 | ExceptionCode exception = 0;
|
|---|
| 1049 | m_element->parent()->insertBefore(element.m_element, m_element, exception);
|
|---|
| 1050 | }
|
|---|
| 1051 |
|
|---|
| 1052 | /*!
|
|---|
| 1053 | Inserts the result of parsing \a markup before this element.
|
|---|
| 1054 |
|
|---|
| 1055 | Calling this function on a null element does nothing.
|
|---|
| 1056 |
|
|---|
| 1057 | \sa appendInside(), prependInside(), appendOutside()
|
|---|
| 1058 | */
|
|---|
| 1059 | void QWebElement::prependOutside(const QString &markup)
|
|---|
| 1060 | {
|
|---|
| 1061 | if (!m_element)
|
|---|
| 1062 | return;
|
|---|
| 1063 |
|
|---|
| 1064 | if (!m_element->parent())
|
|---|
| 1065 | return;
|
|---|
| 1066 |
|
|---|
| 1067 | if (!m_element->isHTMLElement())
|
|---|
| 1068 | return;
|
|---|
| 1069 |
|
|---|
| 1070 | HTMLElement* htmlElement = static_cast<HTMLElement*>(m_element);
|
|---|
| 1071 | RefPtr<DocumentFragment> fragment = htmlElement->createContextualFragment(markup);
|
|---|
| 1072 |
|
|---|
| 1073 | ExceptionCode exception = 0;
|
|---|
| 1074 | m_element->parent()->insertBefore(fragment, m_element, exception);
|
|---|
| 1075 | }
|
|---|
| 1076 |
|
|---|
| 1077 | /*!
|
|---|
| 1078 | Inserts the given \a element after this element.
|
|---|
| 1079 |
|
|---|
| 1080 | If \a element is the child of another element, it is re-parented to the
|
|---|
| 1081 | parent of this element.
|
|---|
| 1082 |
|
|---|
| 1083 | Calling this function on a null element does nothing.
|
|---|
| 1084 |
|
|---|
| 1085 | \sa appendInside(), prependInside(), prependOutside()
|
|---|
| 1086 | */
|
|---|
| 1087 | void QWebElement::appendOutside(const QWebElement &element)
|
|---|
| 1088 | {
|
|---|
| 1089 | if (!m_element || element.isNull())
|
|---|
| 1090 | return;
|
|---|
| 1091 |
|
|---|
| 1092 | if (!m_element->parent())
|
|---|
| 1093 | return;
|
|---|
| 1094 |
|
|---|
| 1095 | ExceptionCode exception = 0;
|
|---|
| 1096 | if (!m_element->nextSibling())
|
|---|
| 1097 | m_element->parent()->appendChild(element.m_element, exception);
|
|---|
| 1098 | else
|
|---|
| 1099 | m_element->parent()->insertBefore(element.m_element, m_element->nextSibling(), exception);
|
|---|
| 1100 | }
|
|---|
| 1101 |
|
|---|
| 1102 | /*!
|
|---|
| 1103 | Inserts the result of parsing \a markup after this element.
|
|---|
| 1104 |
|
|---|
| 1105 | Calling this function on a null element does nothing.
|
|---|
| 1106 |
|
|---|
| 1107 | \sa appendInside(), prependInside(), prependOutside()
|
|---|
| 1108 | */
|
|---|
| 1109 | void QWebElement::appendOutside(const QString &markup)
|
|---|
| 1110 | {
|
|---|
| 1111 | if (!m_element)
|
|---|
| 1112 | return;
|
|---|
| 1113 |
|
|---|
| 1114 | if (!m_element->parent())
|
|---|
| 1115 | return;
|
|---|
| 1116 |
|
|---|
| 1117 | if (!m_element->isHTMLElement())
|
|---|
| 1118 | return;
|
|---|
| 1119 |
|
|---|
| 1120 | HTMLElement* htmlElement = static_cast<HTMLElement*>(m_element);
|
|---|
| 1121 | RefPtr<DocumentFragment> fragment = htmlElement->createContextualFragment(markup);
|
|---|
| 1122 |
|
|---|
| 1123 | ExceptionCode exception = 0;
|
|---|
| 1124 | if (!m_element->nextSibling())
|
|---|
| 1125 | m_element->parent()->appendChild(fragment, exception);
|
|---|
| 1126 | else
|
|---|
| 1127 | m_element->parent()->insertBefore(fragment, m_element->nextSibling(), exception);
|
|---|
| 1128 | }
|
|---|
| 1129 |
|
|---|
| 1130 | /*!
|
|---|
| 1131 | Returns a clone of this element.
|
|---|
| 1132 |
|
|---|
| 1133 | The clone may be inserted at any point in the document.
|
|---|
| 1134 |
|
|---|
| 1135 | \sa appendInside(), prependInside(), prependOutside(), appendOutside()
|
|---|
| 1136 | */
|
|---|
| 1137 | QWebElement QWebElement::clone() const
|
|---|
| 1138 | {
|
|---|
| 1139 | if (!m_element)
|
|---|
| 1140 | return QWebElement();
|
|---|
| 1141 |
|
|---|
| 1142 | return QWebElement(m_element->cloneElementWithChildren().get());
|
|---|
| 1143 | }
|
|---|
| 1144 |
|
|---|
| 1145 | /*!
|
|---|
| 1146 | Removes this element from the document and returns a reference to it.
|
|---|
| 1147 |
|
|---|
| 1148 | The element is still valid after removal, and can be inserted into other
|
|---|
| 1149 | parts of the document.
|
|---|
| 1150 |
|
|---|
| 1151 | \sa removeAllChildren(), removeFromDocument()
|
|---|
| 1152 | */
|
|---|
| 1153 | QWebElement &QWebElement::takeFromDocument()
|
|---|
| 1154 | {
|
|---|
| 1155 | if (!m_element)
|
|---|
| 1156 | return *this;
|
|---|
| 1157 |
|
|---|
| 1158 | ExceptionCode exception = 0;
|
|---|
| 1159 | m_element->remove(exception);
|
|---|
| 1160 |
|
|---|
| 1161 | return *this;
|
|---|
| 1162 | }
|
|---|
| 1163 |
|
|---|
| 1164 | /*!
|
|---|
| 1165 | Removes this element from the document and makes it a null element.
|
|---|
| 1166 |
|
|---|
| 1167 | \sa removeAllChildren(), takeFromDocument()
|
|---|
| 1168 | */
|
|---|
| 1169 | void QWebElement::removeFromDocument()
|
|---|
| 1170 | {
|
|---|
| 1171 | if (!m_element)
|
|---|
| 1172 | return;
|
|---|
| 1173 |
|
|---|
| 1174 | ExceptionCode exception = 0;
|
|---|
| 1175 | m_element->remove(exception);
|
|---|
| 1176 | m_element->deref();
|
|---|
| 1177 | m_element = 0;
|
|---|
| 1178 | }
|
|---|
| 1179 |
|
|---|
| 1180 | /*!
|
|---|
| 1181 | Removes all children from this element.
|
|---|
| 1182 |
|
|---|
| 1183 | \sa removeFromDocument(), takeFromDocument()
|
|---|
| 1184 | */
|
|---|
| 1185 | void QWebElement::removeAllChildren()
|
|---|
| 1186 | {
|
|---|
| 1187 | if (!m_element)
|
|---|
| 1188 | return;
|
|---|
| 1189 |
|
|---|
| 1190 | m_element->removeAllChildren();
|
|---|
| 1191 | }
|
|---|
| 1192 |
|
|---|
| 1193 | static RefPtr<Node> findInsertionPoint(PassRefPtr<Node> root)
|
|---|
| 1194 | {
|
|---|
| 1195 | RefPtr<Node> node = root;
|
|---|
| 1196 |
|
|---|
| 1197 | // Go as far down the tree as possible.
|
|---|
| 1198 | while (node->hasChildNodes() && node->firstChild()->isElementNode())
|
|---|
| 1199 | node = node->firstChild();
|
|---|
| 1200 |
|
|---|
| 1201 | // TODO: Implement SVG support
|
|---|
| 1202 | if (node->isHTMLElement()) {
|
|---|
| 1203 | HTMLElement* element = static_cast<HTMLElement*>(node.get());
|
|---|
| 1204 |
|
|---|
| 1205 | // The insert point could be a non-enclosable tag and it can thus
|
|---|
| 1206 | // never have children, so go one up. Get the parent element, and not
|
|---|
| 1207 | // note as a root note will always exist.
|
|---|
| 1208 | if (element->endTagRequirement() == TagStatusForbidden)
|
|---|
| 1209 | node = node->parentElement();
|
|---|
| 1210 | }
|
|---|
| 1211 |
|
|---|
| 1212 | return node;
|
|---|
| 1213 | }
|
|---|
| 1214 |
|
|---|
| 1215 | /*!
|
|---|
| 1216 | Encloses the contents of this element with \a element. This element becomes
|
|---|
| 1217 | the child of the deepest descendant within \a element.
|
|---|
| 1218 |
|
|---|
| 1219 | ### illustration
|
|---|
| 1220 |
|
|---|
| 1221 | \sa encloseWith()
|
|---|
| 1222 | */
|
|---|
| 1223 | void QWebElement::encloseContentsWith(const QWebElement &element)
|
|---|
| 1224 | {
|
|---|
| 1225 | if (!m_element || element.isNull())
|
|---|
| 1226 | return;
|
|---|
| 1227 |
|
|---|
| 1228 | RefPtr<Node> insertionPoint = findInsertionPoint(element.m_element);
|
|---|
| 1229 |
|
|---|
| 1230 | if (!insertionPoint)
|
|---|
| 1231 | return;
|
|---|
| 1232 |
|
|---|
| 1233 | ExceptionCode exception = 0;
|
|---|
| 1234 |
|
|---|
| 1235 | // reparent children
|
|---|
| 1236 | for (RefPtr<Node> child = m_element->firstChild(); child;) {
|
|---|
| 1237 | RefPtr<Node> next = child->nextSibling();
|
|---|
| 1238 | insertionPoint->appendChild(child, exception);
|
|---|
| 1239 | child = next;
|
|---|
| 1240 | }
|
|---|
| 1241 |
|
|---|
| 1242 | if (m_element->hasChildNodes())
|
|---|
| 1243 | m_element->insertBefore(element.m_element, m_element->firstChild(), exception);
|
|---|
| 1244 | else
|
|---|
| 1245 | m_element->appendChild(element.m_element, exception);
|
|---|
| 1246 | }
|
|---|
| 1247 |
|
|---|
| 1248 | /*!
|
|---|
| 1249 | Encloses the contents of this element with the result of parsing \a markup.
|
|---|
| 1250 | This element becomes the child of the deepest descendant within \a markup.
|
|---|
| 1251 |
|
|---|
| 1252 | \sa encloseWith()
|
|---|
| 1253 | */
|
|---|
| 1254 | void QWebElement::encloseContentsWith(const QString &markup)
|
|---|
| 1255 | {
|
|---|
| 1256 | if (!m_element)
|
|---|
| 1257 | return;
|
|---|
| 1258 |
|
|---|
| 1259 | if (!m_element->parent())
|
|---|
| 1260 | return;
|
|---|
| 1261 |
|
|---|
| 1262 | if (!m_element->isHTMLElement())
|
|---|
| 1263 | return;
|
|---|
| 1264 |
|
|---|
| 1265 | HTMLElement* htmlElement = static_cast<HTMLElement*>(m_element);
|
|---|
| 1266 | RefPtr<DocumentFragment> fragment = htmlElement->createContextualFragment(markup);
|
|---|
| 1267 |
|
|---|
| 1268 | if (!fragment || !fragment->firstChild())
|
|---|
| 1269 | return;
|
|---|
| 1270 |
|
|---|
| 1271 | RefPtr<Node> insertionPoint = findInsertionPoint(fragment->firstChild());
|
|---|
| 1272 |
|
|---|
| 1273 | if (!insertionPoint)
|
|---|
| 1274 | return;
|
|---|
| 1275 |
|
|---|
| 1276 | ExceptionCode exception = 0;
|
|---|
| 1277 |
|
|---|
| 1278 | // reparent children
|
|---|
| 1279 | for (RefPtr<Node> child = m_element->firstChild(); child;) {
|
|---|
| 1280 | RefPtr<Node> next = child->nextSibling();
|
|---|
| 1281 | insertionPoint->appendChild(child, exception);
|
|---|
| 1282 | child = next;
|
|---|
| 1283 | }
|
|---|
| 1284 |
|
|---|
| 1285 | if (m_element->hasChildNodes())
|
|---|
| 1286 | m_element->insertBefore(fragment, m_element->firstChild(), exception);
|
|---|
| 1287 | else
|
|---|
| 1288 | m_element->appendChild(fragment, exception);
|
|---|
| 1289 | }
|
|---|
| 1290 |
|
|---|
| 1291 | /*!
|
|---|
| 1292 | Encloses this element with \a element. This element becomes the child of
|
|---|
| 1293 | the deepest descendant within \a element.
|
|---|
| 1294 |
|
|---|
| 1295 | \sa replace()
|
|---|
| 1296 | */
|
|---|
| 1297 | void QWebElement::encloseWith(const QWebElement &element)
|
|---|
| 1298 | {
|
|---|
| 1299 | if (!m_element || element.isNull())
|
|---|
| 1300 | return;
|
|---|
| 1301 |
|
|---|
| 1302 | RefPtr<Node> insertionPoint = findInsertionPoint(element.m_element);
|
|---|
| 1303 |
|
|---|
| 1304 | if (!insertionPoint)
|
|---|
| 1305 | return;
|
|---|
| 1306 |
|
|---|
| 1307 | // Keep reference to these two nodes before pulling out this element and
|
|---|
| 1308 | // wrapping it in the fragment. The reason for doing it in this order is
|
|---|
| 1309 | // that once the fragment has been added to the document it is empty, so
|
|---|
| 1310 | // we no longer have access to the nodes it contained.
|
|---|
| 1311 | Node* parentNode = m_element->parent();
|
|---|
| 1312 | Node* siblingNode = m_element->nextSibling();
|
|---|
| 1313 |
|
|---|
| 1314 | ExceptionCode exception = 0;
|
|---|
| 1315 | insertionPoint->appendChild(m_element, exception);
|
|---|
| 1316 |
|
|---|
| 1317 | if (!siblingNode)
|
|---|
| 1318 | parentNode->appendChild(element.m_element, exception);
|
|---|
| 1319 | else
|
|---|
| 1320 | parentNode->insertBefore(element.m_element, siblingNode, exception);
|
|---|
| 1321 | }
|
|---|
| 1322 |
|
|---|
| 1323 | /*!
|
|---|
| 1324 | Encloses this element with the result of parsing \a markup. This element
|
|---|
| 1325 | becomes the child of the deepest descendant within \a markup.
|
|---|
| 1326 |
|
|---|
| 1327 | \sa replace()
|
|---|
| 1328 | */
|
|---|
| 1329 | void QWebElement::encloseWith(const QString &markup)
|
|---|
| 1330 | {
|
|---|
| 1331 | if (!m_element)
|
|---|
| 1332 | return;
|
|---|
| 1333 |
|
|---|
| 1334 | if (!m_element->parent())
|
|---|
| 1335 | return;
|
|---|
| 1336 |
|
|---|
| 1337 | if (!m_element->isHTMLElement())
|
|---|
| 1338 | return;
|
|---|
| 1339 |
|
|---|
| 1340 | HTMLElement* htmlElement = static_cast<HTMLElement*>(m_element);
|
|---|
| 1341 | RefPtr<DocumentFragment> fragment = htmlElement->createContextualFragment(markup);
|
|---|
| 1342 |
|
|---|
| 1343 | if (!fragment || !fragment->firstChild())
|
|---|
| 1344 | return;
|
|---|
| 1345 |
|
|---|
| 1346 | RefPtr<Node> insertionPoint = findInsertionPoint(fragment->firstChild());
|
|---|
| 1347 |
|
|---|
| 1348 | if (!insertionPoint)
|
|---|
| 1349 | return;
|
|---|
| 1350 |
|
|---|
| 1351 | // Keep reference to these two nodes before pulling out this element and
|
|---|
| 1352 | // wrapping it in the fragment. The reason for doing it in this order is
|
|---|
| 1353 | // that once the fragment has been added to the document it is empty, so
|
|---|
| 1354 | // we no longer have access to the nodes it contained.
|
|---|
| 1355 | Node* parentNode = m_element->parent();
|
|---|
| 1356 | Node* siblingNode = m_element->nextSibling();
|
|---|
| 1357 |
|
|---|
| 1358 | ExceptionCode exception = 0;
|
|---|
| 1359 | insertionPoint->appendChild(m_element, exception);
|
|---|
| 1360 |
|
|---|
| 1361 | if (!siblingNode)
|
|---|
| 1362 | parentNode->appendChild(fragment, exception);
|
|---|
| 1363 | else
|
|---|
| 1364 | parentNode->insertBefore(fragment, siblingNode, exception);
|
|---|
| 1365 | }
|
|---|
| 1366 |
|
|---|
| 1367 | /*!
|
|---|
| 1368 | Replaces this element with \a element.
|
|---|
| 1369 |
|
|---|
| 1370 | This method will not replace the <html>, <head> or <body> elements.
|
|---|
| 1371 |
|
|---|
| 1372 | \sa encloseWith()
|
|---|
| 1373 | */
|
|---|
| 1374 | void QWebElement::replace(const QWebElement &element)
|
|---|
| 1375 | {
|
|---|
| 1376 | if (!m_element || element.isNull())
|
|---|
| 1377 | return;
|
|---|
| 1378 |
|
|---|
| 1379 | appendOutside(element);
|
|---|
| 1380 | takeFromDocument();
|
|---|
| 1381 | }
|
|---|
| 1382 |
|
|---|
| 1383 | /*!
|
|---|
| 1384 | Replaces this element with the result of parsing \a markup.
|
|---|
| 1385 |
|
|---|
| 1386 | This method will not replace the <html>, <head> or <body> elements.
|
|---|
| 1387 |
|
|---|
| 1388 | \sa encloseWith()
|
|---|
| 1389 | */
|
|---|
| 1390 | void QWebElement::replace(const QString &markup)
|
|---|
| 1391 | {
|
|---|
| 1392 | if (!m_element)
|
|---|
| 1393 | return;
|
|---|
| 1394 |
|
|---|
| 1395 | appendOutside(markup);
|
|---|
| 1396 | takeFromDocument();
|
|---|
| 1397 | }
|
|---|
| 1398 |
|
|---|
| 1399 | /*!
|
|---|
| 1400 | \internal
|
|---|
| 1401 | Walk \a node's parents until a valid QWebElement is found.
|
|---|
| 1402 | For example, a WebCore::Text node is not a valid Html QWebElement, but its
|
|---|
| 1403 | enclosing p tag is.
|
|---|
| 1404 | */
|
|---|
| 1405 | QWebElement QWebElement::enclosingElement(WebCore::Node* node)
|
|---|
| 1406 | {
|
|---|
| 1407 | QWebElement element(node);
|
|---|
| 1408 |
|
|---|
| 1409 | while (element.isNull() && node) {
|
|---|
| 1410 | node = node->parentNode();
|
|---|
| 1411 | element = QWebElement(node);
|
|---|
| 1412 | }
|
|---|
| 1413 | return element;
|
|---|
| 1414 | }
|
|---|
| 1415 |
|
|---|
| 1416 | /*!
|
|---|
| 1417 | \fn inline bool QWebElement::operator==(const QWebElement& o) const;
|
|---|
| 1418 |
|
|---|
| 1419 | Returns true if this element points to the same underlying DOM object as
|
|---|
| 1420 | \a o; otherwise returns false.
|
|---|
| 1421 | */
|
|---|
| 1422 |
|
|---|
| 1423 | /*!
|
|---|
| 1424 | \fn inline bool QWebElement::operator!=(const QWebElement& o) const;
|
|---|
| 1425 |
|
|---|
| 1426 | Returns true if this element points to a different underlying DOM object
|
|---|
| 1427 | than \a o; otherwise returns false.
|
|---|
| 1428 | */
|
|---|
| 1429 |
|
|---|
| 1430 |
|
|---|
| 1431 | /*!
|
|---|
| 1432 | Render the element into \a painter .
|
|---|
| 1433 | */
|
|---|
| 1434 | void QWebElement::render(QPainter* painter)
|
|---|
| 1435 | {
|
|---|
| 1436 | WebCore::Element* e = m_element;
|
|---|
| 1437 | Document* doc = e ? e->document() : 0;
|
|---|
| 1438 | if (!doc)
|
|---|
| 1439 | return;
|
|---|
| 1440 |
|
|---|
| 1441 | Frame* frame = doc->frame();
|
|---|
| 1442 | if (!frame || !frame->view() || !frame->contentRenderer())
|
|---|
| 1443 | return;
|
|---|
| 1444 |
|
|---|
| 1445 | FrameView* view = frame->view();
|
|---|
| 1446 |
|
|---|
| 1447 | view->layoutIfNeededRecursive();
|
|---|
| 1448 |
|
|---|
| 1449 | IntRect rect = e->getRect();
|
|---|
| 1450 |
|
|---|
| 1451 | if (rect.size().isEmpty())
|
|---|
| 1452 | return;
|
|---|
| 1453 |
|
|---|
| 1454 | GraphicsContext context(painter);
|
|---|
| 1455 |
|
|---|
| 1456 | context.save();
|
|---|
| 1457 | context.translate(-rect.x(), -rect.y());
|
|---|
| 1458 | view->setNodeToDraw(e);
|
|---|
| 1459 | view->paintContents(&context, rect);
|
|---|
| 1460 | view->setNodeToDraw(0);
|
|---|
| 1461 | context.restore();
|
|---|
| 1462 | }
|
|---|
| 1463 |
|
|---|
| 1464 | class QWebElementCollectionPrivate : public QSharedData
|
|---|
| 1465 | {
|
|---|
| 1466 | public:
|
|---|
| 1467 | static QWebElementCollectionPrivate* create(const PassRefPtr<Node> &context, const QString &query);
|
|---|
| 1468 |
|
|---|
| 1469 | RefPtr<NodeList> m_result;
|
|---|
| 1470 |
|
|---|
| 1471 | private:
|
|---|
| 1472 | inline QWebElementCollectionPrivate() {}
|
|---|
| 1473 | };
|
|---|
| 1474 |
|
|---|
| 1475 | QWebElementCollectionPrivate* QWebElementCollectionPrivate::create(const PassRefPtr<Node> &context, const QString &query)
|
|---|
| 1476 | {
|
|---|
| 1477 | if (!context)
|
|---|
| 1478 | return 0;
|
|---|
| 1479 |
|
|---|
| 1480 | // Let WebKit do the hard work hehehe
|
|---|
| 1481 | ExceptionCode exception = 0; // ###
|
|---|
| 1482 | RefPtr<NodeList> nodes = context->querySelectorAll(query, exception);
|
|---|
| 1483 | if (!nodes)
|
|---|
| 1484 | return 0;
|
|---|
| 1485 |
|
|---|
| 1486 | QWebElementCollectionPrivate* priv = new QWebElementCollectionPrivate;
|
|---|
| 1487 | priv->m_result = nodes;
|
|---|
| 1488 | return priv;
|
|---|
| 1489 | }
|
|---|
| 1490 |
|
|---|
| 1491 | /*!
|
|---|
| 1492 | \class QWebElementCollection
|
|---|
| 1493 | \since 4.6
|
|---|
| 1494 | \brief The QWebElementCollection class represents a collection of web elements.
|
|---|
| 1495 | \preliminary
|
|---|
| 1496 |
|
|---|
| 1497 | Elements in a document can be selected using QWebElement::findAll() or using the
|
|---|
| 1498 | QWebElement constructor. The collection is composed by choosing all elements in the
|
|---|
| 1499 | document that match a specified CSS selector expression.
|
|---|
| 1500 |
|
|---|
| 1501 | The number of selected elements is provided through the count() property. Individual
|
|---|
| 1502 | elements can be retrieved by index using at().
|
|---|
| 1503 |
|
|---|
| 1504 | It is also possible to iterate through all elements in the collection using Qt's foreach
|
|---|
| 1505 | macro:
|
|---|
| 1506 |
|
|---|
| 1507 | \code
|
|---|
| 1508 | QWebElementCollection collection = document.findAll("p");
|
|---|
| 1509 | foreach (QWebElement paraElement, collection) {
|
|---|
| 1510 | ...
|
|---|
| 1511 | }
|
|---|
| 1512 | \endcode
|
|---|
| 1513 | */
|
|---|
| 1514 |
|
|---|
| 1515 | /*!
|
|---|
| 1516 | Constructs an empty collection.
|
|---|
| 1517 | */
|
|---|
| 1518 | QWebElementCollection::QWebElementCollection()
|
|---|
| 1519 | {
|
|---|
| 1520 | }
|
|---|
| 1521 |
|
|---|
| 1522 | /*!
|
|---|
| 1523 | Constructs a copy of \a other.
|
|---|
| 1524 | */
|
|---|
| 1525 | QWebElementCollection::QWebElementCollection(const QWebElementCollection &other)
|
|---|
| 1526 | : d(other.d)
|
|---|
| 1527 | {
|
|---|
| 1528 | }
|
|---|
| 1529 |
|
|---|
| 1530 | /*!
|
|---|
| 1531 | Constructs a collection of elements from the list of child elements of \a contextElement that
|
|---|
| 1532 | match the specified CSS selector \a query.
|
|---|
| 1533 | */
|
|---|
| 1534 | QWebElementCollection::QWebElementCollection(const QWebElement &contextElement, const QString &query)
|
|---|
| 1535 | {
|
|---|
| 1536 | d = QExplicitlySharedDataPointer<QWebElementCollectionPrivate>(QWebElementCollectionPrivate::create(contextElement.m_element, query));
|
|---|
| 1537 | }
|
|---|
| 1538 |
|
|---|
| 1539 | /*!
|
|---|
| 1540 | Assigns \a other to this collection and returns a reference to this collection.
|
|---|
| 1541 | */
|
|---|
| 1542 | QWebElementCollection &QWebElementCollection::operator=(const QWebElementCollection &other)
|
|---|
| 1543 | {
|
|---|
| 1544 | d = other.d;
|
|---|
| 1545 | return *this;
|
|---|
| 1546 | }
|
|---|
| 1547 |
|
|---|
| 1548 | /*!
|
|---|
| 1549 | Destroys the collection.
|
|---|
| 1550 | */
|
|---|
| 1551 | QWebElementCollection::~QWebElementCollection()
|
|---|
| 1552 | {
|
|---|
| 1553 | }
|
|---|
| 1554 |
|
|---|
| 1555 | /*! \fn QWebElementCollection &QWebElementCollection::operator+=(const QWebElementCollection &other)
|
|---|
| 1556 |
|
|---|
| 1557 | Appends the items of the \a other list to this list and returns a
|
|---|
| 1558 | reference to this list.
|
|---|
| 1559 |
|
|---|
| 1560 | \sa operator+(), append()
|
|---|
| 1561 | */
|
|---|
| 1562 |
|
|---|
| 1563 | /*!
|
|---|
| 1564 | Returns a collection that contains all the elements of this collection followed
|
|---|
| 1565 | by all the elements in the \a other collection. Duplicates may occur in the result.
|
|---|
| 1566 |
|
|---|
| 1567 | \sa operator+=()
|
|---|
| 1568 | */
|
|---|
| 1569 | QWebElementCollection QWebElementCollection::operator+(const QWebElementCollection &other) const
|
|---|
| 1570 | {
|
|---|
| 1571 | QWebElementCollection n = *this; n.d.detach(); n += other; return n;
|
|---|
| 1572 | }
|
|---|
| 1573 |
|
|---|
| 1574 | /*!
|
|---|
| 1575 | Extends the collection by appending all items of \a other.
|
|---|
| 1576 |
|
|---|
| 1577 | The resulting collection may include duplicate elements.
|
|---|
| 1578 |
|
|---|
| 1579 | \sa operator+=()
|
|---|
| 1580 | */
|
|---|
| 1581 | void QWebElementCollection::append(const QWebElementCollection &other)
|
|---|
| 1582 | {
|
|---|
| 1583 | if (!d) {
|
|---|
| 1584 | *this = other;
|
|---|
| 1585 | return;
|
|---|
| 1586 | }
|
|---|
| 1587 | if (!other.d)
|
|---|
| 1588 | return;
|
|---|
| 1589 | Vector<RefPtr<Node> > nodes;
|
|---|
| 1590 | RefPtr<NodeList> results[] = { d->m_result, other.d->m_result };
|
|---|
| 1591 | nodes.reserveInitialCapacity(results[0]->length() + results[1]->length());
|
|---|
| 1592 |
|
|---|
| 1593 | for (int i = 0; i < 2; ++i) {
|
|---|
| 1594 | int j = 0;
|
|---|
| 1595 | Node* n = results[i]->item(j);
|
|---|
| 1596 | while (n) {
|
|---|
| 1597 | nodes.append(n);
|
|---|
| 1598 | n = results[i]->item(++j);
|
|---|
| 1599 | }
|
|---|
| 1600 | }
|
|---|
| 1601 |
|
|---|
| 1602 | d->m_result = StaticNodeList::adopt(nodes);
|
|---|
| 1603 | }
|
|---|
| 1604 |
|
|---|
| 1605 | /*!
|
|---|
| 1606 | Returns the number of elements in the collection.
|
|---|
| 1607 | */
|
|---|
| 1608 | int QWebElementCollection::count() const
|
|---|
| 1609 | {
|
|---|
| 1610 | if (!d)
|
|---|
| 1611 | return 0;
|
|---|
| 1612 | return d->m_result->length();
|
|---|
| 1613 | }
|
|---|
| 1614 |
|
|---|
| 1615 | /*!
|
|---|
| 1616 | Returns the element at index position \a i in the collection.
|
|---|
| 1617 | */
|
|---|
| 1618 | QWebElement QWebElementCollection::at(int i) const
|
|---|
| 1619 | {
|
|---|
| 1620 | if (!d)
|
|---|
| 1621 | return QWebElement();
|
|---|
| 1622 | Node* n = d->m_result->item(i);
|
|---|
| 1623 | return QWebElement(static_cast<Element*>(n));
|
|---|
| 1624 | }
|
|---|
| 1625 |
|
|---|
| 1626 | /*!
|
|---|
| 1627 | \fn const QWebElement QWebElementCollection::operator[](int position) const
|
|---|
| 1628 |
|
|---|
| 1629 | Returns the element at the specified \a position in the collection.
|
|---|
| 1630 | */
|
|---|
| 1631 |
|
|---|
| 1632 | /*! \fn QWebElement QWebElementCollection::first() const
|
|---|
| 1633 |
|
|---|
| 1634 | Returns the first element in the collection.
|
|---|
| 1635 |
|
|---|
| 1636 | \sa last(), operator[](), at(), count()
|
|---|
| 1637 | */
|
|---|
| 1638 |
|
|---|
| 1639 | /*! \fn QWebElement QWebElementCollection::last() const
|
|---|
| 1640 |
|
|---|
| 1641 | Returns the last element in the collection.
|
|---|
| 1642 |
|
|---|
| 1643 | \sa first(), operator[](), at(), count()
|
|---|
| 1644 | */
|
|---|
| 1645 |
|
|---|
| 1646 | /*!
|
|---|
| 1647 | Returns a QList object with the elements contained in this collection.
|
|---|
| 1648 | */
|
|---|
| 1649 | QList<QWebElement> QWebElementCollection::toList() const
|
|---|
| 1650 | {
|
|---|
| 1651 | if (!d)
|
|---|
| 1652 | return QList<QWebElement>();
|
|---|
| 1653 | QList<QWebElement> elements;
|
|---|
| 1654 | int i = 0;
|
|---|
| 1655 | Node* n = d->m_result->item(i);
|
|---|
| 1656 | while (n) {
|
|---|
| 1657 | if (n->isElementNode())
|
|---|
| 1658 | elements.append(QWebElement(static_cast<Element*>(n)));
|
|---|
| 1659 | n = d->m_result->item(++i);
|
|---|
| 1660 | }
|
|---|
| 1661 | return elements;
|
|---|
| 1662 | }
|
|---|
| 1663 |
|
|---|
| 1664 | /*!
|
|---|
| 1665 | \fn QWebElementCollection::const_iterator QWebElementCollection::begin() const
|
|---|
| 1666 |
|
|---|
| 1667 | Returns an STL-style iterator pointing to the first element in the collection.
|
|---|
| 1668 |
|
|---|
| 1669 | \sa end()
|
|---|
| 1670 | */
|
|---|
| 1671 |
|
|---|
| 1672 | /*!
|
|---|
| 1673 | \fn QWebElementCollection::const_iterator QWebElementCollection::end() const
|
|---|
| 1674 |
|
|---|
| 1675 | Returns an STL-style iterator pointing to the imaginary element after the
|
|---|
| 1676 | last element in the list.
|
|---|
| 1677 |
|
|---|
| 1678 | \sa begin()
|
|---|
| 1679 | */
|
|---|
| 1680 |
|
|---|
| 1681 | /*!
|
|---|
| 1682 | \class QWebElementCollection::const_iterator
|
|---|
| 1683 | \since 4.6
|
|---|
| 1684 | \brief The QWebElementCollection::const_iterator class provides an STL-style const iterator for QWebElementCollection.
|
|---|
| 1685 |
|
|---|
| 1686 | QWebElementCollection provides STL style const iterators for fast low-level access to the elements.
|
|---|
| 1687 |
|
|---|
| 1688 | QWebElementCollection::const_iterator allows you to iterate over a QWebElementCollection.
|
|---|
| 1689 | */
|
|---|
| 1690 |
|
|---|
| 1691 | /*!
|
|---|
| 1692 | \fn QWebElementCollection::const_iterator::const_iterator(const const_iterator &other)
|
|---|
| 1693 |
|
|---|
| 1694 | Constructs a copy of \a other.
|
|---|
| 1695 | */
|
|---|
| 1696 |
|
|---|
| 1697 | /*!
|
|---|
| 1698 | \fn QWebElementCollection::const_iterator::const_iterator(const QWebElementCollection *collection, int index)
|
|---|
| 1699 | \internal
|
|---|
| 1700 | */
|
|---|
| 1701 |
|
|---|
| 1702 | /*!
|
|---|
| 1703 | \fn const QWebElement QWebElementCollection::const_iterator::operator*() const
|
|---|
| 1704 |
|
|---|
| 1705 | Returns the current element.
|
|---|
| 1706 | */
|
|---|
| 1707 |
|
|---|
| 1708 | /*!
|
|---|
| 1709 | \fn bool QWebElementCollection::const_iterator::operator==(const const_iterator &other) const
|
|---|
| 1710 |
|
|---|
| 1711 | Returns true if \a other points to the same item as this iterator;
|
|---|
| 1712 | otherwise returns false.
|
|---|
| 1713 |
|
|---|
| 1714 | \sa operator!=()
|
|---|
| 1715 | */
|
|---|
| 1716 |
|
|---|
| 1717 | /*!
|
|---|
| 1718 | \fn bool QWebElementCollection::const_iterator::operator!=(const const_iterator &other) const
|
|---|
| 1719 |
|
|---|
| 1720 | Returns true if \a other points to a different element than this;
|
|---|
| 1721 | iterator; otherwise returns false.
|
|---|
| 1722 |
|
|---|
| 1723 | \sa operator==()
|
|---|
| 1724 | */
|
|---|
| 1725 |
|
|---|
| 1726 | /*!
|
|---|
| 1727 | \fn QWebElementCollection::const_iterator &QWebElementCollection::const_iterator::operator++()
|
|---|
| 1728 |
|
|---|
| 1729 | The prefix ++ operator (\c{++it}) advances the iterator to the next element in the collection
|
|---|
| 1730 | and returns an iterator to the new current element.
|
|---|
| 1731 |
|
|---|
| 1732 | Calling this function on QWebElementCollection::end() leads to undefined results.
|
|---|
| 1733 |
|
|---|
| 1734 | \sa operator--()
|
|---|
| 1735 | */
|
|---|
| 1736 |
|
|---|
| 1737 | /*!
|
|---|
| 1738 | \fn QWebElementCollection::const_iterator QWebElementCollection::const_iterator::operator++(int)
|
|---|
| 1739 |
|
|---|
| 1740 | \overload
|
|---|
| 1741 |
|
|---|
| 1742 | The postfix ++ operator (\c{it++}) advances the iterator to the next element in the collection
|
|---|
| 1743 | and returns an iterator to the previously current element.
|
|---|
| 1744 |
|
|---|
| 1745 | Calling this function on QWebElementCollection::end() leads to undefined results.
|
|---|
| 1746 | */
|
|---|
| 1747 |
|
|---|
| 1748 | /*!
|
|---|
| 1749 | \fn QWebElementCollection::const_iterator &QWebElementCollection::const_iterator::operator--()
|
|---|
| 1750 |
|
|---|
| 1751 | The prefix -- operator (\c{--it}) makes the preceding element current and returns an
|
|---|
| 1752 | iterator to the new current element.
|
|---|
| 1753 |
|
|---|
| 1754 | Calling this function on QWebElementCollection::begin() leads to undefined results.
|
|---|
| 1755 |
|
|---|
| 1756 | \sa operator++()
|
|---|
| 1757 | */
|
|---|
| 1758 |
|
|---|
| 1759 | /*!
|
|---|
| 1760 | \fn QWebElementCollection::const_iterator QWebElementCollection::const_iterator::operator--(int)
|
|---|
| 1761 |
|
|---|
| 1762 | \overload
|
|---|
| 1763 |
|
|---|
| 1764 | The postfix -- operator (\c{it--}) makes the preceding element current and returns
|
|---|
| 1765 | an iterator to the previously current element.
|
|---|
| 1766 | */
|
|---|
| 1767 |
|
|---|
| 1768 | /*!
|
|---|
| 1769 | \fn QWebElementCollection::const_iterator &QWebElementCollection::const_iterator::operator+=(int j)
|
|---|
| 1770 |
|
|---|
| 1771 | Advances the iterator by \a j elements. If \a j is negative, the iterator goes backward.
|
|---|
| 1772 |
|
|---|
| 1773 | \sa operator-=(), operator+()
|
|---|
| 1774 | */
|
|---|
| 1775 |
|
|---|
| 1776 | /*!
|
|---|
| 1777 | \fn QWebElementCollection::const_iterator &QWebElementCollection::const_iterator::operator-=(int j)
|
|---|
| 1778 |
|
|---|
| 1779 | Makes the iterator go back by \a j elements. If \a j is negative, the iterator goes forward.
|
|---|
| 1780 |
|
|---|
| 1781 | \sa operator+=(), operator-()
|
|---|
| 1782 | */
|
|---|
| 1783 |
|
|---|
| 1784 | /*!
|
|---|
| 1785 | \fn QWebElementCollection::const_iterator QWebElementCollection::const_iterator::operator+(int j) const
|
|---|
| 1786 |
|
|---|
| 1787 | Returns an iterator to the element at \a j positions forward from this iterator. If \a j
|
|---|
| 1788 | is negative, the iterator goes backward.
|
|---|
| 1789 |
|
|---|
| 1790 | \sa operator-(), operator+=()
|
|---|
| 1791 | */
|
|---|
| 1792 |
|
|---|
| 1793 | /*!
|
|---|
| 1794 | \fn QWebElementCollection::const_iterator QWebElementCollection::const_iterator::operator-(int j) const
|
|---|
| 1795 |
|
|---|
| 1796 | Returns an iterator to the element at \a j positiosn backward from this iterator.
|
|---|
| 1797 | If \a j is negative, the iterator goes forward.
|
|---|
| 1798 |
|
|---|
| 1799 | \sa operator+(), operator-=()
|
|---|
| 1800 | */
|
|---|
| 1801 |
|
|---|
| 1802 | /*!
|
|---|
| 1803 | \fn int QWebElementCollection::const_iterator::operator-(const_iterator other) const
|
|---|
| 1804 |
|
|---|
| 1805 | Returns the number of elements between the item point to by \a other
|
|---|
| 1806 | and the element pointed to by this iterator.
|
|---|
| 1807 | */
|
|---|
| 1808 |
|
|---|
| 1809 | /*!
|
|---|
| 1810 | \fn bool QWebElementCollection::const_iterator::operator<(const const_iterator &other) const
|
|---|
| 1811 |
|
|---|
| 1812 | Returns true if the element pointed to by this iterator is less than the element pointed to
|
|---|
| 1813 | by the \a other iterator.
|
|---|
| 1814 | */
|
|---|
| 1815 |
|
|---|
| 1816 | /*!
|
|---|
| 1817 | \fn bool QWebElementCollection::const_iterator::operator<=(const const_iterator &other) const
|
|---|
| 1818 |
|
|---|
| 1819 | Returns true if the element pointed to by this iterator is less than or equal to the
|
|---|
| 1820 | element pointed to by the \a other iterator.
|
|---|
| 1821 | */
|
|---|
| 1822 |
|
|---|
| 1823 | /*!
|
|---|
| 1824 | \fn bool QWebElementCollection::const_iterator::operator>(const const_iterator &other) const
|
|---|
| 1825 |
|
|---|
| 1826 | Returns true if the element pointed to by this iterator is greater than the element pointed to
|
|---|
| 1827 | by the \a other iterator.
|
|---|
| 1828 | */
|
|---|
| 1829 |
|
|---|
| 1830 | /*!
|
|---|
| 1831 | \fn bool QWebElementCollection::const_iterator::operator>=(const const_iterator &other) const
|
|---|
| 1832 |
|
|---|
| 1833 | Returns true if the element pointed to by this iterator is greater than or equal to the
|
|---|
| 1834 | element pointed to by the \a other iterator.
|
|---|
| 1835 | */
|
|---|
| 1836 |
|
|---|
| 1837 | /*!
|
|---|
| 1838 | \fn QWebElementCollection::iterator QWebElementCollection::begin()
|
|---|
| 1839 |
|
|---|
| 1840 | Returns an STL-style iterator pointing to the first element in the collection.
|
|---|
| 1841 |
|
|---|
| 1842 | \sa end()
|
|---|
| 1843 | */
|
|---|
| 1844 |
|
|---|
| 1845 | /*!
|
|---|
| 1846 | \fn QWebElementCollection::iterator QWebElementCollection::end()
|
|---|
| 1847 |
|
|---|
| 1848 | Returns an STL-style iterator pointing to the imaginary element after the
|
|---|
| 1849 | last element in the list.
|
|---|
| 1850 |
|
|---|
| 1851 | \sa begin()
|
|---|
| 1852 | */
|
|---|
| 1853 |
|
|---|
| 1854 | /*!
|
|---|
| 1855 | \fn QWebElementCollection::const_iterator QWebElementCollection::constBegin() const
|
|---|
| 1856 |
|
|---|
| 1857 | Returns an STL-style iterator pointing to the first element in the collection.
|
|---|
| 1858 |
|
|---|
| 1859 | \sa end()
|
|---|
| 1860 | */
|
|---|
| 1861 |
|
|---|
| 1862 | /*!
|
|---|
| 1863 | \fn QWebElementCollection::const_iterator QWebElementCollection::constEnd() const
|
|---|
| 1864 |
|
|---|
| 1865 | Returns an STL-style iterator pointing to the imaginary element after the
|
|---|
| 1866 | last element in the list.
|
|---|
| 1867 |
|
|---|
| 1868 | \sa begin()
|
|---|
| 1869 | */
|
|---|
| 1870 |
|
|---|
| 1871 | /*!
|
|---|
| 1872 | \class QWebElementCollection::iterator
|
|---|
| 1873 | \since 4.6
|
|---|
| 1874 | \brief The QWebElementCollection::iterator class provides an STL-style iterator for QWebElementCollection.
|
|---|
| 1875 |
|
|---|
| 1876 | QWebElementCollection provides STL style iterators for fast low-level access to the elements.
|
|---|
| 1877 |
|
|---|
| 1878 | QWebElementCollection::iterator allows you to iterate over a QWebElementCollection.
|
|---|
| 1879 | */
|
|---|
| 1880 |
|
|---|
| 1881 | /*!
|
|---|
| 1882 | \fn QWebElementCollection::iterator::iterator(const iterator &other)
|
|---|
| 1883 |
|
|---|
| 1884 | Constructs a copy of \a other.
|
|---|
| 1885 | */
|
|---|
| 1886 |
|
|---|
| 1887 | /*!
|
|---|
| 1888 | \fn QWebElementCollection::iterator::iterator(const QWebElementCollection *collection, int index)
|
|---|
| 1889 | \internal
|
|---|
| 1890 | */
|
|---|
| 1891 |
|
|---|
| 1892 | /*!
|
|---|
| 1893 | \fn const QWebElement QWebElementCollection::iterator::operator*() const
|
|---|
| 1894 |
|
|---|
| 1895 | Returns the current element.
|
|---|
| 1896 | */
|
|---|
| 1897 |
|
|---|
| 1898 | /*!
|
|---|
| 1899 | \fn bool QWebElementCollection::iterator::operator==(const iterator &other) const
|
|---|
| 1900 |
|
|---|
| 1901 | Returns true if \a other points to the same item as this iterator;
|
|---|
| 1902 | otherwise returns false.
|
|---|
| 1903 |
|
|---|
| 1904 | \sa operator!=()
|
|---|
| 1905 | */
|
|---|
| 1906 |
|
|---|
| 1907 | /*!
|
|---|
| 1908 | \fn bool QWebElementCollection::iterator::operator!=(const iterator &other) const
|
|---|
| 1909 |
|
|---|
| 1910 | Returns true if \a other points to a different element than this;
|
|---|
| 1911 | iterator; otherwise returns false.
|
|---|
| 1912 |
|
|---|
| 1913 | \sa operator==()
|
|---|
| 1914 | */
|
|---|
| 1915 |
|
|---|
| 1916 | /*!
|
|---|
| 1917 | \fn QWebElementCollection::iterator &QWebElementCollection::iterator::operator++()
|
|---|
| 1918 |
|
|---|
| 1919 | The prefix ++ operator (\c{++it}) advances the iterator to the next element in the collection
|
|---|
| 1920 | and returns an iterator to the new current element.
|
|---|
| 1921 |
|
|---|
| 1922 | Calling this function on QWebElementCollection::end() leads to undefined results.
|
|---|
| 1923 |
|
|---|
| 1924 | \sa operator--()
|
|---|
| 1925 | */
|
|---|
| 1926 |
|
|---|
| 1927 | /*!
|
|---|
| 1928 | \fn QWebElementCollection::iterator QWebElementCollection::iterator::operator++(int)
|
|---|
| 1929 |
|
|---|
| 1930 | \overload
|
|---|
| 1931 |
|
|---|
| 1932 | The postfix ++ operator (\c{it++}) advances the iterator to the next element in the collection
|
|---|
| 1933 | and returns an iterator to the previously current element.
|
|---|
| 1934 |
|
|---|
| 1935 | Calling this function on QWebElementCollection::end() leads to undefined results.
|
|---|
| 1936 | */
|
|---|
| 1937 |
|
|---|
| 1938 | /*!
|
|---|
| 1939 | \fn QWebElementCollection::iterator &QWebElementCollection::iterator::operator--()
|
|---|
| 1940 |
|
|---|
| 1941 | The prefix -- operator (\c{--it}) makes the preceding element current and returns an
|
|---|
| 1942 | iterator to the new current element.
|
|---|
| 1943 |
|
|---|
| 1944 | Calling this function on QWebElementCollection::begin() leads to undefined results.
|
|---|
| 1945 |
|
|---|
| 1946 | \sa operator++()
|
|---|
| 1947 | */
|
|---|
| 1948 |
|
|---|
| 1949 | /*!
|
|---|
| 1950 | \fn QWebElementCollection::iterator QWebElementCollection::iterator::operator--(int)
|
|---|
| 1951 |
|
|---|
| 1952 | \overload
|
|---|
| 1953 |
|
|---|
| 1954 | The postfix -- operator (\c{it--}) makes the preceding element current and returns
|
|---|
| 1955 | an iterator to the previously current element.
|
|---|
| 1956 | */
|
|---|
| 1957 |
|
|---|
| 1958 | /*!
|
|---|
| 1959 | \fn QWebElementCollection::iterator &QWebElementCollection::iterator::operator+=(int j)
|
|---|
| 1960 |
|
|---|
| 1961 | Advances the iterator by \a j elements. If \a j is negative, the iterator goes backward.
|
|---|
| 1962 |
|
|---|
| 1963 | \sa operator-=(), operator+()
|
|---|
| 1964 | */
|
|---|
| 1965 |
|
|---|
| 1966 | /*!
|
|---|
| 1967 | \fn QWebElementCollection::iterator &QWebElementCollection::iterator::operator-=(int j)
|
|---|
| 1968 |
|
|---|
| 1969 | Makes the iterator go back by \a j elements. If \a j is negative, the iterator goes forward.
|
|---|
| 1970 |
|
|---|
| 1971 | \sa operator+=(), operator-()
|
|---|
| 1972 | */
|
|---|
| 1973 |
|
|---|
| 1974 | /*!
|
|---|
| 1975 | \fn QWebElementCollection::iterator QWebElementCollection::iterator::operator+(int j) const
|
|---|
| 1976 |
|
|---|
| 1977 | Returns an iterator to the element at \a j positions forward from this iterator. If \a j
|
|---|
| 1978 | is negative, the iterator goes backward.
|
|---|
| 1979 |
|
|---|
| 1980 | \sa operator-(), operator+=()
|
|---|
| 1981 | */
|
|---|
| 1982 |
|
|---|
| 1983 | /*!
|
|---|
| 1984 | \fn QWebElementCollection::iterator QWebElementCollection::iterator::operator-(int j) const
|
|---|
| 1985 |
|
|---|
| 1986 | Returns an iterator to the element at \a j positiosn backward from this iterator.
|
|---|
| 1987 | If \a j is negative, the iterator goes forward.
|
|---|
| 1988 |
|
|---|
| 1989 | \sa operator+(), operator-=()
|
|---|
| 1990 | */
|
|---|
| 1991 |
|
|---|
| 1992 | /*!
|
|---|
| 1993 | \fn int QWebElementCollection::iterator::operator-(iterator other) const
|
|---|
| 1994 |
|
|---|
| 1995 | Returns the number of elements between the item point to by \a other
|
|---|
| 1996 | and the element pointed to by this iterator.
|
|---|
| 1997 | */
|
|---|
| 1998 |
|
|---|
| 1999 | /*!
|
|---|
| 2000 | \fn bool QWebElementCollection::iterator::operator<(const iterator &other) const
|
|---|
| 2001 |
|
|---|
| 2002 | Returns true if the element pointed to by this iterator is less than the element pointed to
|
|---|
| 2003 | by the \a other iterator.
|
|---|
| 2004 | */
|
|---|
| 2005 |
|
|---|
| 2006 | /*!
|
|---|
| 2007 | \fn bool QWebElementCollection::iterator::operator<=(const iterator &other) const
|
|---|
| 2008 |
|
|---|
| 2009 | Returns true if the element pointed to by this iterator is less than or equal to the
|
|---|
| 2010 | element pointed to by the \a other iterator.
|
|---|
| 2011 | */
|
|---|
| 2012 |
|
|---|
| 2013 | /*!
|
|---|
| 2014 | \fn bool QWebElementCollection::iterator::operator>(const iterator &other) const
|
|---|
| 2015 |
|
|---|
| 2016 | Returns true if the element pointed to by this iterator is greater than the element pointed to
|
|---|
| 2017 | by the \a other iterator.
|
|---|
| 2018 | */
|
|---|
| 2019 |
|
|---|
| 2020 | /*!
|
|---|
| 2021 | \fn bool QWebElementCollection::iterator::operator>=(const iterator &other) const
|
|---|
| 2022 |
|
|---|
| 2023 | Returns true if the element pointed to by this iterator is greater than or equal to the
|
|---|
| 2024 | element pointed to by the \a other iterator.
|
|---|
| 2025 | */
|
|---|