[M120 Migration]Fix for crash during chrome exit
[platform/framework/web/chromium-efl.git] / chrome / browser / global_keyboard_shortcuts_mac.h
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.
4
5 #ifndef CHROME_BROWSER_GLOBAL_KEYBOARD_SHORTCUTS_MAC_H_
6 #define CHROME_BROWSER_GLOBAL_KEYBOARD_SHORTCUTS_MAC_H_
7
8 #include <stddef.h>
9
10 #include <vector>
11
12 #if defined(__OBJC__)
13 @class NSEvent;
14 #endif  // __OBJC__
15
16 namespace ui {
17 class Accelerator;
18 }
19
20 constexpr int NO_COMMAND = -1;
21
22 struct KeyboardShortcutData {
23   bool command_key;
24   bool shift_key;
25   bool cntrl_key;
26   bool opt_key;
27   int vkey_code;  // Virtual Key code for the command.
28
29   int chrome_command;  // The chrome command # to execute for this shortcut.
30 };
31
32 struct CommandForKeyEventResult {
33   bool found() { return chrome_command != NO_COMMAND; }
34
35   // The command to execute. NO_COMMAND if none was found.
36   int chrome_command;
37
38   // Whether the command was from a mapping in the main menu. Only relevant if
39   // command != NO_COMMAND.
40   bool from_main_menu;
41 };
42
43 #if defined(__OBJC__)
44
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
48 // downsides:
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.
52 //
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.
56 //
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);
62
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);
67
68 // Whether the event goes through the performKeyEquivalent: path and is handled
69 // by CommandDispatcher.
70 bool EventUsesPerformKeyEquivalent(NSEvent* event);
71
72 #endif  // __OBJC__
73
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);
82
83 // For testing purposes.
84 const std::vector<KeyboardShortcutData>& GetShortcutsNotPresentInMainMenu();
85
86 #endif  // CHROME_BROWSER_GLOBAL_KEYBOARD_SHORTCUTS_MAC_H_