Chromium Code Reviews| Index: chrome/browser/ui/views/frame/browser_frame_mac.mm |
| diff --git a/chrome/browser/ui/views/frame/browser_frame_mac.mm b/chrome/browser/ui/views/frame/browser_frame_mac.mm |
| index 5e0242dd9be3f5e00a98808a45081af35210d0a5..94813f1aea77deb7840fb78be073af1f91161b78 100644 |
| --- a/chrome/browser/ui/views/frame/browser_frame_mac.mm |
| +++ b/chrome/browser/ui/views/frame/browser_frame_mac.mm |
| @@ -4,14 +4,52 @@ |
| #include "chrome/browser/ui/views/frame/browser_frame_mac.h" |
| +#include "chrome/browser/global_keyboard_shortcuts_mac.h" |
| +#include "chrome/browser/ui/browser_command_controller.h" |
| +#include "chrome/browser/ui/browser_commands.h" |
| #import "chrome/browser/ui/cocoa/browser_window_command_handler.h" |
| #import "chrome/browser/ui/cocoa/chrome_command_dispatcher_delegate.h" |
| +#import "chrome/browser/ui/cocoa/chrome_command_dispatcher_delegate.h" |
| #include "chrome/browser/ui/views/frame/browser_frame.h" |
| #include "chrome/browser/ui/views/frame/browser_view.h" |
| #import "chrome/browser/ui/views/frame/native_widget_mac_frameless_nswindow.h" |
| #include "components/web_modal/web_contents_modal_dialog_host.h" |
| +#include "content/public/browser/native_web_keyboard_event.h" |
| #import "ui/base/cocoa/window_size_constants.h" |
| +namespace { |
| + |
| +bool ShouldHandleKeyboardEvent(const content::NativeWebKeyboardEvent& event) { |
|
tapted
2016/10/26 08:40:47
comment?
themblsha
2016/10/26 17:10:03
It's adapted from +[BrowserWindowUtils shouldHandl
tapted
2016/10/28 04:59:48
Hm - it's possible that this and HandleExtraKeyboa
themblsha
2016/10/28 17:32:22
Without my changes the only code path that should
|
| + // Do not fire shortcuts on key up. |
| + if ([event.os_event type] != NSKeyDown) |
| + return false; |
| + |
| + if (event.skip_in_browser || |
| + event.type == content::NativeWebKeyboardEvent::Char) |
| + return false; |
| + |
| + DCHECK(event.os_event != NULL); |
|
tapted
2016/10/26 08:40:47
DCHECK(event.os_event) - this should probably be a
themblsha
2016/10/28 17:32:22
I guess it could fail in case the event was simula
tapted
2016/10/31 10:16:57
Ah, good point - I think I've encountered strangen
themblsha
2016/10/31 16:56:29
Makes sense, done.
|
| + return true; |
| +} |
| + |
| +// Copied from chrome_command_dispatcher_delegate.mm's |
| +// HandleExtraBrowserKeyboardShortcut and adapted for MacViews to only consult |
| +// the CommandForMacViewsKeyboardShortcut table. |
| +bool HandleExtraKeyboardShortcut(NSEvent* event, Browser* browser) { |
| + // Send the event to the menu before sending it to the browser/window |
| + // shortcut handling, so that if a user configures cmd-left to mean |
| + // "previous tab", it takes precedence over the built-in "history back" |
| + // binding. |
| + if ([[NSApp mainMenu] performKeyEquivalent:event]) |
| + return true; |
| + |
| + return command_dispatcher::HandleExtraKeyboardShortcut( |
| + event, browser->window()->GetNativeWindow(), |
| + CommandForMacViewsKeyboardShortcut); |
| +} |
| + |
| +} // namespace |
| + |
| BrowserFrameMac::BrowserFrameMac(BrowserFrame* browser_frame, |
| BrowserView* browser_view) |
| : views::NativeWidgetMac(browser_frame), |
| @@ -68,6 +106,11 @@ NativeWidgetMacNSWindow* BrowserFrameMac::CreateNSWindow( |
| return ns_window.autorelease(); |
| } |
| +int BrowserFrameMac::GetMinimizeButtonOffset() const { |
| + NOTIMPLEMENTED(); |
| + return 0; |
| +} |
| + |
| //////////////////////////////////////////////////////////////////////////////// |
| // BrowserFrameMac, NativeBrowserFrame implementation: |
| @@ -95,7 +138,30 @@ void BrowserFrameMac::GetWindowPlacement( |
| return NativeWidgetMac::GetWindowPlacement(bounds, show_state); |
| } |
| -int BrowserFrameMac::GetMinimizeButtonOffset() const { |
| - NOTIMPLEMENTED(); |
| - return 0; |
| +bool BrowserFrameMac::PreHandleKeyboardEvent( |
| + const content::NativeWebKeyboardEvent& event) { |
| + // Copied from BrowserWindowCocoa::PreHandleKeyboardEvent(). |
|
tapted
2016/10/26 08:40:47
BrowserWindowCocoa may not be with us forever, so
themblsha
2016/10/28 17:32:22
Tried my best to fill the code with sensible comme
|
| + if (!ShouldHandleKeyboardEvent(event)) |
| + return false; |
| + |
| + // CommandForKeyEventOnMacViews consults the [NSApp mainMenu] and |
| + // CommandForMacViewsKeyboardShortcut accelerator table internally. |
| + int command_id = CommandForKeyEventOnMacViews(event.os_event); |
| + if (command_id == -1) |
| + return false; |
| + |
| + Browser* browser = browser_view_->browser(); |
| + if (!browser->command_controller()->IsReservedCommandOrKey( |
| + command_id, event)) |
| + return false; |
| + |
| + return HandleExtraKeyboardShortcut(event.os_event, browser); |
| +} |
| + |
| +bool BrowserFrameMac::HandleKeyboardEvent( |
| + const content::NativeWebKeyboardEvent& event) { |
| + if (!ShouldHandleKeyboardEvent(event)) |
| + return false; |
| + |
| + return HandleExtraKeyboardShortcut(event.os_event, browser_view_->browser()); |
| } |