feat: hide menu bar on windows fullscreen (#43402)
* feat: hide menu bar on windows fullscreen * test: state prior to html fullscreen transition * refactor: restore `#ifdef` for readability Reference: https://github.com/electron/electron/pull/43402#discussion_r1729356262 * docs: menu bar behavior changed --------- Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org>
This commit is contained in:
parent
3dd7e46291
commit
29c2744e57
3 changed files with 53 additions and 0 deletions
|
@ -14,6 +14,10 @@ This document uses the following convention to categorize breaking changes:
|
||||||
|
|
||||||
## Planned Breaking API Changes (33.0)
|
## 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`
|
### Behavior Changed: `webContents` property on `login` on `app`
|
||||||
|
|
||||||
The `webContents` property in the `login` event from `app` will be `null`
|
The `webContents` property in the `login` event from `app` will be `null`
|
||||||
|
|
|
@ -746,6 +746,24 @@ void NativeWindowViews::SetFullScreen(bool fullscreen) {
|
||||||
// Note: the following must be after "widget()->SetFullscreen(fullscreen);"
|
// Note: the following must be after "widget()->SetFullscreen(fullscreen);"
|
||||||
if (leaving_fullscreen && !IsVisible())
|
if (leaving_fullscreen && !IsVisible())
|
||||||
FlipWindowStyle(GetAcceleratedWidget(), true, WS_VISIBLE);
|
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
|
#else
|
||||||
if (IsVisible())
|
if (IsVisible())
|
||||||
widget()->SetFullscreen(fullscreen);
|
widget()->SetFullscreen(fullscreen);
|
||||||
|
|
|
@ -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', () => {
|
ifdescribe(process.platform === 'darwin')('fullscreenable state', () => {
|
||||||
it('with functions', () => {
|
it('with functions', () => {
|
||||||
it('can be set with fullscreenable constructor option', () => {
|
it('can be set with fullscreenable constructor option', () => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue