fix: calculate frame when setting window placement (#25014)
This commit is contained in:
parent
9021843850
commit
52d7afa4ef
3 changed files with 33 additions and 8 deletions
|
@ -278,8 +278,8 @@ class NativeWindowViews : public NativeWindow,
|
||||||
// Set to true if the window is always on top and behind the task bar.
|
// Set to true if the window is always on top and behind the task bar.
|
||||||
bool behind_task_bar_ = false;
|
bool behind_task_bar_ = false;
|
||||||
|
|
||||||
// Whether to block Chromium from handling window messages.
|
// Whether we want to set window placement without side effect.
|
||||||
bool block_chromium_message_handler_ = false;
|
bool is_setting_window_placement_ = false;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Handles unhandled keyboard messages coming back from the renderer process.
|
// Handles unhandled keyboard messages coming back from the renderer process.
|
||||||
|
|
|
@ -180,11 +180,16 @@ bool NativeWindowViews::PreHandleMSG(UINT message,
|
||||||
LRESULT* result) {
|
LRESULT* result) {
|
||||||
NotifyWindowMessage(message, w_param, l_param);
|
NotifyWindowMessage(message, w_param, l_param);
|
||||||
|
|
||||||
// See code below for why blocking Chromium from handling messages.
|
// Avoid side effects when calling SetWindowPlacement.
|
||||||
if (block_chromium_message_handler_) {
|
if (is_setting_window_placement_) {
|
||||||
// Handle the message with default proc.
|
// 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);
|
*result = DefWindowProc(GetAcceleratedWidget(), message, w_param, l_param);
|
||||||
// Tell Chromium to ignore this message.
|
// and tell Chromium to ignore this message.
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -239,9 +244,9 @@ bool NativeWindowViews::PreHandleMSG(UINT message,
|
||||||
// messages until the SetWindowPlacement call is done.
|
// messages until the SetWindowPlacement call is done.
|
||||||
//
|
//
|
||||||
// See https://github.com/electron/electron/issues/21614 for more.
|
// See https://github.com/electron/electron/issues/21614 for more.
|
||||||
block_chromium_message_handler_ = true;
|
is_setting_window_placement_ = true;
|
||||||
SetWindowPlacement(GetAcceleratedWidget(), &wp);
|
SetWindowPlacement(GetAcceleratedWidget(), &wp);
|
||||||
block_chromium_message_handler_ = false;
|
is_setting_window_placement_ = false;
|
||||||
|
|
||||||
last_normal_placement_bounds_ = gfx::Rect();
|
last_normal_placement_bounds_ = gfx::Rect();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1005,6 +1005,26 @@ describe('BrowserWindow module', () => {
|
||||||
await restore;
|
await restore;
|
||||||
expectBoundsEqual(w.getNormalBounds(), bounds);
|
expectBoundsEqual(w.getNormalBounds(), bounds);
|
||||||
});
|
});
|
||||||
|
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', () => {
|
ifdescribe(process.platform === 'win32')('Fullscreen state', () => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue