Skip to content

Commit

Permalink
fix: ensure child windows respect fullscreenability/resizability when…
Browse files Browse the repository at this point in the history
… parent is fullscreen

Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
  • Loading branch information
trop[bot] and codebytere committed Aug 25, 2023
1 parent c406384 commit 1adf953
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
24 changes: 10 additions & 14 deletions shell/browser/native_window_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -834,23 +834,19 @@ void ReorderChildWindowAbove(NSWindow* child_window, NSWindow* other_window) {
ScopedDisableResize disable_resize;
SetStyleMask(resizable, NSWindowStyleMaskResizable);

bool was_fullscreenable = IsFullScreenable();

// Right now, resizable and fullscreenable are decoupled in
// documentation and on Windows/Linux. Chromium disables
// fullscreenability if resizability is false on macOS as well
// as disabling the maximize traffic light unless the window
// is both resizable and maximizable. To work around this, we want
// to match behavior on other platforms by disabiliting the maximize
// button but keeping fullscreenability enabled.
// TODO(codebytere): refactor this once we have a better solution.
// fullscreen collection behavior as well as the maximize traffic
// light in SetCanResize if resizability is false on macOS unless
// the window is both resizable and maximizable. We want consistent
// cross-platform behavior, so if resizability is disabled we disable
// the maximize button and ensure fullscreenability matches user setting.
SetCanResize(resizable);
if (!resizable) {
SetFullScreenable(true);
[[window_ standardWindowButton:NSWindowZoomButton] setEnabled:false];
} else {
SetFullScreenable(true);
[[window_ standardWindowButton:NSWindowZoomButton]
setEnabled:IsFullScreenable()];
}
SetFullScreenable(was_fullscreenable);
[[window_ standardWindowButton:NSWindowZoomButton]
setEnabled:resizable ? was_fullscreenable : false];
}

bool NativeWindowMac::IsResizable() {
Expand Down
16 changes: 16 additions & 0 deletions spec/api-browser-window-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5456,6 +5456,22 @@ describe('BrowserWindow module', () => {
expect(w.isFullScreenable()).to.be.true('isFullScreenable');
});
});

it('does not open non-fullscreenable child windows in fullscreen if parent is fullscreen', async () => {
const w = new BrowserWindow();

const enterFS = once(w, 'enter-full-screen');
w.setFullScreen(true);
await enterFS;

const child = new BrowserWindow({ parent: w, resizable: false, fullscreenable: false });
const shown = once(child, 'show');
await shown;

expect(child.resizable).to.be.false('resizable');
expect(child.fullScreen).to.be.false('fullscreen');
expect(child.fullScreenable).to.be.false('fullscreenable');
});
});

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

0 comments on commit 1adf953

Please sign in to comment.