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: calculate frame when setting window placement #25057

Merged
merged 1 commit into from Aug 20, 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
4 changes: 2 additions & 2 deletions shell/browser/native_window_views.h
Expand Up @@ -273,8 +273,8 @@ class NativeWindowViews : public NativeWindow,
// Set to true if the window is always on top and behind the task bar.
bool behind_task_bar_ = false;

// Whether to block Chromium from handling window messages.
bool block_chromium_message_handler_ = false;
// Whether we want to set window placement without side effect.
bool is_setting_window_placement_ = false;
#endif

// Handles unhandled keyboard messages coming back from the renderer process.
Expand Down
17 changes: 11 additions & 6 deletions shell/browser/native_window_views_win.cc
Expand Up @@ -180,11 +180,16 @@ bool NativeWindowViews::PreHandleMSG(UINT message,
LRESULT* result) {
NotifyWindowMessage(message, w_param, l_param);

// See code below for why blocking Chromium from handling messages.
if (block_chromium_message_handler_) {
// Handle the message with default proc.
// Avoid side effects when calling SetWindowPlacement.
if (is_setting_window_placement_) {
// Let Chromium handle the WM_NCCALCSIZE message otherwise the window size
// would be wrong.
// See https://github.com/electron/electron/issues/22393 for more.
if (message == WM_NCCALCSIZE)
return false;
// Otherwise handle the message with default proc,
*result = DefWindowProc(GetAcceleratedWidget(), message, w_param, l_param);
// Tell Chromium to ignore this message.
// and tell Chromium to ignore this message.
return true;
}

Expand Down Expand Up @@ -239,9 +244,9 @@ bool NativeWindowViews::PreHandleMSG(UINT message,
// messages until the SetWindowPlacement call is done.
//
// See https://github.com/electron/electron/issues/21614 for more.
block_chromium_message_handler_ = true;
is_setting_window_placement_ = true;
SetWindowPlacement(GetAcceleratedWidget(), &wp);
block_chromium_message_handler_ = false;
is_setting_window_placement_ = false;

last_normal_placement_bounds_ = gfx::Rect();
}
Expand Down
20 changes: 20 additions & 0 deletions spec-main/api-browser-window-spec.ts
Expand Up @@ -971,6 +971,26 @@ describe('BrowserWindow module', () => {
w.show()
w.minimize()
})
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('minimize', () => {
w.restore()
})
const restore = emittedOnce(w, 'restore')
w.show()
w.minimize()
await restore
expectBoundsEqual(w.getNormalBounds(), bounds)
})
})
ifdescribe(process.platform === 'win32')(`Fullscreen state`, () => {
it(`checks normal bounds when fullscreen'ed`, (done) => {
Expand Down