[SCM] WebKit Debian packaging branch, webkit-1.1, updated. upstream/1.1.15.1-1414-gc69ee75

laszlo.1.gombos at nokia.com laszlo.1.gombos at nokia.com
Thu Oct 29 20:47:43 UTC 2009


The following commit has been merged in the webkit-1.1 branch:
commit ada0dca5ef5c87c538be2715b4674cdb14af6a2c
Author: laszlo.1.gombos at nokia.com <laszlo.1.gombos at nokia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Mon Oct 19 15:53:36 2009 +0000

    2009-10-19  Viatcheslav Ostapenko  <ostapenko.viatcheslav at nokia.com>
    
            Reviewed by Ariya Hidayat.
    
            Add QWebElement::render API which allows rendering of single
            element.
    
            * Api/qwebelement.cpp:
            (QWebElement::render):
            * Api/qwebelement.h:
            * tests/qwebelement/tst_qwebelement.cpp:
            (tst_QWebElement::render):
            * tests/qwebelement/qwebelement.qrc:
            * tests/qwebelement/image.png: Added.
    
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@49785 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebKit/qt/Api/qwebelement.cpp b/WebKit/qt/Api/qwebelement.cpp
index 939d881..5b83870 100644
--- a/WebKit/qt/Api/qwebelement.cpp
+++ b/WebKit/qt/Api/qwebelement.cpp
@@ -30,12 +30,14 @@
 #include "Document.h"
 #include "DocumentFragment.h"
 #include "FrameView.h"
+#include "GraphicsContext.h"
 #include "HTMLElement.h"
 #include "JSGlobalObject.h"
 #include "JSHTMLElement.h"
 #include "JSObject.h"
 #include "NodeList.h"
 #include "PropertyNameArray.h"
+#include "RenderImage.h"
 #include "ScriptFunctionCall.h"
 #include "StaticNodeList.h"
 #include "qt_runtime.h"
@@ -45,6 +47,8 @@
 #include <parser/SourceCode.h>
 #include <wtf/Vector.h>
 
+#include <QPainter>
+
 using namespace WebCore;
 
 class QWebElementPrivate {
@@ -1411,3 +1415,38 @@ QWebElement QWebElement::enclosingElement(WebCore::Node* node)
     Returns true if this element points to a different underlying DOM object
     than \a o; otherwise returns false.
 */
+
+
+/*! 
+  Render the element into \a painter .
+*/
+void QWebElement::render(QPainter* painter)
+{
+    WebCore::Element* e = m_element;
+    Document* doc = e ? e->document() : 0;
+    if (!doc)
+        return;
+
+    Frame* frame = doc->frame();
+    if (!frame || !frame->view() || !frame->contentRenderer())
+        return;
+
+    FrameView* view = frame->view();
+
+    view->layoutIfNeededRecursive();
+
+    IntRect rect = e->getRect();
+
+    if (rect.size().isEmpty())
+        return;
+
+    GraphicsContext context(painter);
+
+    context.save();
+    context.translate(-rect.x(), -rect.y());
+    view->setNodeToDraw(e);
+    view->paintContents(&context, rect);
+    view->setNodeToDraw(0);
+    context.restore();
+}
+
diff --git a/WebKit/qt/Api/qwebelement.h b/WebKit/qt/Api/qwebelement.h
index 3db4637..351ccb4 100644
--- a/WebKit/qt/Api/qwebelement.h
+++ b/WebKit/qt/Api/qwebelement.h
@@ -31,6 +31,10 @@ namespace WebCore {
     class Node;
 }
 
+QT_BEGIN_NAMESPACE
+class QPainter;
+QT_END_NAMESPACE
+
 class QWebFrame;
 class QWebElementPrivate;
 
@@ -133,6 +137,8 @@ public:
     QString styleProperty(const QString& name, StyleResolveStrategy strategy) const;
     void setStyleProperty(const QString& name, const QString& value);
 
+    void render(QPainter* painter);
+
 private:
     explicit QWebElement(WebCore::Element*);
     explicit QWebElement(WebCore::Node*);
diff --git a/WebKit/qt/ChangeLog b/WebKit/qt/ChangeLog
index d62d4aa..4106b99 100644
--- a/WebKit/qt/ChangeLog
+++ b/WebKit/qt/ChangeLog
@@ -1,3 +1,18 @@
+2009-10-19  Viatcheslav Ostapenko  <ostapenko.viatcheslav at nokia.com>
+
+        Reviewed by Ariya Hidayat.
+
+        Add QWebElement::render API which allows rendering of single
+        element.
+
+        * Api/qwebelement.cpp:
+        (QWebElement::render):
+        * Api/qwebelement.h:
+        * tests/qwebelement/tst_qwebelement.cpp:
+        (tst_QWebElement::render):
+        * tests/qwebelement/qwebelement.qrc:
+        * tests/qwebelement/image.png: Added.
+
 2009-10-19  Markus Goetz <Markus.Goetz at nokia.com>
 
         Reviewed by Ariya Hidayat.
diff --git a/WebKit/qt/tests/qwebframe/image.png b/WebKit/qt/tests/qwebelement/image.png
similarity index 100%
copy from WebKit/qt/tests/qwebframe/image.png
copy to WebKit/qt/tests/qwebelement/image.png
diff --git a/WebKit/qt/tests/qwebelement/qwebelement.qrc b/WebKit/qt/tests/qwebelement/qwebelement.qrc
index ed01440..28b9d7b 100644
--- a/WebKit/qt/tests/qwebelement/qwebelement.qrc
+++ b/WebKit/qt/tests/qwebelement/qwebelement.qrc
@@ -2,5 +2,6 @@
 <qresource prefix="/">
 <file>style.css</file>
 <file>style2.css</file>
+<file>image.png</file>
 </qresource>
 </RCC>
diff --git a/WebKit/qt/tests/qwebelement/tst_qwebelement.cpp b/WebKit/qt/tests/qwebelement/tst_qwebelement.cpp
index 00783d1..db2f7d7 100644
--- a/WebKit/qt/tests/qwebelement/tst_qwebelement.cpp
+++ b/WebKit/qt/tests/qwebelement/tst_qwebelement.cpp
@@ -87,6 +87,7 @@ private slots:
     void firstChildNextSibling();
     void lastChildPreviousSibling();
     void hasSetFocus();
+    void render();
 
 private:
     QWebView* m_view;
@@ -825,5 +826,79 @@ void tst_QWebElement::hasSetFocus()
     QVERIFY(input2.hasFocus());
 }
 
