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: add nativeTheme.inForcedColorsMode #33360

Merged
merged 1 commit into from Mar 23, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/api/native-theme.md
Expand Up @@ -67,3 +67,8 @@ or is being instructed to show a high-contrast UI.

A `Boolean` for if the OS / Chromium currently has an inverted color scheme
or is being instructed to use an inverted color scheme.

### `nativeTheme.inForcedColorsMode` _Windows_ _Readonly_

A `boolean` indicating whether Chromium is in forced colors mode, controlled by system accessibility settings.
Currently, Windows high contrast is the only system setting that triggers forced colors mode.
7 changes: 6 additions & 1 deletion shell/browser/api/electron_api_native_theme.cc
Expand Up @@ -67,6 +67,10 @@ bool NativeTheme::ShouldUseHighContrastColors() {
return ui_theme_->UserHasContrastPreference();
}

bool NativeTheme::InForcedColorsMode() {
return ui_theme_->InForcedColorsMode();
}

#if defined(OS_MAC)
const CFStringRef WhiteOnBlack = CFSTR("whiteOnBlack");
const CFStringRef UniversalAccessDomain = CFSTR("com.apple.universalaccess");
Expand Down Expand Up @@ -106,7 +110,8 @@ gin::ObjectTemplateBuilder NativeTheme::GetObjectTemplateBuilder(
.SetProperty("shouldUseHighContrastColors",
&NativeTheme::ShouldUseHighContrastColors)
.SetProperty("shouldUseInvertedColorScheme",
&NativeTheme::ShouldUseInvertedColorScheme);
&NativeTheme::ShouldUseInvertedColorScheme)
.SetProperty("inForcedColorsMode", &NativeTheme::InForcedColorsMode);
}

const char* NativeTheme::GetTypeName() {
Expand Down
1 change: 1 addition & 0 deletions shell/browser/api/electron_api_native_theme.h
Expand Up @@ -42,6 +42,7 @@ class NativeTheme : public gin::Wrappable<NativeTheme>,
bool ShouldUseDarkColors();
bool ShouldUseHighContrastColors();
bool ShouldUseInvertedColorScheme();
bool InForcedColorsMode();

// ui::NativeThemeObserver:
void OnNativeThemeUpdated(ui::NativeTheme* theme) override;
Expand Down
6 changes: 6 additions & 0 deletions spec-main/api-native-theme-spec.ts
Expand Up @@ -109,4 +109,10 @@ describe('nativeTheme module', () => {
expect(nativeTheme.shouldUseHighContrastColors).to.be.a('boolean');
});
});

describe('nativeTheme.inForcedColorsMode', () => {
it('returns a boolean', () => {
expect(nativeTheme.inForcedColorsMode).to.be.a('boolean');
});
});
});