diff --git a/shell/browser/native_window_views.h b/shell/browser/native_window_views.h index 7f6c44793ea7..ab75b7ad76d5 100644 --- a/shell/browser/native_window_views.h +++ b/shell/browser/native_window_views.h @@ -305,7 +305,7 @@ class NativeWindowViews : public NativeWindow, // Whether the window is currently being moved. bool is_moving_ = false; - std::variant accent_color_ = true; + std::variant accent_color_; std::optional pending_bounds_change_; diff --git a/shell/browser/native_window_views_win.cc b/shell/browser/native_window_views_win.cc index 219fdaca646a..159e77a9c0a1 100644 --- a/shell/browser/native_window_views_win.cc +++ b/shell/browser/native_window_views_win.cc @@ -572,28 +572,42 @@ void NativeWindowViews::UpdateWindowAccentColor() { if (base::win::GetVersion() < base::win::Version::WIN11) return; - if (!IsAccentColorOnTitleBarsEnabled()) - return; - COLORREF border_color; + bool should_apply_accent = false; + if (std::holds_alternative(accent_color_)) { - // Don't set accent color if the user has disabled it. - if (!std::get(accent_color_)) - return; - - std::optional accent_color = GetAccentColor(); - if (!accent_color.has_value()) - return; - - border_color = - RGB(GetRValue(accent_color.value()), GetGValue(accent_color.value()), - GetBValue(accent_color.value())); - } else { + bool force_accent = std::get(accent_color_); + if (!force_accent) { + should_apply_accent = false; + } else { + std::optional accent_color = GetAccentColor(); + if (accent_color.has_value()) { + border_color = RGB(GetRValue(accent_color.value()), + GetGValue(accent_color.value()), + GetBValue(accent_color.value())); + should_apply_accent = true; + } + } + } else if (std::holds_alternative(accent_color_)) { SkColor color = std::get(accent_color_); border_color = RGB(SkColorGetR(color), SkColorGetG(color), SkColorGetB(color)); + should_apply_accent = true; + } else if (std::holds_alternative(accent_color_)) { + if (IsAccentColorOnTitleBarsEnabled()) { + std::optional accent_color = GetAccentColor(); + if (accent_color.has_value()) { + border_color = RGB(GetRValue(accent_color.value()), + GetGValue(accent_color.value()), + GetBValue(accent_color.value())); + should_apply_accent = true; + } + } } + // Reset to default system colors when accent color should not be applied. + if (!should_apply_accent) + border_color = DWMWA_COLOR_DEFAULT; SetWindowBorderAndCaptionColor(GetAcceleratedWidget(), border_color); }