Flutter Engine
The Flutter Engine
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
12namespace 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 */
19extern 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 */
27extern 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 */
34extern const uint64_t kValueMask;
35
36/**
37 * The plane value for keys which have a Unicode representation.
38 */
39extern const uint64_t kUnicodePlane;
40
41/**
42 * The plane value for the private keys defined by the macOS embedding.
43 */
44extern 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 */
51extern 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 */
59extern const NSDictionary* modifierFlagToKeyCode;
60
61/**
62 * The physical key for CapsLock, which needs special handling.
63 */
64extern const uint64_t kCapsLockPhysicalKey;
65
66/**
67 * The logical key for CapsLock, which needs special handling.
68 */
69extern 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 */
79typedef enum {
89
90/**
91 * A character that Flutter wants to derive layout for, and guides on how to
92 * derive it.
93 */
94typedef 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.
104} LayoutGoal;
105
106/**
107 * All keys that Flutter wants to derive layout for, and guides on how to derive
108 * them.
109 */
110extern const std::vector<LayoutGoal> kLayoutGoals;
111
112} // namespace flutter
113
114#endif // FLUTTER_SHELL_PLATFORM_DARWIN_MACOS_FRAMEWORK_SOURCE_KEYCODEMAP_INTERNAL_H_
const NSDictionary * keyCodeToLogicalKey
const uint64_t kUnicodePlane
Definition: KeyCodeMap.g.mm:23
const std::vector< LayoutGoal > kLayoutGoals
const NSDictionary * keyCodeToPhysicalKey
Definition: KeyCodeMap.g.mm:26
const NSDictionary * keyCodeToModifierFlag
const uint64_t kValueMask
Definition: KeyCodeMap.g.mm:22
const uint64_t kCapsLockLogicalKey
const NSDictionary * modifierFlagToKeyCode
const uint64_t kMacosPlane
Definition: KeyCodeMap.g.mm:24
const uint64_t kCapsLockPhysicalKey
@ kModifierFlagControlLeft
@ kModifierFlagControlRight