fix: don't restore maximized BrowserWindow when calling showInactive (#32870)
This commit is contained in:
parent
bdad6335c4
commit
069cde09fb
3 changed files with 59 additions and 0 deletions
|
@ -111,3 +111,4 @@ fix_aspect_ratio_with_max_size.patch
|
|||
fix_dont_delete_SerialPortManager_on_main_thread.patch
|
||||
feat_add_data_transfer_to_requestsingleinstancelock.patch
|
||||
fix_crash_when_saving_edited_pdf_files.patch
|
||||
fix_don_t_restore_maximized_windows_when_calling_showinactive.patch
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: David Sanders <dsanders11@ucsbalum.com>
|
||||
Date: Fri, 11 Feb 2022 22:37:39 +0000
|
||||
Subject: fix: don't restore maximized windows when calling ShowInactive
|
||||
|
||||
This is a backport from Chromium of
|
||||
https://chromium-review.googlesource.com/c/chromium/src/+/3371573.
|
||||
|
||||
diff --git a/ui/views/win/hwnd_message_handler.cc b/ui/views/win/hwnd_message_handler.cc
|
||||
index 067861bb743ee2f3c1916794d45efb7dd591b230..6507557bf5a47492343602607e0dbb7d8f88246d 100644
|
||||
--- a/ui/views/win/hwnd_message_handler.cc
|
||||
+++ b/ui/views/win/hwnd_message_handler.cc
|
||||
@@ -664,9 +664,16 @@ void HWNDMessageHandler::Show(ui::WindowShowState show_state,
|
||||
SetWindowPlacement(hwnd(), &placement);
|
||||
native_show_state = SW_SHOWMAXIMIZED;
|
||||
} else {
|
||||
+ const bool is_maximized = IsMaximized();
|
||||
+
|
||||
+ // Use SW_SHOW/SW_SHOWNA instead of SW_SHOWNORMAL/SW_SHOWNOACTIVATE so that
|
||||
+ // the window is not restored to its original position if it is maximized.
|
||||
+ // This could be used unconditionally for ui::SHOW_STATE_INACTIVE, but
|
||||
+ // cross-platform behavior when showing a minimized window is inconsistent,
|
||||
+ // some platforms restore the position, some do not. See crbug.com/1296710
|
||||
switch (show_state) {
|
||||
case ui::SHOW_STATE_INACTIVE:
|
||||
- native_show_state = SW_SHOWNOACTIVATE;
|
||||
+ native_show_state = is_maximized ? SW_SHOWNA : SW_SHOWNOACTIVATE;
|
||||
break;
|
||||
case ui::SHOW_STATE_MAXIMIZED:
|
||||
native_show_state = SW_SHOWMAXIMIZED;
|
||||
@@ -677,9 +684,9 @@ void HWNDMessageHandler::Show(ui::WindowShowState show_state,
|
||||
case ui::SHOW_STATE_NORMAL:
|
||||
if ((GetWindowLong(hwnd(), GWL_EXSTYLE) & WS_EX_TRANSPARENT) ||
|
||||
(GetWindowLong(hwnd(), GWL_EXSTYLE) & WS_EX_NOACTIVATE)) {
|
||||
- native_show_state = SW_SHOWNOACTIVATE;
|
||||
+ native_show_state = is_maximized ? SW_SHOWNA : SW_SHOWNOACTIVATE;
|
||||
} else {
|
||||
- native_show_state = SW_SHOWNORMAL;
|
||||
+ native_show_state = is_maximized ? SW_SHOW : SW_SHOWNORMAL;
|
||||
}
|
||||
break;
|
||||
case ui::SHOW_STATE_FULLSCREEN:
|
|
@ -735,6 +735,22 @@ describe('BrowserWindow module', () => {
|
|||
w.showInactive();
|
||||
expect(w.isFocused()).to.equal(false);
|
||||
});
|
||||
|
||||
// TODO(dsanders11): Enable for Linux once CI plays nice with these kinds of tests
|
||||
ifit(process.platform !== 'linux')('should not restore maximized windows', async () => {
|
||||
const maximize = emittedOnce(w, 'maximize');
|
||||
const shown = emittedOnce(w, 'show');
|
||||
w.maximize();
|
||||
// TODO(dsanders11): The maximize event isn't firing on macOS for a window initially hidden
|
||||
if (process.platform !== 'darwin') {
|
||||
await maximize;
|
||||
} else {
|
||||
await delay(1000);
|
||||
}
|
||||
w.showInactive();
|
||||
await shown;
|
||||
expect(w.isMaximized()).to.equal(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('BrowserWindow.focus()', () => {
|
||||
|
|
Loading…
Reference in a new issue