| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/global_keyboard_shortcuts_mac.h" | 5 #include "chrome/browser/global_keyboard_shortcuts_mac.h" |
| 6 | 6 |
| 7 #import <AppKit/AppKit.h> | 7 #import <AppKit/AppKit.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 shortcut.cntrl_key == cntrl_key && | 60 shortcut.cntrl_key == cntrl_key && |
| 61 shortcut.opt_key == opt_key && | 61 shortcut.opt_key == opt_key && |
| 62 shortcut.vkey_code == vkey_code) | 62 shortcut.vkey_code == vkey_code) |
| 63 return true; | 63 return true; |
| 64 } else { | 64 } else { |
| 65 NOTREACHED(); // Shouldn't happen. | 65 NOTREACHED(); // Shouldn't happen. |
| 66 } | 66 } |
| 67 return false; | 67 return false; |
| 68 } | 68 } |
| 69 | 69 |
| 70 } // namespace |
| 71 |
| 70 int CommandForKeyboardShortcut(const std::vector<KeyboardShortcutData>& table, | 72 int CommandForKeyboardShortcut(const std::vector<KeyboardShortcutData>& table, |
| 71 bool command_key, | 73 bool command_key, |
| 72 bool shift_key, | 74 bool shift_key, |
| 73 bool cntrl_key, | 75 bool cntrl_key, |
| 74 bool opt_key, | 76 bool opt_key, |
| 75 int vkey_code, | 77 int vkey_code, |
| 76 unichar key_char) { | 78 unichar key_char) { |
| 77 // Scan through keycodes and see if it corresponds to one of the global | 79 // Scan through keycodes and see if it corresponds to one of the global |
| 78 // shortcuts on file. | 80 // shortcuts on file. |
| 79 // | 81 // |
| 80 // TODO(jeremy): Change this into a hash table once we get enough | 82 // TODO(jeremy): Change this into a hash table once we get enough |
| 81 // entries in the array to make a difference. | 83 // entries in the array to make a difference. |
| 82 // (When turning this into a hash table, note that the current behavior | 84 // (When turning this into a hash table, note that the current behavior |
| 83 // relies on the order of the table (see the comment for '{' / '}' above). | 85 // relies on the order of the table (see the comment for '{' / '}' above). |
| 84 for (const auto& shortcut : table) { | 86 for (const auto& shortcut : table) { |
| 85 if (MatchesEventForKeyboardShortcut(shortcut, command_key, shift_key, | 87 if (MatchesEventForKeyboardShortcut(shortcut, command_key, shift_key, |
| 86 cntrl_key, opt_key, vkey_code, | 88 cntrl_key, opt_key, vkey_code, |
| 87 key_char)) | 89 key_char)) |
| 88 return shortcut.chrome_command; | 90 return shortcut.chrome_command; |
| 89 } | 91 } |
| 90 | 92 |
| 91 return -1; | 93 return -1; |
| 92 } | 94 } |
| 93 | 95 |
| 94 } // namespace | |
| 95 | |
| 96 int CommandForWindowKeyboardShortcut( | 96 int CommandForWindowKeyboardShortcut( |
| 97 bool command_key, bool shift_key, bool cntrl_key, bool opt_key, | 97 bool command_key, bool shift_key, bool cntrl_key, bool opt_key, |
| 98 int vkey_code, unichar key_char) { | 98 int vkey_code, unichar key_char) { |
| 99 return CommandForKeyboardShortcut(GetWindowKeyboardShortcutTable(), | 99 return CommandForKeyboardShortcut(GetWindowKeyboardShortcutTable(), |
| 100 command_key, shift_key, | 100 command_key, shift_key, |
| 101 cntrl_key, opt_key, vkey_code, | 101 cntrl_key, opt_key, vkey_code, |
| 102 key_char); | 102 key_char); |
| 103 } | 103 } |
| 104 | 104 |
| 105 int CommandForDelayedWindowKeyboardShortcut( | 105 int CommandForDelayedWindowKeyboardShortcut( |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 } | 219 } |
| 220 } | 220 } |
| 221 | 221 |
| 222 // opt/alt modifier is set (e.g. on german layout we want '{' for opt-8). | 222 // opt/alt modifier is set (e.g. on german layout we want '{' for opt-8). |
| 223 if ([event modifierFlags] & NSAlternateKeyMask) | 223 if ([event modifierFlags] & NSAlternateKeyMask) |
| 224 return rawChar; | 224 return rawChar; |
| 225 } | 225 } |
| 226 | 226 |
| 227 return noModifiersChar; | 227 return noModifiersChar; |
| 228 } | 228 } |
| OLD | NEW |