diff --git base/win/dark_mode_support.cc base/win/dark_mode_support.cc index daecebb507070..aed51c2e6b06e 100644 --- base/win/dark_mode_support.cc +++ base/win/dark_mode_support.cc @@ -7,6 +7,7 @@ #include #include "base/check.h" +#include "base/command_line.h" #include "base/native_library.h" #include "base/win/win_util.h" #include "base/win/windows_version.h" @@ -85,11 +86,20 @@ const DarkModeSupport& GetDarkModeSupport() { return dark_mode_support; } +bool IsForcedLightMode() { + static bool kIsForcedLightMode = + base::CommandLine::ForCurrentProcess()->HasSwitch( + "force-light-mode"); + return kIsForcedLightMode; +} + } // namespace namespace base::win { bool IsDarkModeAvailable() { + if (IsForcedLightMode()) + return false; auto& dark_mode_support = GetDarkModeSupport(); return (dark_mode_support.allow_dark_mode_for_app || dark_mode_support.set_preferred_app_mode) && diff --git chrome/browser/ui/views/chrome_browser_main_extra_parts_views_linux.cc chrome/browser/ui/views/chrome_browser_main_extra_parts_views_linux.cc index 963360a3247e1..18e6a1db9a73e 100644 --- chrome/browser/ui/views/chrome_browser_main_extra_parts_views_linux.cc +++ chrome/browser/ui/views/chrome_browser_main_extra_parts_views_linux.cc @@ -56,7 +56,10 @@ void ChromeBrowserMainExtraPartsViewsLinux::ToolkitInitialized() { ui::CursorFactory::GetInstance()->ObserveThemeChanges(); } #if BUILDFLAG(USE_DBUS) - dark_mode_manager_ = std::make_unique(); + if (!ui::NativeTheme::IsForcedDarkMode() && + !ui::NativeTheme::IsForcedLightMode()) { + dark_mode_manager_ = std::make_unique(); + } #endif } diff --git ui/gtk/native_theme_gtk.cc ui/gtk/native_theme_gtk.cc index a28c128deecd3..e8c8a9825b0fe 100644 --- ui/gtk/native_theme_gtk.cc +++ ui/gtk/native_theme_gtk.cc @@ -157,9 +157,11 @@ void NativeThemeGtk::OnThemeChanged(GtkSettings* settings, // have a light variant and aren't affected by the setting. Because of this, // experimentally check if the theme is dark by checking if the window // background color is dark. - const SkColor window_bg_color = GetBgColor(""); - set_use_dark_colors(IsForcedDarkMode() || - color_utils::IsDark(window_bg_color)); + if (!IsForcedLightMode()) { + const SkColor window_bg_color = GetBgColor(""); + set_use_dark_colors(IsForcedDarkMode() || + color_utils::IsDark(window_bg_color)); + } set_preferred_color_scheme(CalculatePreferredColorScheme()); // GTK doesn't have a native high contrast setting. Rather, it's implied by diff --git ui/native_theme/native_theme.cc ui/native_theme/native_theme.cc index 95876b4040844..2f4480cacade6 100644 --- ui/native_theme/native_theme.cc +++ ui/native_theme/native_theme.cc @@ -146,6 +146,7 @@ void NativeTheme::NotifyOnNativeThemeUpdated() { color_provider_manager.ResetColorProviderCache(); native_theme_observers_.Notify(&NativeThemeObserver::OnNativeThemeUpdated, this); + color_provider_manager.AfterNativeThemeUpdated(); RecordNumColorProvidersInitializedDuringOnNativeThemeUpdated( color_provider_manager.num_providers_initialized() - @@ -294,6 +295,13 @@ bool NativeTheme::IsForcedDarkMode() { return kIsForcedDarkMode; } +bool NativeTheme::IsForcedLightMode() { + static bool kIsForcedLightMode = + base::CommandLine::ForCurrentProcess()->HasSwitch( + "force-light-mode"); + return kIsForcedLightMode; +} + bool NativeTheme::IsForcedHighContrast() { static bool kIsForcedHighContrast = base::CommandLine::ForCurrentProcess()->HasSwitch( diff --git ui/native_theme/native_theme.h ui/native_theme/native_theme.h index 4e825d649919c..ff1af10d30758 100644 --- ui/native_theme/native_theme.h +++ ui/native_theme/native_theme.h @@ -636,6 +636,9 @@ class NATIVE_THEME_EXPORT NativeTheme { // Calculates and returns the use overlay scrollbar setting. static bool CalculateUseOverlayScrollbar(); + // Whether light mode is forced via command-line flag. + static bool IsForcedLightMode(); + protected: explicit NativeTheme( bool should_only_use_dark_colors, diff --git ui/native_theme/native_theme_mac.mm ui/native_theme/native_theme_mac.mm index 36d8e38eb0b07..0b96dd332363a 100644 --- ui/native_theme/native_theme_mac.mm +++ ui/native_theme/native_theme_mac.mm @@ -631,11 +631,15 @@ void NativeThemeMac::PaintSelectedMenuItem( void NativeThemeMac::InitializeDarkModeStateAndObserver() { __block auto theme = this; - set_use_dark_colors(IsDarkMode()); + if (!IsForcedLightMode()) { + set_use_dark_colors(IsForcedDarkMode() || IsDarkMode()); + } set_preferred_color_scheme(CalculatePreferredColorScheme()); appearance_observer_ = [[NativeThemeEffectiveAppearanceObserver alloc] initWithHandler:^{ - theme->set_use_dark_colors(IsDarkMode()); + if (!IsForcedLightMode()) { + theme->set_use_dark_colors(IsForcedDarkMode() || IsDarkMode()); + } theme->set_preferred_color_scheme(CalculatePreferredColorScheme()); theme->NotifyOnNativeThemeUpdated(); }]; diff --git ui/native_theme/native_theme_win.cc ui/native_theme/native_theme_win.cc index 2b2a12cd9d1ac..00c034b7f81f7 100644 --- ui/native_theme/native_theme_win.cc +++ ui/native_theme/native_theme_win.cc @@ -685,7 +685,10 @@ bool NativeThemeWin::ShouldUseDarkColors() const { // Windows high contrast modes are entirely different themes, // so let them take priority over dark mode. // ...unless --force-dark-mode was specified in which case caveat emptor. - if (InForcedColorsMode() && !IsForcedDarkMode()) { + if (supports_windows_dark_mode_ && IsForcedDarkMode()) { + return true; + } + if (InForcedColorsMode()) { return false; } return NativeTheme::ShouldUseDarkColors(); @@ -693,7 +696,7 @@ bool NativeThemeWin::ShouldUseDarkColors() const { NativeTheme::PreferredColorScheme NativeThemeWin::CalculatePreferredColorScheme() const { - if (!InForcedColorsMode()) { + if (!InForcedColorsMode() || !supports_windows_dark_mode_) { return NativeTheme::CalculatePreferredColorScheme(); } @@ -1679,9 +1682,10 @@ void NativeThemeWin::RegisterColorFilteringRegkeyObserver() { } void NativeThemeWin::UpdateDarkModeStatus() { - bool dark_mode_enabled = false; - bool system_dark_mode_enabled = false; - if (hkcu_themes_regkey_.Valid()) { + bool dark_mode_enabled = ShouldUseDarkColors(); + bool system_dark_mode_enabled = ShouldUseDarkColors(); + if (supports_windows_dark_mode_ && !IsForcedDarkMode() && + hkcu_themes_regkey_.Valid()) { DWORD apps_use_light_theme = 1; hkcu_themes_regkey_.ReadValueDW(L"AppsUseLightTheme", &apps_use_light_theme);