From c754b5efdc300b448c4b1f2c71925da4c65a4b1b Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 15 Aug 2016 12:30:26 -0700 Subject: [PATCH 1/2] Add failing spec for state changes resizing frameless window --- spec/api-browser-window-spec.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/spec/api-browser-window-spec.js b/spec/api-browser-window-spec.js index 39299eeae1bc..ba8c979a9f8b 100644 --- a/spec/api-browser-window-spec.js +++ b/spec/api-browser-window-spec.js @@ -751,6 +751,36 @@ describe('browser-window module', function () { }) describe('window states', function () { + it('does not resize frameless windows when states change', function () { + w.destroy() + w = new BrowserWindow({ + frame: false, + width: 300, + height: 200, + show: false + }) + + w.setMinimizable(false) + w.setMinimizable(true) + assert.deepEqual(w.getSize(), [300, 200]) + + w.setResizable(false) + w.setResizable(true) + assert.deepEqual(w.getSize(), [300, 200]) + + w.setMaximizable(false) + w.setMaximizable(true) + assert.deepEqual(w.getSize(), [300, 200]) + + w.setFullScreenable(false) + w.setFullScreenable(true) + assert.deepEqual(w.getSize(), [300, 200]) + + w.setClosable(false) + w.setClosable(true) + assert.deepEqual(w.getSize(), [300, 200]) + }) + describe('resizable state', function () { it('can be changed with resizable option', function () { w.destroy() From 86e5bd35525ad3c4afdb9cb22832cfbdd49628a6 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 15 Aug 2016 13:14:19 -0700 Subject: [PATCH 2/2] Disable resize during any stylemask change --- atom/browser/native_window_mac.mm | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/atom/browser/native_window_mac.mm b/atom/browser/native_window_mac.mm index 8e8f988ee99c..f1145348e8eb 100644 --- a/atom/browser/native_window_mac.mm +++ b/atom/browser/native_window_mac.mm @@ -160,7 +160,7 @@ bool ScopedDisableResize::disable_resize_ = false; - (void)windowDidMove:(NSNotification*)notification { // TODO(zcbenz): Remove the alias after figuring out a proper - // way to disptach move. + // way to dispatch move. shell_->NotifyWindowMove(); shell_->NotifyWindowMoved(); } @@ -321,6 +321,13 @@ bool ScopedDisableResize::disable_resize_ = false; return [super constrainFrameRect:frameRect toScreen:screen]; } +- (void)setFrame:(NSRect)windowFrame display:(BOOL)displayViews { + // constrainFrameRect is not called on hidden windows so disable adjusting + // the frame directly when resize is disabled + if (!ScopedDisableResize::IsResizeDisabled()) + [super setFrame:windowFrame display:displayViews]; +} + - (id)accessibilityAttributeValue:(NSString*)attribute { if (![attribute isEqualToString:@"AXChildren"]) return [super accessibilityAttributeValue:attribute]; @@ -784,9 +791,6 @@ void NativeWindowMac::SetContentSizeConstraints( } void NativeWindowMac::SetResizable(bool resizable) { - // Change styleMask for frameless causes the window to change size, so we have - // to explicitly disables that. - ScopedDisableResize disable_resize; SetStyleMask(resizable, NSResizableWindowMask); } @@ -1201,6 +1205,10 @@ void NativeWindowMac::UpdateDraggableRegionViews( } void NativeWindowMac::SetStyleMask(bool on, NSUInteger flag) { + // Changing the styleMask of a frameless windows causes it to change size so + // we explicitly disable resizing while setting it. + ScopedDisableResize disable_resize; + bool was_maximizable = IsMaximizable(); if (on) [window_ setStyleMask:[window_ styleMask] | flag];