From 32d4c9ad85cb53f14007cd61460d0b0241cb8fbc Mon Sep 17 00:00:00 2001 From: Michaela Laurencin <35157522+mlaurencin@users.noreply.github.com> Date: Mon, 30 Nov 2020 22:27:58 -0800 Subject: [PATCH] fix: add check in IsMaximized for non-WS_THICKFRAME windows (#26586) * fix: add check in IsMaximized for non-WS_THICKFRAME windows * remove logs * change GetPosition for GetNativeWindow * change GetPosition for GetNativeWindow in IsMaximize * add top left corner check * add transparent maximization test * replace window and display comparison * rebase off master --- shell/browser/native_window_views.cc | 14 ++++++++++++++ shell/browser/native_window_views_win.cc | 8 +++----- spec-main/api-browser-window-spec.ts | 19 +++++++++++++++++++ 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/shell/browser/native_window_views.cc b/shell/browser/native_window_views.cc index cb53ac2fd104..17d1975c797a 100644 --- a/shell/browser/native_window_views.cc +++ b/shell/browser/native_window_views.cc @@ -530,6 +530,20 @@ void NativeWindowViews::Unmaximize() { } bool NativeWindowViews::IsMaximized() { + // For window without WS_THICKFRAME style, we can not call IsMaximized(). + // This path will be used for transparent windows as well. + +#if defined(OS_WIN) + if (!(::GetWindowLong(GetAcceleratedWidget(), GWL_STYLE) & WS_THICKFRAME)) { + // Compare the size of the window with the size of the display + auto display = display::Screen::GetScreen()->GetDisplayNearestWindow( + GetNativeWindow()); + // Maximized if the window is the same dimensions and placement as the + // display + return GetBounds() == display.work_area(); + } +#endif + return widget()->IsMaximized(); } diff --git a/shell/browser/native_window_views_win.cc b/shell/browser/native_window_views_win.cc index 5e2894e9dd1f..8d228cb0c76f 100644 --- a/shell/browser/native_window_views_win.cc +++ b/shell/browser/native_window_views_win.cc @@ -149,9 +149,7 @@ std::set NativeWindowViews::forwarding_windows_; HHOOK NativeWindowViews::mouse_hook_ = NULL; void NativeWindowViews::Maximize() { - // Only use Maximize() when: - // 1. window has WS_THICKFRAME style; - // 2. and window is not frameless when there is autohide taskbar. + // Only use Maximize() when window has WS_THICKFRAME style if (::GetWindowLong(GetAcceleratedWidget(), GWL_STYLE) & WS_THICKFRAME) { if (IsVisible()) widget()->Maximize(); @@ -161,8 +159,8 @@ void NativeWindowViews::Maximize() { return; } else { restore_bounds_ = GetBounds(); - auto display = - display::Screen::GetScreen()->GetDisplayNearestPoint(GetPosition()); + auto display = display::Screen::GetScreen()->GetDisplayNearestWindow( + GetNativeWindow()); SetBounds(display.work_area(), false); } } diff --git a/spec-main/api-browser-window-spec.ts b/spec-main/api-browser-window-spec.ts index d72b8daad002..89902c7ed808 100644 --- a/spec-main/api-browser-window-spec.ts +++ b/spec-main/api-browser-window-spec.ts @@ -1059,6 +1059,25 @@ describe('BrowserWindow module', () => { await unmaximize; expectBoundsEqual(w.getNormalBounds(), bounds); }); + it('can check transparent window maximization', async () => { + w.destroy(); + w = new BrowserWindow({ + show: false, + width: 300, + height: 300, + transparent: true + }); + + const maximize = emittedOnce(w, 'resize'); + w.show(); + w.maximize(); + await maximize; + expect(w.isMaximized()).to.equal(true); + const unmaximize = emittedOnce(w, 'resize'); + w.unmaximize(); + await unmaximize; + expect(w.isMaximized()).to.equal(false); + }); }); ifdescribe(process.platform !== 'linux')('Minimized state', () => {