| 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* GetKeyboardShortCutTable(size_t* num_entries) { | 12 const KeyboardShortcutData* GetWindowKeyboardShortcutTable |
| 13 (size_t* num_entries) { |
| 13 static const KeyboardShortcutData keyboard_shortcuts[] = { | 14 static const KeyboardShortcutData keyboard_shortcuts[] = { |
| 14 {true, true, false, kVK_ANSI_RightBracket, IDC_SELECT_NEXT_TAB}, | 15 {true, true, false, kVK_ANSI_RightBracket, IDC_SELECT_NEXT_TAB}, |
| 15 {false, false, true, kVK_PageDown, IDC_SELECT_NEXT_TAB}, | 16 {false, false, true, kVK_PageDown, IDC_SELECT_NEXT_TAB}, |
| 16 {false, false, true, kVK_Tab, IDC_SELECT_NEXT_TAB}, | 17 {false, false, true, kVK_Tab, IDC_SELECT_NEXT_TAB}, |
| 17 {true, true, false, kVK_ANSI_LeftBracket, IDC_SELECT_PREVIOUS_TAB}, | 18 {true, true, false, kVK_ANSI_LeftBracket, IDC_SELECT_PREVIOUS_TAB}, |
| 18 {false, false, true, kVK_PageUp, IDC_SELECT_PREVIOUS_TAB}, | 19 {false, false, true, kVK_PageUp, IDC_SELECT_PREVIOUS_TAB}, |
| 19 {false, true, true, kVK_Tab, IDC_SELECT_PREVIOUS_TAB}, | 20 {false, true, true, kVK_Tab, IDC_SELECT_PREVIOUS_TAB}, |
| 20 // 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". |
| 21 {true, false, false, kVK_ANSI_1, IDC_SELECT_TAB_0}, | 22 {true, false, false, kVK_ANSI_1, IDC_SELECT_TAB_0}, |
| 22 {true, false, false, kVK_ANSI_2, IDC_SELECT_TAB_1}, | 23 {true, false, false, kVK_ANSI_2, IDC_SELECT_TAB_1}, |
| 23 {true, false, false, kVK_ANSI_3, IDC_SELECT_TAB_2}, | 24 {true, false, false, kVK_ANSI_3, IDC_SELECT_TAB_2}, |
| 24 {true, false, false, kVK_ANSI_4, IDC_SELECT_TAB_3}, | 25 {true, false, false, kVK_ANSI_4, IDC_SELECT_TAB_3}, |
| 25 {true, false, false, kVK_ANSI_5, IDC_SELECT_TAB_4}, | 26 {true, false, false, kVK_ANSI_5, IDC_SELECT_TAB_4}, |
| 26 {true, false, false, kVK_ANSI_6, IDC_SELECT_TAB_5}, | 27 {true, false, false, kVK_ANSI_6, IDC_SELECT_TAB_5}, |
| 27 {true, false, false, kVK_ANSI_7, IDC_SELECT_TAB_6}, | 28 {true, false, false, kVK_ANSI_7, IDC_SELECT_TAB_6}, |
| 28 {true, false, false, kVK_ANSI_8, IDC_SELECT_TAB_7}, | 29 {true, false, false, kVK_ANSI_8, IDC_SELECT_TAB_7}, |
| 29 {true, false, false, kVK_ANSI_9, IDC_SELECT_LAST_TAB}, | 30 {true, false, false, kVK_ANSI_9, IDC_SELECT_LAST_TAB}, |
| 30 // TODO(pinkerton): These can't live here yet, they need to be plumbed | |
| 31 // through the renderer first so it can override if in a text field. | |
| 32 // http://crbug.com/12557 | |
| 33 // {true, false, false, kVK_LeftArrow, IDC_BACK}, | |
| 34 // {true, false, false, kVK_RightArrow, IDC_FORWARD}, | |
| 35 }; | 31 }; |
| 36 | 32 |
| 37 *num_entries = arraysize(keyboard_shortcuts); | 33 *num_entries = arraysize(keyboard_shortcuts); |
| 38 | 34 |
| 39 return keyboard_shortcuts; | 35 return keyboard_shortcuts; |
| 40 } | 36 } |
| 41 | 37 |
| 42 int CommandForKeyboardShortcut(bool command_key, bool shift_key, bool cntrl_key, | 38 const KeyboardShortcutData* GetBrowserKeyboardShortcutTable |
| 43 int vkey_code) { | 39 (size_t* num_entries) { |
| 40 static const KeyboardShortcutData keyboard_shortcuts[] = { |
| 41 {true, false, false, kVK_LeftArrow, IDC_BACK}, |
| 42 {true, false, false, kVK_RightArrow, IDC_FORWARD}, |
| 43 }; |
| 44 |
| 45 *num_entries = arraysize(keyboard_shortcuts); |
| 46 |
| 47 return keyboard_shortcuts; |
| 48 } |
| 49 |
| 50 static int CommandForKeyboardShortcut( |
| 51 const KeyboardShortcutData* (*get_keyboard_shortcut_table)(size_t*), |
| 52 bool command_key, bool shift_key, bool cntrl_key, int vkey_code) { |
| 44 | 53 |
| 45 // Scan through keycodes and see if it corresponds to one of the global | 54 // Scan through keycodes and see if it corresponds to one of the global |
| 46 // shortcuts on file. | 55 // shortcuts on file. |
| 47 // | 56 // |
| 48 // TODO(jeremy): Change this into a hash table once we get enough | 57 // TODO(jeremy): Change this into a hash table once we get enough |
| 49 // entries in the array to make a difference. | 58 // entries in the array to make a difference. |
| 50 size_t num_shortcuts = 0; | 59 size_t num_shortcuts = 0; |
| 51 const KeyboardShortcutData *it = GetKeyboardShortCutTable(&num_shortcuts); | 60 const KeyboardShortcutData *it = get_keyboard_shortcut_table(&num_shortcuts); |
| 52 for (size_t i = 0; i < num_shortcuts; ++i, ++it) { | 61 for (size_t i = 0; i < num_shortcuts; ++i, ++it) { |
| 53 if (it->command_key == command_key && | 62 if (it->command_key == command_key && |
| 54 it->shift_key == shift_key && | 63 it->shift_key == shift_key && |
| 55 it->cntrl_key == cntrl_key && | 64 it->cntrl_key == cntrl_key && |
| 56 it->vkey_code == vkey_code) { | 65 it->vkey_code == vkey_code) { |
| 57 return it->chrome_command; | 66 return it->chrome_command; |
| 58 } | 67 } |
| 59 } | 68 } |
| 60 | 69 |
| 61 return -1; | 70 return -1; |
| 62 } | 71 } |
| 72 |
| 73 int CommandForWindowKeyboardShortcut( |
| 74 bool command_key, bool shift_key, bool cntrl_key, int vkey_code) { |
| 75 return CommandForKeyboardShortcut(GetWindowKeyboardShortcutTable, |
| 76 command_key, shift_key, |
| 77 cntrl_key, vkey_code); |
| 78 } |
| 79 |
| 80 int CommandForBrowserKeyboardShortcut( |
| 81 bool command_key, bool shift_key, bool cntrl_key, int vkey_code) { |
| 82 return CommandForKeyboardShortcut(GetBrowserKeyboardShortcutTable, |
| 83 command_key, shift_key, |
| 84 cntrl_key, vkey_code); |
| 85 } |
| OLD | NEW |