1 // Copyright 2009 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_GLOBAL_KEYBOARD_SHORTCUTS_MAC_H_
6 #define CHROME_BROWSER_GLOBAL_KEYBOARD_SHORTCUTS_MAC_H_
20 constexpr int NO_COMMAND = -1;
22 struct KeyboardShortcutData {
27 int vkey_code; // Virtual Key code for the command.
29 int chrome_command; // The chrome command # to execute for this shortcut.
32 struct CommandForKeyEventResult {
33 bool found() { return chrome_command != NO_COMMAND; }
35 // The command to execute. NO_COMMAND if none was found.
38 // Whether the command was from a mapping in the main menu. Only relevant if
39 // command != NO_COMMAND.
45 // macOS applications are supposed to put all keyEquivalents [hotkeys] in the
46 // menu bar. For legacy reasons, Chrome does not. There are around 30 hotkeys
47 // that are explicitly coded to virtual keycodes. This has the following
49 // * There is no way for the user to configure or disable these keyEquivalents.
50 // * This can cause keyEquivalent conflicts for non-US keyboard layouts with
51 // different default keyEquivalents, see https://crbug.com/841299.
53 // This function first searches the menu bar for a matching keyEquivalent. If
54 // nothing is found, then it searches through the explicitly coded virtual
55 // keycodes not present in the NSMenu.
57 // Note: AppKit exposes symbolic hotkeys [e.g. cmd + `] not present in the
58 // NSMenu as well. The user can remap these to conflict with Chrome hotkeys.
59 // This function will return the Chrome hotkey, regardless of whether there's a
60 // conflicting symbolic hotkey.
61 CommandForKeyEventResult CommandForKeyEvent(NSEvent* event);
63 // For legacy reasons and compatibility with Safari, some commands [e.g. cmd +
64 // left arrow] are only allowed to fire if the firstResponder is a WebContents,
65 // and the WebContents has chosen not to handle the event.
66 int DelayedWebContentsCommandForKeyEvent(NSEvent* event);
68 // Whether the event goes through the performKeyEquivalent: path and is handled
69 // by CommandDispatcher.
70 bool EventUsesPerformKeyEquivalent(NSEvent* event);
74 // On macOS, most accelerators are defined in MainMenu.xib and are user
75 // configurable. Furthermore, their values and enabled state depends on the key
76 // window. Views code relies on a static mapping that is not dependent on the
77 // key window. Thus, we provide the default Mac accelerator for each CommandId,
78 // which is static. This may be inaccurate, but is at least sufficiently well
79 // defined for Views to use.
80 bool GetDefaultMacAcceleratorForCommandId(int command_id,
81 ui::Accelerator* accelerator);
83 // For testing purposes.
84 const std::vector<KeyboardShortcutData>& GetShortcutsNotPresentInMainMenu();
86 #endif // CHROME_BROWSER_GLOBAL_KEYBOARD_SHORTCUTS_MAC_H_