Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update normal bounds prior to minimizing #34485

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions shell/browser/native_window_mac.h
Expand Up @@ -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);
Expand Down
15 changes: 10 additions & 5 deletions shell/browser/native_window_mac.mm
Expand Up @@ -451,7 +451,7 @@ void ViewDidMoveToSuperview(NSView* self, SEL _cmd) {
SetContentView(new views::View());
AddContentViewLayers();

original_frame_ = [window_ frame];
UpdateWindowOriginalFrame();
original_level_ = [window_ level];
}

Expand Down Expand Up @@ -618,7 +618,7 @@ void ViewDidMoveToSuperview(NSView* self, SEL _cmd) {

// Take note of the current window size
if (IsNormal())
original_frame_ = [window_ frame];
UpdateWindowOriginalFrame();
[window_ zoom:nil];

if (!is_visible) {
Expand Down Expand Up @@ -662,7 +662,7 @@ void ViewDidMoveToSuperview(NSView* self, SEL _cmd) {

// Take note of the current window size
if (IsNormal())
original_frame_ = [window_ frame];
UpdateWindowOriginalFrame();
[window_ miniaturize:nil];
}

Expand Down Expand Up @@ -715,7 +715,7 @@ void ViewDidMoveToSuperview(NSView* self, SEL _cmd) {

// 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
Expand Down Expand Up @@ -751,6 +751,7 @@ void ViewDidMoveToSuperview(NSView* self, SEL _cmd) {

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

gfx::Rect NativeWindowMac::GetBounds() {
Expand Down Expand Up @@ -1025,7 +1026,7 @@ void ViewDidMoveToSuperview(NSView* self, SEL _cmd) {

// Take note of the current window size and level
if (IsNormal()) {
original_frame_ = [window_ frame];
UpdateWindowOriginalFrame();
original_level_ = [window_ level];
}

Expand Down Expand Up @@ -1423,6 +1424,10 @@ void ViewDidMoveToSuperview(NSView* self, SEL _cmd) {
}
}

void NativeWindowMac::UpdateWindowOriginalFrame() {
original_frame_ = [window_ frame];
}

void NativeWindowMac::SetVibrancy(const std::string& type) {
NSVisualEffectView* vibrantView = [window_ vibrantView];

Expand Down
1 change: 1 addition & 0 deletions shell/browser/ui/cocoa/electron_ns_window_delegate.mm
Expand Up @@ -203,6 +203,7 @@ - (void)windowWillMiniaturize:(NSNotification*)notification {
// windowDidDeminiaturize
level_ = [window level];
shell_->SetWindowLevel(NSNormalWindowLevel);
shell_->UpdateWindowOriginalFrame();
}

- (void)windowDidMiniaturize:(NSNotification*)notification {
Expand Down
173 changes: 173 additions & 0 deletions spec-main/api-browser-window-spec.ts
Expand Up @@ -1230,6 +1230,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');
Expand All @@ -1248,6 +1249,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', () => {
Expand All @@ -1259,6 +1305,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({
Expand All @@ -1279,6 +1326,7 @@ describe('BrowserWindow module', () => {
await unmaximize;
expectBoundsEqual(w.getNormalBounds(), bounds);
});

it('correctly checks transparent window maximization state', async () => {
w.destroy();
w = new BrowserWindow({
Expand All @@ -1298,6 +1346,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({
Expand Down Expand Up @@ -1327,6 +1376,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', () => {
Expand All @@ -1338,6 +1422,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({
Expand Down Expand Up @@ -1383,6 +1468,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', () => {
Expand Down Expand Up @@ -1420,6 +1549,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();
Expand Down