From 9b8a77f0d8996ff24fcaaa033594fb8165aedefe Mon Sep 17 00:00:00 2001 From: Aleksei Kuzmin Date: Sat, 17 Jun 2017 00:35:43 +0300 Subject: [PATCH] Adds the ability for WebContentsDelegate to decide if event should be updated https://codereview.chromium.org/2775553002 --- atom/browser/api/atom_api_web_contents.cc | 14 ++++++++------ atom/browser/api/atom_api_web_contents.h | 7 ++++--- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index 27925c52e74c..e9a4012ff4e0 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -587,16 +587,18 @@ void WebContents::HandleKeyboardEvent( } } -bool WebContents::PreHandleKeyboardEvent( +content::KeyboardEventProcessingResult WebContents::PreHandleKeyboardEvent( content::WebContents* source, - const content::NativeWebKeyboardEvent& event, - bool* is_keyboard_shortcut) { + const content::NativeWebKeyboardEvent& event) { if (event.GetType() == blink::WebInputEvent::Type::kRawKeyDown || event.GetType() == blink::WebInputEvent::Type::kKeyUp) { - return Emit("before-input-event", event); - } else { - return false; + bool prevent_default = Emit("before-input-event", event); + if (prevent_default) { + return content::KeyboardEventProcessingResult::HANDLED; + } } + + return content::KeyboardEventProcessingResult::NOT_HANDLED; } void WebContents::EnterFullscreenModeForTab(content::WebContents* source, diff --git a/atom/browser/api/atom_api_web_contents.h b/atom/browser/api/atom_api_web_contents.h index 1270a0ce2c79..dbc388bbec9a 100644 --- a/atom/browser/api/atom_api_web_contents.h +++ b/atom/browser/api/atom_api_web_contents.h @@ -14,6 +14,7 @@ #include "atom/browser/common_web_contents_delegate.h" #include "atom/browser/ui/autofill_popup.h" #include "content/common/cursors/webcursor.h" +#include "content/public/browser/keyboard_event_processing_result.h" #include "content/public/browser/web_contents_observer.h" #include "content/public/common/favicon_url.h" #include "native_mate/handle.h" @@ -268,9 +269,9 @@ class WebContents : public mate::TrackableObject, void HandleKeyboardEvent( content::WebContents* source, const content::NativeWebKeyboardEvent& event) override; - bool PreHandleKeyboardEvent(content::WebContents* source, - const content::NativeWebKeyboardEvent& event, - bool* is_keyboard_shortcut) override; + content::KeyboardEventProcessingResult PreHandleKeyboardEvent( + content::WebContents* source, + const content::NativeWebKeyboardEvent& event) override; void EnterFullscreenModeForTab(content::WebContents* source, const GURL& origin) override; void ExitFullscreenModeForTab(content::WebContents* source) override;