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