From c8bdd014c87b5c33b77c845f853b7e52bb31de8f Mon Sep 17 00:00:00 2001 From: wgsheng <88312105+wugaosheng123@users.noreply.github.com> Date: Thu, 8 Jun 2023 18:19:34 +0800 Subject: [PATCH] fix: menu bar visibility when exiting full screen (#38599) --- shell/browser/native_window_views.cc | 10 +++++-- shell/browser/native_window_views.h | 3 ++ spec/api-browser-window-spec.ts | 42 ++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 3 deletions(-) diff --git a/shell/browser/native_window_views.cc b/shell/browser/native_window_views.cc index 0298aba40c65..a1581d98d002 100644 --- a/shell/browser/native_window_views.cc +++ b/shell/browser/native_window_views.cc @@ -731,10 +731,14 @@ void NativeWindowViews::SetFullScreen(bool fullscreen) { gfx::Rect()); // Auto-hide menubar when in fullscreen. - if (fullscreen) + if (fullscreen) { + menu_bar_visible_before_fullscreen_ = IsMenuBarVisible(); SetMenuBarVisibility(false); - else - SetMenuBarVisibility(!IsMenuBarAutoHide()); + } else { + SetMenuBarVisibility(!IsMenuBarAutoHide() && + menu_bar_visible_before_fullscreen_); + menu_bar_visible_before_fullscreen_ = false; + } #endif } diff --git a/shell/browser/native_window_views.h b/shell/browser/native_window_views.h index 179f4575b2c5..942dfc0460d6 100644 --- a/shell/browser/native_window_views.h +++ b/shell/browser/native_window_views.h @@ -321,6 +321,9 @@ class NativeWindowViews : public NativeWindow, // Handles unhandled keyboard messages coming back from the renderer process. views::UnhandledKeyboardEventHandler keyboard_event_handler_; + // Whether the menubar is visible before the window enters fullscreen + bool menu_bar_visible_before_fullscreen_ = false; + // Whether the window should be enabled based on user calls to SetEnabled() bool is_enabled_ = true; // How many modal children this window has; diff --git a/spec/api-browser-window-spec.ts b/spec/api-browser-window-spec.ts index 8fb8b50598c2..4e421ae744e9 100644 --- a/spec/api-browser-window-spec.ts +++ b/spec/api-browser-window-spec.ts @@ -5353,6 +5353,48 @@ describe('BrowserWindow module', () => { }); }); + ifdescribe(process.platform !== 'darwin')('when fullscreen state is changed', () => { + it('correctly remembers state prior to fullscreen change', async () => { + const w = new BrowserWindow({ show: false }); + expect(w.isMenuBarVisible()).to.be.true('isMenuBarVisible'); + w.setMenuBarVisibility(false); + expect(w.isMenuBarVisible()).to.be.false('isMenuBarVisible'); + + const enterFS = once(w, 'enter-full-screen'); + w.setFullScreen(true); + await enterFS; + expect(w.fullScreen).to.be.true('not fullscreen'); + + const exitFS = once(w, 'leave-full-screen'); + w.setFullScreen(false); + await exitFS; + expect(w.fullScreen).to.be.false('not fullscreen'); + + expect(w.isMenuBarVisible()).to.be.false('isMenuBarVisible'); + }); + + it('correctly remembers state prior to fullscreen change with autoHide', async () => { + const w = new BrowserWindow({ show: false }); + expect(w.autoHideMenuBar).to.be.false('autoHideMenuBar'); + w.autoHideMenuBar = true; + expect(w.autoHideMenuBar).to.be.true('autoHideMenuBar'); + w.setMenuBarVisibility(false); + expect(w.isMenuBarVisible()).to.be.false('isMenuBarVisible'); + + const enterFS = once(w, 'enter-full-screen'); + w.setFullScreen(true); + await enterFS; + expect(w.fullScreen).to.be.true('not fullscreen'); + + const exitFS = once(w, 'leave-full-screen'); + w.setFullScreen(false); + await exitFS; + expect(w.fullScreen).to.be.false('not fullscreen'); + + expect(w.isMenuBarVisible()).to.be.false('isMenuBarVisible'); + }); + }); + ifdescribe(process.platform === 'darwin')('fullscreenable state', () => { it('with functions', () => { it('can be set with fullscreenable constructor option', () => {