New scheme for keyboard logical key ID (#85121)

This PR updates the ID used by logical keyboard keys.

The logical key ID is still composed of 2 parts: 32 bits of value, and 8 bits of plane. But the assignment of planes has been drastically changed. HID plane is removed, and unprintable plane and Flutter plane are added. This is to reflect the new generation method for logical key IDs. Now keys that are defined by Flutter but not by dom_key_data are placed into the Flutter plane, including numpad keys, sided modifier keys, and gamepad keys. The values for platform planes have also been adjusted.

The generation script and README have been updated accordingly as well.

A new file, test_utils/key_codes.h is now generated to assist engine unit testing.

All lists generated by the script are now sorted by the key.
This commit is contained in:
Tong Mu
2021-07-14 13:07:22 -07:00
committed by GitHub
parent 252f6a0285
commit c8d0b1d9db
38 changed files with 4814 additions and 4724 deletions

View File

@@ -51,24 +51,24 @@ class KeyboardMapsCodeGenerator extends BaseCodeGenerator {
/// This generates the map of GLFW number pad key codes to logical keys.
String get _glfwNumpadMap {
final StringBuffer glfwNumpadMap = StringBuffer();
final OutputLines<int> lines = OutputLines<int>('GLFW numpad map');
for (final PhysicalKeyEntry entry in _numpadKeyData) {
for (final int code in entry.glfwKeyCodes) {
glfwNumpadMap.writeln(' $code: LogicalKeyboardKey.${entry.constantName},');
lines.add(code, ' $code: LogicalKeyboardKey.${entry.constantName},');
}
}
return glfwNumpadMap.toString().trimRight();
return lines.sortedJoin().trimRight();
}
/// This generates the map of GLFW key codes to logical keys.
String get _glfwKeyCodeMap {
final StringBuffer glfwKeyCodeMap = StringBuffer();
final OutputLines<int> lines = OutputLines<int>('GLFW key code map');
for (final PhysicalKeyEntry entry in keyData.entries) {
for (final int code in entry.glfwKeyCodes) {
glfwKeyCodeMap.writeln(' $code: LogicalKeyboardKey.${entry.constantName},');
lines.add(code, ' $code: LogicalKeyboardKey.${entry.constantName},');
}
}
return glfwKeyCodeMap.toString().trimRight();
return lines.sortedJoin().trimRight();
}
/// This generates the map of GTK number pad key codes to logical keys.
@@ -95,13 +95,14 @@ class KeyboardMapsCodeGenerator extends BaseCodeGenerator {
/// This generates the map of XKB USB HID codes to physical keys.
String get _xkbScanCodeMap {
final StringBuffer xkbScanCodeMap = StringBuffer();
final OutputLines<int> lines = OutputLines<int>('GTK scancode map');
for (final PhysicalKeyEntry entry in keyData.entries) {
if (entry.xKbScanCode != null) {
xkbScanCodeMap.writeln(' ${toHex(entry.xKbScanCode)}: PhysicalKeyboardKey.${entry.constantName},');
lines.add(entry.xKbScanCode!,
' ${toHex(entry.xKbScanCode)}: PhysicalKeyboardKey.${entry.constantName},');
}
}
return xkbScanCodeMap.toString().trimRight();
return lines.sortedJoin().trimRight();
}
/// This generates the map of Android key codes to logical keys.
@@ -128,26 +129,26 @@ class KeyboardMapsCodeGenerator extends BaseCodeGenerator {
/// This generates the map of Android scan codes to physical keys.
String get _androidScanCodeMap {
final StringBuffer androidScanCodeMap = StringBuffer();
final OutputLines<int> lines = OutputLines<int>('Android scancode map');
for (final PhysicalKeyEntry entry in keyData.entries) {
if (entry.androidScanCodes != null) {
for (final int code in entry.androidScanCodes) {
androidScanCodeMap.writeln(' $code: PhysicalKeyboardKey.${entry.constantName},');
lines.add(code, ' $code: PhysicalKeyboardKey.${entry.constantName},');
}
}
}
return androidScanCodeMap.toString().trimRight();
return lines.sortedJoin().trimRight();
}
/// This generates the map of Windows scan codes to physical keys.
String get _windowsScanCodeMap {
final StringBuffer windowsScanCodeMap = StringBuffer();
final OutputLines<int> lines = OutputLines<int>('Windows scancode map');
for (final PhysicalKeyEntry entry in keyData.entries) {
if (entry.windowsScanCode != null) {
windowsScanCodeMap.writeln(' ${toHex(entry.windowsScanCode)}: PhysicalKeyboardKey.${entry.constantName},');
lines.add(entry.windowsScanCode!, ' ${entry.windowsScanCode}: PhysicalKeyboardKey.${entry.constantName},');
}
}
return windowsScanCodeMap.toString().trimRight();
return lines.sortedJoin().trimRight();
}
/// This generates the map of Windows number pad key codes to logical keys.
@@ -181,34 +182,34 @@ class KeyboardMapsCodeGenerator extends BaseCodeGenerator {
/// This generates the map of macOS key codes to physical keys.
String get _macOSScanCodeMap {
final StringBuffer macOSScanCodeMap = StringBuffer();
final OutputLines<int> lines = OutputLines<int>('macOS scancode map');
for (final PhysicalKeyEntry entry in keyData.entries) {
if (entry.macOSScanCode != null) {
macOSScanCodeMap.writeln(' ${toHex(entry.macOSScanCode)}: PhysicalKeyboardKey.${entry.constantName},');
lines.add(entry.macOSScanCode!, ' ${toHex(entry.macOSScanCode)}: PhysicalKeyboardKey.${entry.constantName},');
}
}
return macOSScanCodeMap.toString().trimRight();
return lines.sortedJoin().trimRight();
}
/// This generates the map of macOS number pad key codes to logical keys.
String get _macOSNumpadMap {
final StringBuffer macOSNumPadMap = StringBuffer();
final OutputLines<int> lines = OutputLines<int>('macOS numpad map');
for (final PhysicalKeyEntry entry in _numpadKeyData) {
if (entry.macOSScanCode != null) {
macOSNumPadMap.writeln(' ${toHex(entry.macOSScanCode)}: LogicalKeyboardKey.${entry.constantName},');
lines.add(entry.macOSScanCode!, ' ${toHex(entry.macOSScanCode)}: LogicalKeyboardKey.${entry.constantName},');
}
}
return macOSNumPadMap.toString().trimRight();
return lines.sortedJoin().trimRight();
}
String get _macOSFunctionKeyMap {
final StringBuffer macOSFunctionKeyMap = StringBuffer();
final OutputLines<int> lines = OutputLines<int>('macOS function key map');
for (final PhysicalKeyEntry entry in _functionKeyData) {
if (entry.macOSScanCode != null) {
macOSFunctionKeyMap.writeln(' ${toHex(entry.macOSScanCode)}: LogicalKeyboardKey.${entry.constantName},');
lines.add(entry.macOSScanCode!, ' ${toHex(entry.macOSScanCode)}: LogicalKeyboardKey.${entry.constantName},');
}
}
return macOSFunctionKeyMap.toString().trimRight();
return lines.sortedJoin().trimRight();
}
/// This generates the map of macOS key codes to physical keys.
@@ -290,38 +291,38 @@ class KeyboardMapsCodeGenerator extends BaseCodeGenerator {
/// This generates the map of Web KeyboardEvent codes to physical keys.
String get _webPhysicalKeyMap {
final StringBuffer result = StringBuffer();
final OutputLines<String> lines = OutputLines<String>('Web physical key map');
for (final PhysicalKeyEntry entry in keyData.entries) {
if (entry.name != null) {
result.writeln(" '${entry.name}': PhysicalKeyboardKey.${entry.constantName},");
lines.add(entry.name, " '${entry.name}': PhysicalKeyboardKey.${entry.constantName},");
}
}
return result.toString().trimRight();
return lines.sortedJoin().trimRight();
}
String get _webNumpadMap {
final StringBuffer result = StringBuffer();
final OutputLines<String> lines = OutputLines<String>('Web numpad map');
for (final LogicalKeyEntry entry in _numpadLogicalKeyData) {
if (entry.name != null) {
result.writeln(" '${entry.name}': LogicalKeyboardKey.${entry.constantName},");
lines.add(entry.name, " '${entry.name}': LogicalKeyboardKey.${entry.constantName},");
}
}
return result.toString().trimRight();
return lines.sortedJoin().trimRight();
}
/// This generates the map of Web number pad codes to logical keys.
String get _webLocationMap {
final String jsonRaw = File(path.join(dataRoot, 'web_logical_location_mapping.json')).readAsStringSync();
final Map<String, List<String?>> locationMap = parseMapOfListOfNullableString(jsonRaw);
final StringBuffer result = StringBuffer();
final OutputLines<String> lines = OutputLines<String>('Web location map');
locationMap.forEach((String key, List<String?> keyNames) {
final String keyStrings = keyNames.map((String? keyName) {
final String? constantName = keyName == null ? null : logicalData.entryByName(keyName).constantName;
return constantName != null ? 'LogicalKeyboardKey.$constantName' : 'null';
}).join(', ');
result.writeln(" '$key': <LogicalKeyboardKey?>[$keyStrings],");
lines.add(key, " '$key': <LogicalKeyboardKey?>[$keyStrings],");
});
return result.toString().trimRight();
return lines.sortedJoin().trimRight();
}
@override