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 78a93c1
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 24 deletions.
16 changes: 9 additions & 7 deletions shell/browser/api/electron_api_browser_window.cc
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
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
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
2 changes: 0 additions & 2 deletions shell/browser/web_contents_preferences.h
Expand Up @@ -48,7 +48,6 @@ class WebContentsPreferences
base::Value* last_preference() { return &last_web_preferences_; }

bool IsOffscreen() const { return offscreen_; }
bool IsTransparent() const { return transparent_; }
absl::optional<SkColor> GetBackgroundColor() const {
return background_color_;
}
Expand Down Expand Up @@ -124,7 +123,6 @@ class WebContentsPreferences
bool safe_dialogs_;
absl::optional<std::string> safe_dialogs_message_;
bool ignore_menu_shortcuts_;
bool transparent_;
absl::optional<SkColor> background_color_;
blink::mojom::ImageAnimationPolicy image_animation_policy_;
absl::optional<base::FilePath> preload_path_;
Expand Down
3 changes: 1 addition & 2 deletions spec-main/fixtures/snapshots/native-window-open.snapshot.txt
Expand Up @@ -88,8 +88,7 @@
"sandbox": true,
"webviewTag": false,
"nodeIntegrationInSubFrames": false,
"openerId": null,
"backgroundColor": "gray"
"openerId": null
},
"x": 100,
"y": 100,
Expand Down
3 changes: 1 addition & 2 deletions spec-main/fixtures/snapshots/proxy-window-open.snapshot.txt
Expand Up @@ -88,8 +88,7 @@
"nodeIntegration": false,
"webviewTag": false,
"nodeIntegrationInSubFrames": false,
"openerId": "placeholder-opener-id",
"backgroundColor": "gray"
"openerId": "placeholder-opener-id"
},
"x": 100,
"y": 100,
Expand Down

0 comments on commit 78a93c1

Please sign in to comment.