fix: only exit fullscreen conditionally with setKiosk (#38219)

fix: only exit fullscreen conditionally with setKiosk
This commit is contained in:
Shelley Vohr 2023-05-09 18:28:37 +02:00 committed by GitHub
parent f432245456
commit 13e309e1fb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 8 deletions

View file

@ -234,6 +234,7 @@ class NativeWindowMac : public NativeWindow,
// The views::View that fills the client area.
std::unique_ptr<RootViewMac> root_view_;
bool fullscreen_before_kiosk_ = false;
bool is_kiosk_ = false;
bool zoom_to_page_width_ = false;
absl::optional<gfx::Point> traffic_light_position_;

View file

@ -1029,10 +1029,13 @@ void NativeWindowMac::SetKiosk(bool kiosk) {
NSApplicationPresentationDisableHideApplication;
[NSApp setPresentationOptions:options];
is_kiosk_ = true;
SetFullScreen(true);
fullscreen_before_kiosk_ = IsFullscreen();
if (!fullscreen_before_kiosk_)
SetFullScreen(true);
} else if (!kiosk && is_kiosk_) {
is_kiosk_ = false;
SetFullScreen(false);
if (!fullscreen_before_kiosk_)
SetFullScreen(false);
// Set presentation options *after* asynchronously exiting
// fullscreen to ensure they take effect.

View file

@ -5521,19 +5521,32 @@ describe('BrowserWindow module', () => {
it('should not be changed by setKiosk method', async () => {
const w = new BrowserWindow();
const enterFullScreen = once(w, 'enter-full-screen');
w.setKiosk(true);
await enterFullScreen;
expect(w.isFullScreen()).to.be.true('isFullScreen');
const leaveFullScreen = once(w, 'leave-full-screen');
w.setKiosk(false);
await leaveFullScreen;
expect(w.isFullScreen()).to.be.false('isFullScreen');
});
it('should stay fullscreen if fullscreen before kiosk', async () => {
const w = new BrowserWindow();
const enterFullScreen = once(w, 'enter-full-screen');
w.setFullScreen(true);
await enterFullScreen;
expect(w.isFullScreen()).to.be.true('isFullScreen');
await setTimeout();
w.setKiosk(true);
await setTimeout();
w.setKiosk(false);
// Wait enough time for a fullscreen change to take effect.
await setTimeout(2000);
expect(w.isFullScreen()).to.be.true('isFullScreen');
const leaveFullScreen = once(w, 'leave-full-screen');
w.setFullScreen(false);
await leaveFullScreen;
expect(w.isFullScreen()).to.be.false('isFullScreen');
});
it('multiple windows inherit correct fullscreen state', async () => {