Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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)
19extern 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)
28extern 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 */
40extern NSDictionary<NSString*, NSNumber*>* specialKeyMapping;
41
42// Several mask constants. See KeyCodeMap.g.mm for their descriptions.
43
44extern const uint64_t kValueMask;
45extern const uint64_t kUnicodePlane;
46extern const uint64_t kIosPlane;
47
48/**
49 * The physical key for CapsLock, which needs special handling.
50 */
51extern const uint64_t kCapsLockPhysicalKey;
52
53/**
54 * The logical key for CapsLock, which needs special handling.
55 */
56extern const uint64_t kCapsLockLogicalKey;
57
58/**
59 * Bits in |UIKey.modifierFlags| indicating whether a modifier key is pressed.
60 */
61typedef 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
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 */
86constexpr 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)
102extern 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)
109extern 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)
116extern 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)
123extern const std::map<ModifierFlag, ModifierFlag> anyModifierToLeft;
124
125/**
126 * A set of keycodes corresponding to function keys.
127 */
128// NOLINTNEXTLINE(readability-identifier-naming)
129extern const std::set<uint32_t> functionKeyCodes;
130
131#endif // FLUTTER_SHELL_PLATFORM_DARWIN_IOS_FRAMEWORK_SOURCE_KEYCODEMAP_INTERNAL_H_
const std::map< uint32_t, ModifierFlag > keyCodeToModifierFlag
@ kModifierFlagCapsLock
@ kModifierFlagNumPadKey
@ kModifierFlagControlLeft
@ kModifierFlagAltRight
@ kModifierFlagShiftAny
@ kModifierFlagControlRight
@ kModifierFlagMetaAny
@ kModifierFlagMetaRight
@ kModifierFlagShiftLeft
@ kModifierFlagShiftRight
@ kModifierFlagControlAny
@ kModifierFlagAltLeft
@ kModifierFlagMetaLeft
@ kModifierFlagAltAny
const std::map< ModifierFlag, ModifierFlag > sidedModifierToAny
const std::set< uint32_t > functionKeyCodes
const uint64_t kValueMask
const std::map< uint32_t, uint64_t > keyCodeToPhysicalKey
constexpr uint32_t kModifierFlagAnyMask
NSDictionary< NSString *, NSNumber * > * specialKeyMapping
const uint64_t kUnicodePlane
const std::map< uint32_t, uint64_t > keyCodeToLogicalKey
const uint64_t kCapsLockLogicalKey
const uint64_t kCapsLockPhysicalKey
const std::map< ModifierFlag, uint32_t > modifierFlagToKeyCode
const uint64_t kIosPlane
const std::map< ModifierFlag, ModifierFlag > anyModifierToLeft
constexpr uint32_t kModifierFlagSidedMask