fix: handle shortcuts by default if no WebPreferences object exists (#15066)

This commit is contained in:
Shelley Vohr 2018-10-10 19:37:55 -07:00 committed by Samuel Attard
parent 3d8af9d279
commit 502b0b988e
6 changed files with 579 additions and 19 deletions

View file

@ -28,18 +28,20 @@ void CommonWebContentsDelegate::HandleKeyboardEvent(
if (event.windows_key_code == ui::VKEY_ESCAPE && is_html_fullscreen())
ExitFullscreenModeForTab(source);
if (auto* web_preferences = WebContentsPreferences::From(source)) {
if (!web_preferences->IsEnabled("ignoreMenuShortcuts", 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;
// 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;
if (event.os_event.window &&
[event.os_event.window isKindOfClass:[EventDispatchingWindow class]])
[event.os_event.window redispatchKeyEvent:event.os_event];
}
}
// 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;
if (event.os_event.window &&
[event.os_event.window isKindOfClass:[EventDispatchingWindow class]])
[event.os_event.window redispatchKeyEvent:event.os_event];
}
} // namespace atom

View file

@ -24,12 +24,15 @@ void CommonWebContentsDelegate::HandleKeyboardEvent(
if (event.windows_key_code == ui::VKEY_ESCAPE && is_html_fullscreen())
ExitFullscreenModeForTab(source);
// 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;
// Let the NativeWindow handle other parts.
if (auto* web_preferences = WebContentsPreferences::From(source)) {
if (owner_window() &&
!web_preferences->IsEnabled("ignoreMenuShortcuts", false)) {
owner_window()->HandleKeyboardEvent(source, event);
}
if (owner_window()) {
owner_window()->HandleKeyboardEvent(source, event);
}
}