Modify key info generation for new iOS key code. (#83439)
The (new, not yet used) code gen for iOS was setting up a std::map from key codes to logical and physical key codes, but it was using uint32_t, which isn't big enough to hold the Flutter key codes. Also, iOS needs to be able to filter out function keys, so I added a function key set.
This commit is contained in:
@@ -43,6 +43,21 @@ class IOSCodeGenerator extends PlatformCodeGenerator {
|
||||
return lines.sortedJoin().trimRight();
|
||||
}
|
||||
|
||||
Iterable<PhysicalKeyEntry> get _functionKeyData {
|
||||
final RegExp functionKeyRe = RegExp(r'^f[0-9]+$');
|
||||
return keyData.entries.where((PhysicalKeyEntry entry) {
|
||||
return functionKeyRe.hasMatch(entry.constantName);
|
||||
});
|
||||
}
|
||||
|
||||
String get _functionKeys {
|
||||
final StringBuffer result = StringBuffer();
|
||||
for (final PhysicalKeyEntry entry in _functionKeyData) {
|
||||
result.writeln(' ${toHex(entry.iOSScanCode)}, // ${entry.constantName}');
|
||||
}
|
||||
return result.toString().trimRight();
|
||||
}
|
||||
|
||||
String get _keyCodeToLogicalMap {
|
||||
final OutputLines<int> lines = OutputLines<int>('iOS keycode map');
|
||||
for (final LogicalKeyEntry entry in logicalData.entries) {
|
||||
@@ -75,7 +90,7 @@ class IOSCodeGenerator extends PlatformCodeGenerator {
|
||||
String get _keyToModifierFlagMap {
|
||||
final StringBuffer modifierKeyMap = StringBuffer();
|
||||
for (final String name in kModifiersOfInterest) {
|
||||
final String line = '{${toHex(logicalData.entryByName(name).iOSKeyCodeValues[0])}, kModifierFlag${lowerCamelToUpperCamel(name)}},';
|
||||
final String line =' {${toHex(logicalData.entryByName(name).iOSKeyCodeValues[0])}, kModifierFlag${lowerCamelToUpperCamel(name)}},';
|
||||
modifierKeyMap.writeln(' ${line.padRight(42)}// $name');
|
||||
}
|
||||
return modifierKeyMap.toString().trimRight();
|
||||
@@ -85,7 +100,7 @@ class IOSCodeGenerator extends PlatformCodeGenerator {
|
||||
String get _modifierFlagToKeyMap {
|
||||
final StringBuffer modifierKeyMap = StringBuffer();
|
||||
for (final String name in kModifiersOfInterest) {
|
||||
final String line = '{kModifierFlag${lowerCamelToUpperCamel(name)}, ${toHex(logicalData.entryByName(name).iOSKeyCodeValues[0])}},';
|
||||
final String line =' {kModifierFlag${lowerCamelToUpperCamel(name)}, ${toHex(logicalData.entryByName(name).iOSKeyCodeValues[0])}},';
|
||||
modifierKeyMap.writeln(' ${line.padRight(42)}// $name');
|
||||
}
|
||||
return modifierKeyMap.toString().trimRight();
|
||||
@@ -104,7 +119,7 @@ class IOSCodeGenerator extends PlatformCodeGenerator {
|
||||
}
|
||||
|
||||
@override
|
||||
String get templatePath => path.join(dataRoot, 'ios_key_code_map_cc.tmpl');
|
||||
String get templatePath => path.join(dataRoot, 'ios_key_code_map_mm.tmpl');
|
||||
|
||||
@override
|
||||
String outputPath(String platform) => path.join(PlatformCodeGenerator.engineRoot,
|
||||
@@ -119,6 +134,7 @@ class IOSCodeGenerator extends PlatformCodeGenerator {
|
||||
'MASK_CONSTANTS': _maskConstants,
|
||||
'IOS_SCAN_CODE_MAP': _scanCodeMap,
|
||||
'IOS_KEYCODE_LOGICAL_MAP': _keyCodeToLogicalMap,
|
||||
'IOS_FUNCTION_KEY_SET': _functionKeys,
|
||||
'KEYCODE_TO_MODIFIER_FLAG_MAP': _keyToModifierFlagMap,
|
||||
'MODIFIER_FLAG_TO_KEYCODE_MAP': _modifierFlagToKeyMap,
|
||||
'SPECIAL_KEY_CONSTANTS': _specialKeyConstants,
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:meta/meta.dart';
|
||||
import 'package:path/path.dart' as path;
|
||||
|
||||
import 'constants.dart';
|
||||
@@ -12,7 +13,12 @@ import 'constants.dart';
|
||||
/// The location of the Flutter root directory, based on the known location of
|
||||
/// this script.
|
||||
final Directory flutterRoot = Directory(path.dirname(Platform.script.toFilePath())).parent.parent.parent.parent;
|
||||
final String dataRoot = path.join(flutterRoot.path, 'dev', 'tools', 'gen_keycodes', 'data');
|
||||
String get dataRoot => testDataRoot ?? _dataRoot;
|
||||
String _dataRoot = path.join(flutterRoot.path, 'dev', 'tools', 'gen_keycodes', 'data');
|
||||
|
||||
/// Allows overriding of the [dataRoot] for testing purposes.
|
||||
@visibleForTesting
|
||||
String? testDataRoot;
|
||||
|
||||
/// Converts `FOO_BAR` to `FooBar`.
|
||||
String shoutingToUpperCamel(String shouting) {
|
||||
|
||||
Reference in New Issue
Block a user