common_web_contents_delegate_mac.mm 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Copyright (c) 2016 GitHub, Inc.
  2. // Use of this source code is governed by the MIT license that can be
  3. // found in the LICENSE file.
  4. #include "atom/browser/common_web_contents_delegate.h"
  5. #import <Cocoa/Cocoa.h>
  6. #include "brightray/browser/mac/event_dispatching_window.h"
  7. #include "content/public/browser/native_web_keyboard_event.h"
  8. #include "ui/events/keycodes/keyboard_codes.h"
  9. @interface NSWindow (EventDispatchingWindow)
  10. - (void)redispatchKeyEvent:(NSEvent*)event;
  11. @end
  12. namespace atom {
  13. void CommonWebContentsDelegate::HandleKeyboardEvent(
  14. content::WebContents* source,
  15. const content::NativeWebKeyboardEvent& event) {
  16. if (event.skip_in_browser ||
  17. event.GetType() == content::NativeWebKeyboardEvent::kChar)
  18. return;
  19. // Escape exits tabbed fullscreen mode.
  20. if (event.windows_key_code == ui::VKEY_ESCAPE && is_html_fullscreen())
  21. ExitFullscreenModeForTab(source);
  22. if (!ignore_menu_shortcuts_) {
  23. // Send the event to the menu before sending it to the window
  24. if (event.os_event.type == NSKeyDown &&
  25. [[NSApp mainMenu] performKeyEquivalent:event.os_event])
  26. return;
  27. if (event.os_event.window &&
  28. [event.os_event.window isKindOfClass:[EventDispatchingWindow class]])
  29. [event.os_event.window redispatchKeyEvent:event.os_event];
  30. }
  31. }
  32. } // namespace atom