Hardware keyboard: codegen (#73440)
Rewrites tools/gen_keycodes, the script that generates key mappings across the framework and the engine.
This commit is contained in:
@@ -5,22 +5,27 @@
|
||||
import 'package:path/path.dart' as path;
|
||||
|
||||
import 'base_code_gen.dart';
|
||||
import 'key_data.dart';
|
||||
import 'logical_key_data.dart';
|
||||
import 'physical_key_data.dart';
|
||||
import 'utils.dart';
|
||||
|
||||
|
||||
/// Generates the key mapping of Web, based on the information in the key
|
||||
/// Generates the key mapping for Web, based on the information in the key
|
||||
/// data structure given to it.
|
||||
class WebCodeGenerator extends PlatformCodeGenerator {
|
||||
WebCodeGenerator(KeyData keyData) : super(keyData);
|
||||
WebCodeGenerator(
|
||||
PhysicalKeyData keyData,
|
||||
LogicalKeyData logicalData,
|
||||
String logicalLocationMap,
|
||||
) : _logicalLocationMap = parseMapOfListOfNullableString(logicalLocationMap),
|
||||
super(keyData, logicalData);
|
||||
|
||||
/// This generates the map of Web KeyboardEvent codes to logical key ids.
|
||||
String get _webLogicalKeyCodeMap {
|
||||
final StringBuffer result = StringBuffer();
|
||||
for (final Key entry in keyData.data) {
|
||||
if (entry.name != null) {
|
||||
result.writeln(" '${entry.name}': ${toHex(entry.flutterId, digits: 10)},");
|
||||
}
|
||||
for (final LogicalKeyEntry entry in logicalData.entries) {
|
||||
zipStrict(entry.webValues, entry.webNames, (int value, String name) {
|
||||
result.writeln(" '$name': ${toHex(value, digits: 10)},");
|
||||
});
|
||||
}
|
||||
return result.toString().trimRight();
|
||||
}
|
||||
@@ -28,7 +33,7 @@ class WebCodeGenerator extends PlatformCodeGenerator {
|
||||
/// This generates the map of Web KeyboardEvent codes to physical key USB HID codes.
|
||||
String get _webPhysicalKeyCodeMap {
|
||||
final StringBuffer result = StringBuffer();
|
||||
for (final Key entry in keyData.data) {
|
||||
for (final PhysicalKeyEntry entry in keyData.entries) {
|
||||
if (entry.name != null) {
|
||||
result.writeln(" '${entry.name}': ${toHex(entry.usbHidCode)},");
|
||||
}
|
||||
@@ -37,28 +42,31 @@ class WebCodeGenerator extends PlatformCodeGenerator {
|
||||
}
|
||||
|
||||
/// This generates the map of Web number pad codes to logical key ids.
|
||||
String get _webNumpadCodeMap {
|
||||
String get _webLogicalLocationMap {
|
||||
final StringBuffer result = StringBuffer();
|
||||
for (final Key entry in numpadKeyData) {
|
||||
if (entry.name != null) {
|
||||
result.writeln(" '${entry.name}': ${toHex(entry.flutterId, digits: 10)},");
|
||||
}
|
||||
}
|
||||
_logicalLocationMap.forEach((String webKey, List<String?> locations) {
|
||||
final String valuesString = locations.map((String? value) {
|
||||
return value == null ? 'null' : toHex(logicalData.entryByName(value).value, digits: 10);
|
||||
}).join(', ');
|
||||
result.writeln(" '$webKey': <int?>[$valuesString],");
|
||||
});
|
||||
return result.toString().trimRight();
|
||||
}
|
||||
final Map<String, List<String?>> _logicalLocationMap;
|
||||
|
||||
@override
|
||||
String get templatePath => path.join(flutterRoot.path, 'dev', 'tools', 'gen_keycodes', 'data', 'keyboard_map_web.tmpl');
|
||||
String get templatePath => path.join(dataRoot, 'web_key_map_dart.tmpl');
|
||||
|
||||
@override
|
||||
String outputPath(String platform) => path.join(flutterRoot.path, '..', 'engine', 'src', 'flutter', path.join('lib', 'web_ui', 'lib', 'src', 'engine', 'keycodes', 'keyboard_map_web.dart'));
|
||||
String outputPath(String platform) => path.join(PlatformCodeGenerator.engineRoot,
|
||||
'lib', 'web_ui', 'lib', 'src', 'engine', 'key_map.dart');
|
||||
|
||||
@override
|
||||
Map<String, String> mappings() {
|
||||
return <String, String>{
|
||||
'WEB_LOGICAL_KEY_CODE_MAP': _webLogicalKeyCodeMap,
|
||||
'WEB_PHYSICAL_KEY_CODE_MAP': _webPhysicalKeyCodeMap,
|
||||
'WEB_NUMPAD_CODE_MAP': _webNumpadCodeMap,
|
||||
'WEB_LOGICAL_LOCATION_MAP': _webLogicalLocationMap,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user