Skip to content

Commit

Permalink
fix: pressing ESC should exit fullscreen from webview
Browse files Browse the repository at this point in the history
  • Loading branch information
zcbenz committed Jul 13, 2021
1 parent cd031a7 commit d9f8135
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
4 changes: 1 addition & 3 deletions shell/browser/api/electron_api_web_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3609,9 +3609,7 @@ void WebContents::UpdateHtmlApiFullscreen(bool fullscreen) {
manager->ForEachGuest(
web_contents(), base::BindRepeating([](content::WebContents* guest) {
WebContents* api_web_contents = WebContents::From(guest);
// Use UpdateHtmlApiFullscreen instead of SetXXX becuase there is no
// need to interact with the owner window.
api_web_contents->UpdateHtmlApiFullscreen(false);
api_web_contents->SetHtmlApiFullscreen(false);
return false;
}));
}
Expand Down
15 changes: 15 additions & 0 deletions spec-main/webview-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as url from 'url';
import { BrowserWindow, session, ipcMain, app, WebContents } from 'electron/main';
import { closeAllWindows } from './window-helpers';
import { emittedOnce, emittedUntil } from './events-helpers';
import { ifit, delay } from './spec-helpers';
import { expect } from 'chai';

async function loadWebView (w: WebContents, attributes: Record<string, string>, openDevTools: boolean = false): Promise<void> {
Expand Down Expand Up @@ -406,6 +407,20 @@ describe('<webview> tag', function () {
await parentFullscreen;
expect(await w.webContents.executeJavaScript('isIframeFullscreen()')).to.be.true();
});

// Sending ESC via sendInputEvent only works on Windows.
ifit(process.platform === 'win32')('pressing ESC should unfullscreen window', async () => {
const [w, webview] = await loadWebViewWindow();
const enterFullScreen = emittedOnce(w, 'enter-full-screen');
await webview.executeJavaScript('document.getElementById("div").requestFullscreen()', true);
await enterFullScreen;

const leaveFullScreen = emittedOnce(w, 'leave-full-screen');
w.webContents.sendInputEvent({ type: 'keyDown', keyCode: 'Escape' });
await leaveFullScreen;
await delay(0);
expect(w.isFullScreen()).to.be.false();
});
});

describe('nativeWindowOpen option', () => {
Expand Down

0 comments on commit d9f8135

Please sign in to comment.