Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions shell/browser/native_window_mac.h
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,8 @@ class NativeWindowMac : public NativeWindow,
// Maximizable window state; necessary for persistence through redraws.
bool maximizable_ = true;

bool user_set_bounds_maximized_ = false;

// Simple (pre-Lion) Fullscreen Settings
bool always_simple_fullscreen_ = false;
bool is_simple_fullscreen_ = false;
Expand Down
14 changes: 13 additions & 1 deletion shell/browser/native_window_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,18 @@ void ViewDidMoveToSuperview(NSView* self, SEL _cmd) {
}

void NativeWindowMac::Unmaximize() {
if (!IsMaximized())
// Bail if the last user set bounds were the same size as the window
// screen (e.g. the user set the window to maximized via setBounds)
//
// Per docs during zoom:
// > If there’s no saved user state because there has been no previous
// > zoom,the size and location of the window don’t change.
//
// However, in classic Apple fashion, this is not the case in practice,
// and the frame inexplicably becomes very tiny. We should prevent
// zoom from being called if the window is being unmaximized and its
// unmaximized window bounds are themselves functionally maximized.
if (!IsMaximized() || user_set_bounds_maximized_)
return;

[window_ zoom:nil];
Expand Down Expand Up @@ -714,6 +725,7 @@ void ViewDidMoveToSuperview(NSView* self, SEL _cmd) {
cocoa_bounds.origin.y = NSHeight([screen frame]) - size.height() - bounds.y();

[window_ setFrame:cocoa_bounds display:YES animate:animate];
user_set_bounds_maximized_ = IsMaximized() ? true : false;
}

gfx::Rect NativeWindowMac::GetBounds() {
Expand Down
16 changes: 16 additions & 0 deletions spec-main/api-browser-window-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3606,6 +3606,22 @@ describe('BrowserWindow module', () => {
expectBoundsEqual(w.getSize(), initialSize);
expectBoundsEqual(w.getPosition(), initialPosition);
});

ifit(process.platform === 'darwin')('should not change size or position of a window which is functionally maximized', async () => {
const { workArea } = screen.getPrimaryDisplay();

const bounds = {
x: workArea.x,
y: workArea.y,
width: workArea.width,
height: workArea.height
};

const w = new BrowserWindow(bounds);
w.unmaximize();
await delay(1000);
expectBoundsEqual(w.getBounds(), bounds);
});
});

describe('setFullScreen(false)', () => {
Expand Down