| Flutter iOS 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_IOS_FRAMEWORK_SOURCE_KEY_CODE_MAP_INTERNAL_H_
6 #define FLUTTER_SHELL_PLATFORM_DARWIN_IOS_FRAMEWORK_SOURCE_KEY_CODE_MAP_INTERNAL_H_
7
8 #import <UIKit/UIKit.h>
9 #include <map>
10 #include <set>
11
12 /**
13 * Maps iOS-specific key code values representing |PhysicalKeyboardKey|.
14 *
15 * MacOS doesn't provide a scan code, but a virtual keycode to represent a
16 * physical key.
17 */
18 extern const std::map<uint32_t, uint64_t> keyCodeToPhysicalKey;
19
20 /**
21 * A map from iOS key codes to Flutter's logical key values.
22 *
23 * This is used to derive logical keys that can't or shouldn't be derived from
24 * |charactersIgnoringModifiers|.
25 */
26 extern const std::map<uint32_t, uint64_t> keyCodeToLogicalKey;
27
28 /**
29 * Maps iOS specific string values of nonvisible keys to logical keys.
30 *
31 * TODO(dkwingsmt): Change this getter function to a global variable. I tried to
32 * do this but the unit test on CI threw errors saying "message sent to
33 * deallocated instance" on the NSDictionary.
34 *
35 * See:
36 * https://developer.apple.com/documentation/uikit/uikeycommand/input_strings_for_special_keys?language=objc
37 */
38 extern NSDictionary<NSString*, NSNumber*>* specialKeyMapping;
39
40 // Several mask constants. See KeyCodeMap.g.mm for their descriptions.
41
42 extern const uint64_t kValueMask;
43 extern const uint64_t kUnicodePlane;
44 extern const uint64_t kIosPlane;
45
46 /**
47 * The physical key for CapsLock, which needs special handling.
48 */
49 extern const uint64_t kCapsLockPhysicalKey;
50
51 /**
52 * The logical key for CapsLock, which needs special handling.
53 */
54 extern const uint64_t kCapsLockLogicalKey;
55
56 /**
57 * Bits in |UIKey.modifierFlags| indicating whether a modifier key is pressed.
58 */
59 typedef enum {
60 // These sided flags are not in any official Apple docs, they are derived from
61 // experiments.
62 kModifierFlagControlLeft = 0x1,
63 kModifierFlagShiftLeft = 0x2,
64 kModifierFlagShiftRight = 0x4,
65 kModifierFlagMetaLeft = 0x8,
66 kModifierFlagMetaRight = 0x10,
67 kModifierFlagAltLeft = 0x20,
68 kModifierFlagAltRight = 0x40,
69 kModifierFlagControlRight = 0x2000,
70
71 // These are equivalent to non-sided iOS values.
72 kModifierFlagCapsLock = UIKeyModifierAlphaShift, // 0x010000
73 kModifierFlagShiftAny = UIKeyModifierShift, // 0x020000
74 kModifierFlagControlAny = UIKeyModifierControl, // 0x040000
75 kModifierFlagAltAny = UIKeyModifierAlternate, // 0x080000
76 kModifierFlagMetaAny = UIKeyModifierCommand, // 0x100000
77 kModifierFlagNumPadKey = UIKeyModifierNumericPad // 0x200000
78 } ModifierFlag;
79
80 /**
81 * A mask of all the modifier flags that represent a modifier being pressed, but
82 * not whether it is the left or right modifier.
83 */
84 constexpr uint32_t kModifierFlagAnyMask =
85 kModifierFlagShiftAny | kModifierFlagControlAny | kModifierFlagAltAny | kModifierFlagMetaAny;
86
87 /**
88 * A mask of the modifier flags that represent only left or right modifier
89 * keys, and not the generic "Any" mask.
90 */
91 constexpr uint32_t kModifierFlagSidedMask = kModifierFlagControlLeft | kModifierFlagShiftLeft |
92 kModifierFlagShiftRight | kModifierFlagMetaLeft |
93 kModifierFlagMetaRight | kModifierFlagAltLeft |
94 kModifierFlagAltRight | kModifierFlagControlRight;
95
96 /**
97 * Map |UIKey.keyCode| to the matching sided modifier in UIEventModifierFlags.
98 */
99 extern const std::map<uint32_t, ModifierFlag> keyCodeToModifierFlag;
100
101 /**
102 * Map a bit of bitmask of sided modifiers in UIEventModifierFlags to their
103 * corresponding |UIKey.keyCode|.
104 */
105 extern const std::map<ModifierFlag, uint32_t> modifierFlagToKeyCode;
106
107 /**
108 * Maps a sided modifier key to the corresponding flag matching either side of
109 * that type of modifier.
110 */
111 extern const std::map<ModifierFlag, ModifierFlag> sidedModifierToAny;
112
113 /**
114 * Maps a non-sided modifier key to the corresponding flag matching the left key
115 * of that type of modifier.
116 */
117 extern const std::map<ModifierFlag, ModifierFlag> anyModifierToLeft;
118
119 /**
120 * A set of keycodes corresponding to function keys.
121 */
122 extern const std::set<uint32_t> functionKeyCodes;
123
124 #endif // FLUTTER_SHELL_PLATFORM_DARWIN_IOS_FRAMEWORK_SOURCE_KEY_CODE_MAP_INTERNAL_H_
kModifierFlagNumPadKey
@ kModifierFlagNumPadKey
Definition: KeyCodeMap_Internal.h:77
kModifierFlagCapsLock
@ kModifierFlagCapsLock
Definition: KeyCodeMap_Internal.h:72
kCapsLockLogicalKey
const uint64_t kCapsLockLogicalKey
specialKeyMapping
NSDictionary< NSString *, NSNumber * > * specialKeyMapping
anyModifierToLeft
const std::map< ModifierFlag, ModifierFlag > anyModifierToLeft
keyCodeToModifierFlag
const std::map< uint32_t, ModifierFlag > keyCodeToModifierFlag
Definition: KeyCodeMap.g.mm:279
modifierFlagToKeyCode
const std::map< ModifierFlag, uint32_t > modifierFlagToKeyCode
Definition: KeyCodeMap.g.mm:291
kModifierFlagAltAny
@ kModifierFlagAltAny
Definition: KeyCodeMap_Internal.h:75
kModifierFlagShiftRight
@ kModifierFlagShiftRight
Definition: KeyCodeMap_Internal.h:64
sidedModifierToAny
const std::map< ModifierFlag, ModifierFlag > sidedModifierToAny
kModifierFlagControlAny
@ kModifierFlagControlAny
Definition: KeyCodeMap_Internal.h:74
kIosPlane
const uint64_t kIosPlane
Definition: KeyCodeMap.g.mm:32
kModifierFlagAnyMask
constexpr uint32_t kModifierFlagAnyMask
Definition: KeyCodeMap_Internal.h:84
kCapsLockPhysicalKey
const uint64_t kCapsLockPhysicalKey
kModifierFlagSidedMask
constexpr uint32_t kModifierFlagSidedMask
Definition: KeyCodeMap_Internal.h:91
kUnicodePlane
const uint64_t kUnicodePlane
Definition: KeyCodeMap.g.mm:27
keyCodeToLogicalKey
const std::map< uint32_t, uint64_t > keyCodeToLogicalKey
Definition: KeyCodeMap.g.mm:201
kModifierFlagControlRight
@ kModifierFlagControlRight
Definition: KeyCodeMap_Internal.h:69
ModifierFlag
ModifierFlag
Definition: KeyCodeMap_Internal.h:59
kModifierFlagShiftAny
@ kModifierFlagShiftAny
Definition: KeyCodeMap_Internal.h:73
kModifierFlagShiftLeft
@ kModifierFlagShiftLeft
Definition: KeyCodeMap_Internal.h:63
kModifierFlagAltRight
@ kModifierFlagAltRight
Definition: KeyCodeMap_Internal.h:68
kModifierFlagMetaLeft
@ kModifierFlagMetaLeft
Definition: KeyCodeMap_Internal.h:65
keyCodeToPhysicalKey
const std::map< uint32_t, uint64_t > keyCodeToPhysicalKey
Definition: KeyCodeMap.g.mm:37
kModifierFlagMetaRight
@ kModifierFlagMetaRight
Definition: KeyCodeMap_Internal.h:66
kModifierFlagAltLeft
@ kModifierFlagAltLeft
Definition: KeyCodeMap_Internal.h:67
kModifierFlagControlLeft
@ kModifierFlagControlLeft
Definition: KeyCodeMap_Internal.h:62
kModifierFlagMetaAny
@ kModifierFlagMetaAny
Definition: KeyCodeMap_Internal.h:76
kValueMask
const uint64_t kValueMask
Definition: KeyCodeMap.g.mm:22
functionKeyCodes
const std::set< uint32_t > functionKeyCodes
Definition: KeyCodeMap.g.mm:304