+void tst_QWebElement::render()
+{
+    QString html( "<html>"
+                    "<head><style>"
+                       "body, iframe { margin: 0px; border: none; }"
+                    "</style></head>"
+                    "<body><table width='300px' height='300px' border='1'>"
+                           "<tr>"
+                               "<td>test"
+                               "</td>"
+                               "<td><img src='qrc:///image.png'>"
+                               "</td>"
+                           "</tr>"
+                          "</table>"
+                    "</body>"
+                 "</html>"
+                );
+
+    QWebPage page;
+    QSignalSpy loadSpy(&page, SIGNAL(loadFinished(bool)));
+    page.mainFrame()->setHtml(html);
+
+    waitForSignal(&page, SIGNAL(loadFinished(bool)));
+    QCOMPARE(loadSpy.count(), 1);
+
+    QList<QWebElement> imgs = page.mainFrame()->findAllElements("img");
+    QCOMPARE(imgs.count(), 1);
+
+    QImage resource(":/image.png");
+    QRect imageRect(0, 0, resource.width(), resource.height());
+
+    QImage testImage(resource.width(), resource.height(), QImage::Format_ARGB32);
+    QPainter painter0(&testImage);
+    painter0.fillRect(imageRect, Qt::white);
+    painter0.drawImage(0, 0, resource);
+    painter0.end();
+
+    QImage image1(resource.width(), resource.height(), QImage::Format_ARGB32);
+    QPainter painter1(&image1);
+    painter1.fillRect(imageRect, Qt::white);
+    imgs[0].render(&painter1);
+    painter1.end();
+
+    QVERIFY(image1 == testImage);
+
+    // render image 2nd time to make sure that cached rendering works fine
+    QImage image2(resource.width(), resource.height(), QImage::Format_ARGB32);
+    QPainter painter2(&image2);
+    painter2.fillRect(imageRect, Qt::white);
+    imgs[0].render(&painter2);
+    painter2.end();
+
+    QVERIFY(image2 == testImage);
+
+    // compare table rendered through QWebElement::render to whole page table rendering
+    QRect tableRect(0, 0, 300, 300);
+    QList<QWebElement> tables = page.mainFrame()->findAllElements("table");
+    QCOMPARE(tables.count(), 1);
+
+    QImage image3(300, 300, QImage::Format_ARGB32);
+    QPainter painter3(&image3);
+    painter3.fillRect(tableRect, Qt::white);
+    tables[0].render(&painter3);
+    painter3.end();
+
+    QImage image4(300, 300, QImage::Format_ARGB32);
+    QPainter painter4(&image4);
+    page.mainFrame()->setClipRenderToViewport(false);
+    page.mainFrame()->render(&painter4, tableRect);
+    painter4.end();
+
+    QVERIFY(image3 == image4);
+}
+
 QTEST_MAIN(tst_QWebElement)
 #include "tst_qwebelement.moc"

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list