summaryrefslogtreecommitdiff
path: root/chromium/ui/native_theme/native_theme_win.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/ui/native_theme/native_theme_win.cc')
-rw-r--r--chromium/ui/native_theme/native_theme_win.cc47
1 files changed, 43 insertions, 4 deletions
diff --git a/chromium/ui/native_theme/native_theme_win.cc b/chromium/ui/native_theme/native_theme_win.cc
index c0344b4337d..932abb6b7c4 100644
--- a/chromium/ui/native_theme/native_theme_win.cc
+++ b/chromium/ui/native_theme/native_theme_win.cc
@@ -10,9 +10,11 @@
#include <vsstyle.h>
#include <vssym32.h>
+#include "base/bind.h"
#include "base/command_line.h"
+#include "base/feature_list.h"
#include "base/logging.h"
-#include "base/macros.h"
+#include "base/stl_util.h"
#include "base/win/scoped_gdi_object.h"
#include "base/win/scoped_hdc.h"
#include "base/win/scoped_select_object.h"
@@ -28,6 +30,7 @@
#include "third_party/skia/include/core/SkRefCnt.h"
#include "third_party/skia/include/core/SkShader.h"
#include "third_party/skia/include/core/SkSurface.h"
+#include "ui/base/ui_base_features.h"
#include "ui/base/ui_base_switches.h"
#include "ui/display/win/screen_win.h"
#include "ui/gfx/color_palette.h"
@@ -253,6 +256,19 @@ NativeThemeWin::NativeThemeWin()
close_theme_ = reinterpret_cast<CloseThemeDataPtr>(
GetProcAddress(theme_dll_, "CloseThemeData"));
}
+ if (base::FeatureList::IsEnabled(features::kDarkMode)) {
+ // Dark Mode currently targets UWP apps, which means Win32 apps need to use
+ // alternate, less reliable means of detecting the state. The following
+ // can break in future Windows versions.
+ bool key_open_succeeded =
+ hkcu_themes_regkey_.Open(
+ HKEY_CURRENT_USER,
+ L"Software\\Microsoft\\Windows\\CurrentVersion\\"
+ L"Themes\\Personalize",
+ KEY_READ | KEY_NOTIFY) == ERROR_SUCCESS;
+ if (key_open_succeeded)
+ RegisterThemeRegkeyObserver();
+ }
memset(theme_handles_, 0, sizeof(theme_handles_));
// Initialize the cached system colors.
@@ -516,12 +532,12 @@ SkColor NativeThemeWin::GetSystemColor(ColorId color_id) const {
return system_colors_[COLOR_WINDOW];
case kColorId_ResultsTableHoveredBackground:
return color_utils::AlphaBlend(system_colors_[COLOR_HIGHLIGHT],
- system_colors_[COLOR_WINDOW], 0x40);
+ system_colors_[COLOR_WINDOW], 0.25f);
case kColorId_ResultsTableNormalText:
return system_colors_[COLOR_WINDOWTEXT];
case kColorId_ResultsTableDimmedText:
return color_utils::AlphaBlend(system_colors_[COLOR_WINDOWTEXT],
- system_colors_[COLOR_WINDOW], 0x80);
+ system_colors_[COLOR_WINDOW], 0.5f);
default:
break;
}
@@ -562,6 +578,17 @@ bool NativeThemeWin::UsesHighContrastColors() const {
return force_enabled || IsUsingHighContrastThemeInternal();
}
+bool NativeThemeWin::SystemDarkModeEnabled() const {
+ bool fDarkModeEnabled = false;
+ if (hkcu_themes_regkey_.Valid()) {
+ DWORD apps_use_light_theme = 1;
+ hkcu_themes_regkey_.ReadValueDW(L"AppsUseLightTheme",
+ &apps_use_light_theme);
+ fDarkModeEnabled = (apps_use_light_theme == 0);
+ }
+ return fDarkModeEnabled || NativeTheme::SystemDarkModeEnabled();
+}
+
void NativeThemeWin::PaintIndirect(cc::PaintCanvas* destination_canvas,
Part part,
State state,
@@ -980,7 +1007,7 @@ HRESULT NativeThemeWin::PaintScrollbarArrow(
if (handle && draw_theme_) {
int index = part - kScrollbarDownArrow;
DCHECK_GE(index, 0);
- DCHECK_LT(static_cast<size_t>(index), arraysize(state_id_matrix));
+ DCHECK_LT(static_cast<size_t>(index), base::size(state_id_matrix));
int state_id = state_id_matrix[index][state];
// Hovering means that the cursor is over the scroolbar, but not over the
@@ -1890,4 +1917,16 @@ HANDLE NativeThemeWin::GetThemeHandle(ThemeName theme_name) const {
return handle;
}
+void NativeThemeWin::RegisterThemeRegkeyObserver() {
+ DCHECK(hkcu_themes_regkey_.Valid());
+ hkcu_themes_regkey_.StartWatching(base::BindOnce(
+ [](NativeThemeWin* native_theme) {
+ native_theme->NotifyObservers();
+ // RegKey::StartWatching only provides one notification. Reregistration
+ // is required to get future notifications.
+ native_theme->RegisterThemeRegkeyObserver();
+ },
+ base::Unretained(this)));
+}
+
} // namespace ui