Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(326)

Side by Side Diff: chrome/browser/global_keyboard_shortcuts_mac.mm

Issue 313004: Fix cmd-opt-left/right. (Closed)
Patch Set: Rebase ToT Created 11 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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, kVK_ANSI_RightBracket, IDC_SELECT_NEXT_TAB}, 15 {true, true, false, false, kVK_ANSI_RightBracket, IDC_SELECT_NEXT_TAB},
16 {false, false, true, kVK_PageDown, IDC_SELECT_NEXT_TAB}, 16 {false, false, true, false, kVK_PageDown, IDC_SELECT_NEXT_TAB},
17 {false, false, true, kVK_Tab, IDC_SELECT_NEXT_TAB}, 17 {false, false, true, false, kVK_Tab, IDC_SELECT_NEXT_TAB},
18 {true, true, false, kVK_ANSI_LeftBracket, IDC_SELECT_PREVIOUS_TAB}, 18 {true, true, false, false, kVK_ANSI_LeftBracket, IDC_SELECT_PREVIOUS_TAB},
19 {false, false, true, kVK_PageUp, IDC_SELECT_PREVIOUS_TAB}, 19 {false, false, true, false, kVK_PageUp, IDC_SELECT_PREVIOUS_TAB},
20 {false, true, true, kVK_Tab, IDC_SELECT_PREVIOUS_TAB}, 20 {false, true, true, false, 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, kVK_ANSI_1, IDC_SELECT_TAB_0}, 22 {true, false, false, false, kVK_ANSI_1, IDC_SELECT_TAB_0},
23 {true, false, false, kVK_ANSI_2, IDC_SELECT_TAB_1}, 23 {true, false, false, false, kVK_ANSI_2, IDC_SELECT_TAB_1},
24 {true, false, false, kVK_ANSI_3, IDC_SELECT_TAB_2}, 24 {true, false, false, false, kVK_ANSI_3, IDC_SELECT_TAB_2},
25 {true, false, false, kVK_ANSI_4, IDC_SELECT_TAB_3}, 25 {true, false, false, false, kVK_ANSI_4, IDC_SELECT_TAB_3},
26 {true, false, false, kVK_ANSI_5, IDC_SELECT_TAB_4}, 26 {true, false, false, false, kVK_ANSI_5, IDC_SELECT_TAB_4},
27 {true, false, false, kVK_ANSI_6, IDC_SELECT_TAB_5}, 27 {true, false, false, false, kVK_ANSI_6, IDC_SELECT_TAB_5},
28 {true, false, false, kVK_ANSI_7, IDC_SELECT_TAB_6}, 28 {true, false, false, false, kVK_ANSI_7, IDC_SELECT_TAB_6},
29 {true, false, false, kVK_ANSI_8, IDC_SELECT_TAB_7}, 29 {true, false, false, false, kVK_ANSI_8, IDC_SELECT_TAB_7},
30 {true, false, false, kVK_ANSI_9, IDC_SELECT_LAST_TAB}, 30 {true, false, 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, kVK_LeftArrow, IDC_BACK}, 41 {true, false, false, false, kVK_LeftArrow, IDC_BACK},
42 {true, false, false, kVK_RightArrow, IDC_FORWARD}, 42 {true, false, false, false, kVK_RightArrow, IDC_FORWARD},
43 {false, false, false, kVK_Delete, IDC_BACK}, 43 {false, false, false, false, kVK_Delete, IDC_BACK},
44 {false, true, false, kVK_Delete, IDC_FORWARD}, 44 {false, true, false, 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, int vkey_code) { 54 bool command_key, bool shift_key, bool cntrl_key, bool opt_key,
55 int vkey_code) {
55 56
56 // Scan through keycodes and see if it corresponds to one of the global 57 // Scan through keycodes and see if it corresponds to one of the global
57 // shortcuts on file. 58 // shortcuts on file.
58 // 59 //
59 // TODO(jeremy): Change this into a hash table once we get enough 60 // TODO(jeremy): Change this into a hash table once we get enough
60 // entries in the array to make a difference. 61 // entries in the array to make a difference.
61 size_t num_shortcuts = 0; 62 size_t num_shortcuts = 0;
62 const KeyboardShortcutData *it = get_keyboard_shortcut_table(&num_shortcuts); 63 const KeyboardShortcutData *it = get_keyboard_shortcut_table(&num_shortcuts);
63 for (size_t i = 0; i < num_shortcuts; ++i, ++it) { 64 for (size_t i = 0; i < num_shortcuts; ++i, ++it) {
64 if (it->command_key == command_key && 65 if (it->command_key == command_key &&
65 it->shift_key == shift_key && 66 it->shift_key == shift_key &&
66 it->cntrl_key == cntrl_key && 67 it->cntrl_key == cntrl_key &&
68 it->opt_key == opt_key &&
67 it->vkey_code == vkey_code) { 69 it->vkey_code == vkey_code) {
68 return it->chrome_command; 70 return it->chrome_command;
69 } 71 }
70 } 72 }
71 73
72 return -1; 74 return -1;
73 } 75 }
74 76
75 int CommandForWindowKeyboardShortcut( 77 int CommandForWindowKeyboardShortcut(
76 bool command_key, bool shift_key, bool cntrl_key, int vkey_code) { 78 bool command_key, bool shift_key, bool cntrl_key, bool opt_key,
79 int vkey_code) {
77 return CommandForKeyboardShortcut(GetWindowKeyboardShortcutTable, 80 return CommandForKeyboardShortcut(GetWindowKeyboardShortcutTable,
78 command_key, shift_key, 81 command_key, shift_key,
79 cntrl_key, vkey_code); 82 cntrl_key, opt_key, vkey_code);
80 } 83 }
81 84
82 int CommandForBrowserKeyboardShortcut( 85 int CommandForBrowserKeyboardShortcut(
83 bool command_key, bool shift_key, bool cntrl_key, int vkey_code) { 86 bool command_key, bool shift_key, bool cntrl_key, bool opt_key,
87 int vkey_code) {
84 return CommandForKeyboardShortcut(GetBrowserKeyboardShortcutTable, 88 return CommandForKeyboardShortcut(GetBrowserKeyboardShortcutTable,
85 command_key, shift_key, 89 command_key, shift_key,
86 cntrl_key, vkey_code); 90 cntrl_key, opt_key, vkey_code);
87 } 91 }
OLDNEW
« no previous file with comments | « chrome/browser/global_keyboard_shortcuts_mac.h ('k') | chrome/browser/global_keyboard_shortcuts_mac_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698