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