2011-03-10 Alexis Menard <alexis.menard@openbossa.org>
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 10 Mar 2011 23:36:38 +0000 (23:36 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 10 Mar 2011 23:36:38 +0000 (23:36 +0000)
        Reviewed by Andreas Kling.

        [Qt] QtDeclarative Webview element has a fixed white background
        https://bugs.webkit.org/show_bug.cgi?id=40918

        Implement a way to change the background color of the WebView QML element.
        This feature is activated for QtWebKit 1.1 version of the plugin.

        * declarative/plugin.cpp:
        (WebKitQmlPlugin::registerTypes):
        * declarative/qdeclarativewebview.cpp:
        (QDeclarativeWebView::backgroundColor):
        (QDeclarativeWebView::setBackgroundColor):
        * declarative/qdeclarativewebview_p.h:
        * tests/qdeclarativewebview/resources/webviewbackgroundcolor.qml: Added.
        * tests/qdeclarativewebview/tst_qdeclarativewebview.cpp:
        (tst_QDeclarativeWebView::backgroundColor):
        * tests/qdeclarativewebview/tst_qdeclarativewebview.qrc:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@80774 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit/qt/ChangeLog
Source/WebKit/qt/declarative/plugin.cpp
Source/WebKit/qt/declarative/qdeclarativewebview.cpp
Source/WebKit/qt/declarative/qdeclarativewebview_p.h
Source/WebKit/qt/tests/qdeclarativewebview/resources/webviewbackgroundcolor.qml [new file with mode: 0644]
Source/WebKit/qt/tests/qdeclarativewebview/tst_qdeclarativewebview.cpp
Source/WebKit/qt/tests/qdeclarativewebview/tst_qdeclarativewebview.qrc

index e69b3bdccfdcf3128b57fae02d38ccd68219b6fd..9a5daab3a3cfaf90eae885a969c658ad6c034536 100644 (file)
@@ -1,3 +1,24 @@
+2011-03-10  Alexis Menard  <alexis.menard@openbossa.org>
+
+        Reviewed by Andreas Kling.
+
+        [Qt] QtDeclarative Webview element has a fixed white background
+        https://bugs.webkit.org/show_bug.cgi?id=40918
+
+        Implement a way to change the background color of the WebView QML element.
+        This feature is activated for QtWebKit 1.1 version of the plugin.
+
+        * declarative/plugin.cpp:
+        (WebKitQmlPlugin::registerTypes):
+        * declarative/qdeclarativewebview.cpp:
+        (QDeclarativeWebView::backgroundColor):
+        (QDeclarativeWebView::setBackgroundColor):
+        * declarative/qdeclarativewebview_p.h:
+        * tests/qdeclarativewebview/resources/webviewbackgroundcolor.qml: Added.
+        * tests/qdeclarativewebview/tst_qdeclarativewebview.cpp:
+        (tst_QDeclarativeWebView::backgroundColor):
+        * tests/qdeclarativewebview/tst_qdeclarativewebview.qrc:
+
 2011-03-10  Stanislav Paltis  <Stanislav.Paltis@nokia.com>
 
         Reviewed by Laszlo Gombos.
index f1f165e02ec273b80197ea3cc4c27979d2e5c39f..38c6169308c9d893606f51bf104106922a450471 100644 (file)
@@ -32,6 +32,11 @@ public:
         Q_ASSERT(QLatin1String(uri) == QLatin1String("QtWebKit"));
         qmlRegisterType<QDeclarativeWebSettings>();
         qmlRegisterType<QDeclarativeWebView>(uri, 1, 0, "WebView");
+#if QT_VERSION >= 0x040702
+        qmlRegisterType<QDeclarativeWebView>(uri, 1, 1, "WebView");
+        qmlRegisterRevision<QDeclarativeWebView, 0>("QtWebKit", 1, 0);
+        qmlRegisterRevision<QDeclarativeWebView, 1>("QtWebKit", 1, 1);
+#endif
     }
 };
 
index 9313d6c2b55f2323da0d7117b57f2a2a89d4c9ae..11c892876aecb2dbb911a9008a22c97d94b3e02d 100644 (file)
@@ -983,6 +983,29 @@ void QDeclarativeWebView::setContentsScale(qreal scale)
     emit contentsScaleChanged();
 }
 
