| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 <Carbon/Carbon.h> | 5 #include <Carbon/Carbon.h> |
| 6 | 6 |
| 7 #include "chrome/browser/global_keyboard_shortcuts_mac.h" | 7 #include "chrome/browser/global_keyboard_shortcuts_mac.h" |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "chrome/app/chrome_dll_resource.h" | 10 #include "chrome/app/chrome_dll_resource.h" |
| 11 | 11 |
| 12 const KeyboardShortcutData* GetWindowKeyboardShortcutTable | 12 const KeyboardShortcutData* GetWindowKeyboardShortcutTable |
| 13 (size_t* num_entries) { | 13 (size_t* num_entries) { |
| 14 static const KeyboardShortcutData keyboard_shortcuts[] = { | 14 static const KeyboardShortcutData keyboard_shortcuts[] = { |
| 15 {true, true, false, false, kVK_ANSI_RightBracket, IDC_SELECT_NEXT_TAB}, | 15 {true, true, false, kVK_ANSI_RightBracket, IDC_SELECT_NEXT_TAB}, |
| 16 {false, false, true, false, kVK_PageDown, IDC_SELECT_NEXT_TAB}, | 16 {false, false, true, kVK_PageDown, IDC_SELECT_NEXT_TAB}, |
| 17 {false, false, true, false, kVK_Tab, IDC_SELECT_NEXT_TAB}, | 17 {false, false, true, kVK_Tab, IDC_SELECT_NEXT_TAB}, |
| 18 {true, true, false, false, kVK_ANSI_LeftBracket, IDC_SELECT_PREVIOUS_TAB}, | 18 {true, true, false, kVK_ANSI_LeftBracket, IDC_SELECT_PREVIOUS_TAB}, |
| 19 {false, false, true, false, kVK_PageUp, IDC_SELECT_PREVIOUS_TAB}, | 19 {false, false, true, kVK_PageUp, IDC_SELECT_PREVIOUS_TAB}, |
| 20 {false, true, true, false, kVK_Tab, IDC_SELECT_PREVIOUS_TAB}, | 20 {false, true, true, kVK_Tab, IDC_SELECT_PREVIOUS_TAB}, |
| 21 // Cmd-0..8 select the Nth tab, with cmd-9 being "last tab". | 21 // Cmd-0..8 select the Nth tab, with cmd-9 being "last tab". |
| 22 {true, false, false, false, kVK_ANSI_1, IDC_SELECT_TAB_0}, | 22 {true, false, false, kVK_ANSI_1, IDC_SELECT_TAB_0}, |
| 23 {true, false, false, false, kVK_ANSI_2, IDC_SELECT_TAB_1}, | 23 {true, false, false, kVK_ANSI_2, IDC_SELECT_TAB_1}, |
| 24 {true, false, false, false, kVK_ANSI_3, IDC_SELECT_TAB_2}, | 24 {true, false, false, kVK_ANSI_3, IDC_SELECT_TAB_2}, |
| 25 {true, false, false, false, kVK_ANSI_4, IDC_SELECT_TAB_3}, | 25 {true, false, false, kVK_ANSI_4, IDC_SELECT_TAB_3}, |
| 26 {true, false, false, false, kVK_ANSI_5, IDC_SELECT_TAB_4}, | 26 {true, false, false, kVK_ANSI_5, IDC_SELECT_TAB_4}, |
| 27 {true, false, false, false, kVK_ANSI_6, IDC_SELECT_TAB_5}, | 27 {true, false, false, kVK_ANSI_6, IDC_SELECT_TAB_5}, |
| 28 {true, false, false, false, kVK_ANSI_7, IDC_SELECT_TAB_6}, | 28 {true, false, false, kVK_ANSI_7, IDC_SELECT_TAB_6}, |
| 29 {true, false, false, false, kVK_ANSI_8, IDC_SELECT_TAB_7}, | 29 {true, false, false, kVK_ANSI_8, IDC_SELECT_TAB_7}, |
| 30 {true, false, false, false, kVK_ANSI_9, IDC_SELECT_LAST_TAB}, | 30 {true, false, false, kVK_ANSI_9, IDC_SELECT_LAST_TAB}, |
| 31 }; | 31 }; |
| 32 | 32 |
| 33 *num_entries = arraysize(keyboard_shortcuts); | 33 *num_entries = arraysize(keyboard_shortcuts); |
| 34 | 34 |
| 35 return keyboard_shortcuts; | 35 return keyboard_shortcuts; |
| 36 } | 36 } |
| 37 | 37 |
| 38 const KeyboardShortcutData* GetBrowserKeyboardShortcutTable | 38 const KeyboardShortcutData* GetBrowserKeyboardShortcutTable |
| 39 (size_t* num_entries) { | 39 (size_t* num_entries) { |
| 40 static const KeyboardShortcutData keyboard_shortcuts[] = { | 40 static const KeyboardShortcutData keyboard_shortcuts[] = { |
| 41 {true, false, false, false, kVK_LeftArrow, IDC_BACK}, | 41 {true, false, false, kVK_LeftArrow, IDC_BACK}, |
| 42 {true, false, false, false, kVK_RightArrow, IDC_FORWARD}, | 42 {true, false, false, kVK_RightArrow, IDC_FORWARD}, |
| 43 {false, false, false, false, kVK_Delete, IDC_BACK}, | 43 {false, false, false, kVK_Delete, IDC_BACK}, |
| 44 {false, true, false, false, kVK_Delete, IDC_FORWARD}, | 44 {false, true, false, kVK_Delete, IDC_FORWARD}, |
| 45 }; | 45 }; |
| 46 | 46 |
| 47 *num_entries = arraysize(keyboard_shortcuts); | 47 *num_entries = arraysize(keyboard_shortcuts); |
| 48 | 48 |
| 49 return keyboard_shortcuts; | 49 return keyboard_shortcuts; |
| 50 } | 50 } |
| 51 | 51 |
| 52 static int CommandForKeyboardShortcut( | 52 static int CommandForKeyboardShortcut( |
| 53 const KeyboardShortcutData* (*get_keyboard_shortcut_table)(size_t*), | 53 const KeyboardShortcutData* (*get_keyboard_shortcut_table)(size_t*), |
| 54 bool command_key, bool shift_key, bool cntrl_key, bool opt_key, | 54 bool command_key, bool shift_key, bool cntrl_key, int vkey_code) { |
| 55 int vkey_code) { | |
| 56 | 55 |
| 57 // Scan through keycodes and see if it corresponds to one of the global | 56 // Scan through keycodes and see if it corresponds to one of the global |
| 58 // shortcuts on file. | 57 // shortcuts on file. |
| 59 // | 58 // |
| 60 // TODO(jeremy): Change this into a hash table once we get enough | 59 // TODO(jeremy): Change this into a hash table once we get enough |
| 61 // entries in the array to make a difference. | 60 // entries in the array to make a difference. |
| 62 size_t num_shortcuts = 0; | 61 size_t num_shortcuts = 0; |
| 63 const KeyboardShortcutData *it = get_keyboard_shortcut_table(&num_shortcuts); | 62 const KeyboardShortcutData *it = get_keyboard_shortcut_table(&num_shortcuts); |
| 64 for (size_t i = 0; i < num_shortcuts; ++i, ++it) { | 63 for (size_t i = 0; i < num_shortcuts; ++i, ++it) { |
| 65 if (it->command_key == command_key && | 64 if (it->command_key == command_key && |
| 66 it->shift_key == shift_key && | 65 it->shift_key == shift_key && |
| 67 it->cntrl_key == cntrl_key && | 66 it->cntrl_key == cntrl_key && |
| 68 it->opt_key == opt_key && | |
| 69 it->vkey_code == vkey_code) { | 67 it->vkey_code == vkey_code) { |
| 70 return it->chrome_command; | 68 return it->chrome_command; |
| 71 } | 69 } |
| 72 } | 70 } |
| 73 | 71 |
| 74 return -1; | 72 return -1; |
| 75 } | 73 } |
| 76 | 74 |
| 77 int CommandForWindowKeyboardShortcut( | 75 int CommandForWindowKeyboardShortcut( |
| 78 bool command_key, bool shift_key, bool cntrl_key, bool opt_key, | 76 bool command_key, bool shift_key, bool cntrl_key, int vkey_code) { |
| 79 int vkey_code) { | |
| 80 return CommandForKeyboardShortcut(GetWindowKeyboardShortcutTable, | 77 return CommandForKeyboardShortcut(GetWindowKeyboardShortcutTable, |
| 81 command_key, shift_key, | 78 command_key, shift_key, |
| 82 cntrl_key, opt_key, vkey_code); | 79 cntrl_key, vkey_code); |
| 83 } | 80 } |
| 84 | 81 |
| 85 int CommandForBrowserKeyboardShortcut( | 82 int CommandForBrowserKeyboardShortcut( |
| 86 bool command_key, bool shift_key, bool cntrl_key, bool opt_key, | 83 bool command_key, bool shift_key, bool cntrl_key, int vkey_code) { |
| 87 int vkey_code) { | |
| 88 return CommandForKeyboardShortcut(GetBrowserKeyboardShortcutTable, | 84 return CommandForKeyboardShortcut(GetBrowserKeyboardShortcutTable, |
| 89 command_key, shift_key, | 85 command_key, shift_key, |
| 90 cntrl_key, opt_key, vkey_code); | 86 cntrl_key, vkey_code); |
| 91 } | 87 } |
| OLD | NEW |