0001-qtwebengine-Add-a-backgroundColor-property.patch 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532
  1. From 3adadda878f63fcca6892c49c4ddc82143d59b66 Mon Sep 17 00:00:00 2001
  2. From: Jocelyn Turcotte <jturcotte@woboq.com>
  3. Date: Thu, 9 Jul 2015 21:52:43 +0200
  4. Subject: [PATCH] Add a backgroundColor property
  5. This also allows setting a transparent color to see through
  6. the web view's body if its background color isn't specified.
  7. The color is initially held by the top API view and is pulled
  8. by the WebContentsAdapter in order to set it on the RenderView.
  9. Since both blink and our local compositors (in the QOpenGLWidget
  10. case) need to know about this color, RWHVQt takes care of pushing
  11. it to both. The former through an IPC message and the latter
  12. directly on the RWHVQtDelegate.
  13. Task-number: QTBUG-41960
  14. Change-Id: Ie13317b2d087f5612ad9c5fb0e05ca3e91aec9af
  15. Reviewed-by: Allan Sandfeld Jensen <allan.jensen@theqtcompany.com>
  16. Reviewed-by: Andras Becsi <andras.becsi@theqtcompany.com>
  17. ---
  18. qtwebengine/src/core/common/qt_messages.h | 3 ++
  19. qtwebengine/src/core/render_widget_host_view_qt.cpp | 9 ++++++
  20. qtwebengine/src/core/render_widget_host_view_qt.h | 1 +
  21. qtwebengine/src/core/render_widget_host_view_qt_delegate.h | 1 +
  22. qtwebengine/src/core/renderer/qt_render_view_observer.cpp | 6 ++++
  23. qtwebengine/src/core/renderer/qt_render_view_observer.h | 1 +
  24. qtwebengine/src/core/type_conversion.h | 5 ++++
  25. qtwebengine/src/core/web_contents_adapter.cpp | 7 +++++
  26. qtwebengine/src/core/web_contents_adapter.h | 1 +
  27. qtwebengine/src/core/web_contents_adapter_client.h | 1 +
  28. qtwebengine/src/core/web_contents_view_qt.cpp | 7 +++++
  29. qtwebengine/src/core/web_contents_view_qt.h | 2 +-
  30. qtwebengine/src/webengine/api/qquickwebengineview.cpp | 34 ++++++++++++++++++++++
  31. qtwebengine/src/webengine/api/qquickwebengineview_p.h | 5 +++-
  32. qtwebengine/src/webengine/api/qquickwebengineview_p_p.h | 2 ++
  33. .../render_widget_host_view_qt_delegate_quick.h | 2 ++
  34. ...nder_widget_host_view_qt_delegate_quickwindow.h | 1 +
  35. qtwebengine/src/webenginewidgets/api/qwebenginepage.cpp | 33 +++++++++++++++++++++
  36. qtwebengine/src/webenginewidgets/api/qwebenginepage.h | 3 ++
  37. qtwebengine/src/webenginewidgets/api/qwebenginepage_p.h | 2 ++
  38. .../render_widget_host_view_qt_delegate_widget.cpp | 16 +++++++++-
  39. .../render_widget_host_view_qt_delegate_widget.h | 2 ++
  40. 22 files changed, 141 insertions(+), 3 deletions(-)
  41. diff --git a/qtwebengine/src/core/common/qt_messages.h b/src/core/common/qt_messages.h
  42. index c692ee5..25a995b 100644
  43. --- a/qtwebengine/src/core/common/qt_messages.h
  44. +++ b/qtwebengine/src/core/common/qt_messages.h
  45. @@ -31,6 +31,9 @@ IPC_MESSAGE_ROUTED1(QtRenderViewObserver_FetchDocumentMarkup,
  46. IPC_MESSAGE_ROUTED1(QtRenderViewObserver_FetchDocumentInnerText,
  47. uint64 /* requestId */)
  48. +IPC_MESSAGE_ROUTED1(QtRenderViewObserver_SetBackgroundColor,
  49. + uint32 /* color */)
  50. +
  51. IPC_MESSAGE_ROUTED1(WebChannelIPCTransport_Message, std::vector<char> /*binaryJSON*/)
  52. // User scripts messages
  53. diff --git a/qtwebengine/src/core/render_widget_host_view_qt.cpp b/src/core/render_widget_host_view_qt.cpp
  54. index 572bc34..20b41bc 100644
  55. --- a/qtwebengine/src/core/render_widget_host_view_qt.cpp
  56. +++ b/qtwebengine/src/core/render_widget_host_view_qt.cpp
  57. @@ -36,6 +36,7 @@
  58. #include "render_widget_host_view_qt.h"
  59. +#include "common/qt_messages.h"
  60. #include "browser_accessibility_manager_qt.h"
  61. #include "browser_accessibility_qt.h"
  62. #include "chromium_overrides.h"
  63. @@ -408,6 +409,14 @@ gfx::Rect RenderWidgetHostViewQt::GetViewBounds() const
  64. return gfx::BoundingRect(p1, p2);
  65. }
  66. +void RenderWidgetHostViewQt::SetBackgroundColor(SkColor color) {
  67. + RenderWidgetHostViewBase::SetBackgroundColor(color);
  68. + // Set the background of the compositor if necessary
  69. + m_delegate->setClearColor(toQt(color));
  70. + // Set the background of the blink::FrameView
  71. + m_host->Send(new QtRenderViewObserver_SetBackgroundColor(m_host->GetRoutingID(), color));
  72. +}
  73. +
  74. // Return value indicates whether the mouse is locked successfully or not.
  75. bool RenderWidgetHostViewQt::LockMouse()
  76. {
  77. diff --git a/qtwebengine/src/core/render_widget_host_view_qt.h b/src/core/render_widget_host_view_qt.h
  78. index 248c52f..2724292 100644
  79. --- a/qtwebengine/src/core/render_widget_host_view_qt.h
  80. +++ b/qtwebengine/src/core/render_widget_host_view_qt.h
  81. @@ -125,6 +125,7 @@ public:
  82. virtual void Hide() Q_DECL_OVERRIDE;
  83. virtual bool IsShowing() Q_DECL_OVERRIDE;
  84. virtual gfx::Rect GetViewBounds() const Q_DECL_OVERRIDE;
  85. + virtual void SetBackgroundColor(SkColor color) Q_DECL_OVERRIDE;
  86. virtual bool LockMouse() Q_DECL_OVERRIDE;
  87. virtual void UnlockMouse() Q_DECL_OVERRIDE;
  88. virtual void WasShown() Q_DECL_OVERRIDE;
  89. diff --git a/qtwebengine/src/core/render_widget_host_view_qt_delegate.h b/src/core/render_widget_host_view_qt_delegate.h
  90. index da595b9..f4aa9b2 100644
  91. --- a/qtwebengine/src/core/render_widget_host_view_qt_delegate.h
  92. +++ b/qtwebengine/src/core/render_widget_host_view_qt_delegate.h
  93. @@ -96,6 +96,7 @@ public:
  94. virtual void move(const QPoint &) = 0;
  95. virtual void inputMethodStateChanged(bool editorVisible) = 0;
  96. virtual void setTooltip(const QString &) = 0;
  97. + virtual void setClearColor(const QColor &color) = 0;
  98. };
  99. } // namespace QtWebEngineCore
  100. diff --git a/qtwebengine/src/core/renderer/qt_render_view_observer.cpp b/src/core/renderer/qt_render_view_observer.cpp
  101. index 83534da..ba91e54 100644
  102. --- a/qtwebengine/src/core/renderer/qt_render_view_observer.cpp
  103. +++ b/qtwebengine/src/core/renderer/qt_render_view_observer.cpp
  104. @@ -65,6 +65,11 @@ void QtRenderViewObserver::onFetchDocumentInnerText(quint64 requestId)
  105. render_view()->GetWebView()->mainFrame()->contentAsText(std::numeric_limits<std::size_t>::max())));
  106. }
  107. +void QtRenderViewObserver::onSetBackgroundColor(quint32 color)
  108. +{
  109. + render_view()->GetWebView()->setBaseBackgroundColor(color);
  110. +}
  111. +
  112. void QtRenderViewObserver::OnFirstVisuallyNonEmptyLayout()
  113. {
  114. Send(new QtRenderViewObserverHost_DidFirstVisuallyNonEmptyLayout(routing_id()));
  115. @@ -76,6 +81,7 @@ bool QtRenderViewObserver::OnMessageReceived(const IPC::Message& message)
  116. IPC_BEGIN_MESSAGE_MAP(QtRenderViewObserver, message)
  117. IPC_MESSAGE_HANDLER(QtRenderViewObserver_FetchDocumentMarkup, onFetchDocumentMarkup)
  118. IPC_MESSAGE_HANDLER(QtRenderViewObserver_FetchDocumentInnerText, onFetchDocumentInnerText)
  119. + IPC_MESSAGE_HANDLER(QtRenderViewObserver_SetBackgroundColor, onSetBackgroundColor)
  120. IPC_MESSAGE_UNHANDLED(handled = false)
  121. IPC_END_MESSAGE_MAP()
  122. return handled;
  123. diff --git a/qtwebengine/src/core/renderer/qt_render_view_observer.h b/src/core/renderer/qt_render_view_observer.h
  124. index cb77cd0..3f7829a 100644
  125. --- a/qtwebengine/src/core/renderer/qt_render_view_observer.h
  126. +++ b/qtwebengine/src/core/renderer/qt_render_view_observer.h
  127. @@ -47,6 +47,7 @@ public:
  128. private:
  129. void onFetchDocumentMarkup(quint64 requestId);
  130. void onFetchDocumentInnerText(quint64 requestId);
  131. + void onSetBackgroundColor(quint32 color);
  132. void OnFirstVisuallyNonEmptyLayout() Q_DECL_OVERRIDE;
  133. diff --git a/qtwebengine/src/core/type_conversion.h b/src/core/type_conversion.h
  134. index 66fcd4d..f1bf54b 100644
  135. --- a/qtwebengine/src/core/type_conversion.h
  136. +++ b/qtwebengine/src/core/type_conversion.h
  137. @@ -122,6 +122,11 @@ inline QColor toQt(const SkColor &c)
  138. return QColor(SkColorGetR(c), SkColorGetG(c), SkColorGetB(c), SkColorGetA(c));
  139. }
  140. +inline SkColor toSk(const QColor &c)
  141. +{
  142. + return c.rgba();
  143. +}
  144. +
  145. inline QMatrix4x4 toQt(const SkMatrix44 &m)
  146. {
  147. QMatrix4x4 qtMatrix(
  148. diff --git a/qtwebengine/src/core/web_contents_adapter.cpp b/src/core/web_contents_adapter.cpp
  149. index 8c13035..0c5b6ca 100644
  150. --- a/qtwebengine/src/core/web_contents_adapter.cpp
  151. +++ b/qtwebengine/src/core/web_contents_adapter.cpp
  152. @@ -837,6 +837,13 @@ void WebContentsAdapter::filesSelectedInChooser(const QStringList &fileList, Web
  153. rvh->FilesSelectedInChooser(toVector<content::FileChooserFileInfo>(files), static_cast<content::FileChooserParams::Mode>(mode));
  154. }
  155. +void WebContentsAdapter::backgroundColorChanged()
  156. +{
  157. + Q_D(WebContentsAdapter);
  158. + if (content::RenderWidgetHostView *rwhv = d->webContents->GetRenderWidgetHostView())
  159. + rwhv->SetBackgroundColor(toSk(d->adapterClient->backgroundColor()));
  160. +}
  161. +
  162. content::WebContents *WebContentsAdapter::webContents() const
  163. {
  164. Q_D(const WebContentsAdapter);
  165. diff --git a/qtwebengine/src/core/web_contents_adapter.h b/src/core/web_contents_adapter.h
  166. index 5ea55c1..929967a 100644
  167. --- a/qtwebengine/src/core/web_contents_adapter.h
  168. +++ b/qtwebengine/src/core/web_contents_adapter.h
  169. @@ -120,6 +120,7 @@ public:
  170. void grantMouseLockPermission(bool granted);
  171. void dpiScaleChanged();
  172. + void backgroundColorChanged();
  173. QAccessibleInterface *browserAccessible();
  174. BrowserContextQt* browserContext();
  175. BrowserContextAdapter* browserContextAdapter();
  176. diff --git a/qtwebengine/src/core/web_contents_adapter_client.h b/src/core/web_contents_adapter_client.h
  177. index 3ed3ab9..acf3095 100644
  178. --- a/qtwebengine/src/core/web_contents_adapter_client.h
  179. +++ b/qtwebengine/src/core/web_contents_adapter_client.h
  180. @@ -152,6 +152,7 @@ public:
  181. virtual void selectionChanged() = 0;
  182. virtual QRectF viewportRect() const = 0;
  183. virtual qreal dpiScale() const = 0;
  184. + virtual QColor backgroundColor() const = 0;
  185. virtual void loadStarted(const QUrl &provisionalUrl, bool isErrorPage = false) = 0;
  186. virtual void loadCommitted() = 0;
  187. virtual void loadVisuallyCommitted() = 0;
  188. diff --git a/qtwebengine/src/core/web_contents_view_qt.cpp b/src/core/web_contents_view_qt.cpp
  189. index 9321706..f40bf8f 100644
  190. --- a/qtwebengine/src/core/web_contents_view_qt.cpp
  191. +++ b/qtwebengine/src/core/web_contents_view_qt.cpp
  192. @@ -81,6 +81,13 @@ content::RenderWidgetHostViewBase* WebContentsViewQt::CreateViewForPopupWidget(c
  193. return view;
  194. }
  195. +void WebContentsViewQt::RenderViewCreated(content::RenderViewHost* host)
  196. +{
  197. + // The render process is done creating the RenderView and it's ready to be routed
  198. + // messages at this point.
  199. + host->GetView()->SetBackgroundColor(toSk(m_client->backgroundColor()));
  200. +}
  201. +
  202. void WebContentsViewQt::CreateView(const gfx::Size& initial_size, gfx::NativeView context)
  203. {
  204. // This is passed through content::WebContents::CreateParams::context either as the native view's client
  205. diff --git a/qtwebengine/src/core/web_contents_view_qt.h b/src/core/web_contents_view_qt.h
  206. index 896955f..3ede530 100644
  207. --- a/qtwebengine/src/core/web_contents_view_qt.h
  208. +++ b/qtwebengine/src/core/web_contents_view_qt.h
  209. @@ -75,7 +75,7 @@ public:
  210. virtual void SetPageTitle(const base::string16& title) Q_DECL_OVERRIDE { }
  211. - virtual void RenderViewCreated(content::RenderViewHost* host) Q_DECL_OVERRIDE { QT_NOT_YET_IMPLEMENTED }
  212. + virtual void RenderViewCreated(content::RenderViewHost* host) Q_DECL_OVERRIDE;
  213. virtual void RenderViewSwappedIn(content::RenderViewHost* host) Q_DECL_OVERRIDE { QT_NOT_YET_IMPLEMENTED }
  214. diff --git a/qtwebengine/src/webengine/api/qquickwebengineview.cpp b/src/webengine/api/qquickwebengineview.cpp
  215. index 7405cae..c57d8d1 100644
  216. --- a/qtwebengine/src/webengine/api/qquickwebengineview.cpp
  217. +++ b/qtwebengine/src/webengine/api/qquickwebengineview.cpp
  218. @@ -104,6 +104,7 @@ QQuickWebEngineViewPrivate::QQuickWebEngineViewPrivate()
  219. , isLoading(false)
  220. , devicePixelRatio(QGuiApplication::primaryScreen()->devicePixelRatio())
  221. , m_dpiScale(1.0)
  222. + , m_backgroundColor(Qt::white)
  223. {
  224. // The gold standard for mobile web content is 160 dpi, and the devicePixelRatio expected
  225. // is the (possibly quantized) ratio of device dpi to 160 dpi.
  226. @@ -310,6 +311,11 @@ qreal QQuickWebEngineViewPrivate::dpiScale() const
  227. return m_dpiScale;
  228. }
  229. +QColor QQuickWebEngineViewPrivate::backgroundColor() const
  230. +{
  231. + return m_backgroundColor;
  232. +}
  233. +
  234. void QQuickWebEngineViewPrivate::loadStarted(const QUrl &provisionalUrl, bool isErrorPage)
  235. {
  236. Q_Q(QQuickWebEngineView);
  237. @@ -858,6 +864,34 @@ qreal QQuickWebEngineView::zoomFactor() const
  238. return d->adapter->currentZoomFactor();
  239. }
  240. +/*!
  241. + \qmlproperty bool WebEngineView::backgroundColor
  242. + \since QtWebEngine 1.3
  243. +
  244. + Sets this property to change the color of the WebEngineView's background,
  245. + behing the document's body. You can set it to "transparent" or to a translucent
  246. + color to see through the document, or you can set this color to match your
  247. + web content in an hybrid app to prevent the white flashes that may appear
  248. + during loading.
  249. +
  250. + The default value is white.
  251. +*/
  252. +QColor QQuickWebEngineView::backgroundColor() const
  253. +{
  254. + Q_D(const QQuickWebEngineView);
  255. + return d->m_backgroundColor;
  256. +}
  257. +
  258. +void QQuickWebEngineView::setBackgroundColor(const QColor &color)
  259. +{
  260. + Q_D(QQuickWebEngineView);
  261. + if (color == d->m_backgroundColor)
  262. + return;
  263. + d->m_backgroundColor = color;
  264. + d->ensureContentsAdapter();
  265. + d->adapter->backgroundColorChanged();
  266. + emit backgroundColorChanged();
  267. +}
  268. bool QQuickWebEngineView::isFullScreen() const
  269. {
  270. diff --git a/qtwebengine/src/webengine/api/qquickwebengineview_p.h b/src/webengine/api/qquickwebengineview_p.h
  271. index 40299c1..362c3a2 100644
  272. --- a/qtwebengine/src/webengine/api/qquickwebengineview_p.h
  273. +++ b/qtwebengine/src/webengine/api/qquickwebengineview_p.h
  274. @@ -89,6 +89,7 @@ class Q_WEBENGINE_PRIVATE_EXPORT QQuickWebEngineView : public QQuickItem {
  275. Q_PROPERTY(QQuickWebEngineHistory *navigationHistory READ navigationHistory CONSTANT FINAL REVISION 1)
  276. Q_PROPERTY(QQmlWebChannel *webChannel READ webChannel WRITE setWebChannel NOTIFY webChannelChanged REVISION 1)
  277. Q_PROPERTY(QQmlListProperty<QQuickWebEngineScript> userScripts READ userScripts FINAL)
  278. + Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor NOTIFY backgroundColorChanged REVISION 1)
  279. #ifdef ENABLE_QML_TESTSUPPORT_API
  280. Q_PROPERTY(QQuickWebEngineTestSupport *testSupport READ testSupport WRITE setTestSupport FINAL)
  281. @@ -118,6 +119,8 @@ public:
  282. bool isFullScreen() const;
  283. qreal zoomFactor() const;
  284. void setZoomFactor(qreal arg);
  285. + QColor backgroundColor() const;
  286. + void setBackgroundColor(const QColor &color);
  287. QQuickWebEngineViewExperimental *experimental() const;
  288. @@ -230,7 +233,7 @@ Q_SIGNALS:
  289. Q_REVISION(1) void zoomFactorChanged(qreal arg);
  290. Q_REVISION(1) void profileChanged();
  291. Q_REVISION(1) void webChannelChanged();
  292. -
  293. + Q_REVISION(1) void backgroundColorChanged();
  294. protected:
  295. void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry);
  296. diff --git a/qtwebengine/src/webengine/api/qquickwebengineview_p_p.h b/src/webengine/api/qquickwebengineview_p_p.h
  297. index edc8c1a..3bfed2f 100644
  298. --- a/qtwebengine/src/webengine/api/qquickwebengineview_p_p.h
  299. +++ b/qtwebengine/src/webengine/api/qquickwebengineview_p_p.h
  300. @@ -123,6 +123,7 @@ public:
  301. virtual void selectionChanged() Q_DECL_OVERRIDE { }
  302. virtual QRectF viewportRect() const Q_DECL_OVERRIDE;
  303. virtual qreal dpiScale() const Q_DECL_OVERRIDE;
  304. + virtual QColor backgroundColor() const Q_DECL_OVERRIDE;
  305. virtual void loadStarted(const QUrl &provisionalUrl, bool isErrorPage = false) Q_DECL_OVERRIDE;
  306. virtual void loadCommitted() Q_DECL_OVERRIDE;
  307. virtual void loadVisuallyCommitted() Q_DECL_OVERRIDE;
  308. @@ -192,6 +193,7 @@ private:
  309. QScopedPointer<QtWebEngineCore::UIDelegatesManager> m_uIDelegatesManager;
  310. QList<QQuickWebEngineScript *> m_userScripts;
  311. qreal m_dpiScale;
  312. + QColor m_backgroundColor;
  313. };
  314. #ifndef QT_NO_ACCESSIBILITY
  315. diff --git a/qtwebengine/src/webengine/render_widget_host_view_qt_delegate_quick.h b/src/webengine/render_widget_host_view_qt_delegate_quick.h
  316. index ddd0e4d..eb2860b 100644
  317. --- a/qtwebengine/src/webengine/render_widget_host_view_qt_delegate_quick.h
  318. +++ b/qtwebengine/src/webengine/render_widget_host_view_qt_delegate_quick.h
  319. @@ -70,6 +70,8 @@ public:
  320. virtual void move(const QPoint&) Q_DECL_OVERRIDE { }
  321. virtual void inputMethodStateChanged(bool editorVisible) Q_DECL_OVERRIDE;
  322. virtual void setTooltip(const QString&) Q_DECL_OVERRIDE { }
  323. + // The QtQuick view doesn't have a backbuffer of its own and doesn't need this
  324. + virtual void setClearColor(const QColor &) Q_DECL_OVERRIDE { }
  325. protected:
  326. virtual void focusInEvent(QFocusEvent *event) Q_DECL_OVERRIDE;
  327. diff --git a/qtwebengine/src/webengine/render_widget_host_view_qt_delegate_quickwindow.h b/src/webengine/render_widget_host_view_qt_delegate_quickwindow.h
  328. index cda51a1..a4b0848 100644
  329. --- a/qtwebengine/src/webengine/render_widget_host_view_qt_delegate_quickwindow.h
  330. +++ b/qtwebengine/src/webengine/render_widget_host_view_qt_delegate_quickwindow.h
  331. @@ -73,6 +73,7 @@ public:
  332. virtual void move(const QPoint &screenPos) Q_DECL_OVERRIDE;
  333. virtual void inputMethodStateChanged(bool) Q_DECL_OVERRIDE {}
  334. virtual void setTooltip(const QString &tooltip) Q_DECL_OVERRIDE;
  335. + virtual void setClearColor(const QColor &) Q_DECL_OVERRIDE { }
  336. private:
  337. QScopedPointer<RenderWidgetHostViewQtDelegate> m_realDelegate;
  338. diff --git a/qtwebengine/src/webenginewidgets/api/qwebenginepage.cpp b/src/webenginewidgets/api/qwebenginepage.cpp
  339. index 1b5a243..1cd7d6a 100644
  340. --- a/qtwebengine/src/webenginewidgets/api/qwebenginepage.cpp
  341. +++ b/qtwebengine/src/webenginewidgets/api/qwebenginepage.cpp
  342. @@ -185,6 +185,7 @@ QWebEnginePagePrivate::QWebEnginePagePrivate(QWebEngineProfile *_profile)
  343. , view(0)
  344. , isLoading(false)
  345. , scriptCollection(new QWebEngineScriptCollectionPrivate(browserContextAdapter()->userScriptController(), adapter.data()))
  346. + , m_backgroundColor(Qt::white)
  347. {
  348. memset(actions, 0, sizeof(actions));
  349. }
  350. @@ -247,6 +248,11 @@ qreal QWebEnginePagePrivate::dpiScale() const
  351. return 1.0;
  352. }
  353. +QColor QWebEnginePagePrivate::backgroundColor() const
  354. +{
  355. + return m_backgroundColor;
  356. +}
  357. +
  358. void QWebEnginePagePrivate::loadStarted(const QUrl &provisionalUrl, bool isErrorPage)
  359. {
  360. Q_UNUSED(provisionalUrl);
  361. @@ -531,6 +537,33 @@ void QWebEnginePage::setWebChannel(QWebChannel *channel)
  362. d->adapter->setWebChannel(channel);
  363. }
  364. +/*!
  365. + \property QWebEnginePage::backgroundColor
  366. + \brief the page's background color, behing the document's body.
  367. + \since 5.6
  368. +
  369. + You can set it to Qt::transparent or to a translucent
  370. + color to see through the document, or you can set this color to match your
  371. + web content in an hybrid app to prevent the white flashes that may appear
  372. + during loading.
  373. +
  374. + The default value is white.
  375. +*/
  376. +QColor QWebEnginePage::backgroundColor() const
  377. +{
  378. + Q_D(const QWebEnginePage);
  379. + return d->m_backgroundColor;
  380. +}
  381. +
  382. +void QWebEnginePage::setBackgroundColor(const QColor &color)
  383. +{
  384. + Q_D(QWebEnginePage);
  385. + if (d->m_backgroundColor == color)
  386. + return;
  387. + d->m_backgroundColor = color;
  388. + d->adapter->backgroundColorChanged();
  389. +}
  390. +
  391. void QWebEnginePage::setView(QWidget *view)
  392. {
  393. QWebEngineViewPrivate::bind(qobject_cast<QWebEngineView*>(view), this);
  394. diff --git a/qtwebengine/src/webenginewidgets/api/qwebenginepage.h b/src/webenginewidgets/api/qwebenginepage.h
  395. index b4cf522..57ed071 100644
  396. --- a/qtwebengine/src/webenginewidgets/api/qwebenginepage.h
  397. +++ b/qtwebengine/src/webenginewidgets/api/qwebenginepage.h
  398. @@ -98,6 +98,7 @@ class QWEBENGINEWIDGETS_EXPORT QWebEnginePage : public QObject {
  399. Q_PROPERTY(QString title READ title)
  400. Q_PROPERTY(QUrl url READ url WRITE setUrl)
  401. Q_PROPERTY(QUrl iconUrl READ iconUrl)
  402. + Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor)
  403. public:
  404. enum WebAction {
  405. @@ -236,6 +237,8 @@ public:
  406. QWebChannel *webChannel() const;
  407. void setWebChannel(QWebChannel *);
  408. + QColor backgroundColor() const;
  409. + void setBackgroundColor(const QColor &color);
  410. Q_SIGNALS:
  411. void loadStarted();
  412. diff --git a/qtwebengine/src/webenginewidgets/api/qwebenginepage_p.h b/src/webenginewidgets/api/qwebenginepage_p.h
  413. index 8f45ecd..7d74d3f 100644
  414. --- a/qtwebengine/src/webenginewidgets/api/qwebenginepage_p.h
  415. +++ b/qtwebengine/src/webenginewidgets/api/qwebenginepage_p.h
  416. @@ -118,6 +118,7 @@ public:
  417. virtual void selectionChanged() Q_DECL_OVERRIDE;
  418. virtual QRectF viewportRect() const Q_DECL_OVERRIDE;
  419. virtual qreal dpiScale() const Q_DECL_OVERRIDE;
  420. + virtual QColor backgroundColor() const Q_DECL_OVERRIDE;
  421. virtual void loadStarted(const QUrl &provisionalUrl, bool isErrorPage = false) Q_DECL_OVERRIDE;
  422. virtual void loadCommitted() Q_DECL_OVERRIDE;
  423. virtual void loadVisuallyCommitted() Q_DECL_OVERRIDE { }
  424. @@ -170,6 +171,7 @@ public:
  425. QtWebEngineCore::WebEngineContextMenuData m_menuData;
  426. bool isLoading;
  427. QWebEngineScriptCollection scriptCollection;
  428. + QColor m_backgroundColor;
  429. mutable CallbackDirectory m_callbacks;
  430. mutable QAction *actions[QWebEnginePage::WebActionCount];
  431. diff --git a/qtwebengine/src/webenginewidgets/render_widget_host_view_qt_delegate_widget.cpp b/src/webenginewidgets/render_widget_host_view_qt_delegate_widget.cpp
  432. index dba37ce..76ca8d3 100644
  433. --- a/qtwebengine/src/webenginewidgets/render_widget_host_view_qt_delegate_widget.cpp
  434. +++ b/qtwebengine/src/webenginewidgets/render_widget_host_view_qt_delegate_widget.cpp
  435. @@ -59,6 +59,7 @@ RenderWidgetHostViewQtDelegateWidget::RenderWidgetHostViewQtDelegateWidget(Rende
  436. , m_rootNode(new QSGRootNode)
  437. , m_sgEngine(new QSGEngine)
  438. , m_isPopup(false)
  439. + , m_clearColor(Qt::white)
  440. {
  441. setFocusPolicy(Qt::StrongFocus);
  442. @@ -218,6 +219,19 @@ void RenderWidgetHostViewQtDelegateWidget::setTooltip(const QString &tooltip)
  443. setToolTip(wrappedTip);
  444. }
  445. +void RenderWidgetHostViewQtDelegateWidget::setClearColor(const QColor &color)
  446. +{
  447. + m_clearColor = color;
  448. + // QOpenGLWidget is usually blended by punching holes into widgets
  449. + // above it to simulate the visual stacking order. If we want it to be
  450. + // transparent we have to throw away the proper stacking order and always
  451. + // blend the complete normal widgets backing store under it.
  452. + bool isTranslucent = color.alpha() < 255;
  453. + setAttribute(Qt::WA_AlwaysStackOnTop, isTranslucent);
  454. + setAttribute(Qt::WA_OpaquePaintEvent, !isTranslucent);
  455. + update();
  456. +}
  457. +
  458. QVariant RenderWidgetHostViewQtDelegateWidget::inputMethodQuery(Qt::InputMethodQuery query) const
  459. {
  460. return m_client->inputMethodQuery(query);
  461. @@ -270,7 +284,7 @@ void RenderWidgetHostViewQtDelegateWidget::initializeGL()
  462. m_sgEngine->initialize(QOpenGLContext::currentContext());
  463. m_sgRenderer.reset(m_sgEngine->createRenderer());
  464. m_sgRenderer->setRootNode(m_rootNode.data());
  465. - m_sgRenderer->setClearColor(Qt::white);
  466. + m_sgRenderer->setClearColor(m_clearColor);
  467. }
  468. void RenderWidgetHostViewQtDelegateWidget::paintGL()
  469. diff --git a/qtwebengine/src/webenginewidgets/render_widget_host_view_qt_delegate_widget.h b/src/webenginewidgets/render_widget_host_view_qt_delegate_widget.h
  470. index d0dfdc6..d228bd4 100644
  471. --- a/qtwebengine/src/webenginewidgets/render_widget_host_view_qt_delegate_widget.h
  472. +++ b/qtwebengine/src/webenginewidgets/render_widget_host_view_qt_delegate_widget.h
  473. @@ -78,6 +78,7 @@ public:
  474. virtual void move(const QPoint &screenPos) Q_DECL_OVERRIDE;
  475. virtual void inputMethodStateChanged(bool editorVisible) Q_DECL_OVERRIDE;
  476. virtual void setTooltip(const QString &tooltip) Q_DECL_OVERRIDE;
  477. + virtual void setClearColor(const QColor &color) Q_DECL_OVERRIDE;
  478. protected:
  479. bool event(QEvent *event) Q_DECL_OVERRIDE;
  480. @@ -98,6 +99,7 @@ private:
  481. QScopedPointer<QSGEngine> m_sgEngine;
  482. QScopedPointer<QSGAbstractRenderer> m_sgRenderer;
  483. bool m_isPopup;
  484. + QColor m_clearColor;
  485. QList<QMetaObject::Connection> m_windowConnections;
  486. };
  487. --
  488. 2.3.3