mirror of
https://github.com/electron/electron.git
synced 2026-04-10 03:01:51 -04:00
Merge pull request #4777 from deepak1556/webview_background_patch
webview: allow setting background color
This commit is contained in:
@@ -1101,11 +1101,6 @@ void WebContents::SetSize(const SetSizeParams& params) {
|
||||
guest_delegate_->SetSize(params);
|
||||
}
|
||||
|
||||
void WebContents::SetAllowTransparency(bool allow) {
|
||||
if (guest_delegate_)
|
||||
guest_delegate_->SetAllowTransparency(allow);
|
||||
}
|
||||
|
||||
bool WebContents::IsGuest() const {
|
||||
return type_ == WEB_VIEW;
|
||||
}
|
||||
@@ -1203,7 +1198,6 @@ void WebContents::BuildPrototype(v8::Isolate* isolate,
|
||||
&WebContents::BeginFrameSubscription)
|
||||
.SetMethod("endFrameSubscription", &WebContents::EndFrameSubscription)
|
||||
.SetMethod("setSize", &WebContents::SetSize)
|
||||
.SetMethod("setAllowTransparency", &WebContents::SetAllowTransparency)
|
||||
.SetMethod("isGuest", &WebContents::IsGuest)
|
||||
.SetMethod("getWebPreferences", &WebContents::GetWebPreferences)
|
||||
.SetMethod("getOwnerBrowserWindow", &WebContents::GetOwnerBrowserWindow)
|
||||
|
||||
@@ -131,7 +131,6 @@ class WebContents : public mate::TrackableObject<WebContents>,
|
||||
|
||||
// Methods for creating <webview>.
|
||||
void SetSize(const SetSizeParams& params);
|
||||
void SetAllowTransparency(bool allow);
|
||||
bool IsGuest() const;
|
||||
|
||||
// Callback triggered on permission response.
|
||||
|
||||
@@ -22,8 +22,7 @@ const int kDefaultHeight = 300;
|
||||
} // namespace
|
||||
|
||||
WebViewGuestDelegate::WebViewGuestDelegate()
|
||||
: guest_opaque_(true),
|
||||
guest_host_(nullptr),
|
||||
: guest_host_(nullptr),
|
||||
auto_size_enabled_(false),
|
||||
is_full_page_plugin_(false),
|
||||
api_web_contents_(nullptr) {
|
||||
@@ -96,23 +95,6 @@ void WebViewGuestDelegate::SetSize(const SetSizeParams& params) {
|
||||
auto_size_enabled_ = enable_auto_size;
|
||||
}
|
||||
|
||||
void WebViewGuestDelegate::SetAllowTransparency(bool allow) {
|
||||
if (guest_opaque_ != allow)
|
||||
return;
|
||||
|
||||
auto render_view_host = web_contents()->GetRenderViewHost();
|
||||
guest_opaque_ = !allow;
|
||||
if (!render_view_host->GetWidget()->GetView())
|
||||
return;
|
||||
|
||||
if (guest_opaque_) {
|
||||
render_view_host->GetWidget()->GetView()->SetBackgroundColorToDefault();
|
||||
} else {
|
||||
render_view_host->GetWidget()->GetView()->SetBackgroundColor(
|
||||
SK_ColorTRANSPARENT);
|
||||
}
|
||||
}
|
||||
|
||||
void WebViewGuestDelegate::HandleKeyboardEvent(
|
||||
content::WebContents* source,
|
||||
const content::NativeWebKeyboardEvent& event) {
|
||||
@@ -120,19 +102,6 @@ void WebViewGuestDelegate::HandleKeyboardEvent(
|
||||
embedder_web_contents_->GetDelegate()->HandleKeyboardEvent(source, event);
|
||||
}
|
||||
|
||||
void WebViewGuestDelegate::RenderViewReady() {
|
||||
// We don't want to accidentally set the opacity of an interstitial page.
|
||||
// WebContents::GetRenderWidgetHostView will return the RWHV of an
|
||||
// interstitial page if one is showing at this time. We only want opacity
|
||||
// to apply to web pages.
|
||||
auto render_view_host_view =
|
||||
web_contents()->GetRenderViewHost()->GetWidget()->GetView();
|
||||
if (guest_opaque_)
|
||||
render_view_host_view->SetBackgroundColorToDefault();
|
||||
else
|
||||
render_view_host_view->SetBackgroundColor(SK_ColorTRANSPARENT);
|
||||
}
|
||||
|
||||
void WebViewGuestDelegate::DidCommitProvisionalLoadForFrame(
|
||||
content::RenderFrameHost* render_frame_host,
|
||||
const GURL& url, ui::PageTransition transition_type) {
|
||||
|
||||
@@ -49,16 +49,12 @@ class WebViewGuestDelegate : public content::BrowserPluginGuestDelegate,
|
||||
// and normal sizes.
|
||||
void SetSize(const SetSizeParams& params);
|
||||
|
||||
// Sets the transparency of the guest.
|
||||
void SetAllowTransparency(bool allow);
|
||||
|
||||
// Transfer the keyboard event to embedder.
|
||||
void HandleKeyboardEvent(content::WebContents* source,
|
||||
const content::NativeWebKeyboardEvent& event);
|
||||
|
||||
protected:
|
||||
// content::WebContentsObserver:
|
||||
void RenderViewReady() override;
|
||||
void DidCommitProvisionalLoadForFrame(
|
||||
content::RenderFrameHost* render_frame_host,
|
||||
const GURL& url, ui::PageTransition transition_type) override;
|
||||
@@ -85,9 +81,6 @@ class WebViewGuestDelegate : public content::BrowserPluginGuestDelegate,
|
||||
// Returns the default size of the guestview.
|
||||
gfx::Size GetDefaultSize() const;
|
||||
|
||||
// Stores whether the contents of the guest can be transparent.
|
||||
bool guest_opaque_;
|
||||
|
||||
// The WebContents that attaches this guest view.
|
||||
content::WebContents* embedder_web_contents_;
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include "content/public/renderer/render_frame.h"
|
||||
#include "content/public/renderer/render_frame_observer.h"
|
||||
#include "content/public/renderer/render_thread.h"
|
||||
#include "content/public/renderer/render_view.h"
|
||||
#include "ipc/ipc_message_macros.h"
|
||||
#include "third_party/WebKit/public/web/WebCustomElement.h"
|
||||
#include "third_party/WebKit/public/web/WebLocalFrame.h"
|
||||
@@ -131,6 +132,9 @@ void AtomRendererClient::RenderFrameCreated(
|
||||
}
|
||||
|
||||
void AtomRendererClient::RenderViewCreated(content::RenderView* render_view) {
|
||||
// Set default UA-dependent background as transparent.
|
||||
render_view->GetWebView()->setBaseBackgroundColor(SK_ColorTRANSPARENT);
|
||||
|
||||
new printing::PrintWebViewHelper(render_view);
|
||||
new AtomRenderViewObserver(render_view, this);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user