| OLD | NEW | 
|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #import <AppKit/AppKit.h> | 7 #import <AppKit/AppKit.h> | 
| 8 | 8 | 
| 9 #include "base/logging.h" | 9 #include "base/logging.h" | 
| 10 #include "base/macros.h" | 10 #include "base/macros.h" | 
| (...skipping 17 matching lines...) Expand all  Loading... | 
| 28 | 28 | 
| 29     if (result) | 29     if (result) | 
| 30       break; | 30       break; | 
| 31   } | 31   } | 
| 32 | 32 | 
| 33   return result; | 33   return result; | 
| 34 } | 34 } | 
| 35 | 35 | 
| 36 }  // namespace | 36 }  // namespace | 
| 37 | 37 | 
| 38 // Basically, there are two kinds of keyboard shortcuts: Ones that should work |  | 
| 39 // only if the tab contents is focused (BrowserKeyboardShortcut), and ones that |  | 
| 40 // should work in all other cases (WindowKeyboardShortcut). In the latter case, |  | 
| 41 // we differentiate between shortcuts that are checked before any other view |  | 
| 42 // gets the chance to handle them (WindowKeyboardShortcut) or after all views |  | 
| 43 // had a chance but did not handle the keypress event |  | 
| 44 // (DelayedWindowKeyboardShortcut). |  | 
| 45 |  | 
| 46 const KeyboardShortcutData* GetWindowKeyboardShortcutTable( |  | 
| 47     size_t* num_entries) { |  | 
| 48   static const KeyboardShortcutData keyboard_shortcuts[] = { |  | 
| 49       // cmd   shift  cntrl  option |  | 
| 50       // ---   -----  -----  ------ |  | 
| 51       // '{' / '}' characters should be matched earlier than virtual key code |  | 
| 52       // (therefore we can match alt-8 as '{' on german keyboards). |  | 
| 53       {true, false, false, false, 0, '}', IDC_SELECT_NEXT_TAB}, |  | 
| 54       {true, false, false, false, 0, '{', IDC_SELECT_PREVIOUS_TAB}, |  | 
| 55       {false, false, true, false, kVK_PageDown, 0, IDC_SELECT_NEXT_TAB}, |  | 
| 56       {false, false, true, false, kVK_Tab, 0, IDC_SELECT_NEXT_TAB}, |  | 
| 57       {false, false, true, false, kVK_PageUp, 0, IDC_SELECT_PREVIOUS_TAB}, |  | 
| 58       {false, true, true, false, kVK_Tab, 0, IDC_SELECT_PREVIOUS_TAB}, |  | 
| 59       // Cmd-0..8 select the Nth tab, with cmd-9 being "last tab". |  | 
| 60       {true, false, false, false, kVK_ANSI_1, 0, IDC_SELECT_TAB_0}, |  | 
| 61       {true, false, false, false, kVK_ANSI_Keypad1, 0, IDC_SELECT_TAB_0}, |  | 
| 62       {true, false, false, false, kVK_ANSI_2, 0, IDC_SELECT_TAB_1}, |  | 
| 63       {true, false, false, false, kVK_ANSI_Keypad2, 0, IDC_SELECT_TAB_1}, |  | 
| 64       {true, false, false, false, kVK_ANSI_3, 0, IDC_SELECT_TAB_2}, |  | 
| 65       {true, false, false, false, kVK_ANSI_Keypad3, 0, IDC_SELECT_TAB_2}, |  | 
| 66       {true, false, false, false, kVK_ANSI_4, 0, IDC_SELECT_TAB_3}, |  | 
| 67       {true, false, false, false, kVK_ANSI_Keypad4, 0, IDC_SELECT_TAB_3}, |  | 
| 68       {true, false, false, false, kVK_ANSI_5, 0, IDC_SELECT_TAB_4}, |  | 
| 69       {true, false, false, false, kVK_ANSI_Keypad5, 0, IDC_SELECT_TAB_4}, |  | 
| 70       {true, false, false, false, kVK_ANSI_6, 0, IDC_SELECT_TAB_5}, |  | 
| 71       {true, false, false, false, kVK_ANSI_Keypad6, 0, IDC_SELECT_TAB_5}, |  | 
| 72       {true, false, false, false, kVK_ANSI_7, 0, IDC_SELECT_TAB_6}, |  | 
| 73       {true, false, false, false, kVK_ANSI_Keypad7, 0, IDC_SELECT_TAB_6}, |  | 
| 74       {true, false, false, false, kVK_ANSI_8, 0, IDC_SELECT_TAB_7}, |  | 
| 75       {true, false, false, false, kVK_ANSI_Keypad8, 0, IDC_SELECT_TAB_7}, |  | 
| 76       {true, false, false, false, kVK_ANSI_9, 0, IDC_SELECT_LAST_TAB}, |  | 
| 77       {true, false, false, false, kVK_ANSI_Keypad9, 0, IDC_SELECT_LAST_TAB}, |  | 
| 78       {true, true, false, false, kVK_ANSI_M, 0, IDC_SHOW_AVATAR_MENU}, |  | 
| 79       {true, false, false, true, kVK_ANSI_L, 0, IDC_SHOW_DOWNLOADS}, |  | 
| 80   }; |  | 
| 81 |  | 
| 82   *num_entries = arraysize(keyboard_shortcuts); |  | 
| 83 |  | 
| 84   return keyboard_shortcuts; |  | 
| 85 } |  | 
| 86 |  | 
| 87 const KeyboardShortcutData* GetDelayedWindowKeyboardShortcutTable( |  | 
| 88     size_t* num_entries) { |  | 
| 89   static const KeyboardShortcutData keyboard_shortcuts[] = { |  | 
| 90     //cmd   shift  cntrl  option |  | 
| 91     //---   -----  -----  ------ |  | 
| 92     {false, false, false, false, kVK_Escape,        0, IDC_STOP}, |  | 
| 93   }; |  | 
| 94 |  | 
| 95   *num_entries = arraysize(keyboard_shortcuts); |  | 
| 96 |  | 
| 97   return keyboard_shortcuts; |  | 
| 98 } |  | 
| 99 |  | 
| 100 const KeyboardShortcutData* GetBrowserKeyboardShortcutTable( |  | 
| 101     size_t* num_entries) { |  | 
| 102   static const KeyboardShortcutData keyboard_shortcuts[] = { |  | 
| 103     //cmd   shift  cntrl  option |  | 
| 104     //---   -----  -----  ------ |  | 
| 105     {true,  false, false, false, kVK_LeftArrow,    0,   IDC_BACK}, |  | 
| 106     {true,  false, false, false, kVK_RightArrow,   0,   IDC_FORWARD}, |  | 
| 107     {false, false, false, false, kVK_Delete,       0,   IDC_BACKSPACE_BACK}, |  | 
| 108     {false, true,  false, false, kVK_Delete,       0,   IDC_BACKSPACE_FORWARD}, |  | 
| 109     {true,  true,  false, false, 0,                'c', IDC_DEV_TOOLS_INSPECT}, |  | 
| 110   }; |  | 
| 111 |  | 
| 112   *num_entries = arraysize(keyboard_shortcuts); |  | 
| 113 |  | 
| 114   return keyboard_shortcuts; |  | 
| 115 } |  | 
| 116 |  | 
| 117 static bool MatchesEventForKeyboardShortcut( | 38 static bool MatchesEventForKeyboardShortcut( | 
| 118     const KeyboardShortcutData& shortcut, | 39     const KeyboardShortcutData& shortcut, | 
| 119     bool command_key, bool shift_key, bool cntrl_key, bool opt_key, | 40     bool command_key, bool shift_key, bool cntrl_key, bool opt_key, | 
| 120     int vkey_code, unichar key_char) { | 41     int vkey_code, unichar key_char) { | 
| 121   // Expects that one of |key_char| or |vkey_code| is 0. | 42   // Expects that one of |key_char| or |vkey_code| is 0. | 
| 122   DCHECK((shortcut.key_char == 0) ^ (shortcut.vkey_code == 0)); | 43   DCHECK((shortcut.key_char == 0) ^ (shortcut.vkey_code == 0)); | 
| 123   if (shortcut.key_char) { | 44   if (shortcut.key_char) { | 
| 124     // Shortcuts that have a |key_char| and have |opt_key| set are mistakes, | 45     // Shortcuts that have a |key_char| and have |opt_key| set are mistakes, | 
| 125     // since |opt_key| is not checked when there is a |key_char|. | 46     // since |opt_key| is not checked when there is a |key_char|. | 
| 126     DCHECK(!shortcut.opt_key); | 47     DCHECK(!shortcut.opt_key); | 
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 294       } | 215       } | 
| 295     } | 216     } | 
| 296 | 217 | 
| 297     // opt/alt modifier is set (e.g. on german layout we want '{' for opt-8). | 218     // opt/alt modifier is set (e.g. on german layout we want '{' for opt-8). | 
| 298     if ([event modifierFlags] & NSAlternateKeyMask) | 219     if ([event modifierFlags] & NSAlternateKeyMask) | 
| 299       return rawChar; | 220       return rawChar; | 
| 300   } | 221   } | 
| 301 | 222 | 
| 302   return noModifiersChar; | 223   return noModifiersChar; | 
| 303 } | 224 } | 
| OLD | NEW | 
|---|