From 84bd0f0f2bb6aab60ef5300e502f639380ff6eb6 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Thu, 27 Jan 2022 11:46:36 +0100 Subject: [PATCH 1/3] fix: transparent window max/unmax event firing --- shell/browser/native_window_views.cc | 1 + shell/browser/native_window_views_win.cc | 1 + spec-main/api-browser-window-spec.ts | 31 ++++++++++++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/shell/browser/native_window_views.cc b/shell/browser/native_window_views.cc index ddfae215c910f..c2de7307a80aa 100644 --- a/shell/browser/native_window_views.cc +++ b/shell/browser/native_window_views.cc @@ -583,6 +583,7 @@ void NativeWindowViews::Unmaximize() { #if defined(OS_WIN) if (transparent()) { SetBounds(restore_bounds_, false); + NotifyWindowUnmaximize(); return; } #endif diff --git a/shell/browser/native_window_views_win.cc b/shell/browser/native_window_views_win.cc index 05335aed07d66..cf4eb4855f4c2 100644 --- a/shell/browser/native_window_views_win.cc +++ b/shell/browser/native_window_views_win.cc @@ -187,6 +187,7 @@ void NativeWindowViews::Maximize() { auto display = display::Screen::GetScreen()->GetDisplayNearestWindow( GetNativeWindow()); SetBounds(display.work_area(), false); + NotifyWindowMaximize(); } } diff --git a/spec-main/api-browser-window-spec.ts b/spec-main/api-browser-window-spec.ts index 1af89d38c9046..0549565fc024f 100644 --- a/spec-main/api-browser-window-spec.ts +++ b/spec-main/api-browser-window-spec.ts @@ -3241,6 +3241,21 @@ describe('BrowserWindow module', () => { await maximize; }); + // Transparent window max/unmax uses different logic and does not go through + // NativeWindowViews::HandleSizeEvent, so we need to test it separately. + ifit(process.platform === 'win32')('emits an event when a transparent window is maximized', async () => { + const w = new BrowserWindow({ + show: false, + frame: false, + transparent: true + }); + + const maximize = emittedOnce(w, 'maximize'); + w.show(); + w.maximize(); + await maximize; + }); + it('emits only one event when frameless window is maximized', () => { const w = new BrowserWindow({ show: false, frame: false }); let emitted = 0; @@ -3259,6 +3274,22 @@ describe('BrowserWindow module', () => { await unmaximize; }); + // Transparent window max/unmax uses different logic and does not go through + // NativeWindowViews::HandleSizeEvent, so we need to test it separately. + ifit(process.platform === 'win32')('emits an event when a transparent window is unmaximized', async () => { + const w = new BrowserWindow({ + show: false, + frame: false, + transparent: true + }); + + const unmaximize = emittedOnce(w, 'unmaximize'); + w.show(); + w.maximize(); + w.unmaximize(); + await unmaximize; + }); + it('emits an event when window is minimized', async () => { const w = new BrowserWindow({ show: false }); const minimize = emittedOnce(w, 'minimize'); From 036a198f5299bac0eb82ece08fb1589953c16f24 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Thu, 27 Jan 2022 19:12:55 +0100 Subject: [PATCH 2/3] chore: fixup tests --- spec-main/api-browser-window-spec.ts | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/spec-main/api-browser-window-spec.ts b/spec-main/api-browser-window-spec.ts index 0549565fc024f..d4013ea9fe8eb 100644 --- a/spec-main/api-browser-window-spec.ts +++ b/spec-main/api-browser-window-spec.ts @@ -1118,7 +1118,7 @@ describe('BrowserWindow module', () => { await unmaximize; expectBoundsEqual(w.getNormalBounds(), bounds); }); - it('can check transparent window maximization', async () => { + it('correctly checks transparent window maximization state', async () => { w.destroy(); w = new BrowserWindow({ show: false, @@ -1127,12 +1127,12 @@ describe('BrowserWindow module', () => { transparent: true }); - const maximize = emittedOnce(w, 'resize'); + const maximize = emittedOnce(w, 'maximize'); w.show(); w.maximize(); await maximize; expect(w.isMaximized()).to.equal(true); - const unmaximize = emittedOnce(w, 'resize'); + const unmaximize = emittedOnce(w, 'unmaximize'); w.unmaximize(); await unmaximize; expect(w.isMaximized()).to.equal(false); @@ -3241,9 +3241,7 @@ describe('BrowserWindow module', () => { await maximize; }); - // Transparent window max/unmax uses different logic and does not go through - // NativeWindowViews::HandleSizeEvent, so we need to test it separately. - ifit(process.platform === 'win32')('emits an event when a transparent window is maximized', async () => { + it('emits an event when a transparent window is maximized', async () => { const w = new BrowserWindow({ show: false, frame: false, @@ -3274,9 +3272,7 @@ describe('BrowserWindow module', () => { await unmaximize; }); - // Transparent window max/unmax uses different logic and does not go through - // NativeWindowViews::HandleSizeEvent, so we need to test it separately. - ifit(process.platform === 'win32')('emits an event when a transparent window is unmaximized', async () => { + it('emits an event when a transparent window is unmaximized', async () => { const w = new BrowserWindow({ show: false, frame: false, From 762137cb9003011af5eca7eb4f4cfe39c6fcd5dc Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Thu, 27 Jan 2022 20:32:05 +0100 Subject: [PATCH 3/3] Update spec-main/api-browser-window-spec.ts Co-authored-by: David Sanders --- spec-main/api-browser-window-spec.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spec-main/api-browser-window-spec.ts b/spec-main/api-browser-window-spec.ts index d4013ea9fe8eb..b8ffaebff51f8 100644 --- a/spec-main/api-browser-window-spec.ts +++ b/spec-main/api-browser-window-spec.ts @@ -3279,9 +3279,11 @@ describe('BrowserWindow module', () => { transparent: true }); + const maximize = emittedOnce(w, 'maximize'); const unmaximize = emittedOnce(w, 'unmaximize'); w.show(); w.maximize(); + await maximize; w.unmaximize(); await unmaximize; });