From e589e9b259ecad5a2f2f47f0b8d40618d1c54601 Mon Sep 17 00:00:00 2001 From: David Sanders Date: Wed, 9 Mar 2022 14:30:42 -0800 Subject: [PATCH] fix: fire show event when BrowserWindow shown via maximize() (#32979) --- shell/browser/native_window_views.cc | 6 ++++-- shell/browser/native_window_views_win.cc | 7 ++++--- spec-main/api-browser-window-spec.ts | 23 +++++++++++++++++++++++ 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/shell/browser/native_window_views.cc b/shell/browser/native_window_views.cc index 2d3d866fa71dc..a5c58964016c3 100644 --- a/shell/browser/native_window_views.cc +++ b/shell/browser/native_window_views.cc @@ -580,11 +580,13 @@ void NativeWindowViews::SetEnabledInternal(bool enable) { #if BUILDFLAG(IS_LINUX) void NativeWindowViews::Maximize() { - if (IsVisible()) + if (IsVisible()) { widget()->Maximize(); - else + } else { widget()->native_widget_private()->Show(ui::SHOW_STATE_MAXIMIZED, gfx::Rect()); + NotifyWindowShow(); + } } #endif diff --git a/shell/browser/native_window_views_win.cc b/shell/browser/native_window_views_win.cc index ab336f2e29866..01d88048af794 100644 --- a/shell/browser/native_window_views_win.cc +++ b/shell/browser/native_window_views_win.cc @@ -178,12 +178,13 @@ HHOOK NativeWindowViews::mouse_hook_ = NULL; void NativeWindowViews::Maximize() { // Only use Maximize() when window is NOT transparent style if (!transparent()) { - if (IsVisible()) + if (IsVisible()) { widget()->Maximize(); - else + } else { widget()->native_widget_private()->Show(ui::SHOW_STATE_MAXIMIZED, gfx::Rect()); - return; + NotifyWindowShow(); + } } else { restore_bounds_ = GetBounds(); auto display = display::Screen::GetScreen()->GetDisplayNearestWindow( diff --git a/spec-main/api-browser-window-spec.ts b/spec-main/api-browser-window-spec.ts index 1e9405e0aa3c8..1ed8734711f33 100644 --- a/spec-main/api-browser-window-spec.ts +++ b/spec-main/api-browser-window-spec.ts @@ -3526,6 +3526,29 @@ describe('BrowserWindow module', () => { }); }); + // TODO(dsanders11): Enable once maximize event works on Linux again on CI + ifdescribe(process.platform !== 'linux')('BrowserWindow.maximize()', () => { + afterEach(closeAllWindows); + // TODO(dsanders11): Disabled on macOS, see https://github.com/electron/electron/issues/32947 + ifit(process.platform !== 'darwin')('should show the window if it is not currently shown', async () => { + const w = new BrowserWindow({ show: false }); + const hidden = emittedOnce(w, 'hide'); + const shown = emittedOnce(w, 'show'); + const maximize = emittedOnce(w, 'maximize'); + expect(w.isVisible()).to.be.false('visible'); + w.maximize(); + await maximize; + expect(w.isVisible()).to.be.true('visible'); + // Even if the window is already maximized + w.hide(); + await hidden; + expect(w.isVisible()).to.be.false('visible'); + w.maximize(); + await shown; // Ensure a 'show' event happens when it becomes visible + expect(w.isVisible()).to.be.true('visible'); + }); + }); + describe('BrowserWindow.unmaximize()', () => { afterEach(closeAllWindows); it('should restore the previous window position', () => {