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: save normal window bounds when maximizing #25148

Merged
merged 1 commit into from Sep 2, 2020
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
23 changes: 14 additions & 9 deletions shell/browser/native_window_views_win.cc
Expand Up @@ -315,23 +315,28 @@ void NativeWindowViews::HandleSizeEvent(WPARAM w_param, LPARAM l_param) {
// Here we handle the WM_SIZE event in order to figure out what is the current
// window state and notify the user accordingly.
switch (w_param) {
case SIZE_MAXIMIZED: {
last_window_state_ = ui::SHOW_STATE_MAXIMIZED;
NotifyWindowMaximize();
break;
}
case SIZE_MINIMIZED:
last_window_state_ = ui::SHOW_STATE_MINIMIZED;

case SIZE_MAXIMIZED:
case SIZE_MINIMIZED: {
WINDOWPLACEMENT wp;
wp.length = sizeof(WINDOWPLACEMENT);

if (GetWindowPlacement(GetAcceleratedWidget(), &wp)) {
last_normal_placement_bounds_ = gfx::Rect(wp.rcNormalPosition);
}

NotifyWindowMinimize();
// Note that SIZE_MAXIMIZED and SIZE_MINIMIZED might be emitted for
// multiple times for one resize because of the SetWindowPlacement call.
if (w_param == SIZE_MAXIMIZED &&
last_window_state_ != ui::SHOW_STATE_MAXIMIZED) {
last_window_state_ = ui::SHOW_STATE_MAXIMIZED;
NotifyWindowMaximize();
} else if (w_param == SIZE_MINIMIZED &&
last_window_state_ != ui::SHOW_STATE_MINIMIZED) {
last_window_state_ = ui::SHOW_STATE_MINIMIZED;
NotifyWindowMinimize();
}
break;
}
case SIZE_RESTORED:
switch (last_window_state_) {
case ui::SHOW_STATE_MAXIMIZED:
Expand Down
29 changes: 29 additions & 0 deletions spec-main/api-browser-window-spec.ts
Expand Up @@ -948,6 +948,26 @@ describe('BrowserWindow module', () => {
w.show()
w.maximize()
})
it('does not change size for a frameless window with min size', async () => {
w.destroy()
w = new BrowserWindow({
show: false,
frame: false,
width: 300,
height: 300,
minWidth: 300,
minHeight: 300
})
const bounds = w.getBounds()
w.once('maximize', () => {
w.unmaximize()
})
const unmaximize = emittedOnce(w, 'unmaximize')
w.show()
w.maximize()
await unmaximize
expectBoundsEqual(w.getNormalBounds(), bounds)
})
})
ifdescribe(process.platform !== 'linux')(`Minimized state`, () => {
it(`checks normal bounds when minimized`, (done) => {
Expand Down Expand Up @@ -2811,6 +2831,15 @@ describe('BrowserWindow module', () => {
w.maximize()
})

it('emits only one event when frameless window is maximized', () => {
const w = new BrowserWindow({ show: false, frame: false })
let emitted = 0
w.on('maximize', () => emitted++)
w.show()
w.maximize()
expect(emitted).to.equal(1)
});

it('emits an event when window is unmaximized', (done) => {
const w = new BrowserWindow({show: false})
w.once('unmaximize', () => { done() })
Expand Down