2023-08-29 20:20:37 +02:00
|
|
|
diff --git base/win/dark_mode_support.cc base/win/dark_mode_support.cc
|
2024-03-19 22:11:42 +01:00
|
|
|
index 73d6ad5e9bb36..6c450e79c0f94 100644
|
2023-08-29 20:20:37 +02:00
|
|
|
--- base/win/dark_mode_support.cc
|
|
|
|
+++ base/win/dark_mode_support.cc
|
2023-12-06 21:16:15 +01:00
|
|
|
@@ -7,6 +7,7 @@
|
2023-08-29 20:20:37 +02:00
|
|
|
#include <windows.h>
|
|
|
|
|
2023-12-06 21:16:15 +01:00
|
|
|
#include "base/check.h"
|
2023-08-29 20:20:37 +02:00
|
|
|
+#include "base/command_line.h"
|
|
|
|
#include "base/native_library.h"
|
2024-03-19 22:11:42 +01:00
|
|
|
#include "base/win/win_util.h"
|
2023-08-29 20:20:37 +02:00
|
|
|
#include "base/win/windows_version.h"
|
2024-03-19 22:11:42 +01:00
|
|
|
@@ -89,11 +90,20 @@ const DarkModeSupport& GetDarkModeSupport() {
|
2023-08-29 20:20:37 +02:00
|
|
|
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) &&
|
2024-03-29 17:48:33 +01:00
|
|
|
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
|
2024-07-29 19:09:20 +02:00
|
|
|
index a4fc1857349e4..65f620ac8e289 100644
|
2024-03-29 17:48:33 +01:00
|
|
|
--- chrome/browser/ui/views/chrome_browser_main_extra_parts_views_linux.cc
|
|
|
|
+++ chrome/browser/ui/views/chrome_browser_main_extra_parts_views_linux.cc
|
2024-07-29 19:09:20 +02:00
|
|
|
@@ -56,7 +56,10 @@ void ChromeBrowserMainExtraPartsViewsLinux::ToolkitInitialized() {
|
|
|
|
ui::CursorFactory::GetInstance()->ObserveThemeChanges();
|
2024-03-29 17:48:33 +01:00
|
|
|
}
|
|
|
|
#if defined(USE_DBUS)
|
|
|
|
- dark_mode_manager_ = std::make_unique<ui::DarkModeManagerLinux>();
|
|
|
|
+ if (!ui::NativeTheme::IsForcedDarkMode() &&
|
|
|
|
+ !ui::NativeTheme::IsForcedLightMode()) {
|
|
|
|
+ dark_mode_manager_ = std::make_unique<ui::DarkModeManagerLinux>();
|
|
|
|
+ }
|
|
|
|
#endif
|
2023-08-29 20:20:37 +02:00
|
|
|
}
|
2023-09-15 21:51:43 +02:00
|
|
|
|
2024-03-29 17:48:33 +01:00
|
|
|
diff --git ui/gtk/native_theme_gtk.cc ui/gtk/native_theme_gtk.cc
|
2024-11-14 23:07:03 +01:00
|
|
|
index 184939bdb8b3d..bb13d7c74e20b 100644
|
2024-03-29 17:48:33 +01:00
|
|
|
--- ui/gtk/native_theme_gtk.cc
|
|
|
|
+++ ui/gtk/native_theme_gtk.cc
|
2024-07-29 19:09:20 +02:00
|
|
|
@@ -156,9 +156,11 @@ void NativeThemeGtk::OnThemeChanged(GtkSettings* settings,
|
2024-03-29 17:48:33 +01:00
|
|
|
// 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
|
2024-11-14 23:07:03 +01:00
|
|
|
index 728069cfdba9a..3561f49631e5c 100644
|
2024-03-29 17:48:33 +01:00
|
|
|
--- ui/native_theme/native_theme.cc
|
|
|
|
+++ ui/native_theme/native_theme.cc
|
2024-11-14 23:07:03 +01:00
|
|
|
@@ -146,6 +146,7 @@ void NativeTheme::NotifyOnNativeThemeUpdated() {
|
2024-03-29 17:48:33 +01:00
|
|
|
color_provider_manager.ResetColorProviderCache();
|
2024-10-24 17:05:31 +02:00
|
|
|
native_theme_observers_.Notify(&NativeThemeObserver::OnNativeThemeUpdated,
|
|
|
|
this);
|
2024-03-29 17:48:33 +01:00
|
|
|
+ color_provider_manager.AfterNativeThemeUpdated();
|
|
|
|
|
|
|
|
RecordNumColorProvidersInitializedDuringOnNativeThemeUpdated(
|
|
|
|
color_provider_manager.num_providers_initialized() -
|
2024-11-14 23:07:03 +01:00
|
|
|
@@ -288,6 +289,13 @@ bool NativeTheme::IsForcedDarkMode() {
|
2024-03-29 17:48:33 +01:00
|
|
|
return kIsForcedDarkMode;
|
|
|
|
}
|
|
|
|
|
|
|
|
+bool NativeTheme::IsForcedLightMode() {
|
2023-08-29 20:20:37 +02:00
|
|
|
+ static bool kIsForcedLightMode =
|
|
|
|
+ base::CommandLine::ForCurrentProcess()->HasSwitch(
|
|
|
|
+ "force-light-mode");
|
|
|
|
+ return kIsForcedLightMode;
|
|
|
|
+}
|
|
|
|
+
|
2024-03-29 17:48:33 +01:00
|
|
|
bool NativeTheme::IsForcedHighContrast() {
|
|
|
|
static bool kIsForcedHighContrast =
|
|
|
|
base::CommandLine::ForCurrentProcess()->HasSwitch(
|
|
|
|
diff --git ui/native_theme/native_theme.h ui/native_theme/native_theme.h
|
2024-11-14 23:07:03 +01:00
|
|
|
index b2a7455c7e005..77170b90189c8 100644
|
2024-03-29 17:48:33 +01:00
|
|
|
--- ui/native_theme/native_theme.h
|
|
|
|
+++ ui/native_theme/native_theme.h
|
2024-11-14 23:07:03 +01:00
|
|
|
@@ -610,6 +610,9 @@ class NATIVE_THEME_EXPORT NativeTheme {
|
|
|
|
// Calculates and returns the use overlay scrollbar setting.
|
|
|
|
static bool CalculateUseOverlayScrollbar();
|
2023-08-29 20:20:37 +02:00
|
|
|
|
2024-03-29 17:48:33 +01:00
|
|
|
+ // 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
|
2024-11-14 23:07:03 +01:00
|
|
|
index dc1224ca2fa27..b2a0ce01b4611 100644
|
2024-03-29 17:48:33 +01:00
|
|
|
--- ui/native_theme/native_theme_mac.mm
|
|
|
|
+++ ui/native_theme/native_theme_mac.mm
|
2024-11-14 23:07:03 +01:00
|
|
|
@@ -585,11 +585,15 @@ void NativeThemeMac::PaintSelectedMenuItem(
|
2023-08-29 20:20:37 +02:00
|
|
|
|
|
|
|
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
|
2024-11-14 23:07:03 +01:00
|
|
|
index 1b098cbb291fe..fc8f22b7db5a3 100644
|
2023-08-29 20:20:37 +02:00
|
|
|
--- ui/native_theme/native_theme_win.cc
|
|
|
|
+++ ui/native_theme/native_theme_win.cc
|
2024-11-14 23:07:03 +01:00
|
|
|
@@ -676,14 +676,17 @@ bool NativeThemeWin::ShouldUseDarkColors() const {
|
2023-08-29 21:23:06 +02:00
|
|
|
// 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();
|
|
|
|
}
|
2023-08-29 20:20:37 +02:00
|
|
|
|
|
|
|
NativeTheme::PreferredColorScheme
|
|
|
|
NativeThemeWin::CalculatePreferredColorScheme() const {
|
|
|
|
- if (!InForcedColorsMode())
|
|
|
|
+ if (!InForcedColorsMode() || !supports_windows_dark_mode_)
|
|
|
|
return NativeTheme::CalculatePreferredColorScheme();
|
|
|
|
|
|
|
|
// According to the spec, the preferred color scheme for web content is 'dark'
|
2024-11-14 23:07:03 +01:00
|
|
|
@@ -1653,8 +1656,9 @@ void NativeThemeWin::RegisterColorFilteringRegkeyObserver() {
|
2023-08-29 21:23:06 +02:00
|
|
|
}
|
2023-08-29 20:20:37 +02:00
|
|
|
|
|
|
|
void NativeThemeWin::UpdateDarkModeStatus() {
|
2023-08-29 21:23:06 +02:00
|
|
|
- bool dark_mode_enabled = false;
|
2023-08-29 20:20:37 +02:00
|
|
|
- if (hkcu_themes_regkey_.Valid()) {
|
2023-08-29 21:23:06 +02:00
|
|
|
+ bool dark_mode_enabled = ShouldUseDarkColors();
|
|
|
|
+ if (supports_windows_dark_mode_ && !IsForcedDarkMode() &&
|
|
|
|
+ hkcu_themes_regkey_.Valid()) {
|
2023-08-29 20:20:37 +02:00
|
|
|
DWORD apps_use_light_theme = 1;
|
|
|
|
hkcu_themes_regkey_.ReadValueDW(L"AppsUseLightTheme",
|
|
|
|
&apps_use_light_theme);
|