Changeset 94852 in webkit


Ignore:
Timestamp:
Sep 9, 2011 7:32:15 AM (13 years ago)
Author:
commit-queue@webkit.org
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.albisser@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):

Location:
trunk/Source/WebKit/qt
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/qt/Api/qwebelement.cpp

    r94811 r94852  
    11121112        return;
    11131113
    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));
    11211122
    11221123    ExceptionCode exception = 0;
    1123     m_element->parentNode()->insertBefore(fragment, m_element, exception);
     1124    parent->insertBefore(fragment, m_element, exception);
    11241125}
    11251126
     
    11611162        return;
    11621163
    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));
    11701172
    11711173    ExceptionCode exception = 0;
    11721174    if (!m_element->nextSibling())
    1173         m_element->parentNode()->appendChild(fragment, exception);
     1175        parent->appendChild(fragment, exception);
    11741176    else
    1175         m_element->parentNode()->insertBefore(fragment, m_element->nextSibling(), exception);
     1177        parent->insertBefore(fragment, m_element->nextSibling(), exception);
    11761178}
    11771179
     
    13811383        return;
    13821384
    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));
    13901393
    13911394    if (!fragment || !fragment->firstChild())
     
    13971400        return;
    13981401
    1399     // Keep reference to these two nodes before pulling out this element and
     1402    // Keep reference to parent & siblingNode before pulling out this element and
    14001403    // wrapping it in the fragment. The reason for doing it in this order is
    14011404    // that once the fragment has been added to the document it is empty, so
    14021405    // we no longer have access to the nodes it contained.
    1403     Node* parent = m_element->parentNode();
    14041406    Node* siblingNode = m_element->nextSibling();
    14051407
  • trunk/Source/WebKit/qt/ChangeLog

    r94811 r94852  
     12011-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
    1212011-09-08  Sam Weinig  <sam@webkit.org>
    222
  • trunk/Source/WebKit/qt/tests/qwebelement/tst_qwebelement.cpp

    r92179 r94852  
    647647    QCOMPARE(body.findAll("p div code").count(), 1);
    648648    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
    649669}
    650670
     
    882902    body.findFirst("em").encloseWith(snippet);
    883903    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
    884917}
    885918
Note: See TracChangeset for help on using the changeset viewer.