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

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

Issue 503080: Make cmd-{/} shortcut keys work on any keyboard layouts on Mac (Closed)
Patch Set: rename fix Created 10 years, 11 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 #ifndef CHROME_BROWSER_GLOBAL_KEYBOARD_SHORTCUTS_MAC_H_ 5 #ifndef CHROME_BROWSER_GLOBAL_KEYBOARD_SHORTCUTS_MAC_H_
6 #define CHROME_BROWSER_GLOBAL_KEYBOARD_SHORTCUTS_MAC_H_ 6 #define CHROME_BROWSER_GLOBAL_KEYBOARD_SHORTCUTS_MAC_H_
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 9
10 struct KeyboardShortcutData { 10 struct KeyboardShortcutData {
11 bool command_key; 11 bool command_key;
12 bool shift_key; 12 bool shift_key;
13 bool cntrl_key; 13 bool cntrl_key;
14 bool opt_key; 14 bool opt_key;
15 // Either one of vkey_code or key_char must be specified. For keys
16 // whose virtual key code is hardware-dependent (kVK_ANSI_*) key_char
17 // should be specified instead.
18 // Set 0 for the one you do not want to specify.
15 int vkey_code; // Virtual Key code for the command. 19 int vkey_code; // Virtual Key code for the command.
20 unichar key_char; // Key event characters for the command as reported by
21 // [NSEvent charactersIgnoringModifiers].
16 int chrome_command; // The chrome command # to execute for this shortcut. 22 int chrome_command; // The chrome command # to execute for this shortcut.
17 }; 23 };
18 24
19 // Check if a given keycode + modifiers correspond to a given Chrome command. 25 // Check if a given keycode + modifiers (or keychar + modifiers if the
26 // |key_char| is specified) correspond to a given Chrome command.
20 // returns: Command number (as passed to Browser::ExecuteCommand) or -1 if there 27 // returns: Command number (as passed to Browser::ExecuteCommand) or -1 if there
21 // was no match. 28 // was no match.
22 // 29 //
23 // |performKeyEquivalent:| bubbles events up from the window to the views. If 30 // |performKeyEquivalent:| bubbles events up from the window to the views. If
24 // we let it bubble up to the Omnibox, then the Omnibox handles cmd-left/right 31 // we let it bubble up to the Omnibox, then the Omnibox handles cmd-left/right
25 // just fine, but it swallows cmd-1 and doesn't give us a chance to intercept 32 // just fine, but it swallows cmd-1 and doesn't give us a chance to intercept
26 // this. Hence, we need three types of keyboard shortcuts: shortcuts that are 33 // this. Hence, we need three types of keyboard shortcuts: shortcuts that are
27 // intercepted before the Omnibox handles events, shortcuts that are 34 // intercepted before the Omnibox handles events, shortcuts that are
28 // intercepted after the Omnibox had a chance but did not handle them, and 35 // intercepted after the Omnibox had a chance but did not handle them, and
29 // shortcuts that are only handled when tab contents is focused. 36 // shortcuts that are only handled when tab contents is focused.
30 // 37 //
31 // This means cmd-left doesn't work if you hit cmd-l tab, which focusses 38 // This means cmd-left doesn't work if you hit cmd-l tab, which focusses
32 // something that's neither omnibox nor tab contents. This behavior is 39 // something that's neither omnibox nor tab contents. This behavior is
33 // consistent with safari and camino, and I think it's the best we can do 40 // consistent with safari and camino, and I think it's the best we can do
34 // without rewriting event dispatching ( http://crbug.com/251069 ). 41 // without rewriting event dispatching ( http://crbug.com/251069 ).
35 42
36 // This returns shortcuts that should work no matter what component of the 43 // This returns shortcuts that should work no matter what component of the
37 // browser is focused. They are executed by the window, before any view has the 44 // browser is focused. They are executed by the window, before any view has the
38 // opportunity to override the shortcut (with the exception of the tab contents, 45 // opportunity to override the shortcut (with the exception of the tab contents,
39 // which first checks if the current web page wants to handle the shortcut). 46 // which first checks if the current web page wants to handle the shortcut).
40 int CommandForWindowKeyboardShortcut( 47 int CommandForWindowKeyboardShortcut(
41 bool command_key, bool shift_key, bool cntrl_key, bool opt_key, 48 bool command_key, bool shift_key, bool cntrl_key, bool opt_key,
42 int vkey_code); 49 int vkey_code, unichar key_char);
43 50
44 // This returns shortcuts that should work no matter what component of the 51 // This returns shortcuts that should work no matter what component of the
45 // browser is focused. They are executed by the window, after any view has the 52 // browser is focused. They are executed by the window, after any view has the
46 // opportunity to override the shortcut 53 // opportunity to override the shortcut
47 int CommandForDelayedWindowKeyboardShortcut( 54 int CommandForDelayedWindowKeyboardShortcut(
48 bool command_key, bool shift_key, bool cntrl_key, bool opt_key, 55 bool command_key, bool shift_key, bool cntrl_key, bool opt_key,
49 int vkey_code); 56 int vkey_code, unichar key_char);
50 57
51 // This returns shortcuts that should work only if the tab contents have focus 58 // This returns shortcuts that should work only if the tab contents have focus
52 // (e.g. cmd-left, which shouldn't do history navigation if e.g. the omnibox has 59 // (e.g. cmd-left, which shouldn't do history navigation if e.g. the omnibox has
53 // focus). 60 // focus).
54 int CommandForBrowserKeyboardShortcut( 61 int CommandForBrowserKeyboardShortcut(
55 bool command_key, bool shift_key, bool cntrl_key, bool opt_key, 62 bool command_key, bool shift_key, bool cntrl_key, bool opt_key,
56 int vkey_code); 63 int vkey_code, unichar key_char);
64
65 // Returns a keyboard event character for the given |event|. In most cases
66 // this returns the first character of [NSEvent charactersIgnoringModifiers],
67 // but when [NSEvent character] has different printable ascii character
68 // we may return the first character of [NSEvent characters] instead.
69 // (E.g. for dvorak-qwerty layout we want [NSEvent characters] rather than
70 // [charactersIgnoringModifiers] for command keys. Similarly, on german
71 // layout we want '{' character rather than '8' for opt-8.)
72 unichar KeyCharacterForEvent(NSEvent* event);
57 73
58 // For testing purposes. 74 // For testing purposes.
59 const KeyboardShortcutData* GetWindowKeyboardShortcutTable(size_t* num_entries); 75 const KeyboardShortcutData* GetWindowKeyboardShortcutTable(size_t* num_entries);
60 const KeyboardShortcutData* 76 const KeyboardShortcutData*
61 GetDelayedWindowKeyboardShortcutTable(size_t* num_entries); 77 GetDelayedWindowKeyboardShortcutTable(size_t* num_entries);
62 const KeyboardShortcutData* 78 const KeyboardShortcutData*
63 GetBrowserKeyboardShortcutTable(size_t* num_entries); 79 GetBrowserKeyboardShortcutTable(size_t* num_entries);
64 80
65 #endif // #ifndef CHROME_BROWSER_GLOBAL_KEYBOARD_SHORTCUTS_MAC_H_ 81 #endif // #ifndef CHROME_BROWSER_GLOBAL_KEYBOARD_SHORTCUTS_MAC_H_
OLDNEW
« no previous file with comments | « chrome/browser/cocoa/chrome_event_processing_window.mm ('k') | chrome/browser/global_keyboard_shortcuts_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698