mirror of
https://github.com/electron/electron.git
synced 2026-04-10 03:01:51 -04:00
fix: update normal bounds prior to minimizing (#34484)
Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
This commit is contained in:
@@ -166,6 +166,8 @@ class NativeWindowMac : public NativeWindow,
|
||||
|
||||
void UpdateVibrancyRadii(bool fullscreen);
|
||||
|
||||
void UpdateWindowOriginalFrame();
|
||||
|
||||
// Set the attribute of NSWindow while work around a bug of zoom button.
|
||||
void SetStyleMask(bool on, NSUInteger flag);
|
||||
void SetCollectionBehavior(bool on, NSUInteger flag);
|
||||
|
||||
@@ -451,7 +451,7 @@ NativeWindowMac::NativeWindowMac(const gin_helper::Dictionary& options,
|
||||
SetContentView(new views::View());
|
||||
AddContentViewLayers();
|
||||
|
||||
original_frame_ = [window_ frame];
|
||||
UpdateWindowOriginalFrame();
|
||||
original_level_ = [window_ level];
|
||||
}
|
||||
|
||||
@@ -618,7 +618,7 @@ void NativeWindowMac::Maximize() {
|
||||
|
||||
// Take note of the current window size
|
||||
if (IsNormal())
|
||||
original_frame_ = [window_ frame];
|
||||
UpdateWindowOriginalFrame();
|
||||
[window_ zoom:nil];
|
||||
|
||||
if (!is_visible) {
|
||||
@@ -662,7 +662,7 @@ void NativeWindowMac::Minimize() {
|
||||
|
||||
// Take note of the current window size
|
||||
if (IsNormal())
|
||||
original_frame_ = [window_ frame];
|
||||
UpdateWindowOriginalFrame();
|
||||
[window_ miniaturize:nil];
|
||||
}
|
||||
|
||||
@@ -715,7 +715,7 @@ void NativeWindowMac::SetFullScreen(bool fullscreen) {
|
||||
|
||||
// Take note of the current window size
|
||||
if (IsNormal())
|
||||
original_frame_ = [window_ frame];
|
||||
UpdateWindowOriginalFrame();
|
||||
|
||||
// This needs to be set here because it can be the case that
|
||||
// SetFullScreen is called by a user before windowWillEnterFullScreen
|
||||
@@ -751,6 +751,7 @@ void NativeWindowMac::SetBounds(const gfx::Rect& bounds, bool animate) {
|
||||
|
||||
[window_ setFrame:cocoa_bounds display:YES animate:animate];
|
||||
user_set_bounds_maximized_ = IsMaximized() ? true : false;
|
||||
UpdateWindowOriginalFrame();
|
||||
}
|
||||
|
||||
gfx::Rect NativeWindowMac::GetBounds() {
|
||||
@@ -1025,7 +1026,7 @@ void NativeWindowMac::SetSimpleFullScreen(bool simple_fullscreen) {
|
||||
|
||||
// Take note of the current window size and level
|
||||
if (IsNormal()) {
|
||||
original_frame_ = [window_ frame];
|
||||
UpdateWindowOriginalFrame();
|
||||
original_level_ = [window_ level];
|
||||
}
|
||||
|
||||
@@ -1423,6 +1424,10 @@ void NativeWindowMac::UpdateVibrancyRadii(bool fullscreen) {
|
||||
}
|
||||
}
|
||||
|
||||
void NativeWindowMac::UpdateWindowOriginalFrame() {
|
||||
original_frame_ = [window_ frame];
|
||||
}
|
||||
|
||||
void NativeWindowMac::SetVibrancy(const std::string& type) {
|
||||
NSVisualEffectView* vibrantView = [window_ vibrantView];
|
||||
|
||||
|
||||
@@ -203,6 +203,7 @@ using FullScreenTransitionState =
|
||||
// windowDidDeminiaturize
|
||||
level_ = [window level];
|
||||
shell_->SetWindowLevel(NSNormalWindowLevel);
|
||||
shell_->UpdateWindowOriginalFrame();
|
||||
}
|
||||
|
||||
- (void)windowDidMiniaturize:(NSNotification*)notification {
|
||||
|
||||
@@ -1228,6 +1228,7 @@ describe('BrowserWindow module', () => {
|
||||
await resize;
|
||||
expectBoundsEqual(w.getNormalBounds(), w.getBounds());
|
||||
});
|
||||
|
||||
it('checks normal bounds after move', async () => {
|
||||
const pos = [10, 10];
|
||||
const move = emittedOnce(w, 'move');
|
||||
@@ -1246,6 +1247,51 @@ describe('BrowserWindow module', () => {
|
||||
await maximize;
|
||||
expectBoundsEqual(w.getNormalBounds(), bounds);
|
||||
});
|
||||
|
||||
it('updates normal bounds after resize and maximize', async () => {
|
||||
const size = [300, 400];
|
||||
const resize = emittedOnce(w, 'resize');
|
||||
w.setSize(size[0], size[1]);
|
||||
await resize;
|
||||
const original = w.getBounds();
|
||||
|
||||
const maximize = emittedOnce(w, 'maximize');
|
||||
w.maximize();
|
||||
await maximize;
|
||||
|
||||
const normal = w.getNormalBounds();
|
||||
const bounds = w.getBounds();
|
||||
|
||||
expect(normal).to.deep.equal(original);
|
||||
expect(normal).to.not.deep.equal(bounds);
|
||||
|
||||
const close = emittedOnce(w, 'close');
|
||||
w.close();
|
||||
await close;
|
||||
});
|
||||
|
||||
it('updates normal bounds after move and maximize', async () => {
|
||||
const pos = [10, 10];
|
||||
const move = emittedOnce(w, 'move');
|
||||
w.setPosition(pos[0], pos[1]);
|
||||
await move;
|
||||
const original = w.getBounds();
|
||||
|
||||
const maximize = emittedOnce(w, 'maximize');
|
||||
w.maximize();
|
||||
await maximize;
|
||||
|
||||
const normal = w.getNormalBounds();
|
||||
const bounds = w.getBounds();
|
||||
|
||||
expect(normal).to.deep.equal(original);
|
||||
expect(normal).to.not.deep.equal(bounds);
|
||||
|
||||
const close = emittedOnce(w, 'close');
|
||||
w.close();
|
||||
await close;
|
||||
});
|
||||
|
||||
it('checks normal bounds when unmaximized', async () => {
|
||||
const bounds = w.getBounds();
|
||||
w.once('maximize', () => {
|
||||
@@ -1257,6 +1303,7 @@ describe('BrowserWindow module', () => {
|
||||
await unmaximize;
|
||||
expectBoundsEqual(w.getNormalBounds(), bounds);
|
||||
});
|
||||
|
||||
it('does not change size for a frameless window with min size', async () => {
|
||||
w.destroy();
|
||||
w = new BrowserWindow({
|
||||
@@ -1277,6 +1324,7 @@ describe('BrowserWindow module', () => {
|
||||
await unmaximize;
|
||||
expectBoundsEqual(w.getNormalBounds(), bounds);
|
||||
});
|
||||
|
||||
it('correctly checks transparent window maximization state', async () => {
|
||||
w.destroy();
|
||||
w = new BrowserWindow({
|
||||
@@ -1296,6 +1344,7 @@ describe('BrowserWindow module', () => {
|
||||
await unmaximize;
|
||||
expect(w.isMaximized()).to.equal(false);
|
||||
});
|
||||
|
||||
it('returns the correct value for windows with an aspect ratio', async () => {
|
||||
w.destroy();
|
||||
w = new BrowserWindow({
|
||||
@@ -1325,6 +1374,41 @@ describe('BrowserWindow module', () => {
|
||||
await minimize;
|
||||
expectBoundsEqual(w.getNormalBounds(), bounds);
|
||||
});
|
||||
|
||||
it('updates normal bounds after move and minimize', async () => {
|
||||
const pos = [10, 10];
|
||||
const move = emittedOnce(w, 'move');
|
||||
w.setPosition(pos[0], pos[1]);
|
||||
await move;
|
||||
const original = w.getBounds();
|
||||
|
||||
const minimize = emittedOnce(w, 'minimize');
|
||||
w.minimize();
|
||||
await minimize;
|
||||
|
||||
const normal = w.getNormalBounds();
|
||||
|
||||
expect(original).to.deep.equal(normal);
|
||||
expectBoundsEqual(normal, w.getBounds());
|
||||
});
|
||||
|
||||
it('updates normal bounds after resize and minimize', async () => {
|
||||
const size = [300, 400];
|
||||
const resize = emittedOnce(w, 'resize');
|
||||
w.setSize(size[0], size[1]);
|
||||
await resize;
|
||||
const original = w.getBounds();
|
||||
|
||||
const minimize = emittedOnce(w, 'minimize');
|
||||
w.minimize();
|
||||
await minimize;
|
||||
|
||||
const normal = w.getNormalBounds();
|
||||
|
||||
expect(original).to.deep.equal(normal);
|
||||
expectBoundsEqual(normal, w.getBounds());
|
||||
});
|
||||
|
||||
it('checks normal bounds when restored', async () => {
|
||||
const bounds = w.getBounds();
|
||||
w.once('minimize', () => {
|
||||
@@ -1336,6 +1420,7 @@ describe('BrowserWindow module', () => {
|
||||
await restore;
|
||||
expectBoundsEqual(w.getNormalBounds(), bounds);
|
||||
});
|
||||
|
||||
it('does not change size for a frameless window with min size', async () => {
|
||||
w.destroy();
|
||||
w = new BrowserWindow({
|
||||
@@ -1381,6 +1466,50 @@ describe('BrowserWindow module', () => {
|
||||
expectBoundsEqual(w.getNormalBounds(), bounds);
|
||||
});
|
||||
|
||||
it('updates normal bounds after resize and fullscreen', async () => {
|
||||
const size = [300, 400];
|
||||
const resize = emittedOnce(w, 'resize');
|
||||
w.setSize(size[0], size[1]);
|
||||
await resize;
|
||||
const original = w.getBounds();
|
||||
|
||||
const fsc = emittedOnce(w, 'enter-full-screen');
|
||||
w.fullScreen = true;
|
||||
await fsc;
|
||||
|
||||
const normal = w.getNormalBounds();
|
||||
const bounds = w.getBounds();
|
||||
|
||||
expect(normal).to.deep.equal(original);
|
||||
expect(normal).to.not.deep.equal(bounds);
|
||||
|
||||
const close = emittedOnce(w, 'close');
|
||||
w.close();
|
||||
await close;
|
||||
});
|
||||
|
||||
it('updates normal bounds after move and fullscreen', async () => {
|
||||
const pos = [10, 10];
|
||||
const move = emittedOnce(w, 'move');
|
||||
w.setPosition(pos[0], pos[1]);
|
||||
await move;
|
||||
const original = w.getBounds();
|
||||
|
||||
const fsc = emittedOnce(w, 'enter-full-screen');
|
||||
w.fullScreen = true;
|
||||
await fsc;
|
||||
|
||||
const normal = w.getNormalBounds();
|
||||
const bounds = w.getBounds();
|
||||
|
||||
expect(normal).to.deep.equal(original);
|
||||
expect(normal).to.not.deep.equal(bounds);
|
||||
|
||||
const close = emittedOnce(w, 'close');
|
||||
w.close();
|
||||
await close;
|
||||
});
|
||||
|
||||
it('checks normal bounds when unfullscreen\'ed', async () => {
|
||||
const bounds = w.getBounds();
|
||||
w.once('enter-full-screen', () => {
|
||||
@@ -1418,6 +1547,50 @@ describe('BrowserWindow module', () => {
|
||||
expectBoundsEqual(w.getNormalBounds(), bounds);
|
||||
});
|
||||
|
||||
it('updates normal bounds after resize and fullscreen', async () => {
|
||||
const size = [300, 400];
|
||||
const resize = emittedOnce(w, 'resize');
|
||||
w.setSize(size[0], size[1]);
|
||||
await resize;
|
||||
const original = w.getBounds();
|
||||
|
||||
const fsc = emittedOnce(w, 'enter-full-screen');
|
||||
w.setFullScreen(true);
|
||||
await fsc;
|
||||
|
||||
const normal = w.getNormalBounds();
|
||||
const bounds = w.getBounds();
|
||||
|
||||
expect(normal).to.deep.equal(original);
|
||||
expect(normal).to.not.deep.equal(bounds);
|
||||
|
||||
const close = emittedOnce(w, 'close');
|
||||
w.close();
|
||||
await close;
|
||||
});
|
||||
|
||||
it('updates normal bounds after move and fullscreen', async () => {
|
||||
const pos = [10, 10];
|
||||
const move = emittedOnce(w, 'move');
|
||||
w.setPosition(pos[0], pos[1]);
|
||||
await move;
|
||||
const original = w.getBounds();
|
||||
|
||||
const fsc = emittedOnce(w, 'enter-full-screen');
|
||||
w.setFullScreen(true);
|
||||
await fsc;
|
||||
|
||||
const normal = w.getNormalBounds();
|
||||
const bounds = w.getBounds();
|
||||
|
||||
expect(normal).to.deep.equal(original);
|
||||
expect(normal).to.not.deep.equal(bounds);
|
||||
|
||||
const close = emittedOnce(w, 'close');
|
||||
w.close();
|
||||
await close;
|
||||
});
|
||||
|
||||
it('checks normal bounds when unfullscreen\'ed', async () => {
|
||||
const bounds = w.getBounds();
|
||||
w.show();
|
||||
|
||||
Reference in New Issue
Block a user