Title: [94852] trunk/Source/WebKit/qt
- Revision
- 94852
- Author
- commit-qu...@webkit.org
- Date
- 2011-09-09 07:32:15 -0700 (Fri, 09 Sep 2011)
Log Message
[Qt] QWebElement::encloseWith doesn't work at all
https://bugs.webkit.org/show_bug.cgi?id=62464
Enclosing an element means wrapping something around an element,
not inserting something into an element. Therefore we need to check
if the parent of the element allows insertion rather than checking
the element itself.
Patch by Zeno Albisser <zeno.albis...@nokia.com> on 2011-09-09
Reviewed by Andreas Kling.
* Api/qwebelement.cpp:
(QWebElement::prependOutside):
(QWebElement::appendOutside):
(QWebElement::encloseWith):
* tests/qwebelement/tst_qwebelement.cpp:
(tst_QWebElement::appendAndPrepend):
(tst_QWebElement::encloseWith):
Modified Paths
Diff
Modified: trunk/Source/WebKit/qt/Api/qwebelement.cpp (94851 => 94852)
--- trunk/Source/WebKit/qt/Api/qwebelement.cpp 2011-09-09 13:08:05 UTC (rev 94851)
+++ trunk/Source/WebKit/qt/Api/qwebelement.cpp 2011-09-09 14:32:15 UTC (rev 94852)
@@ -1111,16 +1111,17 @@
if (!m_element)
return;
- if (!m_element->parentNode())
+ Node* parent = m_element->parentNode();
+ if (!parent)
return;
- if (!m_element->isHTMLElement())
+ if (!parent->isHTMLElement())
return;
- RefPtr<DocumentFragment> fragment = Range::createDocumentFragmentForElement(markup, toHTMLElement(m_element));
+ RefPtr<DocumentFragment> fragment = Range::createDocumentFragmentForElement(markup, toHTMLElement(parent));
ExceptionCode exception = 0;
- m_element->parentNode()->insertBefore(fragment, m_element, exception);
+ parent->insertBefore(fragment, m_element, exception);
}
/*!
@@ -1160,19 +1161,20 @@
if (!m_element)
return;
- if (!m_element->parentNode())
+ Node* parent = m_element->parentNode();
+ if (!parent)
return;
- if (!m_element->isHTMLElement())
+ if (!parent->isHTMLElement())
return;
- RefPtr<DocumentFragment> fragment = Range::createDocumentFragmentForElement(markup, toHTMLElement(m_element));
+ RefPtr<DocumentFragment> fragment = Range::createDocumentFragmentForElement(markup, toHTMLElement(parent));
ExceptionCode exception = 0;
if (!m_element->nextSibling())
- m_element->parentNode()->appendChild(fragment, exception);
+ parent->appendChild(fragment, exception);
else
- m_element->parentNode()->insertBefore(fragment, m_element->nextSibling(), exception);
+ parent->insertBefore(fragment, m_element->nextSibling(), exception);
}
/*!
@@ -1380,13 +1382,14 @@
if (!m_element)
return;
- if (!m_element->parentNode())
+ Node* parent = m_element->parentNode();
+ if (!parent)
return;
- if (!m_element->isHTMLElement())
+ if (!parent->isHTMLElement())
return;
- RefPtr<DocumentFragment> fragment = Range::createDocumentFragmentForElement(markup, toHTMLElement(m_element));
+ RefPtr<DocumentFragment> fragment = Range::createDocumentFragmentForElement(markup, toHTMLElement(parent));
if (!fragment || !fragment->firstChild())
return;
@@ -1396,11 +1399,10 @@
if (!insertionPoint)
return;
- // Keep reference to these two nodes before pulling out this element and
+ // Keep reference to parent & siblingNode before pulling out this element and
// wrapping it in the fragment. The reason for doing it in this order is
// that once the fragment has been added to the document it is empty, so
// we no longer have access to the nodes it contained.
- Node* parent = m_element->parentNode();
Node* siblingNode = m_element->nextSibling();
ExceptionCode exception = 0;
Modified: trunk/Source/WebKit/qt/ChangeLog (94851 => 94852)
--- trunk/Source/WebKit/qt/ChangeLog 2011-09-09 13:08:05 UTC (rev 94851)
+++ trunk/Source/WebKit/qt/ChangeLog 2011-09-09 14:32:15 UTC (rev 94852)
@@ -1,3 +1,23 @@
+2011-09-09 Zeno Albisser <zeno.albis...@nokia.com>
+
+ [Qt] QWebElement::encloseWith doesn't work at all
+ https://bugs.webkit.org/show_bug.cgi?id=62464
+
+ Enclosing an element means wrapping something around an element,
+ not inserting something into an element. Therefore we need to check
+ if the parent of the element allows insertion rather than checking
+ the element itself.
+
+ Reviewed by Andreas Kling.
+
+ * Api/qwebelement.cpp:
+ (QWebElement::prependOutside):
+ (QWebElement::appendOutside):
+ (QWebElement::encloseWith):
+ * tests/qwebelement/tst_qwebelement.cpp:
+ (tst_QWebElement::appendAndPrepend):
+ (tst_QWebElement::encloseWith):
+
2011-09-08 Sam Weinig <s...@webkit.org>
Remove the Completion object from JSC, I have never liked it
Modified: trunk/Source/WebKit/qt/tests/qwebelement/tst_qwebelement.cpp (94851 => 94852)
--- trunk/Source/WebKit/qt/tests/qwebelement/tst_qwebelement.cpp 2011-09-09 13:08:05 UTC (rev 94851)
+++ trunk/Source/WebKit/qt/tests/qwebelement/tst_qwebelement.cpp 2011-09-09 14:32:15 UTC (rev 94852)
@@ -646,6 +646,26 @@
body.findFirst("div").prependInside("<code>yepp</code>");
QCOMPARE(body.findAll("p div code").count(), 1);
QCOMPARE(body.findFirst("p div code").toPlainText(), QString("yepp"));
+
+ // Inserting HTML into an img tag is not allowed, but appending/prepending outside is.
+ body.findFirst("div").appendInside("<img src=""
+ QCOMPARE(body.findAll("p div img").count(), 1);
+
+ QWebElement img = body.findFirst("img");
+ QVERIFY(!img.isNull());
+ img.appendInside("<p id=\"fail1\"></p>");
+ QCOMPARE(body.findAll("p#fail1").count(), 0);
+
+ img.appendOutside("<p id=\"success1\"></p>");
+ QCOMPARE(body.findAll("p#success1").count(), 1);
+
+ img.prependInside("<p id=\"fail2\"></p>");
+ QCOMPARE(body.findAll("p#fail2").count(), 0);
+
+ img.prependOutside("<p id=\"success2\"></p>");
+ QCOMPARE(body.findAll("p#success2").count(), 1);
+
+
}
void tst_QWebElement::insertBeforeAndAfter()
@@ -881,6 +901,19 @@
body.findFirst("em").encloseWith(snippet);
QCOMPARE(body.findFirst("table tbody tr td em").toPlainText(), QString("hey"));
+
+ // Enclosing the contents of an img tag is not allowed, but enclosing the img tag itself is.
+ body.findFirst("td").appendInside("<img src=""
+ QCOMPARE(body.findAll("img").count(), 1);
+
+ QWebElement img = body.findFirst("img");
+ QVERIFY(!img.isNull());
+ img.encloseWith("<p id=\"success\"></p>");
+ QCOMPARE(body.findAll("p#success").count(), 1);
+
+ img.encloseContentsWith("<p id=\"fail\"></p>");
+ QCOMPARE(body.findAll("p#fail").count(), 0);
+
}
void tst_QWebElement::nullSelect()
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes