feat: add transparency checking to nativeTheme (#43137)

feat: add transparency checking to nativeTheme
This commit is contained in:
Shelley Vohr 2024-08-01 12:14:07 +02:00 committed by GitHub
parent 8e21aad444
commit 832090d01c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 18 additions and 1 deletions

View file

@ -72,3 +72,7 @@ or is being instructed to use an inverted color scheme.
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.
### `nativeTheme.prefersReducedTransparency` _Readonly_
A `boolean` that indicates the whether the user has chosen via system accessibility settings to reduce transparency at the OS level.

View file

@ -68,6 +68,10 @@ bool NativeTheme::InForcedColorsMode() {
return ui_theme_->InForcedColorsMode();
}
bool NativeTheme::GetPrefersReducedTransparency() {
return ui_theme_->GetPrefersReducedTransparency();
}
#if BUILDFLAG(IS_MAC)
const CFStringRef WhiteOnBlack = CFSTR("whiteOnBlack");
const CFStringRef UniversalAccessDomain = CFSTR("com.apple.universalaccess");
@ -108,7 +112,9 @@ gin::ObjectTemplateBuilder NativeTheme::GetObjectTemplateBuilder(
&NativeTheme::ShouldUseHighContrastColors)
.SetProperty("shouldUseInvertedColorScheme",
&NativeTheme::ShouldUseInvertedColorScheme)
.SetProperty("inForcedColorsMode", &NativeTheme::InForcedColorsMode);
.SetProperty("inForcedColorsMode", &NativeTheme::InForcedColorsMode)
.SetProperty("prefersReducedTransparency",
&NativeTheme::GetPrefersReducedTransparency);
}
const char* NativeTheme::GetTypeName() {

View file

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

View file

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