summaryrefslogtreecommitdiffstats
path: root/src/core
diff options
context:
space:
mode:
authorJocelyn Turcotte <jturcotte@woboq.com>2015-07-09 21:52:43 +0200
committerAllan Sandfeld Jensen <allan.jensen@theqtcompany.com>2015-07-14 13:06:19 +0000
commit99e98f7bf6aec78fe0d647fb898e65d13ff522e4 (patch)
tree64a38d99e5f6287e80f92df1d9ac125cc2325b87 /src/core
parent8d6b933a971476abe91e72728d997aa5dd2a71be (diff)
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/core')
-rw-r--r--src/core/common/qt_messages.h3
-rw-r--r--src/core/render_widget_host_view_qt.cpp9
-rw-r--r--src/core/render_widget_host_view_qt.h1
-rw-r--r--src/core/render_widget_host_view_qt_delegate.h1
-rw-r--r--src/core/renderer/qt_render_view_observer.cpp6
-rw-r--r--src/core/renderer/qt_render_view_observer.h1
-rw-r--r--src/core/type_conversion.h5
-rw-r--r--src/core/web_contents_adapter.cpp7
-rw-r--r--src/core/web_contents_adapter.h1
-rw-r--r--src/core/web_contents_adapter_client.h1
-rw-r--r--src/core/web_contents_view_qt.cpp7
-rw-r--r--src/core/web_contents_view_qt.h2
12 files changed, 43 insertions, 1 deletions
diff --git a/src/core/common/qt_messages.h b/src/core/common/qt_messages.h
index c692ee5ca..25a995b27 100644
--- a/src/core/common/qt_messages.h
+++ b/src/core/common/qt_messages.h
@@ -31,6 +31,9 @@ IPC_MESSAGE_ROUTED1(QtRenderViewObserver_FetchDocumentMarkup,
IPC_MESSAGE_ROUTED1(QtRenderViewObserver_FetchDocumentInnerText,
uint64 /* requestId */)
+IPC_MESSAGE_ROUTED1(QtRenderViewObserver_SetBackgroundColor,
+ uint32 /* color */)
+
IPC_MESSAGE_ROUTED1(WebChannelIPCTransport_Message, std::vector<char> /*binaryJSON*/)
// User scripts messages
diff --git a/src/core/render_widget_host_view_qt.cpp b/src/core/render_widget_host_view_qt.cpp
index 46f93b90b..ef6610ecb 100644
--- a/src/core/render_widget_host_view_qt.cpp
+++ b/src/core/render_widget_host_view_qt.cpp
@@ -36,6 +36,7 @@
#include "render_widget_host_view_qt.h"
+#include "common/qt_messages.h"
#include "browser_accessibility_manager_qt.h"
#include "browser_accessibility_qt.h"
#include "chromium_overrides.h"
@@ -413,6 +414,14 @@ gfx::Rect RenderWidgetHostViewQt::GetViewBounds() const
return gfx::BoundingRect(p1, p2);
}
+void RenderWidgetHostViewQt::SetBackgroundColor(SkColor color) {
+ RenderWidgetHostViewBase::SetBackgroundColor(color);
+ // Set the background of the compositor if necessary
+ m_delegate->setClearColor(toQt(color));
+ // Set the background of the blink::FrameView
+ m_host->Send(new QtRenderViewObserver_SetBackgroundColor(m_host->GetRoutingID(), color));
+}
+
// Return value indicates whether the mouse is locked successfully or not.
bool RenderWidgetHostViewQt::LockMouse()
{
diff --git a/src/core/render_widget_host_view_qt.h b/src/core/render_widget_host_view_qt.h
index 310ada429..274138dcf 100644
--- a/src/core/render_widget_host_view_qt.h
+++ b/src/core/render_widget_host_view_qt.h
@@ -126,6 +126,7 @@ public:
virtual void Hide() Q_DECL_OVERRIDE;
virtual bool IsShowing() Q_DECL_OVERRIDE;
virtual gfx::Rect GetViewBounds() const Q_DECL_OVERRIDE;
+ virtual void SetBackgroundColor(SkColor color) Q_DECL_OVERRIDE;
virtual bool LockMouse() Q_DECL_OVERRIDE;
virtual void UnlockMouse() Q_DECL_OVERRIDE;
virtual void MovePluginWindows(const std::vector<content::WebPluginGeometry>&) Q_DECL_OVERRIDE;
diff --git a/src/core/render_widget_host_view_qt_delegate.h b/src/core/render_widget_host_view_qt_delegate.h
index da595b91f..f4aa9b27d 100644
--- a/src/core/render_widget_host_view_qt_delegate.h
+++ b/src/core/render_widget_host_view_qt_delegate.h
@@ -96,6 +96,7 @@ public:
virtual void move(const QPoint &) = 0;
virtual void inputMethodStateChanged(bool editorVisible) = 0;
virtual void setTooltip(const QString &) = 0;
+ virtual void setClearColor(const QColor &color) = 0;
};
} // namespace QtWebEngineCore
diff --git a/src/core/renderer/qt_render_view_observer.cpp b/src/core/renderer/qt_render_view_observer.cpp
index 83534dadd..ba91e54ae 100644
--- a/src/core/renderer/qt_render_view_observer.cpp
+++ b/src/core/renderer/qt_render_view_observer.cpp
@@ -65,6 +65,11 @@ void QtRenderViewObserver::onFetchDocumentInnerText(quint64 requestId)
render_view()->GetWebView()->mainFrame()->contentAsText(std::numeric_limits<std::size_t>::max())));
}
+void QtRenderViewObserver::onSetBackgroundColor(quint32 color)
+{
+ render_view()->GetWebView()->setBaseBackgroundColor(color);
+}
+
void QtRenderViewObserver::OnFirstVisuallyNonEmptyLayout()
{
Send(new QtRenderViewObserverHost_DidFirstVisuallyNonEmptyLayout(routing_id()));
@@ -76,6 +81,7 @@ bool QtRenderViewObserver::OnMessageReceived(const IPC::Message& message)
IPC_BEGIN_MESSAGE_MAP(QtRenderViewObserver, message)
IPC_MESSAGE_HANDLER(QtRenderViewObserver_FetchDocumentMarkup, onFetchDocumentMarkup)
IPC_MESSAGE_HANDLER(QtRenderViewObserver_FetchDocumentInnerText, onFetchDocumentInnerText)
+ IPC_MESSAGE_HANDLER(QtRenderViewObserver_SetBackgroundColor, onSetBackgroundColor)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
return handled;
diff --git a/src/core/renderer/qt_render_view_observer.h b/src/core/renderer/qt_render_view_observer.h
index cb77cd0c9..3f7829a92 100644
--- a/src/core/renderer/qt_render_view_observer.h
+++ b/src/core/renderer/qt_render_view_observer.h
@@ -47,6 +47,7 @@ public:
private:
void onFetchDocumentMarkup(quint64 requestId);
void onFetchDocumentInnerText(quint64 requestId);
+ void onSetBackgroundColor(quint32 color);
void OnFirstVisuallyNonEmptyLayout() Q_DECL_OVERRIDE;
diff --git a/src/core/type_conversion.h b/src/core/type_conversion.h
index 90bd38b81..d49edd203 100644
--- a/src/core/type_conversion.h
+++ b/src/core/type_conversion.h
@@ -129,6 +129,11 @@ inline QColor toQt(const SkColor &c)
return QColor(SkColorGetR(c), SkColorGetG(c), SkColorGetB(c), SkColorGetA(c));
}
+inline SkColor toSk(const QColor &c)
+{
+ return c.rgba();
+}
+
inline QMatrix4x4 toQt(const SkMatrix44 &m)
{
QMatrix4x4 qtMatrix(
diff --git a/src/core/web_contents_adapter.cpp b/src/core/web_contents_adapter.cpp
index 4a4e7198e..210704148 100644
--- a/src/core/web_contents_adapter.cpp
+++ b/src/core/web_contents_adapter.cpp
@@ -837,6 +837,13 @@ void WebContentsAdapter::dpiScaleChanged()
impl->NotifyScreenInfoChanged();
}
+void WebContentsAdapter::backgroundColorChanged()
+{
+ Q_D(WebContentsAdapter);
+ if (content::RenderWidgetHostView *rwhv = d->webContents->GetRenderWidgetHostView())
+ rwhv->SetBackgroundColor(toSk(d->adapterClient->backgroundColor()));
+}
+
content::WebContents *WebContentsAdapter::webContents() const
{
Q_D(const WebContentsAdapter);
diff --git a/src/core/web_contents_adapter.h b/src/core/web_contents_adapter.h
index db8449478..902cc61ff 100644
--- a/src/core/web_contents_adapter.h
+++ b/src/core/web_contents_adapter.h
@@ -132,6 +132,7 @@ public:
void grantMouseLockPermission(bool granted);
void dpiScaleChanged();
+ void backgroundColorChanged();
QAccessibleInterface *browserAccessible();
BrowserContextQt* browserContext();
BrowserContextAdapter* browserContextAdapter();
diff --git a/src/core/web_contents_adapter_client.h b/src/core/web_contents_adapter_client.h
index 9bc7698a5..20a5ad7af 100644
--- a/src/core/web_contents_adapter_client.h
+++ b/src/core/web_contents_adapter_client.h
@@ -190,6 +190,7 @@ public:
virtual void selectionChanged() = 0;
virtual QRectF viewportRect() const = 0;
virtual qreal dpiScale() const = 0;
+ virtual QColor backgroundColor() const = 0;
virtual void loadStarted(const QUrl &provisionalUrl, bool isErrorPage = false) = 0;
virtual void loadCommitted() = 0;
virtual void loadVisuallyCommitted() = 0;
diff --git a/src/core/web_contents_view_qt.cpp b/src/core/web_contents_view_qt.cpp
index 004800d5a..aad44c1d9 100644
--- a/src/core/web_contents_view_qt.cpp
+++ b/src/core/web_contents_view_qt.cpp
@@ -82,6 +82,13 @@ content::RenderWidgetHostViewBase* WebContentsViewQt::CreateViewForPopupWidget(c
return view;
}
+void WebContentsViewQt::RenderViewCreated(content::RenderViewHost* host)
+{
+ // The render process is done creating the RenderView and it's ready to be routed
+ // messages at this point.
+ host->GetView()->SetBackgroundColor(toSk(m_client->backgroundColor()));
+}
+
void WebContentsViewQt::CreateView(const gfx::Size& initial_size, gfx::NativeView context)
{
// This is passed through content::WebContents::CreateParams::context either as the native view's client
diff --git a/src/core/web_contents_view_qt.h b/src/core/web_contents_view_qt.h
index a19432fbe..cbbca2371 100644
--- a/src/core/web_contents_view_qt.h
+++ b/src/core/web_contents_view_qt.h
@@ -76,7 +76,7 @@ public:
virtual void SetPageTitle(const base::string16& title) Q_DECL_OVERRIDE { }
- virtual void RenderViewCreated(content::RenderViewHost* host) Q_DECL_OVERRIDE { QT_NOT_YET_IMPLEMENTED }
+ virtual void RenderViewCreated(content::RenderViewHost* host) Q_DECL_OVERRIDE;
virtual void RenderViewSwappedIn(content::RenderViewHost* host) Q_DECL_OVERRIDE { QT_NOT_YET_IMPLEMENTED }