HandleKeyboardEvent returns bool

https://chromium-review.googlesource.com/c/chromium/src/+/1262404
This commit is contained in:
Jeremy Apthorp 2019-01-09 12:01:49 -08:00
parent fd7b49b32b
commit 30e5e993c1
7 changed files with 26 additions and 17 deletions

View file

@ -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);
}
}

View file

@ -362,7 +362,7 @@ class WebContents : public mate::TrackableObject<WebContents>,
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(

View file

@ -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;

View file

@ -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

View file

@ -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(

View file

@ -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) {

View file

@ -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(