feat: add nativeTheme.inForcedColorsMode (#32956)

This commit is contained in:
Milan Burda 2022-03-21 10:30:02 +01:00 committed by GitHub
parent 4cc2ed842e
commit 755feb4d81
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 1 deletions

View file

@ -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 A `boolean` for if the OS / Chromium currently has an inverted color scheme
or is being instructed to use 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.

View file

@ -67,6 +67,10 @@ bool NativeTheme::ShouldUseHighContrastColors() {
return ui_theme_->UserHasContrastPreference(); return ui_theme_->UserHasContrastPreference();
} }
bool NativeTheme::InForcedColorsMode() {
return ui_theme_->InForcedColorsMode();
}
#if BUILDFLAG(IS_MAC) #if BUILDFLAG(IS_MAC)
const CFStringRef WhiteOnBlack = CFSTR("whiteOnBlack"); const CFStringRef WhiteOnBlack = CFSTR("whiteOnBlack");
const CFStringRef UniversalAccessDomain = CFSTR("com.apple.universalaccess"); const CFStringRef UniversalAccessDomain = CFSTR("com.apple.universalaccess");
@ -106,7 +110,8 @@ gin::ObjectTemplateBuilder NativeTheme::GetObjectTemplateBuilder(
.SetProperty("shouldUseHighContrastColors", .SetProperty("shouldUseHighContrastColors",
&NativeTheme::ShouldUseHighContrastColors) &NativeTheme::ShouldUseHighContrastColors)
.SetProperty("shouldUseInvertedColorScheme", .SetProperty("shouldUseInvertedColorScheme",
&NativeTheme::ShouldUseInvertedColorScheme); &NativeTheme::ShouldUseInvertedColorScheme)
.SetProperty("inForcedColorsMode", &NativeTheme::InForcedColorsMode);
} }
const char* NativeTheme::GetTypeName() { const char* NativeTheme::GetTypeName() {

View file

@ -46,6 +46,7 @@ class NativeTheme : public gin::Wrappable<NativeTheme>,
bool ShouldUseDarkColors(); bool ShouldUseDarkColors();
bool ShouldUseHighContrastColors(); bool ShouldUseHighContrastColors();
bool ShouldUseInvertedColorScheme(); bool ShouldUseInvertedColorScheme();
bool InForcedColorsMode();
// ui::NativeThemeObserver: // ui::NativeThemeObserver:
void OnNativeThemeUpdated(ui::NativeTheme* theme) override; void OnNativeThemeUpdated(ui::NativeTheme* theme) override;

View file

@ -109,4 +109,10 @@ describe('nativeTheme module', () => {
expect(nativeTheme.shouldUseHighContrastColors).to.be.a('boolean'); expect(nativeTheme.shouldUseHighContrastColors).to.be.a('boolean');
}); });
}); });
describe('nativeTheme.inForcedColorsMode', () => {
it('returns a boolean', () => {
expect(nativeTheme.inForcedColorsMode).to.be.a('boolean');
});
});
}); });