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: change default background_color from absl::nullopt to transparent #30988

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 1 addition & 1 deletion shell/browser/web_contents_preferences.cc
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ void WebContentsPreferences::Clear() {
safe_dialogs_ = false;
safe_dialogs_message_ = absl::nullopt;
ignore_menu_shortcuts_ = false;
background_color_ = absl::nullopt;
background_color_ = SK_ColorTRANSPARENT;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this is correct 🤔 I think this should only be SK_ColorTRANSPARENT if the owning BrowserWindow is transparent 🤔 I think WebContentsPreferences used to have a concept of transparency but apparently not any more

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was the intention with using the optional value.

The backgroundColor web preferences property was changed to use a hidden field. I wonder if this also needs to be the same with BrowserViews somewhere?

// Copy the backgroundColor to webContents.
v8::Local<v8::Value> value;
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));
}

Also, just a heads up that the v14 implementation differs a bit because of the WebPreferences refactor. Backport might be painful 😞

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw, I have some wip tests written for backgroundColor so hopefully we'll be able to catch these issues in the future! 🤞 https://github.com/electron/electron/compare/main...samuelmaddock:test/bw-bg-color?expand=1

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A little more investigation: BrowserView might not be calling WebContents::SetPageBaseBackgroundColor()? 🤔

void BrowserView::SetBackgroundColor(const std::string& color_name) {
view_->SetBackgroundColor(ParseHexColor(color_name));
}

compared to BrowserWindow's code

void BrowserWindow::SetBackgroundColor(const std::string& color_name) {
BaseWindow::SetBackgroundColor(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_) {
auto* web_preferences =
WebContentsPreferences::From(api_web_contents_->web_contents());
if (web_preferences) {
web_preferences->SetBackgroundColor(ParseHexColor(color_name));
}
}
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may not be calling it or there may be a painting/timing error on when it's called?

I actually found this bug yesterday while digging into this more: #30993 If I start a transparent window in Fiddle, the background renders as white, but then sometimes will switch back to transparent if I alt+tab away. Maybe there's a timing issue where background_color sometimes isn't being set before the first paint? Looking into it more today! 🙂

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@samuelmaddock You were right - it looks like there's an issue with SetPageBaseBackgroundColor, where transparent windows would be white until a repaint (e.g. resize) happened. It looks like Chrome's going to merge the two APIs and address this down the line (https://chromium-review.googlesource.com/c/chromium/src/+/2958369), but we can get around it now by setting the background directly on the render widget host view. There's a new PR open to address this (linked below) 🙂

image_animation_policy_ =
blink::mojom::ImageAnimationPolicy::kImageAnimationPolicyAllowed;
preload_path_ = absl::nullopt;
Expand Down