From 1d38e14e92b1c2a104f1512ad8cb18e79e688138 Mon Sep 17 00:00:00 2001 From: "trop[bot]" <37223003+trop[bot]@users.noreply.github.com> Date: Tue, 7 Sep 2021 17:02:14 +0200 Subject: [PATCH] fix: show maximized frameless window (#30865) * fix: show maximized frameless window * test: show maximized transparent window * fix: test using wrong bounds BrowserWindow will be sized to the workArea when the Windows taskbar is visible. Co-authored-by: samuelmaddock --- shell/browser/native_window_views.cc | 11 ++++++++++- spec-main/api-browser-window-spec.ts | 28 ++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/shell/browser/native_window_views.cc b/shell/browser/native_window_views.cc index cd5e8c19ce4b4..b2ad39ca6c101 100644 --- a/shell/browser/native_window_views.cc +++ b/shell/browser/native_window_views.cc @@ -1629,8 +1629,17 @@ void NativeWindowViews::OnMouseEvent(ui::MouseEvent* event) { } ui::WindowShowState NativeWindowViews::GetRestoredState() { - if (IsMaximized()) + if (IsMaximized()) { +#if defined(OS_WIN) + // Only restore Maximized state when window is NOT transparent style + if (!transparent()) { + return ui::SHOW_STATE_MAXIMIZED; + } +#else return ui::SHOW_STATE_MAXIMIZED; +#endif + } + if (IsFullscreen()) return ui::SHOW_STATE_FULLSCREEN; diff --git a/spec-main/api-browser-window-spec.ts b/spec-main/api-browser-window-spec.ts index 5a7665b2f33c1..a0e98a0bf1d9c 100644 --- a/spec-main/api-browser-window-spec.ts +++ b/spec-main/api-browser-window-spec.ts @@ -4647,4 +4647,32 @@ describe('BrowserWindow module', () => { }); }); }); + + describe('"transparent" option', () => { + afterEach(closeAllWindows); + + // Only applicable on Windows where transparent windows can't be maximized. + ifit(process.platform === 'win32')('can show maximized frameless window', async () => { + const display = screen.getPrimaryDisplay(); + + const w = new BrowserWindow({ + ...display.bounds, + frame: false, + transparent: true, + show: true + }); + + w.loadURL('about:blank'); + await emittedOnce(w, 'ready-to-show'); + + expect(w.isMaximized()).to.be.true(); + + // Fails when the transparent HWND is in an invalid maximized state. + expect(w.getBounds()).to.deep.equal(display.workArea); + + const newBounds = { width: 256, height: 256, x: 0, y: 0 }; + w.setBounds(newBounds); + expect(w.getBounds()).to.deep.equal(newBounds); + }); + }); });