Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support isHighContrastColorScheme() on macOS #19331

Merged
merged 2 commits into from
Jul 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/api/system-preferences.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
4 changes: 1 addition & 3 deletions shell/browser/api/atom_api_system_preferences.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<v8::Value> SystemPreferences::GetAnimationSettings(
v8::Isolate* isolate) {
Expand Down
21 changes: 0 additions & 21 deletions shell/browser/api/atom_api_system_preferences_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down