Commit b721f14b authored by hausmann@webkit.org's avatar hausmann@webkit.org

2009-04-28 Simon Hausmann <simon.hausmann@nokia.com>

        Reviewed by Tor Arne Vestbø.

        QWebElement API changes after another round of API review:

        * Fix argument names of findAll/findFirst
        * Split up toXml into innerXml and outerXml
        * Removed confusing toggleClass overload
        * Fixed casing of namespaceUri to follow QXmlStreamReader
        * Removed tagName from firstChild/nextSibling/etc.
        * Renamed append/prepend/insertAfter/insertBefore to [append|prepend][Inside|Outside]
        * Renamed wrapWith() back to wrap()
        * Made clone() const
        * Renamed remove() to takeFromDocument(), added removeFromDocument()
        * Renamed clear() to removeChildren()
        * Renamed scriptsFunctions/callScriptFunction to functions()/callFunction()
        * Renamed scriptProperty to scriptableProperty

git-svn-id: svn://svn.chromium.org/blink/trunk@42934 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent f69a3349
...@@ -142,22 +142,26 @@ bool QWebElement::isNull() const ...@@ -142,22 +142,26 @@ bool QWebElement::isNull() const
/*! /*!
Returns a new collection of elements that are children of this element Returns a new collection of elements that are children of this element
and that match the given CSS selector \a query. and that match the given CSS selector \a selectorQuery.
*/ */
QWebElementCollection QWebElement::findAll(const QString &query) const QWebElementCollection QWebElement::findAll(const QString &selectorQuery) const
{ {
return QWebElementCollection(*this, query); return QWebElementCollection(*this, selectorQuery);
} }
/*! /*!
Returns the first child element that matches the given CSS selector \a query. Returns the first child element that matches the given CSS selector \a selectorQuery.
This function is equivalent to calling findAll() and taking only the
first element in the returned collection of elements. However calling
this function is more efficient.
*/ */
QWebElement QWebElement::findFirst(const QString &query) const QWebElement QWebElement::findFirst(const QString &selectorQuery) const
{ {
if (!m_element) if (!m_element)
return QWebElement(); return QWebElement();
ExceptionCode exception = 0; // ### ExceptionCode exception = 0; // ###
return QWebElement(m_element->querySelector(query, exception).get()); return QWebElement(m_element->querySelector(selectorQuery, exception).get());
} }
/*! /*!
...@@ -187,54 +191,65 @@ QString QWebElement::toPlainText() const ...@@ -187,54 +191,65 @@ QString QWebElement::toPlainText() const
} }
/*! /*!
Replaces the existing content of this element with \a markup. Replaces the contents of this element as well as its own tag with \a markup.
The string may contain HTML or XML tags, which is parsed and formatted The string may contain HTML or XML tags, which is parsed and formatted
before insertion into the document. before insertion into the document.
If \a scope is InnerXml this is equivalent to setting the HTML innerHTML \note This is currently only implemented for (X)HTML elements.
property, and similarily for OuterXml. */
void QWebElement::setOuterXml(const QString &markup)
{
if (!m_element || !m_element->isHTMLElement())
return;
ExceptionCode exception = 0;
static_cast<HTMLElement*>(m_element)->setOuterHTML(markup, exception);
}
/*!
Returns this element converted to XML, including the start and the end
tag of this element and its attributes.
\note This is currently only implemented for (X)HTML elements. \note This is currently only implemented for (X)HTML elements.
*/ */
void QWebElement::setXml(XmlScope scope, const QString &markup) QString QWebElement::toOuterXml() const
{
if (!m_element || !m_element->isHTMLElement())
return QString();
return static_cast<HTMLElement*>(m_element)->outerHTML();
}
/*!
Replaces the content of this element with \a markup.
The string may contain HTML or XML tags, which is parsed and formatted
before insertion into the document.
\note This is currently only implemented for (X)HTML elements.
*/
void QWebElement::setInnerXml(const QString &markup)
{ {
if (!m_element || !m_element->isHTMLElement()) if (!m_element || !m_element->isHTMLElement())
return; return;
ExceptionCode exception = 0; ExceptionCode exception = 0;
switch (scope) { static_cast<HTMLElement*>(m_element)->setInnerHTML(markup, exception);
case InnerXml:
static_cast<HTMLElement*>(m_element)->setInnerHTML(markup, exception);
break;
case OuterXml:
static_cast<HTMLElement*>(m_element)->setOuterHTML(markup, exception);
break;
}
} }
/*! /*!
Returns the XML between the start and the end tag of this Returns the XML between the start and the end tag of this
element. element.
If \a scope is InnerXml this is equivalent to reading the HTML
innerHTML property, and similarily for OuterXml.
\note This is currently only implemented for (X)HTML elements. \note This is currently only implemented for (X)HTML elements.
*/ */
QString QWebElement::toXml(XmlScope scope) const QString QWebElement::toInnerXml() const
{ {
if (!m_element || !m_element->isHTMLElement()) if (!m_element || !m_element->isHTMLElement())
return QString(); return QString();
switch (scope) { return static_cast<HTMLElement*>(m_element)->innerHTML();
case InnerXml:
return static_cast<HTMLElement*>(m_element)->innerHTML();
case OuterXml:
return static_cast<HTMLElement*>(m_element)->outerHTML();
default:
return QString();
}
} }
/*! /*!
...@@ -388,7 +403,7 @@ QString QWebElement::localName() const ...@@ -388,7 +403,7 @@ QString QWebElement::localName() const
/*! /*!
Returns the namespace URI of this element or an empty string if the element has no namespace URI. Returns the namespace URI of this element or an empty string if the element has no namespace URI.
*/ */
QString QWebElement::namespaceURI() const QString QWebElement::namespaceUri() const
{ {
if (!m_element) if (!m_element)
return QString(); return QString();
...@@ -406,89 +421,73 @@ QWebElement QWebElement::parent() const ...@@ -406,89 +421,73 @@ QWebElement QWebElement::parent() const
} }
/*! /*!
Returns the first child element of this element with tag name Returns the first child element of this element.
\a tagName if \a tagName is non-empty; otherwise returns the
first child element. Returns a null element if no such child exists.
\sa lastChild() previousSibling() nextSibling() \sa lastChild() previousSibling() nextSibling()
*/ */
QWebElement QWebElement::firstChild(const QString &tagName) const QWebElement QWebElement::firstChild() const
{ {
if (!m_element) if (!m_element)
return QWebElement(); return QWebElement();
String tag = tagName;
for (Node* child = m_element->firstChild(); child; child = child->nextSibling()) { for (Node* child = m_element->firstChild(); child; child = child->nextSibling()) {
if (!child->isElementNode()) if (!child->isElementNode())
continue; continue;
Element* e = static_cast<Element*>(child); Element* e = static_cast<Element*>(child);
if (tagName.isEmpty() || equalIgnoringCase(e->tagName(), tag)) return QWebElement(e);
return QWebElement(e);
} }
return QWebElement(); return QWebElement();
} }
/*! /*!
Returns the last child element of this element with tag name Returns the last child element of this element.
\a tagName if \a tagName is non-empty; otherwise returns the
last child element. Returns a null element if no such child exists.
\sa firstChild() previousSibling() nextSibling() \sa firstChild() previousSibling() nextSibling()
*/ */
QWebElement QWebElement::lastChild(const QString &tagName) const QWebElement QWebElement::lastChild() const
{ {
if (!m_element) if (!m_element)
return QWebElement(); return QWebElement();
String tag = tagName;
for (Node* child = m_element->lastChild(); child; child = child->previousSibling()) { for (Node* child = m_element->lastChild(); child; child = child->previousSibling()) {
if (!child->isElementNode()) if (!child->isElementNode())
continue; continue;
Element* e = static_cast<Element*>(child); Element* e = static_cast<Element*>(child);
if (tagName.isEmpty() || equalIgnoringCase(e->tagName(), tag)) return QWebElement(e);
return QWebElement(e);
} }
return QWebElement(); return QWebElement();
} }
/*! /*!
Returns the next sibling element of this element with tag name Returns the next sibling element of this element.
\a tagName if \a tagName is non-empty; otherwise returns any next sibling
element. Returns a null element if no such sibling exists.
\sa firstChild() previousSibling() lastChild() \sa firstChild() previousSibling() lastChild()
*/ */
QWebElement QWebElement::nextSibling(const QString &tagName) const QWebElement QWebElement::nextSibling() const
{ {
if (!m_element) if (!m_element)
return QWebElement(); return QWebElement();
String tag = tagName;
for (Node* sib = m_element->nextSibling(); sib; sib = sib->nextSibling()) { for (Node* sib = m_element->nextSibling(); sib; sib = sib->nextSibling()) {
if (!sib->isElementNode()) if (!sib->isElementNode())
continue; continue;
Element* e = static_cast<Element*>(sib); Element* e = static_cast<Element*>(sib);
if (tagName.isEmpty() || equalIgnoringCase(e->tagName(), tag)) return QWebElement(e);
return QWebElement(e);
} }
return QWebElement(); return QWebElement();
} }
/*! /*!
Returns the previous sibling element of this element with tag name Returns the previous sibling element of this element.
\a tagName if \a tagName is non-empty; otherwise returns any previous sibling
element. Returns a null element if no such sibling exists.
\sa firstChild() nextSibling() lastChild() \sa firstChild() nextSibling() lastChild()
*/ */
QWebElement QWebElement::previousSibling(const QString &tagName) const QWebElement QWebElement::previousSibling() const
{ {
if (!m_element) if (!m_element)
return QWebElement(); return QWebElement();
String tag = tagName;
for (Node* sib = m_element->previousSibling(); sib; sib = sib->previousSibling()) { for (Node* sib = m_element->previousSibling(); sib; sib = sib->previousSibling()) {
if (!sib->isElementNode()) if (!sib->isElementNode())
continue; continue;
Element* e = static_cast<Element*>(sib); Element* e = static_cast<Element*>(sib);
if (tagName.isEmpty() || equalIgnoringCase(e->tagName(), tag)) return QWebElement(e);
return QWebElement(e);
} }
return QWebElement(); return QWebElement();
} }
...@@ -561,9 +560,9 @@ static bool setupScriptObject(WebCore::Element* element, ScriptObject& object, S ...@@ -561,9 +560,9 @@ static bool setupScriptObject(WebCore::Element* element, ScriptObject& object, S
on its type. For example a form element can have the "submit" function, that would submit on its type. For example a form element can have the "submit" function, that would submit
the form to the destination specified in the HTML. the form to the destination specified in the HTML.
\sa scriptFunctions() \sa functions()
*/ */
QVariant QWebElement::callScriptFunction(const QString &name, const QVariantList &arguments) QVariant QWebElement::callFunction(const QString &name, const QVariantList &arguments)
{ {
ScriptState* state = 0; ScriptState* state = 0;
ScriptObject thisObject; ScriptObject thisObject;
...@@ -593,9 +592,9 @@ QVariant QWebElement::callScriptFunction(const QString &name, const QVariantList ...@@ -593,9 +592,9 @@ QVariant QWebElement::callScriptFunction(const QString &name, const QVariantList
The function names returned are the same functions that are callable from the DOM The function names returned are the same functions that are callable from the DOM
element's JavaScript binding. element's JavaScript binding.
\sa callScriptFunction() \sa callFunction()
*/ */
QStringList QWebElement::scriptFunctions() const QStringList QWebElement::functions() const
{ {
ScriptState* state = 0; ScriptState* state = 0;
ScriptObject thisObject; ScriptObject thisObject;
...@@ -649,9 +648,9 @@ QStringList QWebElement::scriptFunctions() const ...@@ -649,9 +648,9 @@ QStringList QWebElement::scriptFunctions() const
Information about all available properties is provided through scriptProperties(). Information about all available properties is provided through scriptProperties().
\sa setScriptProperty(), scriptProperties() \sa setScriptableProperty(), scriptableProperties()
*/ */
QVariant QWebElement::scriptProperty(const QString &name) const QVariant QWebElement::scriptableProperty(const QString &name) const
{ {
ScriptState* state = 0; ScriptState* state = 0;
ScriptObject thisObject; ScriptObject thisObject;
...@@ -679,9 +678,9 @@ QVariant QWebElement::scriptProperty(const QString &name) const ...@@ -679,9 +678,9 @@ QVariant QWebElement::scriptProperty(const QString &name) const
Setting the property will affect the corresponding property Setting the property will affect the corresponding property
in the element's JavaScript binding with the same name. in the element's JavaScript binding with the same name.
\sa scriptProperty(), scriptProperties() \sa scriptableProperty(), scriptableProperties()
*/ */
void QWebElement::setScriptProperty(const QString &name, const QVariant &value) void QWebElement::setScriptableProperty(const QString &name, const QVariant &value)
{ {
ScriptState* state = 0; ScriptState* state = 0;
ScriptObject thisObject; ScriptObject thisObject;
...@@ -706,8 +705,10 @@ void QWebElement::setScriptProperty(const QString &name, const QVariant &value) ...@@ -706,8 +705,10 @@ void QWebElement::setScriptProperty(const QString &name, const QVariant &value)
The function names returned are the same properties that are accessible from the DOM The function names returned are the same properties that are accessible from the DOM
element's JavaScript binding. element's JavaScript binding.
\sa setScriptableProperty(), scriptableProperty()
*/ */
QStringList QWebElement::scriptProperties() const QStringList QWebElement::scriptableProperties() const
{ {
if (!m_element) if (!m_element)
return QStringList(); return QStringList();
...@@ -894,28 +895,6 @@ void QWebElement::toggleClass(const QString &name) ...@@ -894,28 +895,6 @@ void QWebElement::toggleClass(const QString &name)
setAttribute("class", value); setAttribute("class", value);
} }
/*!
Adds the specified class \a name if \a enabled is true or
removes it if \a enabled is false.
*/
void QWebElement::toggleClass(const QString &name, bool enabled)
{
QStringList list = classes();
if (list.contains(name)) {
if (!enabled) {
list.removeAll(name);
QString value = list.join(" ");
setAttribute("class", value);
}
} else {
if (enabled) {
list.append(name);
QString value = list.join(" ");
setAttribute("class", value);
}
}
}
/*! /*!
Appends \a element as the element's last child. Appends \a element as the element's last child.
...@@ -925,9 +904,9 @@ void QWebElement::toggleClass(const QString &name, bool enabled) ...@@ -925,9 +904,9 @@ void QWebElement::toggleClass(const QString &name, bool enabled)
Calling this function on a null element does nothing. Calling this function on a null element does nothing.
\sa prepend(), insertBefore(), insertAfter() \sa prependInside(), prependOutside(), appendOutside()
*/ */
void QWebElement::append(QWebElement element) void QWebElement::appendInside(const QWebElement &element)
{ {
if (!m_element || element.isNull()) if (!m_element || element.isNull())
return; return;
...@@ -941,9 +920,9 @@ void QWebElement::append(QWebElement element) ...@@ -941,9 +920,9 @@ void QWebElement::append(QWebElement element)
Calling this function on a null element does nothing. Calling this function on a null element does nothing.
\sa prepend(), insertBefore(), insertAfter() \sa prependInside(), prependOutside(), appendOutside()
*/ */
void QWebElement::append(const QString &markup) void QWebElement::appendInside(const QString &markup)
{ {
if (!m_element) if (!m_element)
return; return;
...@@ -967,9 +946,9 @@ void QWebElement::append(const QString &markup) ...@@ -967,9 +946,9 @@ void QWebElement::append(const QString &markup)
Calling this function on a null element does nothing. Calling this function on a null element does nothing.
\sa append(), insertBefore(), insertAfter() \sa appendInside(), prependOutside(), appendOutside()
*/ */
void QWebElement::prepend(QWebElement element) void QWebElement::prependInside(const QWebElement &element)
{ {
if (!m_element || element.isNull()) if (!m_element || element.isNull())
return; return;
...@@ -983,9 +962,9 @@ void QWebElement::prepend(QWebElement element) ...@@ -983,9 +962,9 @@ void QWebElement::prepend(QWebElement element)
Calling this function on a null element does nothing. Calling this function on a null element does nothing.
\sa append(), insertBefore(), insertAfter() \sa appendInside(), prependOutside(), appendOutside()
*/ */
void QWebElement::prepend(const QString &markup) void QWebElement::prependInside(const QString &markup)
{ {
if (!m_element) if (!m_element)
return; return;
...@@ -1009,9 +988,9 @@ void QWebElement::prepend(const QString &markup) ...@@ -1009,9 +988,9 @@ void QWebElement::prepend(const QString &markup)
Calling this function on a null element does nothing. Calling this function on a null element does nothing.
\sa append(), prepend(), insertAfter() \sa appendInside(), prependInside(), appendOutside()
*/ */
void QWebElement::insertBefore(QWebElement element) void QWebElement::prependOutside(const QWebElement &element)
{ {
if (!m_element || element.isNull()) if (!m_element || element.isNull())
return; return;
...@@ -1028,9 +1007,9 @@ void QWebElement::insertBefore(QWebElement element) ...@@ -1028,9 +1007,9 @@ void QWebElement::insertBefore(QWebElement element)
Calling this function on a null element does nothing. Calling this function on a null element does nothing.
\sa append(), prepend(), insertAfter() \sa appendInside(), prependInside(), appendOutside()
*/ */
void QWebElement::insertBefore(const QString &markup) void QWebElement::prependOutside(const QString &markup)
{ {
if (!m_element) if (!m_element)
return; return;
...@@ -1056,9 +1035,9 @@ void QWebElement::insertBefore(const QString &markup) ...@@ -1056,9 +1035,9 @@ void QWebElement::insertBefore(const QString &markup)
Calling this function on a null element does nothing. Calling this function on a null element does nothing.
\sa append(), prepend(), insertBefore() \sa appendInside(), prependInside(), prependOutside()
*/ */
void QWebElement::insertAfter(QWebElement element) void QWebElement::appendOutside(const QWebElement &element)
{ {
if (!m_element || element.isNull()) if (!m_element || element.isNull())
return; return;
...@@ -1078,9 +1057,9 @@ void QWebElement::insertAfter(QWebElement element) ...@@ -1078,9 +1057,9 @@ void QWebElement::insertAfter(QWebElement element)
Calling this function on a null element does nothing. Calling this function on a null element does nothing.
\sa append(), prepend(), insertBefore() \sa appendInside(), prependInside(), prependOutside()
*/ */
void QWebElement::insertAfter(const QString &markup) void QWebElement::appendOutside(const QString &markup)
{ {
if (!m_element) if (!m_element)
return; return;
...@@ -1103,9 +1082,9 @@ void QWebElement::insertAfter(const QString &markup) ...@@ -1103,9 +1082,9 @@ void QWebElement::insertAfter(const QString &markup)
The clone may be inserted at any point in the document. The clone may be inserted at any point in the document.
\sa append(), prepend(), insertBefore(), insertAfter() \sa appendInside(), prependInside(), prependOutside(), appendOutside()
*/ */
QWebElement QWebElement::clone() QWebElement QWebElement::clone() const
{ {
if (!m_element) if (!m_element)
return QWebElement(); return QWebElement();
...@@ -1114,14 +1093,15 @@ QWebElement QWebElement::clone() ...@@ -1114,14 +1093,15 @@ QWebElement QWebElement::clone()
} }
/*! /*!
Removes this element from the document. Removes this element from the document and returns a reference
to this.
The element is still valid after removal, and can be inserted into The element is still valid after removal, and can be inserted into
other parts of the document. other parts of the document.
\sa clear() \sa removeChildren(), removeFromDocument()
*/ */
QWebElement &QWebElement::remove() QWebElement &QWebElement::takeFromDocument()
{ {
if (!m_element) if (!m_element)
return *this; return *this;
...@@ -1132,12 +1112,29 @@ QWebElement &QWebElement::remove() ...@@ -1132,12 +1112,29 @@ QWebElement &QWebElement::remove()
return *this; return *this;
} }
/*!
Removes this element from the document and makes this
a null element.
\sa removeChildren(), takeFromDocument()
*/
void QWebElement::removeFromDocument()
{
if (!m_element)
return;
ExceptionCode exception = 0;
m_element->remove(exception);
m_element->deref();
m_element = 0;
}
/*! /*!
Removes all children from this element. Removes all children from this element.
\sa remove() \sa removeFromDocument(), takeFromDocument()
*/ */
void QWebElement::clear() void QWebElement::removeChildren()
{ {
if (!m_element) if (!m_element)
return; return;
...@@ -1148,22 +1145,23 @@ void QWebElement::clear() ...@@ -1148,22 +1145,23 @@ void QWebElement::clear()
/*! /*!
Wraps this element in \a element as the last child. Wraps this element in \a element as the last child.
\sa replaceWith() \sa replace()
*/ */
void QWebElement::wrap(QWebElement element) void QWebElement::wrap(const QWebElement &element)
{ {
if (!m_element || element.isNull()) if (!m_element || element.isNull())
return; return;
insertAfter(element); appendOutside(element);
element.append(*this); QWebElement other = element;
other.appendInside(*this);
} }
/*! /*!
Wraps this element in the result of parsing \a html, Wraps this element in the result of parsing \a html,
as the last child. as the last child.
\sa replaceWith() \sa replace()
*/ */
void QWebElement::wrap(const QString &html) void QWebElement::wrap(const QString &html)
{ {
...@@ -1202,13 +1200,13 @@ void QWebElement::wrap(const QString &html) ...@@ -1202,13 +1200,13 @@ void QWebElement::wrap(const QString &html)
\sa wrap() \sa wrap()
*/ */
void QWebElement::replaceWith(QWebElement element) void QWebElement::replace(const QWebElement &element)
{ {
if (!m_element || element.isNull()) if (!m_element || element.isNull())
return; return;
insertAfter(element); appendOutside(element);
remove(); takeFromDocument();
} }
/*! /*!
...@@ -1219,13 +1217,13 @@ void QWebElement::replaceWith(QWebElement element) ...@@ -1219,13 +1217,13 @@ void QWebElement::replaceWith(QWebElement element)
\sa wrap() \sa wrap()
*/ */
void QWebElement::replaceWith(const QString &html) void QWebElement::replace(const QString &html)
{ {
if (!m_element) if (!m_element)
return; return;
insertAfter(html); appendOutside(html);
remove(); takeFromDocument();
} }
/*! /*!
......
...@@ -47,19 +47,17 @@ public: ...@@ -47,19 +47,17 @@ public:
bool isNull() const; bool isNull() const;
QWebElementCollection findAll(const QString &query) const; QWebElementCollection findAll(const QString &selectorQuery) const;
QWebElement findFirst(const QString &query) const; QWebElement findFirst(const QString &selectorQuery) const;
void setPlainText(const QString &text); void setPlainText(const QString &text);
QString toPlainText() const; QString toPlainText() const;
enum XmlScope { void setOuterXml(const QString &markup);
InnerXml, QString toOuterXml() const;
OuterXml
};
void setXml(XmlScope scope, const QString &markup); void setInnerXml(const QString &markup);
QString toXml(XmlScope scope) const; QString toInnerXml() const;
void setAttribute(const QString &name, const QString &value); void setAttribute(const QString &name, const QString &value);
void setAttributeNS(const QString &namespaceUri, const QString &name, const QString &value); void setAttributeNS(const QString &namespaceUri, const QString &name, const QString &value);
...@@ -76,52 +74,57 @@ public: ...@@ -76,52 +74,57 @@ public:
void addClass(const QString &name); void addClass(const QString &name);
void removeClass(const QString &name); void removeClass(const QString &name);
void toggleClass(const QString &name); void toggleClass(const QString &name);
void toggleClass(const QString &name, bool enabled);
QRect geometry() const; QRect geometry() const;
QString tagName() const; QString tagName() const;
QString prefix() const; QString prefix() const;
QString localName() const; QString localName() const;
QString namespaceURI() const; QString namespaceUri() const;
QWebElement parent() const; QWebElement parent() const;
QWebElement firstChild(const QString &tagName = QString()) const; QWebElement firstChild() const;
QWebElement lastChild(const QString &tagName = QString()) const; QWebElement lastChild() const;
QWebElement nextSibling(const QString &tagName = QString()) const; QWebElement nextSibling() const;
QWebElement previousSibling(const QString &tagName = QString()) const; QWebElement previousSibling() const;
QWebElement document() const; QWebElement document() const;
QWebFrame *webFrame() const; QWebFrame *webFrame() const;
// TODO: Add QWebElementCollection overloads // TODO: Add QWebElementCollection overloads
void append(const QString &markup); // docs need example snippet
void append(QWebElement element); void appendInside(const QString &markup);
void appendInside(const QWebElement &element);
void prepend(const QString &markup); // docs need example snippet
void prepend(QWebElement element); void prependInside(const QString &markup);
void prependInside(const QWebElement &element);
void insertBefore(const QString &markup); // docs need example snippet
void insertBefore(QWebElement element); void appendOutside(const QString &markup);
void appendOutside(const QWebElement &element);
void insertAfter(const QString &markup); // docs need example snippet
void insertAfter(QWebElement element); void prependOutside(const QString &markup);
void prependOutside(const QWebElement &element);
// docs need example snippet
void wrap(const QString &markup); void wrap(const QString &markup);
void wrap(QWebElement element); void wrap(const QWebElement &element);
void replaceWith(const QString &markup); void replace(const QString &markup);
void replaceWith(QWebElement element); void replace(const QWebElement &element);
QWebElement clone(); QWebElement clone() const;
QWebElement &remove(); QWebElement &takeFromDocument();
void clear(); void removeFromDocument();
void removeChildren();
QVariant callScriptFunction(const QString &name, const QVariantList &arguments = QVariantList()); QVariant callFunction(const QString &functionName, const QVariantList &arguments = QVariantList());
QStringList scriptFunctions() const; QStringList functions() const;
QVariant scriptProperty(const QString &name) const; QVariant scriptableProperty(const QString &name) const;
void setScriptProperty(const QString &name, const QVariant &value); void setScriptableProperty(const QString &name, const QVariant &value);
QStringList scriptProperties() const; QStringList scriptableProperties() const;
QString styleProperty(const QString &name) const; QString styleProperty(const QString &name) const;
void setStyleProperty(const QString &name, const QString &value); void setStyleProperty(const QString &name, const QString &value);
......
...@@ -983,22 +983,22 @@ QWebElement QWebFrame::documentElement() const ...@@ -983,22 +983,22 @@ QWebElement QWebFrame::documentElement() const
/*! /*!
\since 4.6 \since 4.6
Returns a new collection of elements that are children of the frame's Returns a new collection of elements that are children of the frame's
document element and that match the given CSS selector \a query. document element and that match the given CSS selector \a selectorQuery.
*/ */
QWebElementCollection QWebFrame::findAllElements(const QString &query) const QWebElementCollection QWebFrame::findAllElements(const QString &selectorQuery) const
{ {
return documentElement().findAll(query); return documentElement().findAll(selectorQuery);
} }
/*! /*!
\since 4.6 \since 4.6
Returns the first element in the frame's document that matches the Returns the first element in the frame's document that matches the
given CSS selector \a query. Returns a null element if there is no given CSS selector \a selectorQuery. Returns a null element if there is no
match. match.
*/ */
QWebElement QWebFrame::findFirstElement(const QString &query) const QWebElement QWebFrame::findFirstElement(const QString &selectorQuery) const
{ {
return documentElement().findFirst(query); return documentElement().findFirst(selectorQuery);
} }
/*! /*!
......
...@@ -179,8 +179,8 @@ public: ...@@ -179,8 +179,8 @@ public:
QSize contentsSize() const; QSize contentsSize() const;
QWebElement documentElement() const; QWebElement documentElement() const;
QWebElementCollection findAllElements(const QString &query) const; QWebElementCollection findAllElements(const QString &selectorQuery) const;
QWebElement findFirstElement(const QString &query) const; QWebElement findFirstElement(const QString &selectorQuery) const;
QWebHitTestResult hitTestContent(const QPoint &pos) const; QWebHitTestResult hitTestContent(const QPoint &pos) const;
......
2009-04-28 Simon Hausmann <simon.hausmann@nokia.com>
Reviewed by Tor Arne Vestbø.
QWebElement API changes after another round of API review:
* Fix argument names of findAll/findFirst
* Split up toXml into innerXml and outerXml
* Removed confusing toggleClass overload
* Fixed casing of namespaceUri to follow QXmlStreamReader
* Removed tagName from firstChild/nextSibling/etc.
* Renamed append/prepend/insertAfter/insertBefore to [append|prepend][Inside|Outside]
* Renamed wrapWith() back to wrap()
* Made clone() const
* Renamed remove() to takeFromDocument(), added removeFromDocument()
* Renamed clear() to removeChildren()
* Renamed scriptsFunctions/callScriptFunction to functions()/callFunction()
* Renamed scriptProperty to scriptableProperty
* Api/qwebelement.cpp:
(QWebElement::findAll):
(QWebElement::findFirst):
(QWebElement::setOuterXml):
(QWebElement::toOuterXml):
(QWebElement::setInnerXml):
(QWebElement::toInnerXml):
(QWebElement::namespaceUri):
(QWebElement::firstChild):
(QWebElement::lastChild):
(QWebElement::nextSibling):
(QWebElement::previousSibling):
(QWebElement::callFunction):
(QWebElement::functions):
(QWebElement::scriptableProperty):
(QWebElement::setScriptableProperty):
(QWebElement::scriptableProperties):
(QWebElement::appendInside):
(QWebElement::prependInside):
(QWebElement::prependOutside):
(QWebElement::appendOutside):
(QWebElement::clone):
(QWebElement::takeFromDocument):
(QWebElement::removeFromDocument):
(QWebElement::removeChildren):
(QWebElement::wrap):
(QWebElement::replace):
* Api/qwebelement.h:
* Api/qwebframe.cpp:
(QWebFrame::findAllElements):
(QWebFrame::findFirstElement):
* Api/qwebframe.h:
* tests/qwebelement/tst_qwebelement.cpp:
(tst_QWebElement::textHtml):
(tst_QWebElement::classes):
(tst_QWebElement::namespaceURI):
(tst_QWebElement::foreachManipulation):
(tst_QWebElement::callFunction):
(tst_QWebElement::callFunctionSubmitForm):
(tst_QWebElement::functionNames):
(tst_QWebElement::properties):
(tst_QWebElement::appendAndPrepend):
(tst_QWebElement::insertBeforeAndAfter):
(tst_QWebElement::remove):
(tst_QWebElement::clear):
(tst_QWebElement::replaceWith):
2009-04-28 Simon Hausmann <simon.hausmann@nokia.com> 2009-04-28 Simon Hausmann <simon.hausmann@nokia.com>
Reviewed by Tor Arne Vestbø. Reviewed by Tor Arne Vestbø.
......
...@@ -90,9 +90,7 @@ private slots: ...@@ -90,9 +90,7 @@ private slots:
void wrap(); void wrap();
void nullSelect(); void nullSelect();
void firstChildNextSibling(); void firstChildNextSibling();
void firstChildNextSiblingWithTag();
void lastChildPreviousSibling(); void lastChildPreviousSibling();
void lastChildPreviousSiblingWithTag();
private: private:
QWebView* m_view; QWebView* m_view;
...@@ -130,7 +128,7 @@ void tst_QWebElement::textHtml() ...@@ -130,7 +128,7 @@ void tst_QWebElement::textHtml()
QCOMPARE(body.toPlainText(), QString("test")); QCOMPARE(body.toPlainText(), QString("test"));
QCOMPARE(body.toPlainText(), m_mainFrame->toPlainText()); QCOMPARE(body.toPlainText(), m_mainFrame->toPlainText());
QCOMPARE(body.toXml(QWebElement::InnerXml), html); QCOMPARE(body.toInnerXml(), html);
} }
void tst_QWebElement::simpleCollection() void tst_QWebElement::simpleCollection()
...@@ -235,20 +233,6 @@ void tst_QWebElement::classes() ...@@ -235,20 +233,6 @@ void tst_QWebElement::classes()
QVERIFY(p.hasClass("f")); QVERIFY(p.hasClass("f"));
QCOMPARE(p.classes().count(), 5); QCOMPARE(p.classes().count(), 5);
p.toggleClass("a", true);
QCOMPARE(p.classes().count(), 5);
p.toggleClass("a", false);
QCOMPARE(p.classes().count(), 4);
p.toggleClass("z", false);
QVERIFY(!p.hasClass("z"));
QCOMPARE(p.classes().count(), 4);
p.toggleClass("z", true);
QVERIFY(p.hasClass("z"));
QCOMPARE(p.classes().count(), 5);
p.toggleClass("a", true);
p.toggleClass("z", false);
QCOMPARE(p.classes().count(), 5);
p.removeClass("f"); p.removeClass("f");
QVERIFY(!p.hasClass("f")); QVERIFY(!p.hasClass("f"));
QCOMPARE(p.classes().count(), 4); QCOMPARE(p.classes().count(), 4);
...@@ -279,13 +263,13 @@ void tst_QWebElement::namespaceURI() ...@@ -279,13 +263,13 @@ void tst_QWebElement::namespaceURI()
m_mainFrame->setContent(content.toUtf8(), "application/xhtml+xml"); m_mainFrame->setContent(content.toUtf8(), "application/xhtml+xml");
QWebElement body = m_mainFrame->documentElement(); QWebElement body = m_mainFrame->documentElement();
QCOMPARE(body.namespaceURI(), QLatin1String("http://www.w3.org/1999/xhtml")); QCOMPARE(body.namespaceUri(), QLatin1String("http://www.w3.org/1999/xhtml"));
QWebElement svg = body.findAll("*#foobar").toList().at(0); QWebElement svg = body.findAll("*#foobar").toList().at(0);
QCOMPARE(svg.prefix(), QLatin1String("svg")); QCOMPARE(svg.prefix(), QLatin1String("svg"));
QCOMPARE(svg.localName(), QLatin1String("svg")); QCOMPARE(svg.localName(), QLatin1String("svg"));
QCOMPARE(svg.tagName(), QLatin1String("svg:svg")); QCOMPARE(svg.tagName(), QLatin1String("svg:svg"));
QCOMPARE(svg.namespaceURI(), QLatin1String("http://www.w3.org/2000/svg")); QCOMPARE(svg.namespaceUri(), QLatin1String("http://www.w3.org/2000/svg"));
} }
...@@ -331,7 +315,7 @@ void tst_QWebElement::foreachManipulation() ...@@ -331,7 +315,7 @@ void tst_QWebElement::foreachManipulation()
QWebElement body = m_mainFrame->documentElement(); QWebElement body = m_mainFrame->documentElement();
foreach(QWebElement p, body.findAll("p")) { foreach(QWebElement p, body.findAll("p")) {
p.setXml(QWebElement::InnerXml, "<div>foo</div><div>bar</div>"); p.setInnerXml("<div>foo</div><div>bar</div>");
} }
QCOMPARE(body.findAll("div").count(), 4); QCOMPARE(body.findAll("div").count(), 4);
...@@ -341,13 +325,13 @@ void tst_QWebElement::callFunction() ...@@ -341,13 +325,13 @@ void tst_QWebElement::callFunction()
{ {
m_mainFrame->setHtml("<body><p>test"); m_mainFrame->setHtml("<body><p>test");
QWebElement body = m_mainFrame->documentElement(); QWebElement body = m_mainFrame->documentElement();
QVERIFY(body.scriptFunctions().contains("hasChildNodes")); QVERIFY(body.functions().contains("hasChildNodes"));
QVariant result = body.callScriptFunction("hasChildNodes"); QVariant result = body.callFunction("hasChildNodes");
QVERIFY(result.isValid()); QVERIFY(result.isValid());
QVERIFY(result.type() == QVariant::Bool); QVERIFY(result.type() == QVariant::Bool);
QVERIFY(result.toBool()); QVERIFY(result.toBool());
body.callScriptFunction("setAttribute", QVariantList() << "foo" << "bar"); body.callFunction("setAttribute", QVariantList() << "foo" << "bar");
QCOMPARE(body.attribute("foo"), QString("bar")); QCOMPARE(body.attribute("foo"), QString("bar"));
} }
...@@ -357,9 +341,9 @@ void tst_QWebElement::callFunctionSubmitForm() ...@@ -357,9 +341,9 @@ void tst_QWebElement::callFunctionSubmitForm()
"<input type='text'><input type='submit'></form></body></html>"), QUrl()); "<input type='text'><input type='submit'></form></body></html>"), QUrl());
QWebElement form = m_mainFrame->documentElement().findAll("form").at(0); QWebElement form = m_mainFrame->documentElement().findAll("form").at(0);
QVERIFY(form.scriptFunctions().contains("submit")); QVERIFY(form.functions().contains("submit"));
QVERIFY(!form.isNull()); QVERIFY(!form.isNull());
form.callScriptFunction("submit"); form.callFunction("submit");
waitForSignal(m_page, SIGNAL(loadFinished(bool))); waitForSignal(m_page, SIGNAL(loadFinished(bool)));
QCOMPARE(m_mainFrame->url().toString(), QString("data:text/html,foo?")); QCOMPARE(m_mainFrame->url().toString(), QString("data:text/html,foo?"));
...@@ -371,7 +355,7 @@ void tst_QWebElement::functionNames() ...@@ -371,7 +355,7 @@ void tst_QWebElement::functionNames()
QWebElement body = m_mainFrame->documentElement(); QWebElement body = m_mainFrame->documentElement();
QVERIFY(body.scriptFunctions().contains("setAttribute")); QVERIFY(body.functions().contains("setAttribute"));
} }
void tst_QWebElement::documentElement() void tst_QWebElement::documentElement()
...@@ -489,27 +473,27 @@ void tst_QWebElement::properties() ...@@ -489,27 +473,27 @@ void tst_QWebElement::properties()
QWebElement checkBox = m_mainFrame->findFirstElement("#ourcheckbox"); QWebElement checkBox = m_mainFrame->findFirstElement("#ourcheckbox");
QVERIFY(!checkBox.isNull()); QVERIFY(!checkBox.isNull());
QVERIFY(checkBox.scriptProperties().contains("checked")); QVERIFY(checkBox.scriptableProperties().contains("checked"));
QCOMPARE(checkBox.scriptProperty("checked"), QVariant(true)); QCOMPARE(checkBox.scriptableProperty("checked"), QVariant(true));
checkBox.setScriptProperty("checked", false); checkBox.setScriptableProperty("checked", false);
QCOMPARE(checkBox.scriptProperty("checked"), QVariant(false)); QCOMPARE(checkBox.scriptableProperty("checked"), QVariant(false));
QVERIFY(!checkBox.scriptProperties().contains("non_existant")); QVERIFY(!checkBox.scriptableProperties().contains("non_existant"));
QCOMPARE(checkBox.scriptProperty("non_existant"), QVariant()); QCOMPARE(checkBox.scriptableProperty("non_existant"), QVariant());
checkBox.setScriptProperty("non_existant", "test"); checkBox.setScriptableProperty("non_existant", "test");
QCOMPARE(checkBox.scriptProperty("non_existant"), QVariant("test")); QCOMPARE(checkBox.scriptableProperty("non_existant"), QVariant("test"));
QVERIFY(checkBox.scriptProperties().contains("non_existant")); QVERIFY(checkBox.scriptableProperties().contains("non_existant"));
// removing scriptProperties is currently not supported. We should look into this // removing scriptableProperties is currently not supported. We should look into this
// and consider the option of just allowing through the QtScript API only. // and consider the option of just allowing through the QtScript API only.
#if 0 #if 0
checkBox.setScriptProperty("non_existant", QVariant()); checkBox.setScriptableProperty("non_existant", QVariant());
QCOMPARE(checkBox.scriptProperty("non_existant"), QVariant()); QCOMPARE(checkBox.scriptableProperty("non_existant"), QVariant());
QVERIFY(!checkBox.scriptProperties().contains("non_existant")); QVERIFY(!checkBox.scriptableProperties().contains("non_existant"));
#endif #endif
} }
...@@ -528,25 +512,25 @@ void tst_QWebElement::appendAndPrepend() ...@@ -528,25 +512,25 @@ void tst_QWebElement::appendAndPrepend()
QWebElement body = m_mainFrame->documentElement().findFirst("body"); QWebElement body = m_mainFrame->documentElement().findFirst("body");
QCOMPARE(body.findAll("p").count(), 2); QCOMPARE(body.findAll("p").count(), 2);
body.append(body.findFirst("p")); body.appendInside(body.findFirst("p"));
QCOMPARE(body.findAll("p").count(), 2); QCOMPARE(body.findAll("p").count(), 2);
QCOMPARE(body.findFirst("p").toPlainText(), QString("bar")); QCOMPARE(body.findFirst("p").toPlainText(), QString("bar"));
QCOMPARE(body.findAll("p").last().toPlainText(), QString("foo")); QCOMPARE(body.findAll("p").last().toPlainText(), QString("foo"));
body.append(body.findFirst("p").clone()); body.appendInside(body.findFirst("p").clone());
QCOMPARE(body.findAll("p").count(), 3); QCOMPARE(body.findAll("p").count(), 3);
QCOMPARE(body.findFirst("p").toPlainText(), QString("bar")); QCOMPARE(body.findFirst("p").toPlainText(), QString("bar"));
QCOMPARE(body.findAll("p").last().toPlainText(), QString("bar")); QCOMPARE(body.findAll("p").last().toPlainText(), QString("bar"));
body.prepend(body.findAll("p").at(1).clone()); body.prependInside(body.findAll("p").at(1).clone());
QCOMPARE(body.findAll("p").count(), 4); QCOMPARE(body.findAll("p").count(), 4);
QCOMPARE(body.findFirst("p").toPlainText(), QString("foo")); QCOMPARE(body.findFirst("p").toPlainText(), QString("foo"));
body.findFirst("p").append("<div>booyakasha</div>"); body.findFirst("p").appendInside("<div>booyakasha</div>");
QCOMPARE(body.findAll("p div").count(), 1); QCOMPARE(body.findAll("p div").count(), 1);
QCOMPARE(body.findFirst("p div").toPlainText(), QString("booyakasha")); QCOMPARE(body.findFirst("p div").toPlainText(), QString("booyakasha"));
body.findFirst("div").prepend("<code>yepp</code>"); body.findFirst("div").prependInside("<code>yepp</code>");
QCOMPARE(body.findAll("p div code").count(), 1); QCOMPARE(body.findAll("p div code").count(), 1);
QCOMPARE(body.findFirst("p div code").toPlainText(), QString("yepp")); QCOMPARE(body.findFirst("p div code").toPlainText(), QString("yepp"));
} }
...@@ -572,23 +556,23 @@ void tst_QWebElement::insertBeforeAndAfter() ...@@ -572,23 +556,23 @@ void tst_QWebElement::insertBeforeAndAfter()
QCOMPARE(body.findAll("p").count(), 2); QCOMPARE(body.findAll("p").count(), 2);
QCOMPARE(body.findAll("div").count(), 1); QCOMPARE(body.findAll("div").count(), 1);
div.insertBefore(body.findAll("p").last().clone()); div.prependOutside(body.findAll("p").last().clone());
QCOMPARE(body.findAll("p").count(), 3); QCOMPARE(body.findAll("p").count(), 3);
QCOMPARE(body.findAll("p").at(0).toPlainText(), QString("foo")); QCOMPARE(body.findAll("p").at(0).toPlainText(), QString("foo"));
QCOMPARE(body.findAll("p").at(1).toPlainText(), QString("bar")); QCOMPARE(body.findAll("p").at(1).toPlainText(), QString("bar"));
QCOMPARE(body.findAll("p").at(2).toPlainText(), QString("bar")); QCOMPARE(body.findAll("p").at(2).toPlainText(), QString("bar"));
div.insertAfter(body.findFirst("p").clone()); div.appendOutside(body.findFirst("p").clone());
QCOMPARE(body.findAll("p").count(), 4); QCOMPARE(body.findAll("p").count(), 4);
QCOMPARE(body.findAll("p").at(0).toPlainText(), QString("foo")); QCOMPARE(body.findAll("p").at(0).toPlainText(), QString("foo"));
QCOMPARE(body.findAll("p").at(1).toPlainText(), QString("bar")); QCOMPARE(body.findAll("p").at(1).toPlainText(), QString("bar"));
QCOMPARE(body.findAll("p").at(2).toPlainText(), QString("foo")); QCOMPARE(body.findAll("p").at(2).toPlainText(), QString("foo"));
QCOMPARE(body.findAll("p").at(3).toPlainText(), QString("bar")); QCOMPARE(body.findAll("p").at(3).toPlainText(), QString("bar"));
div.insertBefore("<span>hey</span>"); div.prependOutside("<span>hey</span>");
QCOMPARE(body.findAll("span").count(), 1); QCOMPARE(body.findAll("span").count(), 1);
div.insertAfter("<span>there</span>"); div.appendOutside("<span>there</span>");
QCOMPARE(body.findAll("span").count(), 2); QCOMPARE(body.findAll("span").count(), 2);
QCOMPARE(body.findAll("span").at(0).toPlainText(), QString("hey")); QCOMPARE(body.findAll("span").at(0).toPlainText(), QString("hey"));
QCOMPARE(body.findAll("span").at(1).toPlainText(), QString("there")); QCOMPARE(body.findAll("span").at(1).toPlainText(), QString("there"));
...@@ -615,13 +599,13 @@ void tst_QWebElement::remove() ...@@ -615,13 +599,13 @@ void tst_QWebElement::remove()
QCOMPARE(body.findAll("p").count(), 3); QCOMPARE(body.findAll("p").count(), 3);
QWebElement div = body.findFirst("div"); QWebElement div = body.findFirst("div");
div.remove(); div.takeFromDocument();
QCOMPARE(div.isNull(), false); QCOMPARE(div.isNull(), false);
QCOMPARE(body.findAll("div").count(), 0); QCOMPARE(body.findAll("div").count(), 0);
QCOMPARE(body.findAll("p").count(), 2); QCOMPARE(body.findAll("p").count(), 2);
body.append(div); body.appendInside(div);
QCOMPARE(body.findAll("div").count(), 1); QCOMPARE(body.findAll("div").count(), 1);
QCOMPARE(body.findAll("p").count(), 3); QCOMPARE(body.findAll("p").count(), 3);
...@@ -646,7 +630,7 @@ void tst_QWebElement::clear() ...@@ -646,7 +630,7 @@ void tst_QWebElement::clear()
QCOMPARE(body.findAll("div").count(), 1); QCOMPARE(body.findAll("div").count(), 1);
QCOMPARE(body.findAll("p").count(), 3); QCOMPARE(body.findAll("p").count(), 3);
body.findFirst("div").clear(); body.findFirst("div").removeChildren();
QCOMPARE(body.findAll("div").count(), 1); QCOMPARE(body.findAll("div").count(), 1);
QCOMPARE(body.findAll("p").count(), 2); QCOMPARE(body.findAll("p").count(), 2);
} }
...@@ -671,12 +655,12 @@ void tst_QWebElement::replaceWith() ...@@ -671,12 +655,12 @@ void tst_QWebElement::replaceWith()
QCOMPARE(body.findAll("div").count(), 1); QCOMPARE(body.findAll("div").count(), 1);
QCOMPARE(body.findAll("span").count(), 1); QCOMPARE(body.findAll("span").count(), 1);
body.findFirst("div").replaceWith(body.findFirst("span").clone()); body.findFirst("div").replace(body.findFirst("span").clone());
QCOMPARE(body.findAll("div").count(), 0); QCOMPARE(body.findAll("div").count(), 0);
QCOMPARE(body.findAll("span").count(), 2); QCOMPARE(body.findAll("span").count(), 2);
QCOMPARE(body.findAll("p").count(), 2); QCOMPARE(body.findAll("p").count(), 2);
body.findFirst("span").replaceWith("<p><code>wow</code></p>"); body.findFirst("span").replace("<p><code>wow</code></p>");
QCOMPARE(body.findAll("p").count(), 3); QCOMPARE(body.findAll("p").count(), 3);
QCOMPARE(body.findAll("p code").count(), 1); QCOMPARE(body.findAll("p code").count(), 1);
QCOMPARE(body.findFirst("p code").toPlainText(), QString("wow")); QCOMPARE(body.findFirst("p code").toPlainText(), QString("wow"));
...@@ -734,23 +718,6 @@ void tst_QWebElement::firstChildNextSibling() ...@@ -734,23 +718,6 @@ void tst_QWebElement::firstChildNextSibling()
QVERIFY(table.nextSibling().isNull()); QVERIFY(table.nextSibling().isNull());
} }
void tst_QWebElement::firstChildNextSiblingWithTag()
{
m_mainFrame->setHtml("<body><!--comment--><p><span>Test</span></p><div>test</div><p><span>test2</span></p><div>last</div>");
QWebElement body = m_mainFrame->findFirstElement("body");
QVERIFY(!body.isNull());
QWebElement div = body.firstChild("div");
QVERIFY(!div.isNull());
QCOMPARE(div.tagName(), QString("DIV"));
QCOMPARE(div.toPlainText(), QString("test"));
QCOMPARE(div.nextSibling().tagName(), QString("P"));
div = div.nextSibling("div");
QVERIFY(!div.isNull());
QCOMPARE(div.tagName(), QString("DIV"));
QCOMPARE(div.toPlainText(), QString("last"));
}
void tst_QWebElement::lastChildPreviousSibling() void tst_QWebElement::lastChildPreviousSibling()
{ {
m_mainFrame->setHtml("<body><!--comment--><p>Test</p><!--another commend><table>"); m_mainFrame->setHtml("<body><!--comment--><p>Test</p><!--another commend><table>");
...@@ -766,23 +733,5 @@ void tst_QWebElement::lastChildPreviousSibling() ...@@ -766,23 +733,5 @@ void tst_QWebElement::lastChildPreviousSibling()
QVERIFY(p.previousSibling().isNull()); QVERIFY(p.previousSibling().isNull());
} }
void tst_QWebElement::lastChildPreviousSiblingWithTag()
{
m_mainFrame->setHtml("<body><!--comment--><p><span>Test</span></p><div>test</div><p><span>test2</span></p><div>last</div>");
QWebElement body = m_mainFrame->findFirstElement("body");
QVERIFY(!body.isNull());
QWebElement div = body.lastChild("div");
QVERIFY(!div.isNull());
QCOMPARE(div.tagName(), QString("DIV"));
QCOMPARE(div.toPlainText(), QString("last"));
QCOMPARE(div.previousSibling().tagName(), QString("P"));
div = div.previousSibling("div");
QVERIFY(!div.isNull());
QCOMPARE(div.tagName(), QString("DIV"));
QCOMPARE(div.toPlainText(), QString("test"));
}
QTEST_MAIN(tst_QWebElement) QTEST_MAIN(tst_QWebElement)
#include "tst_qwebelement.moc" #include "tst_qwebelement.moc"
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment