Skip to content

Commit

Permalink
refactor: propagate transparency via backgroundColor
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelmaddock committed Sep 2, 2021
1 parent 4ec7312 commit 819dae6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 18 deletions.
16 changes: 9 additions & 7 deletions shell/browser/api/electron_api_browser_window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,15 @@ BrowserWindow::BrowserWindow(gin::Arguments* args,

// Copy the backgroundColor to webContents.
v8::Local<v8::Value> value;
if (options.Get(options::kBackgroundColor, &value))
web_preferences.Set(options::kBackgroundColor, value);

// Copy the transparent setting to webContents
v8::Local<v8::Value> transparent;
if (options.Get(options::kTransparent, &transparent))
web_preferences.Set(options::kTransparent, transparent);
bool transparent = false;
if (options.Get(options::kBackgroundColor, &value)) {
web_preferences.SetHidden(options::kBackgroundColor, value);
} else if (options.Get(options::kTransparent, &transparent) && transparent) {
// If the BrowserWindow is transparent, also propagate transparency to the
// WebContents unless a separate backgroundColor has been set.
web_preferences.SetHidden(options::kBackgroundColor,
ToRGBAHex(SK_ColorTRANSPARENT));
}

// Copy the show setting to webContents, but only if we don't want to paint
// when initially hidden
Expand Down
8 changes: 0 additions & 8 deletions shell/browser/api/electron_api_web_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1375,14 +1375,6 @@ void WebContents::HandleNewRenderFrame(
if (web_preferences) {
web_contents()->SetPageBaseBackgroundColor(
web_preferences->GetBackgroundColor());

// 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->IsTransparent()) {
rwhv->SetBackgroundColor(SK_ColorTRANSPARENT);
}
}

if (!background_throttling_)
Expand Down
4 changes: 1 addition & 3 deletions shell/browser/web_contents_preferences.cc
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ void WebContentsPreferences::Clear() {
safe_dialogs_ = false;
safe_dialogs_message_ = absl::nullopt;
ignore_menu_shortcuts_ = false;
transparent_ = false;
background_color_ = absl::nullopt;
image_animation_policy_ =
blink::mojom::ImageAnimationPolicy::kImageAnimationPolicyAllowed;
Expand Down Expand Up @@ -226,9 +225,8 @@ void WebContentsPreferences::SetFromDictionary(
web_preferences.Get("disablePopups", &disable_popups_);
web_preferences.Get("disableDialogs", &disable_dialogs_);
web_preferences.Get("safeDialogs", &safe_dialogs_);
web_preferences.Get(options::kTransparent, &transparent_);
std::string background_color;
if (web_preferences.Get(options::kBackgroundColor, &background_color))
if (web_preferences.GetHidden(options::kBackgroundColor, &background_color))
background_color_ = ParseHexColor(background_color);
std::string safe_dialogs_message;
if (web_preferences.Get("safeDialogsMessage", &safe_dialogs_message))
Expand Down

0 comments on commit 819dae6

Please sign in to comment.