fix: don't unmaximize on macOS if user set max bounds (#33480)
This commit is contained in:
parent
afe0116d59
commit
8c8642634d
3 changed files with 31 additions and 1 deletions
|
@ -267,6 +267,8 @@ class NativeWindowMac : public NativeWindow,
|
||||||
// Maximizable window state; necessary for persistence through redraws.
|
// Maximizable window state; necessary for persistence through redraws.
|
||||||
bool maximizable_ = true;
|
bool maximizable_ = true;
|
||||||
|
|
||||||
|
bool user_set_bounds_maximized_ = false;
|
||||||
|
|
||||||
// Simple (pre-Lion) Fullscreen Settings
|
// Simple (pre-Lion) Fullscreen Settings
|
||||||
bool always_simple_fullscreen_ = false;
|
bool always_simple_fullscreen_ = false;
|
||||||
bool is_simple_fullscreen_ = false;
|
bool is_simple_fullscreen_ = false;
|
||||||
|
|
|
@ -622,7 +622,18 @@ void NativeWindowMac::Maximize() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void NativeWindowMac::Unmaximize() {
|
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;
|
return;
|
||||||
|
|
||||||
[window_ zoom:nil];
|
[window_ zoom:nil];
|
||||||
|
@ -724,6 +735,7 @@ void NativeWindowMac::SetBounds(const gfx::Rect& bounds, bool animate) {
|
||||||
cocoa_bounds.origin.y = NSHeight([screen frame]) - size.height() - bounds.y();
|
cocoa_bounds.origin.y = NSHeight([screen frame]) - size.height() - bounds.y();
|
||||||
|
|
||||||
[window_ setFrame:cocoa_bounds display:YES animate:animate];
|
[window_ setFrame:cocoa_bounds display:YES animate:animate];
|
||||||
|
user_set_bounds_maximized_ = IsMaximized() ? true : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
gfx::Rect NativeWindowMac::GetBounds() {
|
gfx::Rect NativeWindowMac::GetBounds() {
|
||||||
|
|
|
@ -3634,6 +3634,22 @@ describe('BrowserWindow module', () => {
|
||||||
expectBoundsEqual(w.getSize(), initialSize);
|
expectBoundsEqual(w.getSize(), initialSize);
|
||||||
expectBoundsEqual(w.getPosition(), initialPosition);
|
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)', () => {
|
describe('setFullScreen(false)', () => {
|
||||||
|
|
Loading…
Reference in a new issue