Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: cherry-pick a69b99519f91 from chromium
- Loading branch information
1 parent
d46431b
commit 8fc319e
Showing
2 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
From a69b99519f91c6b273b1e91fee317c130e78ba89 Mon Sep 17 00:00:00 2001 | ||
From: David Sanders <dsanders11@ucsbalum.com> | ||
Date: Fri, 11 Feb 2022 22:37:39 +0000 | ||
Subject: [PATCH] Fix Widget::Show/ShowInactive behavior on Windows when window maximized | ||
|
||
Use SW_SHOW/SW_SHOWNA instead of SW_SHOWNORMAL/SW_SHOWNOACTIVATE so | ||
that the window is not restored if it is maximized. | ||
|
||
Add tests for this behavior to ensure it is consistent across | ||
platforms. | ||
|
||
Refs https://github.com/electron/electron/issues/32373 | ||
|
||
Change-Id: Icbaa61613906b63ed4a7d505a9b290e2e74b0025 | ||
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3371573 | ||
Reviewed-by: Peter Kasting <pkasting@chromium.org> | ||
Reviewed-by: Scott Violet <sky@chromium.org> | ||
Reviewed-by: Mike Wasserman <msw@chromium.org> | ||
Commit-Queue: Mike Wasserman <msw@chromium.org> | ||
Cr-Commit-Position: refs/heads/main@{#970172} | ||
--- | ||
|
||
diff --git a/ui/views/widget/widget_interactive_uitest.cc b/ui/views/widget/widget_interactive_uitest.cc | ||
index f427ebf..ba7bcbb 100644 | ||
--- a/ui/views/widget/widget_interactive_uitest.cc | ||
+++ b/ui/views/widget/widget_interactive_uitest.cc | ||
@@ -1173,6 +1173,28 @@ | ||
EXPECT_TRUE(restore_waiter.Wait()); | ||
} | ||
|
||
+// Maximize is not implemented on macOS, see crbug.com/868599 | ||
+#if !BUILDFLAG(IS_MAC) | ||
+// Widget::Show/ShowInactive should not restore a maximized window | ||
+TEST_F(DesktopWidgetTestInteractive, ShowAfterMaximize) { | ||
+ WidgetAutoclosePtr widget(CreateTopLevelNativeWidget()); | ||
+ ShowSync(widget.get()); | ||
+ ASSERT_FALSE(widget->IsMaximized()); | ||
+ | ||
+ PropertyWaiter maximize_waiter( | ||
+ base::BindRepeating(&Widget::IsMaximized, base::Unretained(widget.get())), | ||
+ true); | ||
+ widget->Maximize(); | ||
+ EXPECT_TRUE(maximize_waiter.Wait()); | ||
+ | ||
+ ShowSync(widget.get()); | ||
+ EXPECT_TRUE(widget->IsMaximized()); | ||
+ | ||
+ ShowInactiveSync(widget.get()); | ||
+ EXPECT_TRUE(widget->IsMaximized()); | ||
+} | ||
+#endif | ||
+ | ||
#if BUILDFLAG(IS_WIN) | ||
// TODO(davidbienvenu): Get this test to pass on Linux and ChromeOS by hiding | ||
// the root window when desktop widget is minimized. | ||
diff --git a/ui/views/win/hwnd_message_handler.cc b/ui/views/win/hwnd_message_handler.cc | ||
index 302915b..bf32a08 100644 | ||
--- a/ui/views/win/hwnd_message_handler.cc | ||
+++ b/ui/views/win/hwnd_message_handler.cc | ||
@@ -660,9 +660,16 @@ | ||
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; | ||
@@ -673,9 +680,9 @@ | ||
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: |