Adds the ability for WebContentsDelegate to decide if event should be updated

https://codereview.chromium.org/2775553002
This commit is contained in:
Aleksei Kuzmin 2017-06-17 00:35:43 +03:00
parent d322769de8
commit 9b8a77f0d8
2 changed files with 12 additions and 9 deletions

View file

@ -587,16 +587,18 @@ void WebContents::HandleKeyboardEvent(
} }
} }
bool WebContents::PreHandleKeyboardEvent( content::KeyboardEventProcessingResult WebContents::PreHandleKeyboardEvent(
content::WebContents* source, content::WebContents* source,
const content::NativeWebKeyboardEvent& event, const content::NativeWebKeyboardEvent& event) {
bool* is_keyboard_shortcut) {
if (event.GetType() == blink::WebInputEvent::Type::kRawKeyDown || if (event.GetType() == blink::WebInputEvent::Type::kRawKeyDown ||
event.GetType() == blink::WebInputEvent::Type::kKeyUp) { event.GetType() == blink::WebInputEvent::Type::kKeyUp) {
return Emit("before-input-event", event); bool prevent_default = Emit("before-input-event", event);
} else { if (prevent_default) {
return false; return content::KeyboardEventProcessingResult::HANDLED;
}
} }
return content::KeyboardEventProcessingResult::NOT_HANDLED;
} }
void WebContents::EnterFullscreenModeForTab(content::WebContents* source, void WebContents::EnterFullscreenModeForTab(content::WebContents* source,

View file

@ -14,6 +14,7 @@
#include "atom/browser/common_web_contents_delegate.h" #include "atom/browser/common_web_contents_delegate.h"
#include "atom/browser/ui/autofill_popup.h" #include "atom/browser/ui/autofill_popup.h"
#include "content/common/cursors/webcursor.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/browser/web_contents_observer.h"
#include "content/public/common/favicon_url.h" #include "content/public/common/favicon_url.h"
#include "native_mate/handle.h" #include "native_mate/handle.h"
@ -268,9 +269,9 @@ class WebContents : public mate::TrackableObject<WebContents>,
void HandleKeyboardEvent( void HandleKeyboardEvent(
content::WebContents* source, content::WebContents* source,
const content::NativeWebKeyboardEvent& event) override; const content::NativeWebKeyboardEvent& event) override;
bool PreHandleKeyboardEvent(content::WebContents* source, content::KeyboardEventProcessingResult PreHandleKeyboardEvent(
const content::NativeWebKeyboardEvent& event, content::WebContents* source,
bool* is_keyboard_shortcut) override; const content::NativeWebKeyboardEvent& event) override;
void EnterFullscreenModeForTab(content::WebContents* source, void EnterFullscreenModeForTab(content::WebContents* source,
const GURL& origin) override; const GURL& origin) override;
void ExitFullscreenModeForTab(content::WebContents* source) override; void ExitFullscreenModeForTab(content::WebContents* source) override;