diff options
author | Jocelyn Turcotte <jturcotte@woboq.com> | 2015-07-09 21:52:43 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@theqtcompany.com> | 2015-07-14 13:06:19 +0000 |
commit | 99e98f7bf6aec78fe0d647fb898e65d13ff522e4 (patch) | |
tree | 64a38d99e5f6287e80f92df1d9ac125cc2325b87 /src/webenginewidgets/api | |
parent | 8d6b933a971476abe91e72728d997aa5dd2a71be (diff) | |
download | qtwebengine-99e98f7bf6aec78fe0d647fb898e65d13ff522e4.tar.gz |
Add a backgroundColor property
This also allows setting a transparent color to see through
the web view's body if its background color isn't specified.
The color is initially held by the top API view and is pulled
by the WebContentsAdapter in order to set it on the RenderView.
Since both blink and our local compositors (in the QOpenGLWidget
case) need to know about this color, RWHVQt takes care of pushing
it to both. The former through an IPC message and the latter
directly on the RWHVQtDelegate.
Task-number: QTBUG-41960
Change-Id: Ie13317b2d087f5612ad9c5fb0e05ca3e91aec9af
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@theqtcompany.com>
Reviewed-by: Andras Becsi <andras.becsi@theqtcompany.com>
Diffstat (limited to 'src/webenginewidgets/api')
-rw-r--r-- | src/webenginewidgets/api/qwebenginepage.cpp | 33 | ||||
-rw-r--r-- | src/webenginewidgets/api/qwebenginepage.h | 3 | ||||
-rw-r--r-- | src/webenginewidgets/api/qwebenginepage_p.h | 2 |
3 files changed, 38 insertions, 0 deletions
diff --git a/src/webenginewidgets/api/qwebenginepage.cpp b/src/webenginewidgets/api/qwebenginepage.cpp index f93227297..e7d4e60e5 100644 --- a/src/webenginewidgets/api/qwebenginepage.cpp +++ b/src/webenginewidgets/api/qwebenginepage.cpp @@ -87,6 +87,7 @@ QWebEnginePagePrivate::QWebEnginePagePrivate(QWebEngineProfile *_profile) , view(0) , isLoading(false) , scriptCollection(new QWebEngineScriptCollectionPrivate(browserContextAdapter()->userScriptController(), adapter.data())) + , m_backgroundColor(Qt::white) { memset(actions, 0, sizeof(actions)); } @@ -149,6 +150,11 @@ qreal QWebEnginePagePrivate::dpiScale() const return 1.0; } +QColor QWebEnginePagePrivate::backgroundColor() const +{ + return m_backgroundColor; +} + void QWebEnginePagePrivate::loadStarted(const QUrl &provisionalUrl, bool isErrorPage) { Q_UNUSED(provisionalUrl); @@ -433,6 +439,33 @@ void QWebEnginePage::setWebChannel(QWebChannel *channel) d->adapter->setWebChannel(channel); } +/*! + \property QWebEnginePage::backgroundColor + \brief the page's background color, behing the document's body. + \since 5.6 + + You can set it to Qt::transparent or to a translucent + color to see through the document, or you can set this color to match your + web content in an hybrid app to prevent the white flashes that may appear + during loading. + + The default value is white. +*/ +QColor QWebEnginePage::backgroundColor() const +{ + Q_D(const QWebEnginePage); + return d->m_backgroundColor; +} + +void QWebEnginePage::setBackgroundColor(const QColor &color) +{ + Q_D(QWebEnginePage); + if (d->m_backgroundColor == color) + return; + d->m_backgroundColor = color; + d->adapter->backgroundColorChanged(); +} + void QWebEnginePage::setView(QWidget *view) { QWebEngineViewPrivate::bind(qobject_cast<QWebEngineView*>(view), this); diff --git a/src/webenginewidgets/api/qwebenginepage.h b/src/webenginewidgets/api/qwebenginepage.h index f4d0cd18d..471fd7290 100644 --- a/src/webenginewidgets/api/qwebenginepage.h +++ b/src/webenginewidgets/api/qwebenginepage.h @@ -68,6 +68,7 @@ class QWEBENGINEWIDGETS_EXPORT QWebEnginePage : public QObject { Q_PROPERTY(QString title READ title) Q_PROPERTY(QUrl url READ url WRITE setUrl) Q_PROPERTY(QUrl iconUrl READ iconUrl) + Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor) public: enum WebAction { @@ -223,6 +224,8 @@ public: QWebChannel *webChannel() const; void setWebChannel(QWebChannel *); + QColor backgroundColor() const; + void setBackgroundColor(const QColor &color); Q_SIGNALS: void loadStarted(); diff --git a/src/webenginewidgets/api/qwebenginepage_p.h b/src/webenginewidgets/api/qwebenginepage_p.h index a5ede1a8e..a9449007d 100644 --- a/src/webenginewidgets/api/qwebenginepage_p.h +++ b/src/webenginewidgets/api/qwebenginepage_p.h @@ -75,6 +75,7 @@ public: virtual void selectionChanged() Q_DECL_OVERRIDE; virtual QRectF viewportRect() const Q_DECL_OVERRIDE; virtual qreal dpiScale() const Q_DECL_OVERRIDE; + virtual QColor backgroundColor() const Q_DECL_OVERRIDE; virtual void loadStarted(const QUrl &provisionalUrl, bool isErrorPage = false) Q_DECL_OVERRIDE; virtual void loadCommitted() Q_DECL_OVERRIDE; virtual void loadVisuallyCommitted() Q_DECL_OVERRIDE { } @@ -127,6 +128,7 @@ public: QtWebEngineCore::WebEngineContextMenuData m_menuData; bool isLoading; QWebEngineScriptCollection scriptCollection; + QColor m_backgroundColor; mutable QtWebEngineCore::CallbackDirectory m_callbacks; mutable QAction *actions[QWebEnginePage::WebActionCount]; |