Index: chrome/browser/ui/cocoa/browser_window_utils.mm |
diff --git a/chrome/browser/ui/cocoa/browser_window_utils.mm b/chrome/browser/ui/cocoa/browser_window_utils.mm |
index 83c73b50508a1126504df468c718d56bee16a806..60dd4d1f8827371fc63ecfb3f2469b5eef29e278 100644 |
--- a/chrome/browser/ui/cocoa/browser_window_utils.mm |
+++ b/chrome/browser/ui/cocoa/browser_window_utils.mm |
@@ -11,40 +11,11 @@ |
#include "chrome/browser/global_keyboard_shortcuts_mac.h" |
#include "chrome/browser/ui/browser.h" |
#import "chrome/browser/ui/cocoa/chrome_event_processing_window.h" |
-#import "chrome/browser/ui/cocoa/nsmenuitem_additions.h" |
#import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h" |
#include "content/public/browser/native_web_keyboard_event.h" |
using content::NativeWebKeyboardEvent; |
-@interface MenuWalker : NSObject |
-+ (NSMenuItem*)itemForKeyEquivalent:(NSEvent*)key |
- menu:(NSMenu*)menu; |
-@end |
- |
-@implementation MenuWalker |
-+ (NSMenuItem*)itemForKeyEquivalent:(NSEvent*)key |
Robert Sesek
2015/03/31 22:51:36
(Why was this ever a class?)
Andre
2015/03/31 23:21:57
It came from here: https://codereview.chromium.org
|
- menu:(NSMenu*)menu { |
- NSMenuItem* result = nil; |
- |
- for (NSMenuItem* item in [menu itemArray]) { |
- NSMenu* submenu = [item submenu]; |
- if (submenu) { |
- if (submenu != [NSApp servicesMenu]) |
- result = [self itemForKeyEquivalent:key |
- menu:submenu]; |
- } else if ([item cr_firesForKeyEventIfEnabled:key]) { |
- result = item; |
- } |
- |
- if (result) |
- break; |
- } |
- |
- return result; |
-} |
-@end |
- |
@implementation BrowserWindowUtils |
+ (BOOL)shouldHandleKeyboardEvent:(const NativeWebKeyboardEvent&)event { |
if (event.skip_in_browser || event.type == NativeWebKeyboardEvent::Char) |
@@ -54,47 +25,7 @@ using content::NativeWebKeyboardEvent; |
} |
+ (int)getCommandId:(const NativeWebKeyboardEvent&)event { |
- if ([event.os_event type] != NSKeyDown) |
- return -1; |
- |
- // Look in menu. |
- NSMenuItem* item = [MenuWalker itemForKeyEquivalent:event.os_event |
- menu:[NSApp mainMenu]]; |
- |
- if (item && [item action] == @selector(commandDispatch:) && [item tag] > 0) |
- return [item tag]; |
- |
- // "Close window" doesn't use the |commandDispatch:| mechanism. Menu items |
- // that do not correspond to IDC_ constants need no special treatment however, |
- // as they can't be blacklisted in |
- // |BrowserCommandController::IsReservedCommandOrKey()| anyhow. |
- if (item && [item action] == @selector(performClose:)) |
- return IDC_CLOSE_WINDOW; |
- |
- // "Exit" doesn't use the |commandDispatch:| mechanism either. |
- if (item && [item action] == @selector(terminate:)) |
- return IDC_EXIT; |
- |
- // Look in secondary keyboard shortcuts. |
- NSUInteger modifiers = [event.os_event modifierFlags]; |
- const bool cmdKey = (modifiers & NSCommandKeyMask) != 0; |
- const bool shiftKey = (modifiers & NSShiftKeyMask) != 0; |
- const bool cntrlKey = (modifiers & NSControlKeyMask) != 0; |
- const bool optKey = (modifiers & NSAlternateKeyMask) != 0; |
- const int keyCode = [event.os_event keyCode]; |
- const unichar keyChar = KeyCharacterForEvent(event.os_event); |
- |
- int cmdNum = CommandForWindowKeyboardShortcut( |
- cmdKey, shiftKey, cntrlKey, optKey, keyCode, keyChar); |
- if (cmdNum != -1) |
- return cmdNum; |
- |
- cmdNum = CommandForBrowserKeyboardShortcut( |
- cmdKey, shiftKey, cntrlKey, optKey, keyCode, keyChar); |
- if (cmdNum != -1) |
- return cmdNum; |
- |
- return -1; |
+ return CommandForKeyEvent(event.os_event); |
} |
+ (BOOL)handleKeyboardEvent:(NSEvent*)event |