Changeset 80774 in webkit


Ignore:
Timestamp:
Mar 10, 2011 3:36:38 PM (13 years ago)
Author:
commit-queue@webkit.org
Message:

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:
Location:
trunk/Source/WebKit/qt
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/qt/ChangeLog

    r80769 r80774  
     12011-03-10  Alexis Menard  <alexis.menard@openbossa.org>
     2
     3        Reviewed by Andreas Kling.
     4
     5        [Qt] QtDeclarative Webview element has a fixed white background
     6        https://bugs.webkit.org/show_bug.cgi?id=40918
     7
     8        Implement a way to change the background color of the WebView QML element.
     9        This feature is activated for QtWebKit 1.1 version of the plugin.
     10
     11        * declarative/plugin.cpp:
     12        (WebKitQmlPlugin::registerTypes):
     13        * declarative/qdeclarativewebview.cpp:
     14        (QDeclarativeWebView::backgroundColor):
     15        (QDeclarativeWebView::setBackgroundColor):
     16        * declarative/qdeclarativewebview_p.h:
     17        * tests/qdeclarativewebview/resources/webviewbackgroundcolor.qml: Added.
     18        * tests/qdeclarativewebview/tst_qdeclarativewebview.cpp:
     19        (tst_QDeclarativeWebView::backgroundColor):
     20        * tests/qdeclarativewebview/tst_qdeclarativewebview.qrc:
     21
    1222011-03-10  Stanislav Paltis  <Stanislav.Paltis@nokia.com>
    223
  • trunk/Source/WebKit/qt/declarative/plugin.cpp

    r61325 r80774  
    3333        qmlRegisterType<QDeclarativeWebSettings>();
    3434        qmlRegisterType<QDeclarativeWebView>(uri, 1, 0, "WebView");
     35#if QT_VERSION >= 0x040702
     36        qmlRegisterType<QDeclarativeWebView>(uri, 1, 1, "WebView");
     37        qmlRegisterRevision<QDeclarativeWebView, 0>("QtWebKit", 1, 0);
     38        qmlRegisterRevision<QDeclarativeWebView, 1>("QtWebKit", 1, 1);
     39#endif
    3540    }
    3641};
  • trunk/Source/WebKit/qt/declarative/qdeclarativewebview.cpp

    r79672 r80774  
    984984}
    985985
     986#if QT_VERSION >= 0x040702
     987/*!
     988    \qmlproperty color WebView::backgroundColor
     989    \since QtWebKit 1.1
     990    This property holds the background color of the view.
     991*/
     992
     993QColor QDeclarativeWebView::backgroundColor() const
     994{
     995    return d->view->palette().base().color();
     996}
     997
     998void QDeclarativeWebView::setBackgroundColor(const QColor& color)
     999{
     1000    QPalette palette = d->view->palette();
     1001    if (palette.base().color() == color)
     1002        return;
     1003    palette.setBrush(QPalette::Base, color);
     1004    d->view->setPalette(palette);
     1005    emit backgroundColorChanged();
     1006}
     1007#endif
     1008
    9861009/*!
    9871010    Returns the area of the largest element at position (\a x,\a y) that is no larger
  • trunk/Source/WebKit/qt/declarative/qdeclarativewebview_p.h

    r78270 r80774  
    124124    Q_PROPERTY(QSize contentsSize READ contentsSize NOTIFY contentsSizeChanged)
    125125    Q_PROPERTY(qreal contentsScale READ contentsScale WRITE setContentsScale NOTIFY contentsScaleChanged)
     126#if QT_VERSION >= 0x040702
     127    Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor NOTIFY backgroundColorChanged REVISION 1)
     128#endif
    126129
    127130public:
     
    193196    void setContentsScale(qreal scale);
    194197    qreal contentsScale() const;
     198
     199#if QT_VERSION >= 0x040702
     200    Q_REVISION(1) QColor backgroundColor() const;
     201    Q_REVISION(1) void setBackgroundColor(const QColor&);
     202#endif
    195203
    196204Q_SIGNALS:
     
    210218    void contentsSizeChanged(const QSize&);
    211219    void contentsScaleChanged();
     220#if QT_VERSION >= 0x040702
     221    void backgroundColorChanged();
     222#endif
    212223
    213224    void loadStarted();
  • trunk/Source/WebKit/qt/tests/qdeclarativewebview/tst_qdeclarativewebview.cpp

    r79894 r80774  
    11#include "../util.h"
     2#include <QColor>
    23#include <QDebug>
    34#include <QDeclarativeComponent>
     
    2324    void preferredWidthDefaultTest();
    2425    void preferredHeightDefaultTest();
     26#if QT_VERSION >= 0x040702
     27    void backgroundColor();
     28#endif
    2529
    2630private:
     
    8387}
    8488
     89#if QT_VERSION >= 0x040702
     90void tst_QDeclarativeWebView::backgroundColor()
     91{
     92    // We test here the rendering of the background.
     93    QDeclarativeEngine engine;
     94    QDeclarativeComponent component(&engine, QUrl("qrc:///resources/webviewbackgroundcolor.qml"));
     95    checkNoErrors(component);
     96    QObject* wv = component.create();
     97    QVERIFY(wv);
     98    QCOMPARE(wv->property("backgroundColor").value<QColor>(), QColor(Qt::red));
     99    QDeclarativeView view;
     100    view.setSource(QUrl("qrc:///resources/webviewbackgroundcolor.qml"));
     101    view.show();
     102    QTest::qWaitForWindowShown(&view);
     103    QPixmap result(view.width(), view.height());
     104    QPainter painter(&result);
     105    view.render(&painter);
     106    QPixmap reference(view.width(), view.height());
     107    reference.fill(Qt::red);
     108    QCOMPARE(reference, result);
     109
     110    // We test the emission of the backgroundColorChanged signal.
     111    QSignalSpy spyColorChanged(wv, SIGNAL(backgroundColorChanged()));
     112    wv->setProperty("backgroundColor", Qt::red);
     113    QCOMPARE(spyColorChanged.count(), 0);
     114    wv->setProperty("backgroundColor", Qt::green);
     115    QCOMPARE(spyColorChanged.count(), 1);
     116}
     117#endif
     118
    85119void tst_QDeclarativeWebView::checkNoErrors(const QDeclarativeComponent& component)
    86120{
  • trunk/Source/WebKit/qt/tests/qdeclarativewebview/tst_qdeclarativewebview.qrc

    r79894 r80774  
    44        <file>resources/webviewtest.qml</file>
    55        <file>resources/sample.html</file>
     6        <file>resources/webviewbackgroundcolor.qml</file>
    67    </qresource>
    78</RCC>
Note: See TracChangeset for help on using the changeset viewer.