Compare commits

...

2 Commits

Author SHA1 Message Date
Robert Böhnke
5f325d3dd6 feat: add nativeTheme.shouldDifferentiateWithoutColor on macOS
Adds nativeTheme.shouldDifferentiateWithoutColor on macOS that maps to
NSWorkspace.accessibilityDisplayShouldDifferentiateWithoutColor. If true,
the user has indicated that they prefer UI that differentiates items with
something other than color alone. This is useful for users with color
vision deficiency.
2026-03-12 15:40:08 +01:00
Shelley Vohr
9d0a0a5459 fix: apply zoomFactor from setWindowOpenHandler to window.open() windows (#49886)
fix: apply zoomFactor from setWindowOpenHandler to window.open() windows
2026-02-23 09:02:48 +01:00
7 changed files with 60 additions and 1 deletions

View File

@@ -84,3 +84,7 @@ Currently, Windows high contrast is the only system setting that triggers forced
### `nativeTheme.prefersReducedTransparency` _Readonly_
A `boolean` that indicates whether the user has chosen via system accessibility settings to reduce transparency at the OS level.
### `nativeTheme.shouldDifferentiateWithoutColor` _macOS_ _Readonly_
A `boolean` that indicates whether the user prefers UI that differentiates items using something other than color alone (e.g. shapes or labels). This maps to [NSWorkspace.accessibilityDisplayShouldDifferentiateWithoutColor](https://developer.apple.com/documentation/appkit/nsworkspace/accessibilitydisplayshoulddifferentiatewithoutcolor).

View File

@@ -147,7 +147,12 @@ gin::ObjectTemplateBuilder NativeTheme::GetObjectTemplateBuilder(
&NativeTheme::ShouldUseInvertedColorScheme)
.SetProperty("inForcedColorsMode", &NativeTheme::InForcedColorsMode)
.SetProperty("prefersReducedTransparency",
&NativeTheme::GetPrefersReducedTransparency);
&NativeTheme::GetPrefersReducedTransparency)
#if BUILDFLAG(IS_MAC)
.SetProperty("shouldDifferentiateWithoutColor",
&NativeTheme::ShouldDifferentiateWithoutColor)
#endif
;
}
const char* NativeTheme::GetTypeName() {

View File

@@ -56,6 +56,9 @@ class NativeTheme final : public gin_helper::DeprecatedWrappable<NativeTheme>,
bool ShouldUseInvertedColorScheme();
bool InForcedColorsMode();
bool GetPrefersReducedTransparency();
#if BUILDFLAG(IS_MAC)
bool ShouldDifferentiateWithoutColor();
#endif
// ui::NativeThemeObserver:
void OnNativeThemeUpdated(ui::NativeTheme* theme) override;

View File

@@ -26,4 +26,9 @@ void NativeTheme::UpdateMacOSAppearanceForOverrideValue(
[[NSApplication sharedApplication] setAppearance:new_appearance];
}
bool NativeTheme::ShouldDifferentiateWithoutColor() {
return [[NSWorkspace sharedWorkspace]
accessibilityDisplayShouldDifferentiateWithoutColor];
}
} // namespace electron::api

View File

@@ -4746,6 +4746,19 @@ gin_helper::Handle<WebContents> WebContents::CreateFromWebPreferences(
existing_preferences->SetFromDictionary(web_preferences_dict);
web_contents->SetBackgroundColor(
existing_preferences->GetBackgroundColor());
double zoom_factor;
if (web_preferences.Get(options::kZoomFactor, &zoom_factor)) {
auto* zoom_controller = WebContentsZoomController::FromWebContents(
web_contents->web_contents());
if (zoom_controller) {
zoom_controller->SetDefaultZoomFactor(zoom_factor);
// Also set the current zoom level immediately, since the page
// has already navigated by the time we wrap the webContents.
zoom_controller->SetZoomLevel(
blink::ZoomFactorToZoomLevel(zoom_factor));
}
}
}
} else {
// Create one if not.

View File

@@ -3977,6 +3977,28 @@ describe('BrowserWindow module', () => {
expect(webPreferences!.contextIsolation).to.equal(false);
});
it('should apply zoomFactor from setWindowOpenHandler overrideBrowserWindowOptions', async () => {
const w = new BrowserWindow({
show: false,
webPreferences: {
sandbox: true
}
});
w.webContents.setWindowOpenHandler(() => ({
action: 'allow',
overrideBrowserWindowOptions: {
webPreferences: {
zoomFactor: 2.0
}
}
}));
w.loadFile(path.join(fixtures, 'api', 'new-window.html'));
const [childWindow] = await once(w.webContents, 'did-create-window') as [BrowserWindow, any];
await once(childWindow.webContents, 'did-finish-load');
expect(childWindow.webContents.getZoomFactor()).to.be.closeTo(2.0, 0.1);
});
it('should set ipc event sender correctly', async () => {
const w = new BrowserWindow({
show: false,

View File

@@ -6,6 +6,7 @@ import { once } from 'node:events';
import * as path from 'node:path';
import { setTimeout } from 'node:timers/promises';
import { ifdescribe } from './lib/spec-helpers';
import { closeAllWindows } from './lib/window-helpers';
describe('nativeTheme module', () => {
@@ -119,4 +120,10 @@ describe('nativeTheme module', () => {
expect(nativeTheme.prefersReducedTransparency).to.be.a('boolean');
});
});
ifdescribe(process.platform === 'darwin')('nativeTheme.shouldDifferentiateWithoutColor', () => {
it('returns a boolean', () => {
expect(nativeTheme.shouldDifferentiateWithoutColor).to.be.a('boolean');
});
});
});