Commit 098154a3 authored by hausmann@webkit.org's avatar hausmann@webkit.org

2009-04-14 Kenneth Rohde Christiansen <kenneth.christiansen@openbossa.org>

        Reviewed by Tor Arne Vestbø.

        Rename QWebElement::setHtml and html to setXml and toXml respectivily.

        Also add a mean to define the scope (inner or other).

git-svn-id: svn://svn.chromium.org/blink/trunk@42494 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 1f507486
...@@ -177,31 +177,52 @@ QString QWebElement::toPlainText() const ...@@ -177,31 +177,52 @@ QString QWebElement::toPlainText() const
} }
/*! /*!
Replaces the existing content of this element with \a html. Replaces the existing content of this element with \a markup.
The string may contain HTML 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.
This is equivalent to settng the HTML innerHTML property. If \a scope is InnerXml this is equivalent to setting the HTML innerHTML
property, and similarily for OuterXml.
\note This is currently only implemented for (X)HTML elements.
*/ */
void QWebElement::setHtml(const QString &html) void QWebElement::setXml(XmlScope scope, const QString &markup)
{ {
if (!m_element || !m_element->isHTMLElement()) if (!m_element || !m_element->isHTMLElement())
return; return;
ExceptionCode exception = 0; ExceptionCode exception = 0;
static_cast<HTMLElement*>(m_element)->setInnerHTML(html, exception);
switch (scope) {
case InnerXml:
static_cast<HTMLElement*>(m_element)->setInnerHTML(markup, exception);
break;
case OuterXml:
static_cast<HTMLElement*>(m_element)->setOuterHTML(markup, exception);
break;
}
} }
/*! /*!
Returns the HTML between the start and the end tag of this Returns the XML between the start and the end tag of this
element. element.
This is equivalent to reading the HTML innerHTML property. 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.
*/ */
QString QWebElement::html() const QString QWebElement::toXml(XmlScope scope) const
{ {
if (!m_element || !m_element->isHTMLElement()) if (!m_element || !m_element->isHTMLElement())
return QString(); return QString();
return static_cast<HTMLElement*>(m_element)->innerHTML();
switch (scope) {
case InnerXml:
return static_cast<HTMLElement*>(m_element)->innerHTML();
case OuterXml:
return static_cast<HTMLElement*>(m_element)->outerHTML();
}
} }
/*! /*!
......
...@@ -53,8 +53,13 @@ public: ...@@ -53,8 +53,13 @@ public:
void setPlainText(const QString &text); void setPlainText(const QString &text);
QString toPlainText() const; QString toPlainText() const;
void setHtml(const QString &html); enum XmlScope {
QString html() const; InnerXml,
OuterXml
};
void setXml(XmlScope scope, const QString &markup);
QString toXml(XmlScope scope) 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);
......
2009-04-14 Kenneth Rohde Christiansen <kenneth.christiansen@openbossa.org>
Reviewed by Tor Arne Vestbø.
Rename QWebElement::setHtml and html to setXml and toXml respectivily.
Also add a mean to define the scope (inner or other).
* Api/qwebelement.cpp:
(QWebElement::setXml):
(QWebElement::toXml):
* Api/qwebelement.h:
* tests/qwebelement/tst_qwebelement.cpp:
(tst_QWebElement::textHtml):
(tst_QWebElement::foreachManipulation):
2009-04-14 Kenneth Rohde Christiansen <kenneth.christiansen@openbossa.org> 2009-04-14 Kenneth Rohde Christiansen <kenneth.christiansen@openbossa.org>
Reviewed by Tor Arne Vestbø. Reviewed by Tor Arne Vestbø.
......
...@@ -129,7 +129,7 @@ void tst_QWebElement::textHtml() ...@@ -129,7 +129,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.html(), html); QCOMPARE(body.toXml(QWebElement::InnerXml), html);
} }
void tst_QWebElement::simpleSelection() void tst_QWebElement::simpleSelection()
...@@ -330,7 +330,7 @@ void tst_QWebElement::foreachManipulation() ...@@ -330,7 +330,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.setHtml("<div>foo</div><div>bar</div>"); p.setXml(QWebElement::InnerXml, "<div>foo</div><div>bar</div>");
} }
QCOMPARE(body.findAll("div").count(), 4); QCOMPARE(body.findAll("div").count(), 4);
......
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