In fullscreen mode, pass <esc> to outmost WebContents.
When an inner WebContents is fullscreen, and has focus, pressing <esc>
causes the keyboard event to be handled by that webcontents. But it
should instead be handled by the outermost WebContents so that it can
get to the appropriate delegate.
Bug: 1013640
Change-Id: I4ff81bea8cd9fa43259dde39b3bc479f6fd06f07
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1896771
Reviewed-by: Istiaque Ahmed <[email protected]>
Reviewed-by: Scott Violet <[email protected]>
Reviewed-by: Alex Moshchuk <[email protected]>
Commit-Queue: James MacLean <[email protected]>
Cr-Commit-Position: refs/heads/master@{#714386}
diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc
index 8bb7713..15e5b38 100644
--- a/content/browser/web_contents/web_contents_impl.cc
+++ b/content/browser/web_contents/web_contents_impl.cc
@@ -2288,6 +2288,19 @@
KeyboardEventProcessingResult WebContentsImpl::PreHandleKeyboardEvent(
const NativeWebKeyboardEvent& event) {
+ auto* outermost_contents = GetOutermostWebContents();
+ // TODO(wjmaclean): Generalize this to forward all key events to the outermost
+ // delegate's handler.
+ if (outermost_contents != this && IsFullscreenForCurrentTab() &&
+ event.windows_key_code == ui::VKEY_ESCAPE) {
+ // When an inner WebContents has focus and is fullscreen, redirect <esc>
+ // key events to the outermost WebContents so it can be handled by that
+ // WebContents' delegate.
+ if (outermost_contents->PreHandleKeyboardEvent(event) ==
+ KeyboardEventProcessingResult::HANDLED) {
+ return KeyboardEventProcessingResult::HANDLED;
+ }
+ }
return delegate_ ? delegate_->PreHandleKeyboardEvent(this, event)
: KeyboardEventProcessingResult::NOT_HANDLED;
}