From 30e5e993c12659675197e4b05fcf8d8af4b53ec7 Mon Sep 17 00:00:00 2001 From: Jeremy Apthorp Date: Wed, 9 Jan 2019 12:01:49 -0800 Subject: [PATCH] HandleKeyboardEvent returns bool https://chromium-review.googlesource.com/c/chromium/src/+/1262404 --- atom/browser/api/atom_api_web_contents.cc | 6 +++--- atom/browser/api/atom_api_web_contents.h | 2 +- atom/browser/common_web_contents_delegate.h | 2 +- .../browser/common_web_contents_delegate_mac.mm | 17 ++++++++++++----- .../common_web_contents_delegate_views.cc | 9 ++++++--- .../browser/ui/inspectable_web_contents_impl.cc | 5 ++--- atom/browser/ui/inspectable_web_contents_impl.h | 2 +- 7 files changed, 26 insertions(+), 17 deletions(-) diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index 00f74f97a8f0..bca6c651308f 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -617,15 +617,15 @@ void WebContents::UpdateTargetURL(content::WebContents* source, Emit("update-target-url", url); } -void WebContents::HandleKeyboardEvent( +bool WebContents::HandleKeyboardEvent( content::WebContents* source, const content::NativeWebKeyboardEvent& event) { if (type_ == WEB_VIEW && embedder_) { // Send the unhandled keyboard events back to the embedder. - embedder_->HandleKeyboardEvent(source, event); + return embedder_->HandleKeyboardEvent(source, event); } else { // Go to the default keyboard handling. - CommonWebContentsDelegate::HandleKeyboardEvent(source, event); + return CommonWebContentsDelegate::HandleKeyboardEvent(source, event); } } diff --git a/atom/browser/api/atom_api_web_contents.h b/atom/browser/api/atom_api_web_contents.h index ebf75ead1879..59067e3dd7d1 100644 --- a/atom/browser/api/atom_api_web_contents.h +++ b/atom/browser/api/atom_api_web_contents.h @@ -362,7 +362,7 @@ class WebContents : public mate::TrackableObject, void CloseContents(content::WebContents* source) override; void ActivateContents(content::WebContents* contents) override; void UpdateTargetURL(content::WebContents* source, const GURL& url) override; - void HandleKeyboardEvent( + bool HandleKeyboardEvent( content::WebContents* source, const content::NativeWebKeyboardEvent& event) override; content::KeyboardEventProcessingResult PreHandleKeyboardEvent( diff --git a/atom/browser/common_web_contents_delegate.h b/atom/browser/common_web_contents_delegate.h index f575e9872de7..d38aa16082e3 100644 --- a/atom/browser/common_web_contents_delegate.h +++ b/atom/browser/common_web_contents_delegate.h @@ -100,7 +100,7 @@ class CommonWebContentsDelegate : public content::WebContentsDelegate, content::WebContents* web_contents, content::SecurityStyleExplanations* explanations) override; bool TakeFocus(content::WebContents* source, bool reverse) override; - void HandleKeyboardEvent( + bool HandleKeyboardEvent( content::WebContents* source, const content::NativeWebKeyboardEvent& event) override; diff --git a/atom/browser/common_web_contents_delegate_mac.mm b/atom/browser/common_web_contents_delegate_mac.mm index f8f7fafc6fa7..1611e156c0f0 100644 --- a/atom/browser/common_web_contents_delegate_mac.mm +++ b/atom/browser/common_web_contents_delegate_mac.mm @@ -17,12 +17,12 @@ namespace atom { -void CommonWebContentsDelegate::HandleKeyboardEvent( +bool CommonWebContentsDelegate::HandleKeyboardEvent( content::WebContents* source, const content::NativeWebKeyboardEvent& event) { if (event.skip_in_browser || event.GetType() == content::NativeWebKeyboardEvent::kChar) - return; + return false; // Escape exits tabbed fullscreen mode. if (event.windows_key_code == ui::VKEY_ESCAPE && is_html_fullscreen()) { @@ -34,16 +34,23 @@ void CommonWebContentsDelegate::HandleKeyboardEvent( auto* web_preferences = WebContentsPreferences::From(source); if (web_preferences && web_preferences->IsEnabled("ignoreMenuShortcuts", false)) - return; + return false; // Send the event to the menu before sending it to the window if (event.os_event.type == NSKeyDown && [[NSApp mainMenu] performKeyEquivalent:event.os_event]) - return; + return true; if (event.os_event.window && - [event.os_event.window isKindOfClass:[EventDispatchingWindow class]]) + [event.os_event.window isKindOfClass:[EventDispatchingWindow class]]) { [event.os_event.window redispatchKeyEvent:event.os_event]; + // FIXME(nornagon): this isn't the right return value; we should implement + // devtools windows as Widgets in order to take advantage of the + // pre-existing redispatch code in bridged_native_widget. + return false; + } + + return false; } } // namespace atom diff --git a/atom/browser/common_web_contents_delegate_views.cc b/atom/browser/common_web_contents_delegate_views.cc index c1b1f5e57ef4..5170bd1cbfe3 100644 --- a/atom/browser/common_web_contents_delegate_views.cc +++ b/atom/browser/common_web_contents_delegate_views.cc @@ -17,25 +17,28 @@ namespace atom { -void CommonWebContentsDelegate::HandleKeyboardEvent( +bool CommonWebContentsDelegate::HandleKeyboardEvent( content::WebContents* source, const content::NativeWebKeyboardEvent& event) { // Escape exits tabbed fullscreen mode. if (event.windows_key_code == ui::VKEY_ESCAPE && is_html_fullscreen()) { ExitFullscreenModeForTab(source); - return; + return true; } // Check if the webContents has preferences and to ignore shortcuts auto* web_preferences = WebContentsPreferences::From(source); if (web_preferences && web_preferences->IsEnabled("ignoreMenuShortcuts", false)) - return; + return false; // Let the NativeWindow handle other parts. if (owner_window()) { owner_window()->HandleKeyboardEvent(source, event); + return true; } + + return false; } void CommonWebContentsDelegate::ShowAutofillPopup( diff --git a/atom/browser/ui/inspectable_web_contents_impl.cc b/atom/browser/ui/inspectable_web_contents_impl.cc index 6f29c9180b3c..5b08e79d73c2 100644 --- a/atom/browser/ui/inspectable_web_contents_impl.cc +++ b/atom/browser/ui/inspectable_web_contents_impl.cc @@ -779,12 +779,11 @@ bool InspectableWebContentsImpl::ShouldCreateWebContents( return false; } -void InspectableWebContentsImpl::HandleKeyboardEvent( +bool InspectableWebContentsImpl::HandleKeyboardEvent( content::WebContents* source, const content::NativeWebKeyboardEvent& event) { auto* delegate = web_contents_->GetDelegate(); - if (delegate) - delegate->HandleKeyboardEvent(source, event); + return !delegate || delegate->HandleKeyboardEvent(source, event); } void InspectableWebContentsImpl::CloseContents(content::WebContents* source) { diff --git a/atom/browser/ui/inspectable_web_contents_impl.h b/atom/browser/ui/inspectable_web_contents_impl.h index 90bda6070bf2..f60a19f2fdc1 100644 --- a/atom/browser/ui/inspectable_web_contents_impl.h +++ b/atom/browser/ui/inspectable_web_contents_impl.h @@ -182,7 +182,7 @@ class InspectableWebContentsImpl const GURL& target_url, const std::string& partition_id, content::SessionStorageNamespace* session_storage_namespace) override; - void HandleKeyboardEvent(content::WebContents*, + bool HandleKeyboardEvent(content::WebContents*, const content::NativeWebKeyboardEvent&) override; void CloseContents(content::WebContents* source) override; content::ColorChooser* OpenColorChooser(