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_KEYCODEMAP_INTERNAL_H_
6 #define FLUTTER_SHELL_PLATFORM_DARWIN_IOS_FRAMEWORK_SOURCE_KEYCODEMAP_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 // NOLINTNEXTLINE(readability-identifier-naming)
19 extern const std::map<uint32_t, uint64_t> keyCodeToPhysicalKey;
20 
21 /**
22  * A map from iOS 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 // NOLINTNEXTLINE(readability-identifier-naming)
28 extern const std::map<uint32_t, uint64_t> keyCodeToLogicalKey;
29 
30 /**
31  * Maps iOS specific string values of nonvisible keys to logical keys.
32  *
33  * TODO(dkwingsmt): Change this getter function to a global variable. I tried to
34  * do this but the unit test on CI threw errors saying "message sent to
35  * deallocated instance" on the NSDictionary.
36  *
37  * See:
38  * https://developer.apple.com/documentation/uikit/uikeycommand/input_strings_for_special_keys?language=objc
39  */
40 extern NSDictionary<NSString*, NSNumber*>* specialKeyMapping;
41 
42 // Several mask constants. See KeyCodeMap.g.mm for their descriptions.
43 
44 extern const uint64_t kValueMask;
45 extern const uint64_t kUnicodePlane;
46 extern const uint64_t kIosPlane;
47 
48 /**
49  * The physical key for CapsLock, which needs special handling.
50  */
51 extern const uint64_t kCapsLockPhysicalKey;
52 
53 /**
54  * The logical key for CapsLock, which needs special handling.
55  */
56 extern const uint64_t kCapsLockLogicalKey;
57 
58 /**
59  * Bits in |UIKey.modifierFlags| indicating whether a modifier key is pressed.
60  */
61 typedef enum {
62  // These sided flags are not in any official Apple docs, they are derived from
63  // experiments.
72 
73  // These are equivalent to non-sided iOS values.
74  kModifierFlagCapsLock = UIKeyModifierAlphaShift, // 0x010000
75  kModifierFlagShiftAny = UIKeyModifierShift, // 0x020000
76  kModifierFlagControlAny = UIKeyModifierControl, // 0x040000
77  kModifierFlagAltAny = UIKeyModifierAlternate, // 0x080000
78  kModifierFlagMetaAny = UIKeyModifierCommand, // 0x100000
79  kModifierFlagNumPadKey = UIKeyModifierNumericPad // 0x200000
80 } ModifierFlag;
81 
82 /**
83  * A mask of all the modifier flags that represent a modifier being pressed, but
84  * not whether it is the left or right modifier.
85  */
86 constexpr uint32_t kModifierFlagAnyMask =
88 
89 /**
90  * A mask of the modifier flags that represent only left or right modifier
91  * keys, and not the generic "Any" mask.
92  */
97 
98 /**
99  * Map |UIKey.keyCode| to the matching sided modifier in UIEventModifierFlags.
100  */
101 // NOLINTNEXTLINE(readability-identifier-naming)
102 extern const std::map<uint32_t, ModifierFlag> keyCodeToModifierFlag;
103 
104 /**
105  * Map a bit of bitmask of sided modifiers in UIEventModifierFlags to their
106  * corresponding |UIKey.keyCode|.
107  */
108 // NOLINTNEXTLINE(readability-identifier-naming)
109 extern const std::map<ModifierFlag, uint32_t> modifierFlagToKeyCode;
110 
111 /**
112  * Maps a sided modifier key to the corresponding flag matching either side of
113  * that type of modifier.
114  */
115 // NOLINTNEXTLINE(readability-identifier-naming)
116 extern const std::map<ModifierFlag, ModifierFlag> sidedModifierToAny;
117 
118 /**
119  * Maps a non-sided modifier key to the corresponding flag matching the left key
120  * of that type of modifier.
121  */
122 // NOLINTNEXTLINE(readability-identifier-naming)
123 extern const std::map<ModifierFlag, ModifierFlag> anyModifierToLeft;
124 
125 /**
126  * A set of keycodes corresponding to function keys.
127  */
128 // NOLINTNEXTLINE(readability-identifier-naming)
129 extern const std::set<uint32_t> functionKeyCodes;
130 
131 #endif // FLUTTER_SHELL_PLATFORM_DARWIN_IOS_FRAMEWORK_SOURCE_KEYCODEMAP_INTERNAL_H_
kModifierFlagNumPadKey
@ kModifierFlagNumPadKey
Definition: KeyCodeMap_Internal.h:79
kModifierFlagCapsLock
@ kModifierFlagCapsLock
Definition: KeyCodeMap_Internal.h:74
kCapsLockLogicalKey
const uint64_t kCapsLockLogicalKey
Definition: KeyCodeMap.g.mm:357
specialKeyMapping
NSDictionary< NSString *, NSNumber * > * specialKeyMapping
Definition: KeyCodeMap.g.mm:332
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:77
kModifierFlagShiftRight
@ kModifierFlagShiftRight
Definition: KeyCodeMap_Internal.h:66
sidedModifierToAny
const std::map< ModifierFlag, ModifierFlag > sidedModifierToAny
kModifierFlagControlAny
@ kModifierFlagControlAny
Definition: KeyCodeMap_Internal.h:76
kIosPlane
const uint64_t kIosPlane
Definition: KeyCodeMap.g.mm:32
kModifierFlagAnyMask
constexpr uint32_t kModifierFlagAnyMask
Definition: KeyCodeMap_Internal.h:86
kCapsLockPhysicalKey
const uint64_t kCapsLockPhysicalKey
Definition: KeyCodeMap.g.mm:356
kModifierFlagSidedMask
constexpr uint32_t kModifierFlagSidedMask
Definition: KeyCodeMap_Internal.h:93
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:71
ModifierFlag
ModifierFlag
Definition: KeyCodeMap_Internal.h:61
kModifierFlagShiftAny
@ kModifierFlagShiftAny
Definition: KeyCodeMap_Internal.h:75
kModifierFlagShiftLeft
@ kModifierFlagShiftLeft
Definition: KeyCodeMap_Internal.h:65
kModifierFlagAltRight
@ kModifierFlagAltRight
Definition: KeyCodeMap_Internal.h:70
kModifierFlagMetaLeft
@ kModifierFlagMetaLeft
Definition: KeyCodeMap_Internal.h:67
keyCodeToPhysicalKey
const std::map< uint32_t, uint64_t > keyCodeToPhysicalKey
Definition: KeyCodeMap.g.mm:37
kModifierFlagMetaRight
@ kModifierFlagMetaRight
Definition: KeyCodeMap_Internal.h:68
kModifierFlagAltLeft
@ kModifierFlagAltLeft
Definition: KeyCodeMap_Internal.h:69
kModifierFlagControlLeft
@ kModifierFlagControlLeft
Definition: KeyCodeMap_Internal.h:64
kModifierFlagMetaAny
@ kModifierFlagMetaAny
Definition: KeyCodeMap_Internal.h:78
kValueMask
const uint64_t kValueMask
Definition: KeyCodeMap.g.mm:22
functionKeyCodes
const std::set< uint32_t > functionKeyCodes
Definition: KeyCodeMap.g.mm:304