Skip to content

Commit 33e66b5

Browse files
authored
fix: ensure windows respect fullscreenability with different resizability values (electron#39620)
* fix: ensure child windows respect fullscreenability/resizability when parent is fullscreen * test: add an extra resize test
1 parent 2affecd commit 33e66b5

File tree

2 files changed

+46
-14
lines changed

2 files changed

+46
-14
lines changed

shell/browser/native_window_mac.mm

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -830,23 +830,19 @@ void ReorderChildWindowAbove(NSWindow* child_window, NSWindow* other_window) {
830830
ScopedDisableResize disable_resize;
831831
SetStyleMask(resizable, NSWindowStyleMaskResizable);
832832

833+
bool was_fullscreenable = IsFullScreenable();
834+
833835
// Right now, resizable and fullscreenable are decoupled in
834836
// documentation and on Windows/Linux. Chromium disables
835-
// fullscreenability if resizability is false on macOS as well
836-
// as disabling the maximize traffic light unless the window
837-
// is both resizable and maximizable. To work around this, we want
838-
// to match behavior on other platforms by disabiliting the maximize
839-
// button but keeping fullscreenability enabled.
840-
// TODO(codebytere): refactor this once we have a better solution.
837+
// fullscreen collection behavior as well as the maximize traffic
838+
// light in SetCanResize if resizability is false on macOS unless
839+
// the window is both resizable and maximizable. We want consistent
840+
// cross-platform behavior, so if resizability is disabled we disable
841+
// the maximize button and ensure fullscreenability matches user setting.
841842
SetCanResize(resizable);
842-
if (!resizable) {
843-
SetFullScreenable(true);
844-
[[window_ standardWindowButton:NSWindowZoomButton] setEnabled:false];
845-
} else {
846-
SetFullScreenable(true);
847-
[[window_ standardWindowButton:NSWindowZoomButton]
848-
setEnabled:IsFullScreenable()];
849-
}
843+
SetFullScreenable(was_fullscreenable);
844+
[[window_ standardWindowButton:NSWindowZoomButton]
845+
setEnabled:resizable ? was_fullscreenable : false];
850846
}
851847

852848
bool NativeWindowMac::IsResizable() {

spec/api-browser-window-spec.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5416,6 +5416,42 @@ describe('BrowserWindow module', () => {
54165416
expect(w.isFullScreenable()).to.be.true('isFullScreenable');
54175417
});
54185418
});
5419+
5420+
it('does not open non-fullscreenable child windows in fullscreen if parent is fullscreen', async () => {
5421+
const w = new BrowserWindow();
5422+
5423+
const enterFS = once(w, 'enter-full-screen');
5424+
w.setFullScreen(true);
5425+
await enterFS;
5426+
5427+
const child = new BrowserWindow({ parent: w, resizable: false, fullscreenable: false });
5428+
const shown = once(child, 'show');
5429+
await shown;
5430+
5431+
expect(child.resizable).to.be.false('resizable');
5432+
expect(child.fullScreen).to.be.false('fullscreen');
5433+
expect(child.fullScreenable).to.be.false('fullscreenable');
5434+
});
5435+
5436+
it('is set correctly with different resizable values', async () => {
5437+
const w1 = new BrowserWindow({
5438+
resizable: false,
5439+
fullscreenable: false
5440+
});
5441+
5442+
const w2 = new BrowserWindow({
5443+
resizable: true,
5444+
fullscreenable: false
5445+
});
5446+
5447+
const w3 = new BrowserWindow({
5448+
fullscreenable: false
5449+
});
5450+
5451+
expect(w1.isFullScreenable()).to.be.false('isFullScreenable');
5452+
expect(w2.isFullScreenable()).to.be.false('isFullScreenable');
5453+
expect(w3.isFullScreenable()).to.be.false('isFullScreenable');
5454+
});
54195455
});
54205456

54215457
ifdescribe(process.platform === 'darwin')('isHiddenInMissionControl state', () => {

0 commit comments

Comments
 (0)