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:
@@ -25,10 +25,6 @@ const List<String> kModifiersOfInterest = <String>[
|
||||
const List<String> kSpecialPhysicalKeys = <String>['CapsLock'];
|
||||
const List<String> kSpecialLogicalKeys = <String>['CapsLock'];
|
||||
|
||||
String _toConstantVariableName(String variableName) {
|
||||
return 'k${variableName[0].toUpperCase()}${variableName.substring(1)}';
|
||||
}
|
||||
|
||||
/// Generates the key mapping for macOS, based on the information in the key
|
||||
/// data structure given to it.
|
||||
class MacOSCodeGenerator extends PlatformCodeGenerator {
|
||||
@@ -37,36 +33,36 @@ class MacOSCodeGenerator extends PlatformCodeGenerator {
|
||||
|
||||
/// This generates the map of macOS key codes to physical keys.
|
||||
String get _scanCodeMap {
|
||||
final StringBuffer scanCodeMap = StringBuffer();
|
||||
final OutputLines<int> lines = OutputLines<int>('macOS scancode map');
|
||||
for (final PhysicalKeyEntry entry in keyData.entries) {
|
||||
if (entry.macOSScanCode != null) {
|
||||
scanCodeMap.writeln(' @${toHex(entry.macOSScanCode)} : @${toHex(entry.usbHidCode)}, // ${entry.constantName}');
|
||||
lines.add(entry.macOSScanCode!, ' @${toHex(entry.macOSScanCode)} : @${toHex(entry.usbHidCode)}, // ${entry.constantName}');
|
||||
}
|
||||
}
|
||||
return scanCodeMap.toString().trimRight();
|
||||
return lines.sortedJoin().trimRight();
|
||||
}
|
||||
|
||||
String get _keyCodeToLogicalMap {
|
||||
final StringBuffer result = StringBuffer();
|
||||
final OutputLines<int> lines = OutputLines<int>('macOS keycode map');
|
||||
for (final LogicalKeyEntry entry in logicalData.entries) {
|
||||
zipStrict(entry.macOSKeyCodeValues, entry.macOSKeyCodeNames, (int macOSValue, String macOSName) {
|
||||
result.writeln(' @${toHex(macOSValue)} : @${toHex(entry.value, digits: 11)}, // $macOSName');
|
||||
lines.add(macOSValue,
|
||||
' @${toHex(macOSValue)} : @${toHex(entry.value, digits: 11)}, // $macOSName -> ${entry.constantName}');
|
||||
});
|
||||
}
|
||||
return result.toString().trimRight();
|
||||
return lines.sortedJoin().trimRight();
|
||||
}
|
||||
|
||||
/// This generates the mask values for the part of a key code that defines its plane.
|
||||
String get _maskConstants {
|
||||
final StringBuffer buffer = StringBuffer();
|
||||
const List<MaskConstant> maskConstants = <MaskConstant>[
|
||||
kValueMask,
|
||||
kUnicodePlane,
|
||||
kMacosPlane,
|
||||
];
|
||||
for (final MaskConstant constant in maskConstants) {
|
||||
buffer.writeln('/**');
|
||||
buffer.write(constant.description
|
||||
.map((String line) => wrapString(line, prefix: ' * '))
|
||||
.join(' *\n'));
|
||||
buffer.writeln(' */');
|
||||
buffer.writeln('const uint64_t ${_toConstantVariableName(constant.name)} = ${toHex(constant.value, digits: 11)};');
|
||||
buffer.writeln('');
|
||||
buffer.writeln('const uint64_t k${constant.upperCamelName} = ${toHex(constant.value, digits: 11)};');
|
||||
}
|
||||
return buffer.toString().trimRight();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user