Changeset 94852 in webkit
- Timestamp:
- Sep 9, 2011 7:32:15 AM (13 years ago)
- Location:
- trunk/Source/WebKit/qt
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit/qt/Api/qwebelement.cpp
r94811 r94852 1112 1112 return; 1113 1113 1114 if (!m_element->parentNode()) 1115 return; 1116 1117 if (!m_element->isHTMLElement()) 1118 return; 1119 1120 RefPtr<DocumentFragment> fragment = Range::createDocumentFragmentForElement(markup, toHTMLElement(m_element)); 1114 Node* parent = m_element->parentNode(); 1115 if (!parent) 1116 return; 1117 1118 if (!parent->isHTMLElement()) 1119 return; 1120 1121 RefPtr<DocumentFragment> fragment = Range::createDocumentFragmentForElement(markup, toHTMLElement(parent)); 1121 1122 1122 1123 ExceptionCode exception = 0; 1123 m_element->parentNode()->insertBefore(fragment, m_element, exception);1124 parent->insertBefore(fragment, m_element, exception); 1124 1125 } 1125 1126 … … 1161 1162 return; 1162 1163 1163 if (!m_element->parentNode()) 1164 return; 1165 1166 if (!m_element->isHTMLElement()) 1167 return; 1168 1169 RefPtr<DocumentFragment> fragment = Range::createDocumentFragmentForElement(markup, toHTMLElement(m_element)); 1164 Node* parent = m_element->parentNode(); 1165 if (!parent) 1166 return; 1167 1168 if (!parent->isHTMLElement()) 1169 return; 1170 1171 RefPtr<DocumentFragment> fragment = Range::createDocumentFragmentForElement(markup, toHTMLElement(parent)); 1170 1172 1171 1173 ExceptionCode exception = 0; 1172 1174 if (!m_element->nextSibling()) 1173 m_element->parentNode()->appendChild(fragment, exception);1175 parent->appendChild(fragment, exception); 1174 1176 else 1175 m_element->parentNode()->insertBefore(fragment, m_element->nextSibling(), exception);1177 parent->insertBefore(fragment, m_element->nextSibling(), exception); 1176 1178 } 1177 1179 … … 1381 1383 return; 1382 1384 1383 if (!m_element->parentNode()) 1384 return; 1385 1386 if (!m_element->isHTMLElement()) 1387 return; 1388 1389 RefPtr<DocumentFragment> fragment = Range::createDocumentFragmentForElement(markup, toHTMLElement(m_element)); 1385 Node* parent = m_element->parentNode(); 1386 if (!parent) 1387 return; 1388 1389 if (!parent->isHTMLElement()) 1390 return; 1391 1392 RefPtr<DocumentFragment> fragment = Range::createDocumentFragmentForElement(markup, toHTMLElement(parent)); 1390 1393 1391 1394 if (!fragment || !fragment->firstChild()) … … 1397 1400 return; 1398 1401 1399 // Keep reference to these two nodesbefore pulling out this element and1402 // Keep reference to parent & siblingNode before pulling out this element and 1400 1403 // wrapping it in the fragment. The reason for doing it in this order is 1401 1404 // that once the fragment has been added to the document it is empty, so 1402 1405 // we no longer have access to the nodes it contained. 1403 Node* parent = m_element->parentNode();1404 1406 Node* siblingNode = m_element->nextSibling(); 1405 1407 -
trunk/Source/WebKit/qt/ChangeLog
r94811 r94852 1 2011-09-09 Zeno Albisser <zeno.albisser@nokia.com> 2 3 [Qt] QWebElement::encloseWith doesn't work at all 4 https://bugs.webkit.org/show_bug.cgi?id=62464 5 6 Enclosing an element means wrapping something around an element, 7 not inserting something into an element. Therefore we need to check 8 if the parent of the element allows insertion rather than checking 9 the element itself. 10 11 Reviewed by Andreas Kling. 12 13 * Api/qwebelement.cpp: 14 (QWebElement::prependOutside): 15 (QWebElement::appendOutside): 16 (QWebElement::encloseWith): 17 * tests/qwebelement/tst_qwebelement.cpp: 18 (tst_QWebElement::appendAndPrepend): 19 (tst_QWebElement::encloseWith): 20 1 21 2011-09-08 Sam Weinig <sam@webkit.org> 2 22 -
trunk/Source/WebKit/qt/tests/qwebelement/tst_qwebelement.cpp
r92179 r94852 647 647 QCOMPARE(body.findAll("p div code").count(), 1); 648 648 QCOMPARE(body.findFirst("p div code").toPlainText(), QString("yepp")); 649 650 // Inserting HTML into an img tag is not allowed, but appending/prepending outside is. 651 body.findFirst("div").appendInside("<img src=\"test.png\">"); 652 QCOMPARE(body.findAll("p div img").count(), 1); 653 654 QWebElement img = body.findFirst("img"); 655 QVERIFY(!img.isNull()); 656 img.appendInside("<p id=\"fail1\"></p>"); 657 QCOMPARE(body.findAll("p#fail1").count(), 0); 658 659 img.appendOutside("<p id=\"success1\"></p>"); 660 QCOMPARE(body.findAll("p#success1").count(), 1); 661 662 img.prependInside("<p id=\"fail2\"></p>"); 663 QCOMPARE(body.findAll("p#fail2").count(), 0); 664 665 img.prependOutside("<p id=\"success2\"></p>"); 666 QCOMPARE(body.findAll("p#success2").count(), 1); 667 668 649 669 } 650 670 … … 882 902 body.findFirst("em").encloseWith(snippet); 883 903 QCOMPARE(body.findFirst("table tbody tr td em").toPlainText(), QString("hey")); 904 905 // Enclosing the contents of an img tag is not allowed, but enclosing the img tag itself is. 906 body.findFirst("td").appendInside("<img src=\"test.png\">"); 907 QCOMPARE(body.findAll("img").count(), 1); 908 909 QWebElement img = body.findFirst("img"); 910 QVERIFY(!img.isNull()); 911 img.encloseWith("<p id=\"success\"></p>"); 912 QCOMPARE(body.findAll("p#success").count(), 1); 913 914 img.encloseContentsWith("<p id=\"fail\"></p>"); 915 QCOMPARE(body.findAll("p#fail").count(), 0); 916 884 917 } 885 918
Note: See TracChangeset
for help on using the changeset viewer.