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 "chrome/browser/global_keyboard_shortcuts_mac.h" | 5 #include "chrome/browser/global_keyboard_shortcuts_mac.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "chrome/app/chrome_dll_resource.h" | 8 #include "chrome/app/chrome_dll_resource.h" |
9 | 9 |
10 const KeyboardShortcutData* GetKeyboardShortCutTable(size_t* num_entries) { | 10 const KeyboardShortcutData* GetKeyboardShortCutTable(size_t* num_entries) { |
11 static const KeyboardShortcutData keyboard_shortcuts[] = { | 11 static const KeyboardShortcutData keyboard_shortcuts[] = { |
12 {true, true, false, 30 /* ] */, IDC_SELECT_NEXT_TAB}, | 12 {true, true, false, 30 /* ] */, IDC_SELECT_NEXT_TAB}, |
13 {false, false, true, 121 /* pg down */, IDC_SELECT_NEXT_TAB}, | 13 {false, false, true, 121 /* pg down */, IDC_SELECT_NEXT_TAB}, |
14 {false, false, true, 48 /* tab */, IDC_SELECT_NEXT_TAB}, | 14 {false, false, true, 48 /* tab */, IDC_SELECT_NEXT_TAB}, |
15 {true, true, false, 33 /* [ */, IDC_SELECT_PREVIOUS_TAB}, | 15 {true, true, false, 33 /* [ */, IDC_SELECT_PREVIOUS_TAB}, |
16 {false, false, true, 116 /* pg_up */, IDC_SELECT_PREVIOUS_TAB}, | 16 {false, false, true, 116 /* pg_up */, IDC_SELECT_PREVIOUS_TAB}, |
17 {false, true, true, 48 /* tab */, IDC_SELECT_PREVIOUS_TAB}, | 17 {false, true, true, 48 /* tab */, IDC_SELECT_PREVIOUS_TAB}, |
| 18 // Cmd-0..8 select the Nth tab, with cmd-9 being "last tab". Note that the |
| 19 // vkeys are *not* in natural order. |
| 20 {true, false, false, 18 /* 1 */, IDC_SELECT_TAB_0}, |
| 21 {true, false, false, 19 /* 2 */, IDC_SELECT_TAB_1}, |
| 22 {true, false, false, 20 /* 3 */, IDC_SELECT_TAB_2}, |
| 23 {true, false, false, 21 /* 4 */, IDC_SELECT_TAB_3}, |
| 24 {true, false, false, 23 /* 5 */, IDC_SELECT_TAB_4}, |
| 25 {true, false, false, 22 /* 6 */, IDC_SELECT_TAB_5}, |
| 26 {true, false, false, 26 /* 7 */, IDC_SELECT_TAB_6}, |
| 27 {true, false, false, 28 /* 8 */, IDC_SELECT_TAB_7}, |
| 28 {true, false, false, 25 /* 9 */, IDC_SELECT_LAST_TAB}, |
18 }; | 29 }; |
19 | 30 |
20 *num_entries = arraysize(keyboard_shortcuts); | 31 *num_entries = arraysize(keyboard_shortcuts); |
21 | 32 |
22 return keyboard_shortcuts; | 33 return keyboard_shortcuts; |
23 } | 34 } |
24 | 35 |
25 int CommandForKeyboardShortcut(bool command_key, bool shift_key, bool cntrl_key, | 36 int CommandForKeyboardShortcut(bool command_key, bool shift_key, bool cntrl_key, |
26 int vkey_code) { | 37 int vkey_code) { |
27 | 38 |
28 // Scan through keycodes and see if it corresponds to one of the global | 39 // Scan through keycodes and see if it corresponds to one of the global |
29 // shortcuts on file. | 40 // shortcuts on file. |
30 // | 41 // |
31 // TODO(jeremy): Change this into a hash table once we get enough | 42 // TODO(jeremy): Change this into a hash table once we get enough |
32 // entries in the array to make a difference. | 43 // entries in the array to make a difference. |
33 size_t num_shortcuts = 0; | 44 size_t num_shortcuts = 0; |
34 const KeyboardShortcutData *it = GetKeyboardShortCutTable(&num_shortcuts); | 45 const KeyboardShortcutData *it = GetKeyboardShortCutTable(&num_shortcuts); |
35 for (size_t i = 0; i < num_shortcuts; ++i, ++it) { | 46 for (size_t i = 0; i < num_shortcuts; ++i, ++it) { |
36 if (it->command_key == command_key && | 47 if (it->command_key == command_key && |
37 it->shift_key == shift_key && | 48 it->shift_key == shift_key && |
38 it->cntrl_key == cntrl_key && | 49 it->cntrl_key == cntrl_key && |
39 it->vkey_code == vkey_code) { | 50 it->vkey_code == vkey_code) { |
40 return it->chrome_command; | 51 return it->chrome_command; |
41 } | 52 } |
42 } | 53 } |
43 | 54 |
44 return -1; | 55 return -1; |
45 } | 56 } |
OLD | NEW |