Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: BrowserWindow backgroundColor #30819

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 1 addition & 3 deletions shell/browser/api/electron_api_browser_window.cc
Expand Up @@ -362,9 +362,7 @@ void BrowserWindow::Blur() {

void BrowserWindow::SetBackgroundColor(const std::string& color_name) {
BaseWindow::SetBackgroundColor(color_name);
auto* view = web_contents()->GetRenderWidgetHostView();
if (view)
view->SetBackgroundColor(ParseHexColor(color_name));
web_contents()->SetPageBaseBackgroundColor(ParseHexColor(color_name));
// Also update the web preferences object otherwise the view will be reset on
// the next load URL call
if (api_web_contents_) {
Expand Down
10 changes: 9 additions & 1 deletion shell/browser/api/electron_api_web_contents.cc
Expand Up @@ -1373,8 +1373,16 @@ void WebContents::HandleNewRenderFrame(
std::string color_name;
if (web_preferences->GetPreference(options::kBackgroundColor,
&color_name)) {
rwhv->SetBackgroundColor(ParseHexColor(color_name));
web_contents()->SetPageBaseBackgroundColor(ParseHexColor(color_name));
} else {
web_contents()->SetPageBaseBackgroundColor(absl::nullopt);
}

// When a page base background color is set, transparency needs to be
// explicitly set by calling
// RenderWidgetHostOwnerDelegate::SetBackgroundOpaque(false).
// RenderWidgetHostViewBase::SetBackgroundColor() will do this for us.
if (web_preferences->IsEnabled(options::kTransparent)) {
rwhv->SetBackgroundColor(SK_ColorTRANSPARENT);
}
}
Expand Down