Flutter macOS Embedder
KeyCodeMap_Internal.h
Go to the documentation of this file.
1 // Copyright 2013 The Flutter 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 FLUTTER_SHELL_PLATFORM_DARWIN_MACOS_FRAMEWORK_SOURCE_KEYCODEMAP_INTERNAL_H_
6 #define FLUTTER_SHELL_PLATFORM_DARWIN_MACOS_FRAMEWORK_SOURCE_KEYCODEMAP_INTERNAL_H_
7 
8 #import <Cocoa/Cocoa.h>
9 #include <cinttypes>
10 #include <vector>
11 
12 namespace flutter {
13 
14 /**
15  * Maps macOS-specific key code values representing |PhysicalKeyboardKey|.
16  *
17  * MacOS doesn't provide a scan code, but a virtual keycode to represent a physical key.
18  */
19 extern const NSDictionary* keyCodeToPhysicalKey;
20 
21 /**
22  * A map from macOS key codes to Flutter's logical key values.
23  *
24  * This is used to derive logical keys that can't or shouldn't be derived from
25  * |charactersIgnoringModifiers|.
26  */
27 extern const NSDictionary* keyCodeToLogicalKey;
28 
29 // Several mask constants. See KeyCodeMap.g.mm for their descriptions.
30 
31 /**
32  * Mask for the 32-bit value portion of the key code.
33  */
34 extern const uint64_t kValueMask;
35 
36 /**
37  * The plane value for keys which have a Unicode representation.
38  */
39 extern const uint64_t kUnicodePlane;
40 
41 /**
42  * The plane value for the private keys defined by the macOS embedding.
43  */
44 extern const uint64_t kMacosPlane;
45 
46 /**
47  * Map |NSEvent.keyCode| to its corresponding bitmask of NSEventModifierFlags.
48  *
49  * This does not include CapsLock, for it is handled specially.
50  */
51 extern const NSDictionary* keyCodeToModifierFlag;
52 
53 /**
54  * Map a bit of bitmask of NSEventModifierFlags to its corresponding
55  * |NSEvent.keyCode|.
56  *
57  * This does not include CapsLock, for it is handled specially.
58  */
59 extern const NSDictionary* modifierFlagToKeyCode;
60 
61 /**
62  * The physical key for CapsLock, which needs special handling.
63  */
64 extern const uint64_t kCapsLockPhysicalKey;
65 
66 /**
67  * The logical key for CapsLock, which needs special handling.
68  */
69 extern const uint64_t kCapsLockLogicalKey;
70 
71 /**
72  * Bits in |NSEvent.modifierFlags| indicating whether a modifier key is pressed.
73  *
74  * These constants are not written in the official documentation, but derived
75  * from experiments. This is currently the only way to know whether a one-side
76  * modifier key (such as ShiftLeft) is pressed, instead of the general combined
77  * modifier state (such as Shift).
78  */
79 typedef enum {
88 } ModifierFlag;
89 
90 /**
91  * A character that Flutter wants to derive layout for, and guides on how to
92  * derive it.
93  */
94 typedef struct {
95  // The key code for a key that prints `keyChar` in the US keyboard layout.
96  uint16_t keyCode;
97 
98  // The printable string to derive logical key for.
99  uint64_t keyChar;
100 
101  // If the goal is mandatory, the keyboard manager will make sure to find a
102  // logical key for this character, falling back to the US keyboard layout.
103  bool mandatory;
104 } LayoutGoal;
105 
106 /**
107  * All keys that Flutter wants to derive layout for, and guides on how to derive
108  * them.
109  */
110 extern const std::vector<LayoutGoal> kLayoutGoals;
111 
112 } // namespace flutter
113 
114 #endif // FLUTTER_SHELL_PLATFORM_DARWIN_MACOS_FRAMEWORK_SOURCE_KEYCODEMAP_INTERNAL_H_
flutter::kCapsLockPhysicalKey
const uint64_t kCapsLockPhysicalKey
Definition: KeyCodeMap.g.mm:245
flutter::LayoutGoal::keyCode
uint16_t keyCode
Definition: KeyCodeMap_Internal.h:96
flutter::keyCodeToLogicalKey
const NSDictionary * keyCodeToLogicalKey
Definition: KeyCodeMap.g.mm:149
flutter::keyCodeToPhysicalKey
const NSDictionary * keyCodeToPhysicalKey
Definition: KeyCodeMap.g.mm:26
flutter::kLayoutGoals
const std::vector< LayoutGoal > kLayoutGoals
Definition: KeyCodeMap.g.mm:248
flutter::kModifierFlagMetaLeft
@ kModifierFlagMetaLeft
Definition: KeyCodeMap_Internal.h:83
flutter::kModifierFlagAltRight
@ kModifierFlagAltRight
Definition: KeyCodeMap_Internal.h:86
flutter::kModifierFlagMetaRight
@ kModifierFlagMetaRight
Definition: KeyCodeMap_Internal.h:84
flutter::kValueMask
const uint64_t kValueMask
Definition: KeyCodeMap.g.mm:22
flutter::kModifierFlagControlLeft
@ kModifierFlagControlLeft
Definition: KeyCodeMap_Internal.h:80
flutter::kModifierFlagAltLeft
@ kModifierFlagAltLeft
Definition: KeyCodeMap_Internal.h:85
flutter::keyCodeToModifierFlag
const NSDictionary * keyCodeToModifierFlag
Definition: KeyCodeMap.g.mm:223
flutter
Definition: AccessibilityBridgeMac.h:16
flutter::modifierFlagToKeyCode
const NSDictionary * modifierFlagToKeyCode
Definition: KeyCodeMap.g.mm:234
flutter::LayoutGoal
Definition: KeyCodeMap_Internal.h:94
flutter::ModifierFlag
ModifierFlag
Definition: KeyCodeMap_Internal.h:79
flutter::kModifierFlagShiftRight
@ kModifierFlagShiftRight
Definition: KeyCodeMap_Internal.h:82
flutter::kCapsLockLogicalKey
const uint64_t kCapsLockLogicalKey
Definition: KeyCodeMap.g.mm:246
flutter::LayoutGoal::mandatory
bool mandatory
Definition: KeyCodeMap_Internal.h:103
flutter::kModifierFlagShiftLeft
@ kModifierFlagShiftLeft
Definition: KeyCodeMap_Internal.h:81
flutter::kModifierFlagControlRight
@ kModifierFlagControlRight
Definition: KeyCodeMap_Internal.h:87
flutter::kMacosPlane
const uint64_t kMacosPlane
Definition: KeyCodeMap.g.mm:24
flutter::LayoutGoal::keyChar
uint64_t keyChar
Definition: KeyCodeMap_Internal.h:99
flutter::kUnicodePlane
const uint64_t kUnicodePlane
Definition: KeyCodeMap.g.mm:23