fix: BrowserWindow.setBackgroundColor should work with transparency (#42824)

fix: BrowserWindow.setBackgroundColor should work with transparency
This commit is contained in:
Shelley Vohr 2024-07-16 20:11:49 +02:00 committed by GitHub
parent 81351dd1a9
commit cbd11bb605
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 35 additions and 12 deletions

View file

@ -3729,14 +3729,17 @@ void WebContents::SetBackgroundColor(std::optional<SkColor> maybe_color) {
type_ == Type::kBrowserView
? SK_ColorTRANSPARENT
: SK_ColorWHITE);
bool is_opaque = SkColorGetA(color) == SK_AlphaOPAQUE;
web_contents()->SetPageBaseBackgroundColor(color);
content::RenderFrameHost* rfh = web_contents()->GetPrimaryMainFrame();
if (!rfh)
return;
content::RenderWidgetHostView* rwhv = rfh->GetView();
if (rwhv) {
rwhv->SetBackgroundColor(color);
// RenderWidgetHostView doesn't allow setting an alpha that's not 0 or 255.
rwhv->SetBackgroundColor(is_opaque ? color : SK_ColorTRANSPARENT);
static_cast<content::RenderWidgetHostViewBase*>(rwhv)
->SetContentBackgroundColor(color);
}