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