From dc30b8637748e431583c65fd89f1793f031d0beb Mon Sep 17 00:00:00 2001 From: Micha Hanselmann Date: Fri, 19 Jul 2019 16:04:42 -0700 Subject: [PATCH] feat: support `isHighContrastColorScheme()` on macOS (#19331) * change docs * use NativeTheme to check high contrast scheme --- docs/api/system-preferences.md | 2 +- .../api/atom_api_system_preferences.cc | 4 +--- .../api/atom_api_system_preferences_win.cc | 21 ------------------- 3 files changed, 2 insertions(+), 25 deletions(-) diff --git a/docs/api/system-preferences.md b/docs/api/system-preferences.md index e4753eff35d1..f6dc2af28ffd 100644 --- a/docs/api/system-preferences.md +++ b/docs/api/system-preferences.md @@ -344,7 +344,7 @@ Returns one of several standard system colors that automatically adapt to vibran Returns `Boolean` - `true` if an inverted color scheme (a high contrast color scheme with light text and dark backgrounds) is active, `false` otherwise. -### `systemPreferences.isHighContrastColorScheme()` _Windows_ +### `systemPreferences.isHighContrastColorScheme()` _macOS_ _Windows_ Returns `Boolean` - `true` if a high contrast theme is active, `false` otherwise. diff --git a/shell/browser/api/atom_api_system_preferences.cc b/shell/browser/api/atom_api_system_preferences.cc index 0f51e6036295..b5d32871e33f 100644 --- a/shell/browser/api/atom_api_system_preferences.cc +++ b/shell/browser/api/atom_api_system_preferences.cc @@ -39,11 +39,9 @@ bool SystemPreferences::IsInvertedColorScheme() { return color_utils::IsInvertedColorScheme(); } -#if !defined(OS_WIN) bool SystemPreferences::IsHighContrastColorScheme() { - return false; + return ui::NativeTheme::GetInstanceForNativeUi()->UsesHighContrastColors(); } -#endif // !defined(OS_WIN) v8::Local SystemPreferences::GetAnimationSettings( v8::Isolate* isolate) { diff --git a/shell/browser/api/atom_api_system_preferences_win.cc b/shell/browser/api/atom_api_system_preferences_win.cc index d83de630bff9..2f0faea03628 100644 --- a/shell/browser/api/atom_api_system_preferences_win.cc +++ b/shell/browser/api/atom_api_system_preferences_win.cc @@ -20,18 +20,6 @@ namespace { const wchar_t kSystemPreferencesWindowClass[] = L"Electron_SystemPreferencesHostWindow"; -bool g_is_high_contract_color_scheme = false; -bool g_is_high_contract_color_scheme_initialized = false; - -void UpdateHighContrastColorScheme() { - HIGHCONTRAST high_contrast = {0}; - high_contrast.cbSize = sizeof(HIGHCONTRAST); - g_is_high_contract_color_scheme = - SystemParametersInfo(SPI_GETHIGHCONTRAST, 0, &high_contrast, 0) && - ((high_contrast.dwFlags & HCF_HIGHCONTRASTON) != 0); - g_is_high_contract_color_scheme_initialized = true; -} - } // namespace namespace api { @@ -40,12 +28,6 @@ bool SystemPreferences::IsAeroGlassEnabled() { return ui::win::IsAeroGlassEnabled(); } -bool SystemPreferences::IsHighContrastColorScheme() { - if (!g_is_high_contract_color_scheme_initialized) - UpdateHighContrastColorScheme(); - return g_is_high_contract_color_scheme; -} - std::string hexColorDWORDToRGBA(DWORD color) { DWORD rgba = color << 8 | color >> 24; std::ostringstream stream; @@ -188,9 +170,6 @@ LRESULT CALLBACK SystemPreferences::WndProc(HWND hwnd, Emit("accent-color-changed", hexColorDWORDToRGBA(new_color)); current_color_ = new_color_string; } - } else if (message == WM_SYSCOLORCHANGE || - (message == WM_SETTINGCHANGE && wparam == SPI_SETHIGHCONTRAST)) { - UpdateHighContrastColorScheme(); } return ::DefWindowProc(hwnd, message, wparam, lparam); }