+#if QT_VERSION >= 0x040702
+/*!
+    \qmlproperty color WebView::backgroundColor
+    \since QtWebKit 1.1
+    This property holds the background color of the view.
+*/
+
+QColor QDeclarativeWebView::backgroundColor() const
+{
+    return d->view->palette().base().color();
+}
+
+void QDeclarativeWebView::setBackgroundColor(const QColor& color)
+{
+    QPalette palette = d->view->palette();
+    if (palette.base().color() == color)
+        return;
+    palette.setBrush(QPalette::Base, color);
+    d->view->setPalette(palette);
+    emit backgroundColorChanged();
+}
+#endif
+
 /*!
     Returns the area of the largest element at position (\a x,\a y) that is no larger
     than \a maxWidth by \a maxHeight pixels.
index ca15a1eefbb012bc5cf4d4d85cef145483768a52..d09df6b17f67ddce9aeca9044c0457e53a999397 100644 (file)
@@ -123,6 +123,9 @@ class QDeclarativeWebView : public QDeclarativeItem {
 
     Q_PROPERTY(QSize contentsSize READ contentsSize NOTIFY contentsSizeChanged)
     Q_PROPERTY(qreal contentsScale READ contentsScale WRITE setContentsScale NOTIFY contentsScaleChanged)
+#if QT_VERSION >= 0x040702
+    Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor NOTIFY backgroundColorChanged REVISION 1)
+#endif
 
 public:
     QDeclarativeWebView(QDeclarativeItem *parent = 0);
@@ -193,6 +196,11 @@ public:
     void setContentsScale(qreal scale);
     qreal contentsScale() const;
 
+#if QT_VERSION >= 0x040702
+    Q_REVISION(1) QColor backgroundColor() const;
+    Q_REVISION(1) void setBackgroundColor(const QColor&);
+#endif
+
 Q_SIGNALS:
     void preferredWidthChanged();
     void preferredHeightChanged();
@@ -209,6 +217,9 @@ Q_SIGNALS:
     void renderingEnabledChanged();
     void contentsSizeChanged(const QSize&);
     void contentsScaleChanged();
+#if QT_VERSION >= 0x040702
+    void backgroundColorChanged();
+#endif
 
     void loadStarted();
     void loadFinished();
diff --git a/Source/WebKit/qt/tests/qdeclarativewebview/resources/webviewbackgroundcolor.qml b/Source/WebKit/qt/tests/qdeclarativewebview/resources/webviewbackgroundcolor.qml
new file mode 100644 (file)
index 0000000..2edc794
--- /dev/null
@@ -0,0 +1,10 @@
+import Qt 4.7
+import QtWebKit 1.1
+
+WebView {
+    id: myweb
+    height: 300
+    width: 300
+    focus: true
+    backgroundColor : "red"
+}
index 0025d6c3914024876f394db8ebf1bf25591ed45d..7e8d4bd1a7c84180f4a6c8c98a9f199da2ccaadf 100644 (file)
@@ -1,4 +1,5 @@
 #include "../util.h"
+#include <QColor>
 #include <QDebug>
 #include <QDeclarativeComponent>
 #include <QDeclarativeEngine>
@@ -22,6 +23,9 @@ private slots:
     void preferredHeightTest();
     void preferredWidthDefaultTest();
     void preferredHeightDefaultTest();
+#if QT_VERSION >= 0x040702
+    void backgroundColor();
+#endif
 
 private:
     void checkNoErrors(const QDeclarativeComponent&);
@@ -82,6 +86,36 @@ void tst_QDeclarativeWebView::preferredHeightDefaultTest()
     QCOMPARE(wv->property("prefHeight").toDouble(), view.preferredHeight());
 }
 
+#if QT_VERSION >= 0x040702
+void tst_QDeclarativeWebView::backgroundColor()
+{
+    // We test here the rendering of the background.
+    QDeclarativeEngine engine;
+    QDeclarativeComponent component(&engine, QUrl("qrc:///resources/webviewbackgroundcolor.qml"));
+    checkNoErrors(component);
+    QObject* wv = component.create();
+    QVERIFY(wv);
+    QCOMPARE(wv->property("backgroundColor").value<QColor>(), QColor(Qt::red));
+    QDeclarativeView view;
+    view.setSource(QUrl("qrc:///resources/webviewbackgroundcolor.qml"));
+    view.show();
+    QTest::qWaitForWindowShown(&view);
+    QPixmap result(view.width(), view.height());
+    QPainter painter(&result);
+    view.render(&painter);
+    QPixmap reference(view.width(), view.height());
+    reference.fill(Qt::red);
+    QCOMPARE(reference, result);
+
+    // We test the emission of the backgroundColorChanged signal.
+    QSignalSpy spyColorChanged(wv, SIGNAL(backgroundColorChanged()));
+    wv->setProperty("backgroundColor", Qt::red);
+    QCOMPARE(spyColorChanged.count(), 0);
+    wv->setProperty("backgroundColor", Qt::green);
+    QCOMPARE(spyColorChanged.count(), 1);
+}
+#endif
+
 void tst_QDeclarativeWebView::checkNoErrors(const QDeclarativeComponent& component)
 {
     // Wait until the component is ready
index 9c274097efab33cf09e2ace9606ccfbe46ddd710..e14c33336530d8917a42e487a4a44ee0d3aeb722 100644 (file)
@@ -3,5 +3,6 @@
         <file>resources/webviewtestdefault.qml</file>
         <file>resources/webviewtest.qml</file>
         <file>resources/sample.html</file>
+        <file>resources/webviewbackgroundcolor.qml</file>
     </qresource>
 </RCC>