diff --git a/docs/breaking-changes.md b/docs/breaking-changes.md index ea6e7149de..5e14d39513 100644 --- a/docs/breaking-changes.md +++ b/docs/breaking-changes.md @@ -14,6 +14,10 @@ This document uses the following convention to categorize breaking changes: ## Planned Breaking API Changes (33.0) +### Behavior Changed: menu bar will be hidden during fullscreen on Windows + +This brings the behavior to parity with Linux. Prior behavior: Menu bar is still visible during fullscreen on Windows. New behavior: Menu bar is hidden during fullscreen on Windows. + ### Behavior Changed: `webContents` property on `login` on `app` The `webContents` property in the `login` event from `app` will be `null` diff --git a/shell/browser/native_window_views.cc b/shell/browser/native_window_views.cc index 91745ce91b..29c0b14ccf 100644 --- a/shell/browser/native_window_views.cc +++ b/shell/browser/native_window_views.cc @@ -746,6 +746,24 @@ void NativeWindowViews::SetFullScreen(bool fullscreen) { // Note: the following must be after "widget()->SetFullscreen(fullscreen);" if (leaving_fullscreen && !IsVisible()) FlipWindowStyle(GetAcceleratedWidget(), true, WS_VISIBLE); + + // Auto-hide menubar when in fullscreen. + if (fullscreen) { + menu_bar_visible_before_fullscreen_ = IsMenuBarVisible(); + SetMenuBarVisibility(false); + } else { + // No fullscreen -> fullscreen video -> un-fullscreen video results + // in `NativeWindowViews::SetFullScreen(false)` being called twice. + // `menu_bar_visible_before_fullscreen_` is always false on the + // second call which results in `SetMenuBarVisibility(false)` no + // matter what. We check `leaving_fullscreen` to avoid this. + if (!leaving_fullscreen) + return; + + SetMenuBarVisibility(!IsMenuBarAutoHide() && + menu_bar_visible_before_fullscreen_); + menu_bar_visible_before_fullscreen_ = false; + } #else if (IsVisible()) widget()->SetFullscreen(fullscreen); diff --git a/spec/api-browser-window-spec.ts b/spec/api-browser-window-spec.ts index 91a55b9932..5ec083a0c3 100644 --- a/spec/api-browser-window-spec.ts +++ b/spec/api-browser-window-spec.ts @@ -5630,6 +5630,37 @@ describe('BrowserWindow module', () => { }); }); + ifdescribe(process.platform !== 'darwin')('fullscreen state', () => { + it('correctly remembers state prior to HTML fullscreen transition', async () => { + const w = new BrowserWindow(); + await w.loadFile(path.join(fixtures, 'pages', 'a.html')); + + expect(w.isMenuBarVisible()).to.be.true('isMenuBarVisible'); + expect(w.isFullScreen()).to.be.false('is fullscreen'); + + const enterFullScreen = once(w, 'enter-full-screen'); + const leaveFullScreen = once(w, 'leave-full-screen'); + + await w.webContents.executeJavaScript('document.getElementById("div").requestFullscreen()', true); + await enterFullScreen; + await w.webContents.executeJavaScript('document.exitFullscreen()', true); + await leaveFullScreen; + + expect(w.isFullScreen()).to.be.false('is fullscreen'); + expect(w.isMenuBarVisible()).to.be.true('isMenuBarVisible'); + + w.setMenuBarVisibility(false); + expect(w.isMenuBarVisible()).to.be.false('isMenuBarVisible'); + + await w.webContents.executeJavaScript('document.getElementById("div").requestFullscreen()', true); + await enterFullScreen; + await w.webContents.executeJavaScript('document.exitFullscreen()', true); + await leaveFullScreen; + + expect(w.isMenuBarVisible()).to.be.false('isMenuBarVisible'); + }); + }); + ifdescribe(process.platform === 'darwin')('fullscreenable state', () => { it('with functions', () => { it('can be set with fullscreenable constructor option', () => {