2016-05-18 04:47:50 +00:00
|
|
|
// Copyright (c) 2016 GitHub, Inc.
|
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/browser/common_web_contents_delegate.h"
|
2016-05-18 04:47:50 +00:00
|
|
|
|
|
|
|
#import <Cocoa/Cocoa.h>
|
|
|
|
|
|
|
|
#include "content/public/browser/native_web_keyboard_event.h"
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/browser/ui/cocoa/event_dispatching_window.h"
|
|
|
|
#include "shell/browser/web_contents_preferences.h"
|
2016-05-18 04:47:50 +00:00
|
|
|
#include "ui/events/keycodes/keyboard_codes.h"
|
|
|
|
|
2016-06-19 11:16:19 +00:00
|
|
|
@interface NSWindow (EventDispatchingWindow)
|
|
|
|
- (void)redispatchKeyEvent:(NSEvent*)event;
|
|
|
|
@end
|
|
|
|
|
2016-05-18 04:47:50 +00:00
|
|
|
namespace atom {
|
|
|
|
|
2019-01-09 20:01:49 +00:00
|
|
|
bool CommonWebContentsDelegate::HandleKeyboardEvent(
|
2016-05-18 04:47:50 +00:00
|
|
|
content::WebContents* source,
|
|
|
|
const content::NativeWebKeyboardEvent& event) {
|
|
|
|
if (event.skip_in_browser ||
|
2017-06-16 20:42:33 +00:00
|
|
|
event.GetType() == content::NativeWebKeyboardEvent::kChar)
|
2019-01-09 20:01:49 +00:00
|
|
|
return false;
|
2016-05-18 04:47:50 +00:00
|
|
|
|
|
|
|
// Escape exits tabbed fullscreen mode.
|
2019-01-10 16:03:48 +00:00
|
|
|
if (event.windows_key_code == ui::VKEY_ESCAPE && is_html_fullscreen()) {
|
2016-05-18 04:47:50 +00:00
|
|
|
ExitFullscreenModeForTab(source);
|
2019-01-12 00:25:34 +00:00
|
|
|
return true;
|
2019-01-10 16:03:48 +00:00
|
|
|
}
|
2016-05-18 04:47:50 +00:00
|
|
|
|
2018-09-27 15:41:09 +00:00
|
|
|
// Check if the webContents has preferences and to ignore shortcuts
|
|
|
|
auto* web_preferences = WebContentsPreferences::From(source);
|
|
|
|
if (web_preferences &&
|
|
|
|
web_preferences->IsEnabled("ignoreMenuShortcuts", false))
|
2019-01-09 20:01:49 +00:00
|
|
|
return false;
|
2018-09-27 15:41:09 +00:00
|
|
|
|
|
|
|
// Send the event to the menu before sending it to the window
|
|
|
|
if (event.os_event.type == NSKeyDown &&
|
|
|
|
[[NSApp mainMenu] performKeyEquivalent:event.os_event])
|
2019-01-09 20:01:49 +00:00
|
|
|
return true;
|
2018-09-27 15:41:09 +00:00
|
|
|
|
|
|
|
if (event.os_event.window &&
|
2019-01-09 20:01:49 +00:00
|
|
|
[event.os_event.window isKindOfClass:[EventDispatchingWindow class]]) {
|
2018-09-27 15:41:09 +00:00
|
|
|
[event.os_event.window redispatchKeyEvent:event.os_event];
|
2019-01-09 20:01:49 +00:00
|
|
|
// 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;
|
2016-05-18 04:47:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace atom
|