fix: abnormal behavior of windows background material (#47957)

This commit is contained in:
Shelley Vohr 2025-08-05 16:34:17 +02:00 committed by GitHub
commit e6ac03d0ee
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 195 additions and 107 deletions

View file

@ -850,8 +850,8 @@ void BaseWindow::SetVibrancy(v8::Isolate* isolate,
window_->SetVibrancy(type, animation_duration_ms);
}
void BaseWindow::SetBackgroundMaterial(const std::string& material_type) {
window_->SetBackgroundMaterial(material_type);
void BaseWindow::SetBackgroundMaterial(const std::string& material) {
window_->SetBackgroundMaterial(material);
}
#if BUILDFLAG(IS_MAC)

View file

@ -196,7 +196,7 @@ class BaseWindow : public gin_helper::TrackableObject<BaseWindow>,
virtual void SetVibrancy(v8::Isolate* isolate,
v8::Local<v8::Value> value,
gin_helper::Arguments* args);
void SetBackgroundMaterial(const std::string& vibrancy);
virtual void SetBackgroundMaterial(const std::string& material);
#if BUILDFLAG(IS_MAC)
std::string GetAlwaysOnTopLevel() const;

View file

@ -4,6 +4,7 @@
#include "shell/browser/api/electron_api_browser_window.h"
#include "base/containers/fixed_flat_set.h"
#include "content/browser/renderer_host/render_widget_host_owner_delegate.h" // nogncheck
#include "content/browser/web_contents/web_contents_impl.h" // nogncheck
#include "content/public/browser/render_process_host.h"
@ -247,6 +248,18 @@ void BrowserWindow::SetBackgroundColor(const std::string& color_name) {
}
}
void BrowserWindow::SetBackgroundMaterial(const std::string& material) {
BaseWindow::SetBackgroundMaterial(material);
static constexpr auto materialTypes =
base::MakeFixedFlatSet<std::string_view>({"tabbed", "mica", "acrylic"});
if (materialTypes.contains(material)) {
SetBackgroundColor(ToRGBAHex(SK_ColorTRANSPARENT));
} else if (material == "none") {
SetBackgroundColor(ToRGBAHex(SK_ColorWHITE));
}
}
void BrowserWindow::FocusOnWebView() {
web_contents()->GetRenderViewHost()->GetWidget()->Focus();
}

View file

@ -64,6 +64,7 @@ class BrowserWindow : public BaseWindow,
void Focus() override;
void Blur() override;
void SetBackgroundColor(const std::string& color_name) override;
void SetBackgroundMaterial(const std::string& material) override;
void OnWindowShow() override;
void OnWindowHide() override;