diff --git a/atom/browser/api/atom_api_browser_window.cc b/atom/browser/api/atom_api_browser_window.cc index 98ea05bfec..75aa476469 100644 --- a/atom/browser/api/atom_api_browser_window.cc +++ b/atom/browser/api/atom_api_browser_window.cc @@ -270,6 +270,14 @@ void BrowserWindow::OnWindowResize() { TopLevelWindow::OnWindowResize(); } +void BrowserWindow::OnWindowLeaveFullScreen() { + TopLevelWindow::OnWindowLeaveFullScreen(); +#if defined(OS_MACOSX) + if (web_contents()->IsFullscreenForCurrentTab()) + web_contents()->ExitFullscreen(true); +#endif +} + void BrowserWindow::Focus() { if (api_web_contents_->IsOffScreen()) FocusOnWebView(); diff --git a/atom/browser/api/atom_api_browser_window.h b/atom/browser/api/atom_api_browser_window.h index 5f9610f3a3..37a8a4868d 100644 --- a/atom/browser/api/atom_api_browser_window.h +++ b/atom/browser/api/atom_api_browser_window.h @@ -66,6 +66,7 @@ class BrowserWindow : public TopLevelWindow, void OnWindowBlur() override; void OnWindowFocus() override; void OnWindowResize() override; + void OnWindowLeaveFullScreen() override; void Focus() override; void Blur() override; void SetBackgroundColor(const std::string& color_name) override; diff --git a/spec/api-browser-window-spec.js b/spec/api-browser-window-spec.js index 711354fd6d..4bd8c5b992 100644 --- a/spec/api-browser-window-spec.js +++ b/spec/api-browser-window-spec.js @@ -2590,6 +2590,29 @@ describe('BrowserWindow module', () => { }) }) + describe('BrowserWindow.setFullScreen(false) when HTML fullscreen', () => { + before(function () { + if (process.platform !== 'darwin') { + this.skip() + } + }) + + it('exits HTML fullscreen when window leaves fullscreen', (done) => { + w.destroy() + w = new BrowserWindow() + w.webContents.once('did-finish-load', () => { + w.once('enter-full-screen', () => { + w.once('leave-html-full-screen', () => { + done() + }) + w.setFullScreen(false) + }) + w.webContents.executeJavaScript('document.body.webkitRequestFullscreen()', true) + }) + w.loadURL('about:blank') + }) + }) + describe('parent window', () => { let c = null