Auto-format Framework (#160545)
This auto-formats all *.dart files in the repository outside of the `engine` subdirectory and enforces that these files stay formatted with a presubmit check. **Reviewers:** Please carefully review all the commits except for the one titled "formatted". The "formatted" commit was auto-generated by running `dev/tools/format.sh -a -f`. The other commits were hand-crafted to prepare the repo for the formatting change. I recommend reviewing the commits one-by-one via the "Commits" tab and avoiding Github's "Files changed" tab as it will likely slow down your browser because of the size of this PR. --------- Co-authored-by: Kate Lovett <katelovett@google.com> Co-authored-by: LongCatIsLooong <31859944+LongCatIsLooong@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
8e0993eda8
commit
5491c8c146
@@ -26,25 +26,33 @@ import 'package:path/path.dart' as path;
|
||||
/// Get contents of the file that contains the physical key mapping in Chromium
|
||||
/// source.
|
||||
Future<String> getChromiumCodes() async {
|
||||
final Uri keyCodesUri = Uri.parse('https://chromium.googlesource.com/codesearch/chromium/src/+/refs/heads/main/ui/events/keycodes/dom/dom_code_data.inc?format=TEXT');
|
||||
final Uri keyCodesUri = Uri.parse(
|
||||
'https://chromium.googlesource.com/codesearch/chromium/src/+/refs/heads/main/ui/events/keycodes/dom/dom_code_data.inc?format=TEXT',
|
||||
);
|
||||
return utf8.decode(base64.decode(await http.read(keyCodesUri)));
|
||||
}
|
||||
|
||||
/// Get contents of the file that contains the logical key mapping in Chromium
|
||||
/// source.
|
||||
Future<String> getChromiumKeys() async {
|
||||
final Uri keyCodesUri = Uri.parse('https://chromium.googlesource.com/codesearch/chromium/src/+/refs/heads/main/ui/events/keycodes/dom/dom_key_data.inc?format=TEXT');
|
||||
final Uri keyCodesUri = Uri.parse(
|
||||
'https://chromium.googlesource.com/codesearch/chromium/src/+/refs/heads/main/ui/events/keycodes/dom/dom_key_data.inc?format=TEXT',
|
||||
);
|
||||
return utf8.decode(base64.decode(await http.read(keyCodesUri)));
|
||||
}
|
||||
|
||||
/// Get contents of the file that contains the key codes in Android source.
|
||||
Future<String> getAndroidKeyCodes() async {
|
||||
final Uri keyCodesUri = Uri.parse('https://android.googlesource.com/platform/frameworks/native/+/main/include/android/keycodes.h?format=TEXT');
|
||||
final Uri keyCodesUri = Uri.parse(
|
||||
'https://android.googlesource.com/platform/frameworks/native/+/main/include/android/keycodes.h?format=TEXT',
|
||||
);
|
||||
return utf8.decode(base64.decode(await http.read(keyCodesUri)));
|
||||
}
|
||||
|
||||
Future<String> getWindowsKeyCodes() async {
|
||||
final Uri keyCodesUri = Uri.parse('https://raw.githubusercontent.com/tpn/winsdk-10/master/Include/10.0.10240.0/um/WinUser.h');
|
||||
final Uri keyCodesUri = Uri.parse(
|
||||
'https://raw.githubusercontent.com/tpn/winsdk-10/master/Include/10.0.10240.0/um/WinUser.h',
|
||||
);
|
||||
return http.read(keyCodesUri);
|
||||
}
|
||||
|
||||
@@ -55,17 +63,23 @@ Future<String> getWindowsKeyCodes() async {
|
||||
/// common keyboards. Other than some special keyboards and game pads, this
|
||||
/// should be OK.
|
||||
Future<String> getAndroidScanCodes() async {
|
||||
final Uri scanCodesUri = Uri.parse('https://android.googlesource.com/platform/frameworks/base/+/main/data/keyboards/Generic.kl?format=TEXT');
|
||||
final Uri scanCodesUri = Uri.parse(
|
||||
'https://android.googlesource.com/platform/frameworks/base/+/main/data/keyboards/Generic.kl?format=TEXT',
|
||||
);
|
||||
return utf8.decode(base64.decode(await http.read(scanCodesUri)));
|
||||
}
|
||||
|
||||
Future<String> getGlfwKeyCodes() async {
|
||||
final Uri keyCodesUri = Uri.parse('https://raw.githubusercontent.com/glfw/glfw/master/include/GLFW/glfw3.h');
|
||||
final Uri keyCodesUri = Uri.parse(
|
||||
'https://raw.githubusercontent.com/glfw/glfw/master/include/GLFW/glfw3.h',
|
||||
);
|
||||
return http.read(keyCodesUri);
|
||||
}
|
||||
|
||||
Future<String> getGtkKeyCodes() async {
|
||||
final Uri keyCodesUri = Uri.parse('https://gitlab.gnome.org/GNOME/gtk/-/raw/gtk-3-24/gdk/gdkkeysyms.h');
|
||||
final Uri keyCodesUri = Uri.parse(
|
||||
'https://gitlab.gnome.org/GNOME/gtk/-/raw/gtk-3-24/gdk/gdkkeysyms.h',
|
||||
);
|
||||
return http.read(keyCodesUri);
|
||||
}
|
||||
|
||||
@@ -100,7 +114,8 @@ Future<void> main(List<String> rawArguments) async {
|
||||
argParser.addOption(
|
||||
'engine-root',
|
||||
defaultsTo: path.join(flutterRoot.path, '..', 'engine', 'src', 'flutter'),
|
||||
help: 'The path to the root of the flutter/engine repository. This is used '
|
||||
help:
|
||||
'The path to the root of the flutter/engine repository. This is used '
|
||||
'to place the generated engine mapping files. If --engine-root is not '
|
||||
r'specified, it will default to $flutterRoot/../engine/src/flutter, '
|
||||
'assuming the engine gclient folder is placed at the same folder as '
|
||||
@@ -109,7 +124,8 @@ Future<void> main(List<String> rawArguments) async {
|
||||
argParser.addOption(
|
||||
'physical-data',
|
||||
defaultsTo: path.join(dataRoot, 'physical_key_data.g.json'),
|
||||
help: 'The path to where the physical key data file should be written when '
|
||||
help:
|
||||
'The path to where the physical key data file should be written when '
|
||||
'collected, and read from when generating output code. If --physical-data is '
|
||||
'not specified, the output will be written to/read from the current '
|
||||
"directory. If the output directory doesn't exist, it, and the path to "
|
||||
@@ -118,7 +134,8 @@ Future<void> main(List<String> rawArguments) async {
|
||||
argParser.addOption(
|
||||
'logical-data',
|
||||
defaultsTo: path.join(dataRoot, 'logical_key_data.g.json'),
|
||||
help: 'The path to where the logical key data file should be written when '
|
||||
help:
|
||||
'The path to where the logical key data file should be written when '
|
||||
'collected, and read from when generating output code. If --logical-data is '
|
||||
'not specified, the output will be written to/read from the current '
|
||||
"directory. If the output directory doesn't exist, it, and the path to "
|
||||
@@ -126,33 +143,48 @@ Future<void> main(List<String> rawArguments) async {
|
||||
);
|
||||
argParser.addOption(
|
||||
'code',
|
||||
defaultsTo: path.join(flutterRoot.path, 'packages', 'flutter', 'lib', 'src', 'services', 'keyboard_key.g.dart'),
|
||||
help: 'The path to where the output "keyboard_key.g.dart" file should be '
|
||||
defaultsTo: path.join(
|
||||
flutterRoot.path,
|
||||
'packages',
|
||||
'flutter',
|
||||
'lib',
|
||||
'src',
|
||||
'services',
|
||||
'keyboard_key.g.dart',
|
||||
),
|
||||
help:
|
||||
'The path to where the output "keyboard_key.g.dart" file should be '
|
||||
'written. If --code is not specified, the output will be written to the '
|
||||
'correct directory in the flutter tree. If the output directory does not '
|
||||
'exist, it, and the path to it, will be created.',
|
||||
);
|
||||
argParser.addOption(
|
||||
'maps',
|
||||
defaultsTo: path.join(flutterRoot.path, 'packages', 'flutter', 'lib', 'src', 'services', 'keyboard_maps.g.dart'),
|
||||
help: 'The path to where the output "keyboard_maps.g.dart" file should be '
|
||||
'written. If --maps is not specified, the output will be written to the '
|
||||
'correct directory in the flutter tree. If the output directory does not '
|
||||
'exist, it, and the path to it, will be created.',
|
||||
defaultsTo: path.join(
|
||||
flutterRoot.path,
|
||||
'packages',
|
||||
'flutter',
|
||||
'lib',
|
||||
'src',
|
||||
'services',
|
||||
'keyboard_maps.g.dart',
|
||||
),
|
||||
help:
|
||||
'The path to where the output "keyboard_maps.g.dart" file should be '
|
||||
'written. If --maps is not specified, the output will be written to the '
|
||||
'correct directory in the flutter tree. If the output directory does not '
|
||||
'exist, it, and the path to it, will be created.',
|
||||
);
|
||||
argParser.addFlag(
|
||||
'collect',
|
||||
negatable: false,
|
||||
help: 'If this flag is set, then collect and parse header files from '
|
||||
help:
|
||||
'If this flag is set, then collect and parse header files from '
|
||||
'Chromium and Android instead of reading pre-parsed data from '
|
||||
'"physical_key_data.g.json" and "logical_key_data.g.json", and then '
|
||||
'update these files with the fresh data.',
|
||||
);
|
||||
argParser.addFlag(
|
||||
'help',
|
||||
negatable: false,
|
||||
help: 'Print help for this command.',
|
||||
);
|
||||
argParser.addFlag('help', negatable: false, help: 'Print help for this command.');
|
||||
|
||||
final ArgResults parsedArguments = argParser.parse(rawArguments);
|
||||
|
||||
@@ -212,45 +244,59 @@ Future<void> main(List<String> rawArguments) async {
|
||||
final String logicalJson = encoder.convert(logicalData.toJson());
|
||||
File(parsedArguments['logical-data'] as String).writeAsStringSync('$logicalJson\n');
|
||||
} else {
|
||||
physicalData = PhysicalKeyData.fromJson(json.decode(await File(parsedArguments['physical-data'] as String).readAsString()) as Map<String, dynamic>);
|
||||
logicalData = LogicalKeyData.fromJson(json.decode(await File(parsedArguments['logical-data'] as String).readAsString()) as Map<String, dynamic>);
|
||||
physicalData = PhysicalKeyData.fromJson(
|
||||
json.decode(await File(parsedArguments['physical-data'] as String).readAsString())
|
||||
as Map<String, dynamic>,
|
||||
);
|
||||
logicalData = LogicalKeyData.fromJson(
|
||||
json.decode(await File(parsedArguments['logical-data'] as String).readAsString())
|
||||
as Map<String, dynamic>,
|
||||
);
|
||||
}
|
||||
|
||||
final Map<String, bool> layoutGoals = parseMapOfBool(readDataFile('layout_goals.json'));
|
||||
|
||||
await generate('key codes',
|
||||
parsedArguments['code'] as String,
|
||||
KeyboardKeysCodeGenerator(physicalData, logicalData));
|
||||
await generate('key maps',
|
||||
parsedArguments['maps'] as String,
|
||||
KeyboardMapsCodeGenerator(physicalData, logicalData));
|
||||
await generate('engine utils',
|
||||
path.join(PlatformCodeGenerator.engineRoot,
|
||||
'shell', 'platform', 'embedder', 'test_utils', 'key_codes.g.h'),
|
||||
KeyCodesCcGenerator(physicalData, logicalData));
|
||||
await generate('android utils',
|
||||
path.join(PlatformCodeGenerator.engineRoot, 'shell', 'platform',
|
||||
path.join('android', 'test', 'io', 'flutter', 'util', 'KeyCodes.java')),
|
||||
KeyCodesJavaGenerator(physicalData, logicalData));
|
||||
await generate(
|
||||
'key codes',
|
||||
parsedArguments['code'] as String,
|
||||
KeyboardKeysCodeGenerator(physicalData, logicalData),
|
||||
);
|
||||
await generate(
|
||||
'key maps',
|
||||
parsedArguments['maps'] as String,
|
||||
KeyboardMapsCodeGenerator(physicalData, logicalData),
|
||||
);
|
||||
await generate(
|
||||
'engine utils',
|
||||
path.join(
|
||||
PlatformCodeGenerator.engineRoot,
|
||||
'shell',
|
||||
'platform',
|
||||
'embedder',
|
||||
'test_utils',
|
||||
'key_codes.g.h',
|
||||
),
|
||||
KeyCodesCcGenerator(physicalData, logicalData),
|
||||
);
|
||||
await generate(
|
||||
'android utils',
|
||||
path.join(
|
||||
PlatformCodeGenerator.engineRoot,
|
||||
'shell',
|
||||
'platform',
|
||||
path.join('android', 'test', 'io', 'flutter', 'util', 'KeyCodes.java'),
|
||||
),
|
||||
KeyCodesJavaGenerator(physicalData, logicalData),
|
||||
);
|
||||
|
||||
final Map<String, PlatformCodeGenerator> platforms = <String, PlatformCodeGenerator>{
|
||||
'android': AndroidCodeGenerator(
|
||||
physicalData,
|
||||
logicalData,
|
||||
),
|
||||
'macos': MacOSCodeGenerator(
|
||||
physicalData,
|
||||
logicalData,
|
||||
layoutGoals,
|
||||
),
|
||||
'ios': IOSCodeGenerator(
|
||||
physicalData,
|
||||
logicalData,
|
||||
),
|
||||
'android': AndroidCodeGenerator(physicalData, logicalData),
|
||||
'macos': MacOSCodeGenerator(physicalData, logicalData, layoutGoals),
|
||||
'ios': IOSCodeGenerator(physicalData, logicalData),
|
||||
'windows': WindowsCodeGenerator(
|
||||
physicalData,
|
||||
logicalData,
|
||||
readDataFile('windows_scancode_logical_map.json')
|
||||
readDataFile('windows_scancode_logical_map.json'),
|
||||
),
|
||||
'linux': GtkCodeGenerator(
|
||||
physicalData,
|
||||
@@ -265,11 +311,11 @@ Future<void> main(List<String> rawArguments) async {
|
||||
readDataFile('web_logical_location_mapping.json'),
|
||||
),
|
||||
};
|
||||
await Future.wait(platforms.entries.map((MapEntry<String, PlatformCodeGenerator> entry) {
|
||||
final String platform = entry.key;
|
||||
final PlatformCodeGenerator codeGenerator = entry.value;
|
||||
return generate('$platform map',
|
||||
codeGenerator.outputPath(platform),
|
||||
codeGenerator);
|
||||
}));
|
||||
await Future.wait(
|
||||
platforms.entries.map((MapEntry<String, PlatformCodeGenerator> entry) {
|
||||
final String platform = entry.key;
|
||||
final PlatformCodeGenerator codeGenerator = entry.value;
|
||||
return generate('$platform map', codeGenerator.outputPath(platform), codeGenerator);
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@ import 'logical_key_data.dart';
|
||||
import 'physical_key_data.dart';
|
||||
import 'utils.dart';
|
||||
|
||||
|
||||
/// Generates the key mapping for Android, based on the information in the key
|
||||
/// data structure given to it.
|
||||
class AndroidCodeGenerator extends PlatformCodeGenerator {
|
||||
@@ -21,7 +20,9 @@ class AndroidCodeGenerator extends PlatformCodeGenerator {
|
||||
final StringBuffer androidKeyCodeMap = StringBuffer();
|
||||
for (final LogicalKeyEntry entry in logicalData.entries) {
|
||||
for (final int code in entry.androidValues) {
|
||||
androidKeyCodeMap.writeln(' put(${toHex(code, digits: 10)}L, ${toHex(entry.value, digits: 10)}L); // ${entry.constantName}');
|
||||
androidKeyCodeMap.writeln(
|
||||
' put(${toHex(code, digits: 10)}L, ${toHex(entry.value, digits: 10)}L); // ${entry.constantName}',
|
||||
);
|
||||
}
|
||||
}
|
||||
return androidKeyCodeMap.toString().trimRight();
|
||||
@@ -32,7 +33,9 @@ class AndroidCodeGenerator extends PlatformCodeGenerator {
|
||||
final StringBuffer androidScanCodeMap = StringBuffer();
|
||||
for (final PhysicalKeyEntry entry in keyData.entries) {
|
||||
for (final int code in entry.androidScanCodes.cast<int>()) {
|
||||
androidScanCodeMap.writeln(' put(${toHex(code, digits: 10)}L, ${toHex(entry.usbHidCode, digits: 10)}L); // ${entry.constantName}');
|
||||
androidScanCodeMap.writeln(
|
||||
' put(${toHex(code, digits: 10)}L, ${toHex(entry.usbHidCode, digits: 10)}L); // ${entry.constantName}',
|
||||
);
|
||||
}
|
||||
}
|
||||
return androidScanCodeMap.toString().trimRight();
|
||||
@@ -47,35 +50,38 @@ class AndroidCodeGenerator extends PlatformCodeGenerator {
|
||||
};
|
||||
goalsSource.forEach((String flagName, List<String> keys) {
|
||||
int? lineId;
|
||||
final List<String> keysString = keys.map((String keyName) {
|
||||
final PhysicalKeyEntry physicalKey = keyData.entryByName(keyName);
|
||||
final LogicalKeyEntry logicalKey = logicalData.entryByName(keyName);
|
||||
lineId ??= physicalKey.usbHidCode;
|
||||
return ' new KeyPair(${toHex(physicalKey.usbHidCode)}L, '
|
||||
'${toHex(logicalKey.value, digits: 10)}L), // ${physicalKey.name}';
|
||||
}).toList();
|
||||
lines.add(lineId!,
|
||||
' new PressingGoal(\n'
|
||||
' KeyEvent.META_${flagName}_ON,\n'
|
||||
' new KeyPair[] {\n'
|
||||
'${keysString.join('\n')}\n'
|
||||
' }),');
|
||||
final List<String> keysString =
|
||||
keys.map((String keyName) {
|
||||
final PhysicalKeyEntry physicalKey = keyData.entryByName(keyName);
|
||||
final LogicalKeyEntry logicalKey = logicalData.entryByName(keyName);
|
||||
lineId ??= physicalKey.usbHidCode;
|
||||
return ' new KeyPair(${toHex(physicalKey.usbHidCode)}L, '
|
||||
'${toHex(logicalKey.value, digits: 10)}L), // ${physicalKey.name}';
|
||||
}).toList();
|
||||
lines.add(
|
||||
lineId!,
|
||||
' new PressingGoal(\n'
|
||||
' KeyEvent.META_${flagName}_ON,\n'
|
||||
' new KeyPair[] {\n'
|
||||
'${keysString.join('\n')}\n'
|
||||
' }),',
|
||||
);
|
||||
});
|
||||
return lines.sortedJoin().trimRight();
|
||||
}
|
||||
|
||||
String get _togglingGoals {
|
||||
final OutputLines<int> lines = OutputLines<int>('Android toggling goals');
|
||||
const Map<String, String> goalsSource = <String, String>{
|
||||
'CAPS_LOCK': 'CapsLock',
|
||||
};
|
||||
const Map<String, String> goalsSource = <String, String>{'CAPS_LOCK': 'CapsLock'};
|
||||
goalsSource.forEach((String flagName, String keyName) {
|
||||
final PhysicalKeyEntry physicalKey = keyData.entryByName(keyName);
|
||||
final LogicalKeyEntry logicalKey = logicalData.entryByName(keyName);
|
||||
lines.add(physicalKey.usbHidCode,
|
||||
' new TogglingGoal(KeyEvent.META_${flagName}_ON, '
|
||||
'${toHex(physicalKey.usbHidCode)}L, '
|
||||
'${toHex(logicalKey.value, digits: 10)}L),');
|
||||
lines.add(
|
||||
physicalKey.usbHidCode,
|
||||
' new TogglingGoal(KeyEvent.META_${flagName}_ON, '
|
||||
'${toHex(physicalKey.usbHidCode)}L, '
|
||||
'${toHex(logicalKey.value, digits: 10)}L),',
|
||||
);
|
||||
});
|
||||
return lines.sortedJoin().trimRight();
|
||||
}
|
||||
@@ -89,7 +95,9 @@ class AndroidCodeGenerator extends PlatformCodeGenerator {
|
||||
kAndroidPlane,
|
||||
];
|
||||
for (final MaskConstant constant in maskConstants) {
|
||||
buffer.writeln(' public static final long k${constant.upperCamelName} = ${toHex(constant.value, digits: 11)}L;');
|
||||
buffer.writeln(
|
||||
' public static final long k${constant.upperCamelName} = ${toHex(constant.value, digits: 11)}L;',
|
||||
);
|
||||
}
|
||||
return buffer.toString().trimRight();
|
||||
}
|
||||
@@ -98,8 +106,12 @@ class AndroidCodeGenerator extends PlatformCodeGenerator {
|
||||
String get templatePath => path.join(dataRoot, 'android_keyboard_map_java.tmpl');
|
||||
|
||||
@override
|
||||
String outputPath(String platform) => path.join(PlatformCodeGenerator.engineRoot, 'shell', 'platform',
|
||||
path.join('android', 'io', 'flutter', 'embedding', 'android', 'KeyboardMap.java'));
|
||||
String outputPath(String platform) => path.join(
|
||||
PlatformCodeGenerator.engineRoot,
|
||||
'shell',
|
||||
'platform',
|
||||
path.join('android', 'io', 'flutter', 'embedding', 'android', 'KeyboardMap.java'),
|
||||
);
|
||||
|
||||
@override
|
||||
Map<String, String> mappings() {
|
||||
|
||||
@@ -11,7 +11,7 @@ class MaskConstant {
|
||||
: this(
|
||||
name: '$platform Plane',
|
||||
value: value,
|
||||
description: 'The plane value for the private keys defined by the $platform embedding.'
|
||||
description: 'The plane value for the private keys defined by the $platform embedding.',
|
||||
);
|
||||
|
||||
final String name;
|
||||
@@ -20,9 +20,9 @@ class MaskConstant {
|
||||
|
||||
String get upperCamelName {
|
||||
return name
|
||||
.split(' ')
|
||||
.map<String>((String word) => lowerCamelToUpperCamel(word.toLowerCase()))
|
||||
.join();
|
||||
.split(' ')
|
||||
.map<String>((String word) => lowerCamelToUpperCamel(word.toLowerCase()))
|
||||
.join();
|
||||
}
|
||||
|
||||
String get lowerCamelName {
|
||||
@@ -52,7 +52,8 @@ const MaskConstant kUnicodePlane = MaskConstant(
|
||||
const MaskConstant kUnprintablePlane = MaskConstant(
|
||||
name: 'Unprintable Plane',
|
||||
value: 0x0100000000,
|
||||
description: 'The plane value for keys defined by Chromium and does not have a Unicode representation.',
|
||||
description:
|
||||
'The plane value for keys defined by Chromium and does not have a Unicode representation.',
|
||||
);
|
||||
|
||||
const MaskConstant kFlutterPlane = MaskConstant(
|
||||
@@ -64,45 +65,22 @@ const MaskConstant kFlutterPlane = MaskConstant(
|
||||
const MaskConstant kStartOfPlatformPlanes = MaskConstant(
|
||||
name: 'Start Of Platform Planes',
|
||||
value: 0x1100000000,
|
||||
description: 'The platform plane with the lowest mask value, beyond which the keys are considered autogenerated.',
|
||||
description:
|
||||
'The platform plane with the lowest mask value, beyond which the keys are considered autogenerated.',
|
||||
);
|
||||
|
||||
const MaskConstant kAndroidPlane = MaskConstant.platform(
|
||||
platform: 'Android',
|
||||
value: 0x1100000000,
|
||||
);
|
||||
const MaskConstant kAndroidPlane = MaskConstant.platform(platform: 'Android', value: 0x1100000000);
|
||||
|
||||
const MaskConstant kFuchsiaPlane = MaskConstant.platform(
|
||||
platform: 'Fuchsia',
|
||||
value: 0x1200000000,
|
||||
);
|
||||
const MaskConstant kFuchsiaPlane = MaskConstant.platform(platform: 'Fuchsia', value: 0x1200000000);
|
||||
|
||||
const MaskConstant kIosPlane = MaskConstant.platform(
|
||||
platform: 'iOS',
|
||||
value: 0x1300000000,
|
||||
);
|
||||
const MaskConstant kIosPlane = MaskConstant.platform(platform: 'iOS', value: 0x1300000000);
|
||||
|
||||
const MaskConstant kMacosPlane = MaskConstant.platform(
|
||||
platform: 'macOS',
|
||||
value: 0x1400000000,
|
||||
);
|
||||
const MaskConstant kMacosPlane = MaskConstant.platform(platform: 'macOS', value: 0x1400000000);
|
||||
|
||||
const MaskConstant kGtkPlane = MaskConstant.platform(
|
||||
platform: 'Gtk',
|
||||
value: 0x1500000000,
|
||||
);
|
||||
const MaskConstant kGtkPlane = MaskConstant.platform(platform: 'Gtk', value: 0x1500000000);
|
||||
|
||||
const MaskConstant kWindowsPlane = MaskConstant.platform(
|
||||
platform: 'Windows',
|
||||
value: 0x1600000000,
|
||||
);
|
||||
const MaskConstant kWindowsPlane = MaskConstant.platform(platform: 'Windows', value: 0x1600000000);
|
||||
|
||||
const MaskConstant kWebPlane = MaskConstant.platform(
|
||||
platform: 'Web',
|
||||
value: 0x1700000000,
|
||||
);
|
||||
const MaskConstant kWebPlane = MaskConstant.platform(platform: 'Web', value: 0x1700000000);
|
||||
|
||||
const MaskConstant kGlfwPlane = MaskConstant.platform(
|
||||
platform: 'GLFW',
|
||||
value: 0x1800000000,
|
||||
);
|
||||
const MaskConstant kGlfwPlane = MaskConstant.platform(platform: 'GLFW', value: 0x1800000000);
|
||||
|
||||
@@ -10,7 +10,6 @@ import 'logical_key_data.dart';
|
||||
import 'physical_key_data.dart';
|
||||
import 'utils.dart';
|
||||
|
||||
|
||||
/// Generates the key mapping for GTK, based on the information in the key
|
||||
/// data structure given to it.
|
||||
class GtkCodeGenerator extends PlatformCodeGenerator {
|
||||
@@ -28,8 +27,10 @@ class GtkCodeGenerator extends PlatformCodeGenerator {
|
||||
final OutputLines<int> lines = OutputLines<int>('GTK scancode map');
|
||||
for (final PhysicalKeyEntry entry in keyData.entries) {
|
||||
if (entry.xKbScanCode != null) {
|
||||
lines.add(entry.xKbScanCode!,
|
||||
' {${toHex(entry.xKbScanCode)}, ${toHex(entry.usbHidCode)}}, // ${entry.constantName}');
|
||||
lines.add(
|
||||
entry.xKbScanCode!,
|
||||
' {${toHex(entry.xKbScanCode)}, ${toHex(entry.usbHidCode)}}, // ${entry.constantName}',
|
||||
);
|
||||
}
|
||||
}
|
||||
return lines.sortedJoin().trimRight();
|
||||
@@ -40,18 +41,17 @@ class GtkCodeGenerator extends PlatformCodeGenerator {
|
||||
final OutputLines<int> lines = OutputLines<int>('GTK keyval map');
|
||||
for (final LogicalKeyEntry entry in logicalData.entries) {
|
||||
zipStrict(entry.gtkValues, entry.gtkNames, (int value, String name) {
|
||||
lines.add(value,
|
||||
' {${toHex(value)}, ${toHex(entry.value, digits: 11)}}, // $name');
|
||||
lines.add(value, ' {${toHex(value)}, ${toHex(entry.value, digits: 11)}}, // $name');
|
||||
});
|
||||
}
|
||||
return lines.sortedJoin().trimRight();
|
||||
}
|
||||
|
||||
static String constructMapFromModToKeys(
|
||||
Map<String, List<String>> source,
|
||||
PhysicalKeyData physicalData,
|
||||
LogicalKeyData logicalData,
|
||||
String debugFunctionName,
|
||||
Map<String, List<String>> source,
|
||||
PhysicalKeyData physicalData,
|
||||
LogicalKeyData logicalData,
|
||||
String debugFunctionName,
|
||||
) {
|
||||
final StringBuffer result = StringBuffer();
|
||||
source.forEach((String modifierBitName, List<String> keyNames) {
|
||||
@@ -61,35 +61,49 @@ class GtkCodeGenerator extends PlatformCodeGenerator {
|
||||
final String? secondaryLogicalName = keyNames.length == 3 ? keyNames[2] : null;
|
||||
final PhysicalKeyEntry primaryPhysical = physicalData.entryByName(primaryPhysicalName);
|
||||
final LogicalKeyEntry primaryLogical = logicalData.entryByName(primaryLogicalName);
|
||||
final LogicalKeyEntry? secondaryLogical = secondaryLogicalName == null ? null : logicalData.entryByName(secondaryLogicalName);
|
||||
final LogicalKeyEntry? secondaryLogical =
|
||||
secondaryLogicalName == null ? null : logicalData.entryByName(secondaryLogicalName);
|
||||
if (secondaryLogical == null && secondaryLogicalName != null) {
|
||||
print('Unrecognized secondary logical key $secondaryLogicalName specified for $debugFunctionName.');
|
||||
print(
|
||||
'Unrecognized secondary logical key $secondaryLogicalName specified for $debugFunctionName.',
|
||||
);
|
||||
return;
|
||||
}
|
||||
final String pad = secondaryLogical == null ? '' : ' ';
|
||||
result.writeln('''
|
||||
result.writeln(
|
||||
'''
|
||||
|
||||
data = g_new(FlKeyEmbedderCheckedKey, 1);
|
||||
g_hash_table_insert(table, GUINT_TO_POINTER(GDK_${modifierBitName}_MASK), data);
|
||||
data->is_caps_lock = ${primaryPhysicalName == 'CapsLock' ? 'true' : 'false'};
|
||||
data->primary_physical_key = ${toHex(primaryPhysical.usbHidCode, digits: 9)};$pad // ${primaryPhysical.constantName}
|
||||
data->primary_logical_key = ${toHex(primaryLogical.value, digits: 11)};$pad // ${primaryLogical.constantName}''');
|
||||
data->primary_logical_key = ${toHex(primaryLogical.value, digits: 11)};$pad // ${primaryLogical.constantName}''',
|
||||
);
|
||||
if (secondaryLogical != null) {
|
||||
result.writeln('''
|
||||
data->secondary_logical_key = ${toHex(secondaryLogical.value, digits: 11)}; // ${secondaryLogical.constantName}''');
|
||||
result.writeln(
|
||||
'''
|
||||
data->secondary_logical_key = ${toHex(secondaryLogical.value, digits: 11)}; // ${secondaryLogical.constantName}''',
|
||||
);
|
||||
}
|
||||
});
|
||||
return result.toString().trimRight();
|
||||
}
|
||||
|
||||
String get _gtkModifierBitMap {
|
||||
return constructMapFromModToKeys(_modifierBitMapping, keyData, logicalData, 'gtkModifierBitMap');
|
||||
return constructMapFromModToKeys(
|
||||
_modifierBitMapping,
|
||||
keyData,
|
||||
logicalData,
|
||||
'gtkModifierBitMap',
|
||||
);
|
||||
}
|
||||
|
||||
final Map<String, List<String>> _modifierBitMapping;
|
||||
|
||||
String get _gtkModeBitMap {
|
||||
return constructMapFromModToKeys(_lockBitMapping, keyData, logicalData, 'gtkModeBitMap');
|
||||
}
|
||||
|
||||
final Map<String, List<String>> _lockBitMapping;
|
||||
|
||||
final Map<String, bool> _layoutGoals;
|
||||
@@ -98,14 +112,17 @@ class GtkCodeGenerator extends PlatformCodeGenerator {
|
||||
_layoutGoals.forEach((String name, bool mandatory) {
|
||||
final PhysicalKeyEntry physicalEntry = keyData.entryByName(name);
|
||||
final LogicalKeyEntry logicalEntry = logicalData.entryByName(name);
|
||||
final String line = 'LayoutGoal{'
|
||||
final String line =
|
||||
'LayoutGoal{'
|
||||
'${toHex(physicalEntry.xKbScanCode, digits: 2)}, '
|
||||
'${toHex(logicalEntry.value, digits: 2)}, '
|
||||
'${mandatory ? 'true' : 'false'}'
|
||||
'},';
|
||||
lines.add(logicalEntry.value,
|
||||
' ${line.padRight(39)}'
|
||||
'// ${logicalEntry.name}');
|
||||
lines.add(
|
||||
logicalEntry.value,
|
||||
' ${line.padRight(39)}'
|
||||
'// ${logicalEntry.name}',
|
||||
);
|
||||
});
|
||||
return lines.sortedJoin().trimRight();
|
||||
}
|
||||
@@ -113,13 +130,11 @@ class GtkCodeGenerator extends PlatformCodeGenerator {
|
||||
/// 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,
|
||||
kGtkPlane,
|
||||
];
|
||||
const List<MaskConstant> maskConstants = <MaskConstant>[kValueMask, kUnicodePlane, kGtkPlane];
|
||||
for (final MaskConstant constant in maskConstants) {
|
||||
buffer.writeln('const uint64_t k${constant.upperCamelName} = ${toHex(constant.value, digits: 11)};');
|
||||
buffer.writeln(
|
||||
'const uint64_t k${constant.upperCamelName} = ${toHex(constant.value, digits: 11)};',
|
||||
);
|
||||
}
|
||||
return buffer.toString().trimRight();
|
||||
}
|
||||
@@ -128,8 +143,8 @@ class GtkCodeGenerator extends PlatformCodeGenerator {
|
||||
String get templatePath => path.join(dataRoot, 'gtk_key_mapping_cc.tmpl');
|
||||
|
||||
@override
|
||||
String outputPath(String platform) => path.join(PlatformCodeGenerator.engineRoot,
|
||||
'shell', 'platform', 'linux', 'key_mapping.g.cc');
|
||||
String outputPath(String platform) =>
|
||||
path.join(PlatformCodeGenerator.engineRoot, 'shell', 'platform', 'linux', 'key_mapping.g.cc');
|
||||
|
||||
@override
|
||||
Map<String, String> mappings() {
|
||||
|
||||
@@ -36,8 +36,10 @@ class IOSCodeGenerator extends PlatformCodeGenerator {
|
||||
final OutputLines<int> lines = OutputLines<int>('iOS scancode map');
|
||||
for (final PhysicalKeyEntry entry in keyData.entries) {
|
||||
if (entry.iOSScanCode != null) {
|
||||
lines.add(entry.iOSScanCode!,
|
||||
' {${toHex(entry.iOSScanCode)}, ${toHex(entry.usbHidCode)}}, // ${entry.constantName}');
|
||||
lines.add(
|
||||
entry.iOSScanCode!,
|
||||
' {${toHex(entry.iOSScanCode)}, ${toHex(entry.usbHidCode)}}, // ${entry.constantName}',
|
||||
);
|
||||
}
|
||||
}
|
||||
return lines.sortedJoin().trimRight();
|
||||
@@ -62,7 +64,10 @@ class IOSCodeGenerator extends PlatformCodeGenerator {
|
||||
final OutputLines<int> lines = OutputLines<int>('iOS keycode map');
|
||||
for (final LogicalKeyEntry entry in logicalData.entries) {
|
||||
zipStrict(entry.iOSKeyCodeValues, entry.iOSKeyCodeNames, (int iOSValue, String iOSName) {
|
||||
lines.add(iOSValue, ' {${toHex(iOSValue)}, ${toHex(entry.value, digits: 11)}}, // $iOSName');
|
||||
lines.add(
|
||||
iOSValue,
|
||||
' {${toHex(iOSValue)}, ${toHex(entry.value, digits: 11)}}, // $iOSName',
|
||||
);
|
||||
});
|
||||
}
|
||||
return lines.sortedJoin().trimRight();
|
||||
@@ -71,16 +76,14 @@ class IOSCodeGenerator extends PlatformCodeGenerator {
|
||||
/// 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,
|
||||
kIosPlane,
|
||||
];
|
||||
const List<MaskConstant> maskConstants = <MaskConstant>[kValueMask, kUnicodePlane, kIosPlane];
|
||||
for (final MaskConstant constant in maskConstants) {
|
||||
buffer.writeln('/**');
|
||||
buffer.write(wrapString(constant.description, prefix: ' * '));
|
||||
buffer.writeln(' */');
|
||||
buffer.writeln('const uint64_t k${constant.upperCamelName} = ${toHex(constant.value, digits: 11)};');
|
||||
buffer.writeln(
|
||||
'const uint64_t k${constant.upperCamelName} = ${toHex(constant.value, digits: 11)};',
|
||||
);
|
||||
buffer.writeln();
|
||||
}
|
||||
return buffer.toString().trimRight();
|
||||
@@ -90,7 +93,8 @@ 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();
|
||||
@@ -100,7 +104,8 @@ 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();
|
||||
@@ -119,10 +124,14 @@ class IOSCodeGenerator extends PlatformCodeGenerator {
|
||||
String get _specialKeyConstants {
|
||||
final StringBuffer specialKeyConstants = StringBuffer();
|
||||
for (final String keyName in kSpecialPhysicalKeys) {
|
||||
specialKeyConstants.writeln('const uint64_t k${keyName}PhysicalKey = ${toHex(keyData.entryByName(keyName).usbHidCode)};');
|
||||
specialKeyConstants.writeln(
|
||||
'const uint64_t k${keyName}PhysicalKey = ${toHex(keyData.entryByName(keyName).usbHidCode)};',
|
||||
);
|
||||
}
|
||||
for (final String keyName in kSpecialLogicalKeys) {
|
||||
specialKeyConstants.writeln('const uint64_t k${lowerCamelToUpperCamel(keyName)}LogicalKey = ${toHex(logicalData.entryByName(keyName).value)};');
|
||||
specialKeyConstants.writeln(
|
||||
'const uint64_t k${lowerCamelToUpperCamel(keyName)}LogicalKey = ${toHex(logicalData.entryByName(keyName).value)};',
|
||||
);
|
||||
}
|
||||
return specialKeyConstants.toString().trimRight();
|
||||
}
|
||||
@@ -131,8 +140,16 @@ class IOSCodeGenerator extends PlatformCodeGenerator {
|
||||
String get templatePath => path.join(dataRoot, 'ios_key_code_map_mm.tmpl');
|
||||
|
||||
@override
|
||||
String outputPath(String platform) => path.join(PlatformCodeGenerator.engineRoot,
|
||||
'shell', 'platform', 'darwin', 'ios', 'framework', 'Source', 'KeyCodeMap.g.mm');
|
||||
String outputPath(String platform) => path.join(
|
||||
PlatformCodeGenerator.engineRoot,
|
||||
'shell',
|
||||
'platform',
|
||||
'darwin',
|
||||
'ios',
|
||||
'framework',
|
||||
'Source',
|
||||
'KeyCodeMap.g.mm',
|
||||
);
|
||||
|
||||
@override
|
||||
Map<String, String> mappings() {
|
||||
|
||||
@@ -55,10 +55,14 @@ class KeyboardKeysCodeGenerator extends BaseCodeGenerator {
|
||||
String get _physicalDefinitions {
|
||||
final OutputLines<int> lines = OutputLines<int>('Physical Key Definition');
|
||||
for (final PhysicalKeyEntry entry in keyData.entries) {
|
||||
final String firstComment = _wrapString('Represents the location of the '
|
||||
'"${entry.commentName}" key on a generalized keyboard.');
|
||||
final String otherComments = _wrapString('See the function '
|
||||
'[RawKeyEvent.physicalKey] for more information.');
|
||||
final String firstComment = _wrapString(
|
||||
'Represents the location of the '
|
||||
'"${entry.commentName}" key on a generalized keyboard.',
|
||||
);
|
||||
final String otherComments = _wrapString(
|
||||
'See the function '
|
||||
'[RawKeyEvent.physicalKey] for more information.',
|
||||
);
|
||||
lines.add(entry.usbHidCode, '''
|
||||
$firstComment ///
|
||||
$otherComments static const PhysicalKeyboardKey ${entry.constantName} = PhysicalKeyboardKey(${toHex(entry.usbHidCode)});
|
||||
@@ -78,10 +82,17 @@ $otherComments static const PhysicalKeyboardKey ${entry.constantName} = Physica
|
||||
|
||||
/// Gets the generated definitions of LogicalKeyboardKeys.
|
||||
String get _logicalDefinitions {
|
||||
final OutputLines<int> lines = OutputLines<int>('Logical debug names', behavior: DeduplicateBehavior.kSkip);
|
||||
final OutputLines<int> lines = OutputLines<int>(
|
||||
'Logical debug names',
|
||||
behavior: DeduplicateBehavior.kSkip,
|
||||
);
|
||||
void printKey(int flutterId, String constantName, String commentName, {String? otherComments}) {
|
||||
final String firstComment = _wrapString('Represents the logical "$commentName" key on the keyboard.');
|
||||
otherComments ??= _wrapString('See the function [RawKeyEvent.logicalKey] for more information.');
|
||||
final String firstComment = _wrapString(
|
||||
'Represents the logical "$commentName" key on the keyboard.',
|
||||
);
|
||||
otherComments ??= _wrapString(
|
||||
'See the function [RawKeyEvent.logicalKey] for more information.',
|
||||
);
|
||||
lines.add(flutterId, '''
|
||||
$firstComment ///
|
||||
$otherComments static const LogicalKeyboardKey $constantName = LogicalKeyboardKey(${toHex(flutterId, digits: 11)});
|
||||
@@ -101,11 +112,13 @@ $otherComments static const LogicalKeyboardKey $constantName = LogicalKeyboardK
|
||||
|
||||
String? _otherComments(String name) {
|
||||
if (synonyms.containsKey(name)) {
|
||||
final Set<String> unionNames = synonyms[name]!.keys.map(
|
||||
(LogicalKeyEntry entry) => entry.constantName).toSet();
|
||||
return _wrapString('This key represents the union of the keys '
|
||||
'$unionNames when comparing keys. This key will never be generated '
|
||||
'directly, its main use is in defining key maps.');
|
||||
final Set<String> unionNames =
|
||||
synonyms[name]!.keys.map((LogicalKeyEntry entry) => entry.constantName).toSet();
|
||||
return _wrapString(
|
||||
'This key represents the union of the keys '
|
||||
'$unionNames when comparing keys. This key will never be generated '
|
||||
'directly, its main use is in defining key maps.',
|
||||
);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -125,14 +138,18 @@ $otherComments static const LogicalKeyboardKey $constantName = LogicalKeyboardK
|
||||
final StringBuffer result = StringBuffer();
|
||||
for (final SynonymKeyInfo synonymInfo in synonyms.values) {
|
||||
final LogicalKeyEntry synonym = logicalData.entryByName(synonymInfo.name);
|
||||
final List<String> entries = synonymInfo.keys.map<String>((LogicalKeyEntry entry) => entry.constantName).toList();
|
||||
final List<String> entries =
|
||||
synonymInfo.keys.map<String>((LogicalKeyEntry entry) => entry.constantName).toList();
|
||||
result.writeln(' ${synonym.constantName}: <LogicalKeyboardKey>{${entries.join(', ')}},');
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
String get _logicalKeyLabels {
|
||||
final OutputLines<int> lines = OutputLines<int>('Logical key labels', behavior: DeduplicateBehavior.kSkip);
|
||||
final OutputLines<int> lines = OutputLines<int>(
|
||||
'Logical key labels',
|
||||
behavior: DeduplicateBehavior.kSkip,
|
||||
);
|
||||
for (final LogicalKeyEntry entry in logicalData.entries) {
|
||||
lines.add(entry.value, '''
|
||||
${toHex(entry.value, digits: 11)}: '${entry.commentName}',''');
|
||||
@@ -151,7 +168,10 @@ $otherComments static const LogicalKeyboardKey $constantName = LogicalKeyboardK
|
||||
|
||||
/// This generates the map of Flutter key codes to logical keys.
|
||||
String get _predefinedKeyCodeMap {
|
||||
final OutputLines<int> lines = OutputLines<int>('Logical key map', behavior: DeduplicateBehavior.kSkip);
|
||||
final OutputLines<int> lines = OutputLines<int>(
|
||||
'Logical key map',
|
||||
behavior: DeduplicateBehavior.kSkip,
|
||||
);
|
||||
for (final LogicalKeyEntry entry in logicalData.entries) {
|
||||
lines.add(entry.value, ' ${toHex(entry.value, digits: 11)}: ${entry.constantName},');
|
||||
}
|
||||
@@ -159,7 +179,10 @@ $otherComments static const LogicalKeyboardKey $constantName = LogicalKeyboardK
|
||||
}
|
||||
|
||||
String get _maskConstantVariables {
|
||||
final OutputLines<int> lines = OutputLines<int>('Mask constants', behavior: DeduplicateBehavior.kKeep);
|
||||
final OutputLines<int> lines = OutputLines<int>(
|
||||
'Mask constants',
|
||||
behavior: DeduplicateBehavior.kKeep,
|
||||
);
|
||||
for (final MaskConstant constant in _maskConstants) {
|
||||
lines.add(constant.value, '''
|
||||
${_wrapString(constant.description)} ///
|
||||
@@ -190,14 +213,11 @@ ${_wrapString(constant.description)} ///
|
||||
|
||||
late final Map<String, SynonymKeyInfo> synonyms = Map<String, SynonymKeyInfo>.fromEntries(
|
||||
LogicalKeyData.synonyms.entries.map((MapEntry<String, List<String>> synonymDefinition) {
|
||||
final List<LogicalKeyEntry> entries = synonymDefinition.value.map(
|
||||
(String name) => logicalData.entryByName(name)).toList();
|
||||
final List<LogicalKeyEntry> entries =
|
||||
synonymDefinition.value.map((String name) => logicalData.entryByName(name)).toList();
|
||||
return MapEntry<String, SynonymKeyInfo>(
|
||||
synonymDefinition.key,
|
||||
SynonymKeyInfo(
|
||||
entries,
|
||||
synonymDefinition.key,
|
||||
),
|
||||
SynonymKeyInfo(entries, synonymDefinition.key),
|
||||
);
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -22,8 +22,8 @@ bool _isAsciiLetter(String? char) {
|
||||
const int charLowerZ = 0x7A;
|
||||
assert(char.length == 1);
|
||||
final int charCode = char.codeUnitAt(0);
|
||||
return (charCode >= charUpperA && charCode <= charUpperZ)
|
||||
|| (charCode >= charLowerA && charCode <= charLowerZ);
|
||||
return (charCode >= charUpperA && charCode <= charUpperZ) ||
|
||||
(charCode >= charLowerA && charCode <= charLowerZ);
|
||||
}
|
||||
|
||||
bool _isDigit(String? char) {
|
||||
@@ -44,7 +44,8 @@ class KeyboardMapsCodeGenerator extends BaseCodeGenerator {
|
||||
|
||||
List<PhysicalKeyEntry> get _numpadKeyData {
|
||||
return keyData.entries.where((PhysicalKeyEntry entry) {
|
||||
return entry.constantName.startsWith('numpad') && LogicalKeyData.printable.containsKey(entry.name);
|
||||
return entry.constantName.startsWith('numpad') &&
|
||||
LogicalKeyData.printable.containsKey(entry.name);
|
||||
}).toList();
|
||||
}
|
||||
|
||||
@@ -57,7 +58,8 @@ class KeyboardMapsCodeGenerator extends BaseCodeGenerator {
|
||||
|
||||
List<LogicalKeyEntry> get _numpadLogicalKeyData {
|
||||
return logicalData.entries.where((LogicalKeyEntry entry) {
|
||||
return entry.constantName.startsWith('numpad') && LogicalKeyData.printable.containsKey(entry.name);
|
||||
return entry.constantName.startsWith('numpad') &&
|
||||
LogicalKeyData.printable.containsKey(entry.name);
|
||||
}).toList();
|
||||
}
|
||||
|
||||
@@ -111,8 +113,10 @@ class KeyboardMapsCodeGenerator extends BaseCodeGenerator {
|
||||
final OutputLines<int> lines = OutputLines<int>('GTK scancode map');
|
||||
for (final PhysicalKeyEntry entry in keyData.entries) {
|
||||
if (entry.xKbScanCode != null) {
|
||||
lines.add(entry.xKbScanCode!,
|
||||
' ${toHex(entry.xKbScanCode)}: PhysicalKeyboardKey.${entry.constantName},');
|
||||
lines.add(
|
||||
entry.xKbScanCode!,
|
||||
' ${toHex(entry.xKbScanCode)}: PhysicalKeyboardKey.${entry.constantName},',
|
||||
);
|
||||
}
|
||||
}
|
||||
return lines.sortedJoin().trimRight();
|
||||
@@ -156,7 +160,10 @@ class KeyboardMapsCodeGenerator extends BaseCodeGenerator {
|
||||
final OutputLines<int> lines = OutputLines<int>('Windows scancode map');
|
||||
for (final PhysicalKeyEntry entry in keyData.entries) {
|
||||
if (entry.windowsScanCode != null) {
|
||||
lines.add(entry.windowsScanCode!, ' ${entry.windowsScanCode}: PhysicalKeyboardKey.${entry.constantName},');
|
||||
lines.add(
|
||||
entry.windowsScanCode!,
|
||||
' ${entry.windowsScanCode}: PhysicalKeyboardKey.${entry.constantName},',
|
||||
);
|
||||
}
|
||||
}
|
||||
return lines.sortedJoin().trimRight();
|
||||
@@ -179,11 +186,14 @@ class KeyboardMapsCodeGenerator extends BaseCodeGenerator {
|
||||
for (final LogicalKeyEntry entry in logicalData.entries) {
|
||||
// Letter keys on Windows are not recorded in logical_key_data.g.json,
|
||||
// because they are not used by the embedding. Add them manually.
|
||||
final List<int>? keyCodes = entry.windowsValues.isNotEmpty
|
||||
? entry.windowsValues
|
||||
: (_isAsciiLetter(entry.keyLabel) ? <int>[entry.keyLabel!.toUpperCase().codeUnitAt(0)] :
|
||||
_isDigit(entry.keyLabel) ? <int>[entry.keyLabel!.toUpperCase().codeUnitAt(0)] :
|
||||
null);
|
||||
final List<int>? keyCodes =
|
||||
entry.windowsValues.isNotEmpty
|
||||
? entry.windowsValues
|
||||
: (_isAsciiLetter(entry.keyLabel)
|
||||
? <int>[entry.keyLabel!.toUpperCase().codeUnitAt(0)]
|
||||
: _isDigit(entry.keyLabel)
|
||||
? <int>[entry.keyLabel!.toUpperCase().codeUnitAt(0)]
|
||||
: null);
|
||||
if (keyCodes != null) {
|
||||
for (final int code in keyCodes) {
|
||||
lines.add(code, ' $code: LogicalKeyboardKey.${entry.constantName},');
|
||||
@@ -198,7 +208,10 @@ class KeyboardMapsCodeGenerator extends BaseCodeGenerator {
|
||||
final OutputLines<int> lines = OutputLines<int>('macOS scancode map');
|
||||
for (final PhysicalKeyEntry entry in keyData.entries) {
|
||||
if (entry.macOSScanCode != null) {
|
||||
lines.add(entry.macOSScanCode!, ' ${toHex(entry.macOSScanCode)}: PhysicalKeyboardKey.${entry.constantName},');
|
||||
lines.add(
|
||||
entry.macOSScanCode!,
|
||||
' ${toHex(entry.macOSScanCode)}: PhysicalKeyboardKey.${entry.constantName},',
|
||||
);
|
||||
}
|
||||
}
|
||||
return lines.sortedJoin().trimRight();
|
||||
@@ -209,7 +222,10 @@ class KeyboardMapsCodeGenerator extends BaseCodeGenerator {
|
||||
final OutputLines<int> lines = OutputLines<int>('macOS numpad map');
|
||||
for (final PhysicalKeyEntry entry in _numpadKeyData) {
|
||||
if (entry.macOSScanCode != null) {
|
||||
lines.add(entry.macOSScanCode!, ' ${toHex(entry.macOSScanCode)}: LogicalKeyboardKey.${entry.constantName},');
|
||||
lines.add(
|
||||
entry.macOSScanCode!,
|
||||
' ${toHex(entry.macOSScanCode)}: LogicalKeyboardKey.${entry.constantName},',
|
||||
);
|
||||
}
|
||||
}
|
||||
return lines.sortedJoin().trimRight();
|
||||
@@ -219,7 +235,10 @@ class KeyboardMapsCodeGenerator extends BaseCodeGenerator {
|
||||
final OutputLines<int> lines = OutputLines<int>('macOS function key map');
|
||||
for (final PhysicalKeyEntry entry in _functionKeyData) {
|
||||
if (entry.macOSScanCode != null) {
|
||||
lines.add(entry.macOSScanCode!, ' ${toHex(entry.macOSScanCode)}: LogicalKeyboardKey.${entry.constantName},');
|
||||
lines.add(
|
||||
entry.macOSScanCode!,
|
||||
' ${toHex(entry.macOSScanCode)}: LogicalKeyboardKey.${entry.constantName},',
|
||||
);
|
||||
}
|
||||
}
|
||||
return lines.sortedJoin().trimRight();
|
||||
@@ -241,7 +260,10 @@ class KeyboardMapsCodeGenerator extends BaseCodeGenerator {
|
||||
final OutputLines<int> lines = OutputLines<int>('iOS scancode map');
|
||||
for (final PhysicalKeyEntry entry in keyData.entries) {
|
||||
if (entry.iOSScanCode != null) {
|
||||
lines.add(entry.iOSScanCode!, ' ${toHex(entry.iOSScanCode)}: PhysicalKeyboardKey.${entry.constantName},');
|
||||
lines.add(
|
||||
entry.iOSScanCode!,
|
||||
' ${toHex(entry.iOSScanCode)}: PhysicalKeyboardKey.${entry.constantName},',
|
||||
);
|
||||
}
|
||||
}
|
||||
return lines.sortedJoin().trimRight();
|
||||
@@ -262,7 +284,10 @@ class KeyboardMapsCodeGenerator extends BaseCodeGenerator {
|
||||
final OutputLines<int> lines = OutputLines<int>('iOS numpad map');
|
||||
for (final PhysicalKeyEntry entry in _numpadKeyData) {
|
||||
if (entry.iOSScanCode != null) {
|
||||
lines.add(entry.iOSScanCode!,' ${toHex(entry.iOSScanCode)}: LogicalKeyboardKey.${entry.constantName},');
|
||||
lines.add(
|
||||
entry.iOSScanCode!,
|
||||
' ${toHex(entry.iOSScanCode)}: LogicalKeyboardKey.${entry.constantName},',
|
||||
);
|
||||
}
|
||||
}
|
||||
return lines.sortedJoin().trimRight();
|
||||
@@ -294,7 +319,9 @@ class KeyboardMapsCodeGenerator extends BaseCodeGenerator {
|
||||
String get _fuchsiaHidCodeMap {
|
||||
final StringBuffer fuchsiaScanCodeMap = StringBuffer();
|
||||
for (final PhysicalKeyEntry entry in keyData.entries) {
|
||||
fuchsiaScanCodeMap.writeln(' ${toHex(entry.usbHidCode)}: PhysicalKeyboardKey.${entry.constantName},');
|
||||
fuchsiaScanCodeMap.writeln(
|
||||
' ${toHex(entry.usbHidCode)}: PhysicalKeyboardKey.${entry.constantName},',
|
||||
);
|
||||
}
|
||||
return fuchsiaScanCodeMap.toString().trimRight();
|
||||
}
|
||||
@@ -312,7 +339,10 @@ class KeyboardMapsCodeGenerator extends BaseCodeGenerator {
|
||||
|
||||
/// This generates the map of Web KeyboardEvent codes to physical keys.
|
||||
String get _webPhysicalKeyMap {
|
||||
final OutputLines<String> lines = OutputLines<String>('Web physical key map', behavior: DeduplicateBehavior.kKeep);
|
||||
final OutputLines<String> lines = OutputLines<String>(
|
||||
'Web physical key map',
|
||||
behavior: DeduplicateBehavior.kKeep,
|
||||
);
|
||||
for (final PhysicalKeyEntry entry in keyData.entries) {
|
||||
for (final String webCodes in entry.webCodes()) {
|
||||
lines.add(entry.name, " '$webCodes': PhysicalKeyboardKey.${entry.constantName},");
|
||||
@@ -331,14 +361,18 @@ class KeyboardMapsCodeGenerator extends BaseCodeGenerator {
|
||||
|
||||
/// 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 String jsonRaw =
|
||||
File(path.join(dataRoot, 'web_logical_location_mapping.json')).readAsStringSync();
|
||||
final Map<String, List<String?>> locationMap = parseMapOfListOfNullableString(jsonRaw);
|
||||
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(', ');
|
||||
final String keyStrings = keyNames
|
||||
.map((String? keyName) {
|
||||
final String? constantName =
|
||||
keyName == null ? null : logicalData.entryByName(keyName).constantName;
|
||||
return constantName != null ? 'LogicalKeyboardKey.$constantName' : 'null';
|
||||
})
|
||||
.join(', ');
|
||||
lines.add(key, " '$key': <LogicalKeyboardKey?>[$keyStrings],");
|
||||
});
|
||||
return lines.sortedJoin().trimRight();
|
||||
|
||||
@@ -62,10 +62,11 @@ class LogicalKeyData {
|
||||
_readFuchsiaKeyCodes(data, physicalKeyData);
|
||||
_readGlfwKeyCodes(data, glfwHeaderFile, parseMapOfListOfString(glfwNameMap));
|
||||
// Sort entries by value
|
||||
final List<MapEntry<String, LogicalKeyEntry>> sortedEntries = data.entries.toList()..sort(
|
||||
(MapEntry<String, LogicalKeyEntry> a, MapEntry<String, LogicalKeyEntry> b) =>
|
||||
LogicalKeyEntry.compareByValue(a.value, b.value),
|
||||
);
|
||||
final List<MapEntry<String, LogicalKeyEntry>> sortedEntries =
|
||||
data.entries.toList()..sort(
|
||||
(MapEntry<String, LogicalKeyEntry> a, MapEntry<String, LogicalKeyEntry> b) =>
|
||||
LogicalKeyEntry.compareByValue(a.value, b.value),
|
||||
);
|
||||
data
|
||||
..clear()
|
||||
..addEntries(sortedEntries);
|
||||
@@ -75,10 +76,14 @@ class LogicalKeyData {
|
||||
/// Parses the given JSON data and populates the data structure from it.
|
||||
factory LogicalKeyData.fromJson(Map<String, dynamic> contentMap) {
|
||||
final Map<String, LogicalKeyEntry> data = <String, LogicalKeyEntry>{};
|
||||
data.addEntries(contentMap.values.map((dynamic value) {
|
||||
final LogicalKeyEntry entry = LogicalKeyEntry.fromJsonMapEntry(value as Map<String, dynamic>);
|
||||
return MapEntry<String, LogicalKeyEntry>(entry.name, entry);
|
||||
}));
|
||||
data.addEntries(
|
||||
contentMap.values.map((dynamic value) {
|
||||
final LogicalKeyEntry entry = LogicalKeyEntry.fromJsonMapEntry(
|
||||
value as Map<String, dynamic>,
|
||||
);
|
||||
return MapEntry<String, LogicalKeyEntry>(entry.name, entry);
|
||||
}),
|
||||
);
|
||||
return LogicalKeyData._(data);
|
||||
}
|
||||
|
||||
@@ -102,8 +107,7 @@ class LogicalKeyData {
|
||||
///
|
||||
/// Asserts if the name is not found.
|
||||
LogicalKeyEntry entryByName(String name) {
|
||||
assert(_data.containsKey(name),
|
||||
'Unable to find logical entry by name $name.');
|
||||
assert(_data.containsKey(name), 'Unable to find logical entry by name $name.');
|
||||
return _data[name]!;
|
||||
}
|
||||
|
||||
@@ -150,12 +154,17 @@ class LogicalKeyData {
|
||||
if (webName.startsWith('.')) {
|
||||
continue;
|
||||
}
|
||||
final String name = LogicalKeyEntry.computeName(webName.replaceAll(RegExp('[^A-Za-z0-9]'), ''));
|
||||
final int value = match.namedGroup('unicode') != null ?
|
||||
getHex(match.namedGroup('unicode')!) :
|
||||
match.namedGroup('char')!.codeUnitAt(0);
|
||||
final String? keyLabel = (match.namedGroup('kind')! == 'UNI' && !_isControlCharacter(value)) ?
|
||||
String.fromCharCode(value) : null;
|
||||
final String name = LogicalKeyEntry.computeName(
|
||||
webName.replaceAll(RegExp('[^A-Za-z0-9]'), ''),
|
||||
);
|
||||
final int value =
|
||||
match.namedGroup('unicode') != null
|
||||
? getHex(match.namedGroup('unicode')!)
|
||||
: match.namedGroup('char')!.codeUnitAt(0);
|
||||
final String? keyLabel =
|
||||
(match.namedGroup('kind')! == 'UNI' && !_isControlCharacter(value))
|
||||
? String.fromCharCode(value)
|
||||
: null;
|
||||
// Skip modifier keys from DOM. They will be added with supplemental data.
|
||||
if (_chromeModifiers.containsKey(name) && source == 'DOM') {
|
||||
continue;
|
||||
@@ -163,20 +172,17 @@ class LogicalKeyData {
|
||||
|
||||
final bool isPrintable = keyLabel != null;
|
||||
final int entryValue = toPlane(value, _sourceToPlane(source, isPrintable));
|
||||
final LogicalKeyEntry entry = dataByValue.putIfAbsent(entryValue, () =>
|
||||
LogicalKeyEntry.fromName(
|
||||
value: entryValue,
|
||||
name: name,
|
||||
keyLabel: keyLabel,
|
||||
),
|
||||
final LogicalKeyEntry entry = dataByValue.putIfAbsent(
|
||||
entryValue,
|
||||
() => LogicalKeyEntry.fromName(value: entryValue, name: name, keyLabel: keyLabel),
|
||||
);
|
||||
if (source == 'DOM' && !isPrintable) {
|
||||
entry.webNames.add(webName);
|
||||
}
|
||||
}
|
||||
return Map<String, LogicalKeyEntry>.fromEntries(
|
||||
dataByValue.values.map((LogicalKeyEntry entry) =>
|
||||
MapEntry<String, LogicalKeyEntry>(entry.name, entry),
|
||||
dataByValue.values.map(
|
||||
(LogicalKeyEntry entry) => MapEntry<String, LogicalKeyEntry>(entry.name, entry),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -186,16 +192,21 @@ class LogicalKeyData {
|
||||
PhysicalKeyData physicalKeyData,
|
||||
Map<String, List<String>> logicalToPhysical,
|
||||
) {
|
||||
final Map<String, String> physicalToLogical = reverseMapOfListOfString(logicalToPhysical,
|
||||
(String logicalKeyName, String physicalKeyName) { print('Duplicate logical key name $logicalKeyName for macOS'); });
|
||||
final Map<String, String> physicalToLogical = reverseMapOfListOfString(logicalToPhysical, (
|
||||
String logicalKeyName,
|
||||
String physicalKeyName,
|
||||
) {
|
||||
print('Duplicate logical key name $logicalKeyName for macOS');
|
||||
});
|
||||
|
||||
physicalToLogical.forEach((String physicalKeyName, String logicalKeyName) {
|
||||
final PhysicalKeyEntry physicalEntry = physicalKeyData.entryByName(physicalKeyName);
|
||||
assert(physicalEntry.macOSScanCode != null,
|
||||
'Physical entry $physicalKeyName does not have a macOSScanCode.');
|
||||
assert(
|
||||
physicalEntry.macOSScanCode != null,
|
||||
'Physical entry $physicalKeyName does not have a macOSScanCode.',
|
||||
);
|
||||
final LogicalKeyEntry? logicalEntry = data[logicalKeyName];
|
||||
assert(logicalEntry != null,
|
||||
'Unable to find logical entry by name $logicalKeyName.');
|
||||
assert(logicalEntry != null, 'Unable to find logical entry by name $logicalKeyName.');
|
||||
logicalEntry!.macOSKeyCodeNames.add(physicalEntry.name);
|
||||
logicalEntry.macOSKeyCodeValues.add(physicalEntry.macOSScanCode!);
|
||||
});
|
||||
@@ -206,16 +217,21 @@ class LogicalKeyData {
|
||||
PhysicalKeyData physicalKeyData,
|
||||
Map<String, List<String>> logicalToPhysical,
|
||||
) {
|
||||
final Map<String, String> physicalToLogical = reverseMapOfListOfString(logicalToPhysical,
|
||||
(String logicalKeyName, String physicalKeyName) { print('Duplicate logical key name $logicalKeyName for iOS'); });
|
||||
final Map<String, String> physicalToLogical = reverseMapOfListOfString(logicalToPhysical, (
|
||||
String logicalKeyName,
|
||||
String physicalKeyName,
|
||||
) {
|
||||
print('Duplicate logical key name $logicalKeyName for iOS');
|
||||
});
|
||||
|
||||
physicalToLogical.forEach((String physicalKeyName, String logicalKeyName) {
|
||||
final PhysicalKeyEntry physicalEntry = physicalKeyData.entryByName(physicalKeyName);
|
||||
assert(physicalEntry.iOSScanCode != null,
|
||||
'Physical entry $physicalKeyName does not have an iosScanCode.');
|
||||
assert(
|
||||
physicalEntry.iOSScanCode != null,
|
||||
'Physical entry $physicalKeyName does not have an iosScanCode.',
|
||||
);
|
||||
final LogicalKeyEntry? logicalEntry = data[logicalKeyName];
|
||||
assert(logicalEntry != null,
|
||||
'Unable to find logical entry by name $logicalKeyName.');
|
||||
assert(logicalEntry != null, 'Unable to find logical entry by name $logicalKeyName.');
|
||||
logicalEntry!.iOSKeyCodeNames.add(physicalEntry.name);
|
||||
logicalEntry.iOSKeyCodeValues.add(physicalEntry.iOSScanCode!);
|
||||
});
|
||||
@@ -226,14 +242,22 @@ class LogicalKeyData {
|
||||
/// Lines in this file look like this (without the ///):
|
||||
/// /** Space key. */
|
||||
/// #define GDK_KEY_space 0x020
|
||||
static void _readGtkKeyCodes(Map<String, LogicalKeyEntry> data, String headerFile, Map<String, List<String>> nameToGtkName) {
|
||||
static void _readGtkKeyCodes(
|
||||
Map<String, LogicalKeyEntry> data,
|
||||
String headerFile,
|
||||
Map<String, List<String>> nameToGtkName,
|
||||
) {
|
||||
final RegExp definedCodes = RegExp(
|
||||
r'#define '
|
||||
r'GDK_KEY_(?<name>[a-zA-Z0-9_]+)\s*'
|
||||
r'0x(?<value>[0-9a-f]+),?',
|
||||
);
|
||||
final Map<String, String> gtkNameToFlutterName = reverseMapOfListOfString(nameToGtkName,
|
||||
(String flutterName, String gtkName) { print('Duplicate GTK logical name $gtkName'); });
|
||||
final Map<String, String> gtkNameToFlutterName = reverseMapOfListOfString(nameToGtkName, (
|
||||
String flutterName,
|
||||
String gtkName,
|
||||
) {
|
||||
print('Duplicate GTK logical name $gtkName');
|
||||
});
|
||||
|
||||
for (final RegExpMatch match in definedCodes.allMatches(headerFile)) {
|
||||
final String gtkName = match.namedGroup('name')!;
|
||||
@@ -255,11 +279,19 @@ class LogicalKeyData {
|
||||
}
|
||||
}
|
||||
|
||||
static void _readWindowsKeyCodes(Map<String, LogicalKeyEntry> data, String headerFile, Map<String, List<String>> nameMap) {
|
||||
static void _readWindowsKeyCodes(
|
||||
Map<String, LogicalKeyEntry> data,
|
||||
String headerFile,
|
||||
Map<String, List<String>> nameMap,
|
||||
) {
|
||||
// The mapping from the Flutter name (e.g. "enter") to the Windows name (e.g.
|
||||
// "RETURN").
|
||||
final Map<String, String> nameToFlutterName = reverseMapOfListOfString(nameMap,
|
||||
(String flutterName, String windowsName) { print('Duplicate Windows logical name $windowsName'); });
|
||||
final Map<String, String> nameToFlutterName = reverseMapOfListOfString(nameMap, (
|
||||
String flutterName,
|
||||
String windowsName,
|
||||
) {
|
||||
print('Duplicate Windows logical name $windowsName');
|
||||
});
|
||||
|
||||
final RegExp definedCodes = RegExp(
|
||||
r'define '
|
||||
@@ -279,12 +311,7 @@ class LogicalKeyData {
|
||||
print('Invalid logical entry by name $name (from Windows $windowsName)');
|
||||
continue;
|
||||
}
|
||||
addNameValue(
|
||||
entry.windowsNames,
|
||||
entry.windowsValues,
|
||||
windowsName,
|
||||
value,
|
||||
);
|
||||
addNameValue(entry.windowsNames, entry.windowsValues, windowsName, value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -293,9 +320,17 @@ class LogicalKeyData {
|
||||
/// Lines in this file look like this (without the ///):
|
||||
/// /** Left Control modifier key. */
|
||||
/// AKEYCODE_CTRL_LEFT = 113,
|
||||
static void _readAndroidKeyCodes(Map<String, LogicalKeyEntry> data, String headerFile, Map<String, List<String>> nameMap) {
|
||||
final Map<String, String> nameToFlutterName = reverseMapOfListOfString(nameMap,
|
||||
(String flutterName, String androidName) { print('Duplicate Android logical name $androidName'); });
|
||||
static void _readAndroidKeyCodes(
|
||||
Map<String, LogicalKeyEntry> data,
|
||||
String headerFile,
|
||||
Map<String, List<String>> nameMap,
|
||||
) {
|
||||
final Map<String, String> nameToFlutterName = reverseMapOfListOfString(nameMap, (
|
||||
String flutterName,
|
||||
String androidName,
|
||||
) {
|
||||
print('Duplicate Android logical name $androidName');
|
||||
});
|
||||
|
||||
final RegExp enumBlock = RegExp(r'enum\s*\{(.*)\};', multiLine: true);
|
||||
// Eliminate everything outside of the enum block.
|
||||
@@ -324,22 +359,26 @@ class LogicalKeyData {
|
||||
}
|
||||
}
|
||||
|
||||
static void _readFuchsiaKeyCodes(Map<String, LogicalKeyEntry> data, PhysicalKeyData physicalData) {
|
||||
static void _readFuchsiaKeyCodes(
|
||||
Map<String, LogicalKeyEntry> data,
|
||||
PhysicalKeyData physicalData,
|
||||
) {
|
||||
for (final LogicalKeyEntry entry in data.values) {
|
||||
final int? value = (() {
|
||||
if (entry.value == 0) {
|
||||
return 0;
|
||||
}
|
||||
final String? keyLabel = printable[entry.constantName];
|
||||
if (keyLabel != null && !entry.constantName.startsWith('numpad')) {
|
||||
return toPlane(keyLabel.codeUnitAt(0), kUnicodePlane.value);
|
||||
} else {
|
||||
final PhysicalKeyEntry? physicalEntry = physicalData.tryEntryByName(entry.name);
|
||||
if (physicalEntry != null) {
|
||||
return toPlane(physicalEntry.usbHidCode, kFuchsiaPlane.value);
|
||||
}
|
||||
}
|
||||
})();
|
||||
final int? value =
|
||||
(() {
|
||||
if (entry.value == 0) {
|
||||
return 0;
|
||||
}
|
||||
final String? keyLabel = printable[entry.constantName];
|
||||
if (keyLabel != null && !entry.constantName.startsWith('numpad')) {
|
||||
return toPlane(keyLabel.codeUnitAt(0), kUnicodePlane.value);
|
||||
} else {
|
||||
final PhysicalKeyEntry? physicalEntry = physicalData.tryEntryByName(entry.name);
|
||||
if (physicalEntry != null) {
|
||||
return toPlane(physicalEntry.usbHidCode, kFuchsiaPlane.value);
|
||||
}
|
||||
}
|
||||
})();
|
||||
if (value != null) {
|
||||
entry.fuchsiaValues.add(value);
|
||||
}
|
||||
@@ -352,9 +391,17 @@ class LogicalKeyData {
|
||||
/// /** Space key. */
|
||||
/// #define GLFW_KEY_SPACE 32,
|
||||
/// #define GLFW_KEY_LAST GLFW_KEY_MENU
|
||||
static void _readGlfwKeyCodes(Map<String, LogicalKeyEntry> data, String headerFile, Map<String, List<String>> nameMap) {
|
||||
final Map<String, String> nameToFlutterName = reverseMapOfListOfString(nameMap,
|
||||
(String flutterName, String glfwName) { print('Duplicate GLFW logical name $glfwName'); });
|
||||
static void _readGlfwKeyCodes(
|
||||
Map<String, LogicalKeyEntry> data,
|
||||
String headerFile,
|
||||
Map<String, List<String>> nameMap,
|
||||
) {
|
||||
final Map<String, String> nameToFlutterName = reverseMapOfListOfString(nameMap, (
|
||||
String flutterName,
|
||||
String glfwName,
|
||||
) {
|
||||
print('Duplicate GLFW logical name $glfwName');
|
||||
});
|
||||
|
||||
// Only get the KEY definitions, ignore the rest (mouse, joystick, etc).
|
||||
final RegExp definedCodes = RegExp(
|
||||
@@ -388,47 +435,47 @@ class LogicalKeyData {
|
||||
print('Invalid logical entry by name $name (from GLFW $glfwName)');
|
||||
return;
|
||||
}
|
||||
addNameValue(
|
||||
entry.glfwNames,
|
||||
entry.glfwValues,
|
||||
glfwName,
|
||||
value,
|
||||
);
|
||||
addNameValue(entry.glfwNames, entry.glfwValues, glfwName, value);
|
||||
});
|
||||
}
|
||||
|
||||
// Map Web key to the pair of key names
|
||||
static final Map<String, _ModifierPair> _chromeModifiers = () {
|
||||
final String rawJson = File(path.join(dataRoot, 'chromium_modifiers.json',)).readAsStringSync();
|
||||
final String rawJson = File(path.join(dataRoot, 'chromium_modifiers.json')).readAsStringSync();
|
||||
return (json.decode(rawJson) as Map<String, dynamic>).map((String key, dynamic value) {
|
||||
final List<dynamic> pair = value as List<dynamic>;
|
||||
return MapEntry<String, _ModifierPair>(key, _ModifierPair(pair[0] as String, pair[1] as String));
|
||||
return MapEntry<String, _ModifierPair>(
|
||||
key,
|
||||
_ModifierPair(pair[0] as String, pair[1] as String),
|
||||
);
|
||||
});
|
||||
}();
|
||||
|
||||
/// Returns the static map of printable representations.
|
||||
static final Map<String, String> printable = (() {
|
||||
final String printableKeys = File(path.join(dataRoot, 'printable.json',)).readAsStringSync();
|
||||
return (json.decode(printableKeys) as Map<String, dynamic>)
|
||||
.cast<String, String>();
|
||||
})();
|
||||
static final Map<String, String> printable =
|
||||
(() {
|
||||
final String printableKeys = File(path.join(dataRoot, 'printable.json')).readAsStringSync();
|
||||
return (json.decode(printableKeys) as Map<String, dynamic>).cast<String, String>();
|
||||
})();
|
||||
|
||||
/// Returns the static map of synonym representations.
|
||||
///
|
||||
/// These include synonyms for keys which don't have printable
|
||||
/// representations, and appear in more than one place on the keyboard (e.g.
|
||||
/// SHIFT, ALT, etc.).
|
||||
static final Map<String, List<String>> synonyms = (() {
|
||||
final String synonymKeys = File(path.join(dataRoot, 'synonyms.json',)).readAsStringSync();
|
||||
final Map<String, dynamic> dynamicSynonym = json.decode(synonymKeys) as Map<String, dynamic>;
|
||||
return dynamicSynonym.map((String name, dynamic values) {
|
||||
// The keygen and algorithm of macOS relies on synonyms being pairs.
|
||||
// See siblingKeyMap in macos_code_gen.dart.
|
||||
final List<String> names = (values as List<dynamic>).whereType<String>().toList();
|
||||
assert(names.length == 2);
|
||||
return MapEntry<String, List<String>>(name, names);
|
||||
});
|
||||
})();
|
||||
static final Map<String, List<String>> synonyms =
|
||||
(() {
|
||||
final String synonymKeys = File(path.join(dataRoot, 'synonyms.json')).readAsStringSync();
|
||||
final Map<String, dynamic> dynamicSynonym =
|
||||
json.decode(synonymKeys) as Map<String, dynamic>;
|
||||
return dynamicSynonym.map((String name, dynamic values) {
|
||||
// The keygen and algorithm of macOS relies on synonyms being pairs.
|
||||
// See siblingKeyMap in macos_code_gen.dart.
|
||||
final List<String> names = (values as List<dynamic>).whereType<String>().toList();
|
||||
assert(names.length == 2);
|
||||
return MapEntry<String, List<String>>(name, names);
|
||||
});
|
||||
})();
|
||||
|
||||
static int _sourceToPlane(String source, bool isPrintable) {
|
||||
if (isPrintable) {
|
||||
@@ -446,41 +493,30 @@ class LogicalKeyData {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// A single entry in the key data structure.
|
||||
///
|
||||
/// Can be read from JSON with the [LogicalKeyEntry.fromJsonMapEntry] constructor, or
|
||||
/// written with the [toJson] method.
|
||||
class LogicalKeyEntry {
|
||||
/// Creates a single key entry from available data.
|
||||
LogicalKeyEntry({
|
||||
required this.value,
|
||||
required this.name,
|
||||
this.keyLabel,
|
||||
}) : webNames = <String>[],
|
||||
macOSKeyCodeNames = <String>[],
|
||||
macOSKeyCodeValues = <int>[],
|
||||
iOSKeyCodeNames = <String>[],
|
||||
iOSKeyCodeValues = <int>[],
|
||||
gtkNames = <String>[],
|
||||
gtkValues = <int>[],
|
||||
windowsNames = <String>[],
|
||||
windowsValues = <int>[],
|
||||
androidNames = <String>[],
|
||||
androidValues = <int>[],
|
||||
fuchsiaValues = <int>[],
|
||||
glfwNames = <String>[],
|
||||
glfwValues = <int>[];
|
||||
LogicalKeyEntry({required this.value, required this.name, this.keyLabel})
|
||||
: webNames = <String>[],
|
||||
macOSKeyCodeNames = <String>[],
|
||||
macOSKeyCodeValues = <int>[],
|
||||
iOSKeyCodeNames = <String>[],
|
||||
iOSKeyCodeValues = <int>[],
|
||||
gtkNames = <String>[],
|
||||
gtkValues = <int>[],
|
||||
windowsNames = <String>[],
|
||||
windowsValues = <int>[],
|
||||
androidNames = <String>[],
|
||||
androidValues = <int>[],
|
||||
fuchsiaValues = <int>[],
|
||||
glfwNames = <String>[],
|
||||
glfwValues = <int>[];
|
||||
|
||||
LogicalKeyEntry.fromName({
|
||||
required int value,
|
||||
required String name,
|
||||
String? keyLabel,
|
||||
}) : this(
|
||||
value: value,
|
||||
name: name,
|
||||
keyLabel: keyLabel,
|
||||
);
|
||||
LogicalKeyEntry.fromName({required int value, required String name, String? keyLabel})
|
||||
: this(value: value, name: name, keyLabel: keyLabel);
|
||||
|
||||
/// Populates the key from a JSON map.
|
||||
LogicalKeyEntry.fromJsonMapEntry(Map<String, dynamic> map)
|
||||
@@ -628,23 +664,37 @@ class LogicalKeyEntry {
|
||||
/// separate words (e.g. "wakeUp" converts to "Wake Up").
|
||||
static String computeCommentName(String name) {
|
||||
final String replaced = name.replaceAllMapped(
|
||||
RegExp(r'(Digit|Numpad|Lang|Button|Left|Right)([0-9]+)'), (Match match) => '${match.group(1)} ${match.group(2)}',
|
||||
RegExp(r'(Digit|Numpad|Lang|Button|Left|Right)([0-9]+)'),
|
||||
(Match match) => '${match.group(1)} ${match.group(2)}',
|
||||
);
|
||||
return replaced
|
||||
// 'fooBar' => 'foo Bar', 'fooBAR' => 'foo BAR'
|
||||
.replaceAllMapped(RegExp(r'([^A-Z])([A-Z])'), (Match match) => '${match.group(1)} ${match.group(2)}')
|
||||
// 'ABCDoo' => 'ABC Doo'
|
||||
.replaceAllMapped(RegExp(r'([A-Z])([A-Z])([a-z])'), (Match match) => '${match.group(1)} ${match.group(2)}${match.group(3)}')
|
||||
// 'AB1' => 'AB 1', 'F1' => 'F1'
|
||||
.replaceAllMapped(RegExp(r'([A-Z]{2,})([0-9])'), (Match match) => '${match.group(1)} ${match.group(2)}')
|
||||
// 'Foo1' => 'Foo 1'
|
||||
.replaceAllMapped(RegExp(r'([a-z])([0-9])'), (Match match) => '${match.group(1)} ${match.group(2)}')
|
||||
.trim();
|
||||
// 'fooBar' => 'foo Bar', 'fooBAR' => 'foo BAR'
|
||||
.replaceAllMapped(
|
||||
RegExp(r'([^A-Z])([A-Z])'),
|
||||
(Match match) => '${match.group(1)} ${match.group(2)}',
|
||||
)
|
||||
// 'ABCDoo' => 'ABC Doo'
|
||||
.replaceAllMapped(
|
||||
RegExp(r'([A-Z])([A-Z])([a-z])'),
|
||||
(Match match) => '${match.group(1)} ${match.group(2)}${match.group(3)}',
|
||||
)
|
||||
// 'AB1' => 'AB 1', 'F1' => 'F1'
|
||||
.replaceAllMapped(
|
||||
RegExp(r'([A-Z]{2,})([0-9])'),
|
||||
(Match match) => '${match.group(1)} ${match.group(2)}',
|
||||
)
|
||||
// 'Foo1' => 'Foo 1'
|
||||
.replaceAllMapped(
|
||||
RegExp(r'([a-z])([0-9])'),
|
||||
(Match match) => '${match.group(1)} ${match.group(2)}',
|
||||
)
|
||||
.trim();
|
||||
}
|
||||
|
||||
static String computeConstantName(String commentName) {
|
||||
// Convert the first word in the comment name.
|
||||
final String lowerCamelSpace = commentName.replaceFirstMapped(RegExp(r'^[^ ]+'),
|
||||
final String lowerCamelSpace = commentName.replaceFirstMapped(
|
||||
RegExp(r'^[^ ]+'),
|
||||
(Match match) => match[0]!.toLowerCase(),
|
||||
);
|
||||
final String result = lowerCamelSpace.replaceAll(' ', '');
|
||||
@@ -654,6 +704,5 @@ class LogicalKeyEntry {
|
||||
return result;
|
||||
}
|
||||
|
||||
static int compareByValue(LogicalKeyEntry a, LogicalKeyEntry b) =>
|
||||
a.value.compareTo(b.value);
|
||||
static int compareByValue(LogicalKeyEntry a, LogicalKeyEntry b) => a.value.compareTo(b.value);
|
||||
}
|
||||
|
||||
@@ -35,7 +35,10 @@ class MacOSCodeGenerator extends PlatformCodeGenerator {
|
||||
final OutputLines<int> lines = OutputLines<int>('macOS scancode map');
|
||||
for (final PhysicalKeyEntry entry in keyData.entries) {
|
||||
if (entry.macOSScanCode != null) {
|
||||
lines.add(entry.macOSScanCode!, ' @${toHex(entry.macOSScanCode)} : @${toHex(entry.usbHidCode)}, // ${entry.constantName}');
|
||||
lines.add(
|
||||
entry.macOSScanCode!,
|
||||
' @${toHex(entry.macOSScanCode)} : @${toHex(entry.usbHidCode)}, // ${entry.constantName}',
|
||||
);
|
||||
}
|
||||
}
|
||||
return lines.sortedJoin().trimRight();
|
||||
@@ -44,9 +47,14 @@ class MacOSCodeGenerator extends PlatformCodeGenerator {
|
||||
String get _keyCodeToLogicalMap {
|
||||
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) {
|
||||
lines.add(macOSValue,
|
||||
' @${toHex(macOSValue)} : @${toHex(entry.value, digits: 11)}, // $macOSName -> ${entry.constantName}');
|
||||
zipStrict(entry.macOSKeyCodeValues, entry.macOSKeyCodeNames, (
|
||||
int macOSValue,
|
||||
String macOSName,
|
||||
) {
|
||||
lines.add(
|
||||
macOSValue,
|
||||
' @${toHex(macOSValue)} : @${toHex(entry.value, digits: 11)}, // $macOSName -> ${entry.constantName}',
|
||||
);
|
||||
});
|
||||
}
|
||||
return lines.sortedJoin().trimRight();
|
||||
@@ -55,13 +63,11 @@ class MacOSCodeGenerator extends PlatformCodeGenerator {
|
||||
/// 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,
|
||||
];
|
||||
const List<MaskConstant> maskConstants = <MaskConstant>[kValueMask, kUnicodePlane, kMacosPlane];
|
||||
for (final MaskConstant constant in maskConstants) {
|
||||
buffer.writeln('const uint64_t k${constant.upperCamelName} = ${toHex(constant.value, digits: 11)};');
|
||||
buffer.writeln(
|
||||
'const uint64_t k${constant.upperCamelName} = ${toHex(constant.value, digits: 11)};',
|
||||
);
|
||||
}
|
||||
return buffer.toString().trimRight();
|
||||
}
|
||||
@@ -70,7 +76,9 @@ class MacOSCodeGenerator extends PlatformCodeGenerator {
|
||||
String get _keyToModifierFlagMap {
|
||||
final StringBuffer modifierKeyMap = StringBuffer();
|
||||
for (final String name in kModifiersOfInterest) {
|
||||
modifierKeyMap.writeln(' @${toHex(logicalData.entryByName(name).macOSKeyCodeValues[0])} : @(kModifierFlag${lowerCamelToUpperCamel(name)}),');
|
||||
modifierKeyMap.writeln(
|
||||
' @${toHex(logicalData.entryByName(name).macOSKeyCodeValues[0])} : @(kModifierFlag${lowerCamelToUpperCamel(name)}),',
|
||||
);
|
||||
}
|
||||
return modifierKeyMap.toString().trimRight();
|
||||
}
|
||||
@@ -79,7 +87,9 @@ class MacOSCodeGenerator extends PlatformCodeGenerator {
|
||||
String get _modifierFlagToKeyMap {
|
||||
final StringBuffer modifierKeyMap = StringBuffer();
|
||||
for (final String name in kModifiersOfInterest) {
|
||||
modifierKeyMap.writeln(' @(kModifierFlag${lowerCamelToUpperCamel(name)}) : @${toHex(logicalData.entryByName(name).macOSKeyCodeValues[0])},');
|
||||
modifierKeyMap.writeln(
|
||||
' @(kModifierFlag${lowerCamelToUpperCamel(name)}) : @${toHex(logicalData.entryByName(name).macOSKeyCodeValues[0])},',
|
||||
);
|
||||
}
|
||||
return modifierKeyMap.toString().trimRight();
|
||||
}
|
||||
@@ -88,10 +98,14 @@ class MacOSCodeGenerator extends PlatformCodeGenerator {
|
||||
String get _specialKeyConstants {
|
||||
final StringBuffer specialKeyConstants = StringBuffer();
|
||||
for (final String keyName in kSpecialPhysicalKeys) {
|
||||
specialKeyConstants.writeln('const uint64_t k${keyName}PhysicalKey = ${toHex(keyData.entryByName(keyName).usbHidCode)};');
|
||||
specialKeyConstants.writeln(
|
||||
'const uint64_t k${keyName}PhysicalKey = ${toHex(keyData.entryByName(keyName).usbHidCode)};',
|
||||
);
|
||||
}
|
||||
for (final String keyName in kSpecialLogicalKeys) {
|
||||
specialKeyConstants.writeln('const uint64_t k${lowerCamelToUpperCamel(keyName)}LogicalKey = ${toHex(logicalData.entryByName(keyName).value)};');
|
||||
specialKeyConstants.writeln(
|
||||
'const uint64_t k${lowerCamelToUpperCamel(keyName)}LogicalKey = ${toHex(logicalData.entryByName(keyName).value)};',
|
||||
);
|
||||
}
|
||||
return specialKeyConstants.toString().trimRight();
|
||||
}
|
||||
@@ -102,14 +116,17 @@ class MacOSCodeGenerator extends PlatformCodeGenerator {
|
||||
_layoutGoals.forEach((String name, bool mandatory) {
|
||||
final PhysicalKeyEntry physicalEntry = keyData.entryByName(name);
|
||||
final LogicalKeyEntry logicalEntry = logicalData.entryByName(name);
|
||||
final String line = 'LayoutGoal{'
|
||||
final String line =
|
||||
'LayoutGoal{'
|
||||
'${toHex(physicalEntry.macOSScanCode, digits: 2)}, '
|
||||
'${toHex(logicalEntry.value, digits: 2)}, '
|
||||
'${mandatory ? 'true' : 'false'}'
|
||||
'},';
|
||||
lines.add(logicalEntry.value,
|
||||
' ${line.padRight(32)}'
|
||||
'// ${logicalEntry.name}');
|
||||
lines.add(
|
||||
logicalEntry.value,
|
||||
' ${line.padRight(32)}'
|
||||
'// ${logicalEntry.name}',
|
||||
);
|
||||
});
|
||||
return lines.sortedJoin().trimRight();
|
||||
}
|
||||
@@ -118,8 +135,16 @@ class MacOSCodeGenerator extends PlatformCodeGenerator {
|
||||
String get templatePath => path.join(dataRoot, 'macos_key_code_map_cc.tmpl');
|
||||
|
||||
@override
|
||||
String outputPath(String platform) => path.join(PlatformCodeGenerator.engineRoot,
|
||||
'shell', 'platform', 'darwin', 'macos', 'framework', 'Source', 'KeyCodeMap.g.mm');
|
||||
String outputPath(String platform) => path.join(
|
||||
PlatformCodeGenerator.engineRoot,
|
||||
'shell',
|
||||
'platform',
|
||||
'darwin',
|
||||
'macos',
|
||||
'framework',
|
||||
'Source',
|
||||
'KeyCodeMap.g.mm',
|
||||
);
|
||||
|
||||
@override
|
||||
Map<String, String> mappings() {
|
||||
|
||||
@@ -18,15 +18,19 @@ class PhysicalKeyData {
|
||||
String androidKeyboardLayout,
|
||||
String androidNameMap,
|
||||
) {
|
||||
final Map<String, List<int>> nameToAndroidScanCodes = _readAndroidScanCodes(androidKeyboardLayout, androidNameMap);
|
||||
final Map<String, List<int>> nameToAndroidScanCodes = _readAndroidScanCodes(
|
||||
androidKeyboardLayout,
|
||||
androidNameMap,
|
||||
);
|
||||
final Map<String, PhysicalKeyEntry> data = _readHidEntries(
|
||||
chromiumHidCodes,
|
||||
nameToAndroidScanCodes,
|
||||
);
|
||||
final List<MapEntry<String, PhysicalKeyEntry>> sortedEntries = data.entries.toList()..sort(
|
||||
(MapEntry<String, PhysicalKeyEntry> a, MapEntry<String, PhysicalKeyEntry> b) =>
|
||||
PhysicalKeyEntry.compareByUsbHidCode(a.value, b.value),
|
||||
);
|
||||
final List<MapEntry<String, PhysicalKeyEntry>> sortedEntries =
|
||||
data.entries.toList()..sort(
|
||||
(MapEntry<String, PhysicalKeyEntry> a, MapEntry<String, PhysicalKeyEntry> b) =>
|
||||
PhysicalKeyEntry.compareByUsbHidCode(a.value, b.value),
|
||||
);
|
||||
data
|
||||
..clear()
|
||||
..addEntries(sortedEntries);
|
||||
@@ -37,7 +41,9 @@ class PhysicalKeyData {
|
||||
factory PhysicalKeyData.fromJson(Map<String, dynamic> contentMap) {
|
||||
final Map<String, PhysicalKeyEntry> data = <String, PhysicalKeyEntry>{};
|
||||
for (final MapEntry<String, dynamic> jsonEntry in contentMap.entries) {
|
||||
final PhysicalKeyEntry entry = PhysicalKeyEntry.fromJsonMapEntry(jsonEntry.value as Map<String, dynamic>);
|
||||
final PhysicalKeyEntry entry = PhysicalKeyEntry.fromJsonMapEntry(
|
||||
jsonEntry.value as Map<String, dynamic>,
|
||||
);
|
||||
data[entry.name] = entry;
|
||||
}
|
||||
return PhysicalKeyData._(data);
|
||||
@@ -55,8 +61,7 @@ class PhysicalKeyData {
|
||||
/// Asserts if the name is not found.
|
||||
PhysicalKeyEntry entryByName(String name) {
|
||||
final PhysicalKeyEntry? entry = tryEntryByName(name);
|
||||
assert(entry != null,
|
||||
'Unable to find logical entry by name $name.');
|
||||
assert(entry != null, 'Unable to find logical entry by name $name.');
|
||||
return entry!;
|
||||
}
|
||||
|
||||
@@ -98,7 +103,7 @@ class PhysicalKeyData {
|
||||
r'key\s+' // Literal "key"
|
||||
r'(?<id>[0-9]+)\s*' // ID section
|
||||
r'"?(?:KEY_)?(?<name>[0-9A-Z_]+|\(undefined\))"?\s*' // Name section
|
||||
r'(?<function>FUNCTION)?' // Optional literal "FUNCTION"
|
||||
r'(?<function>FUNCTION)?', // Optional literal "FUNCTION"
|
||||
);
|
||||
final Map<String, List<int>> androidNameToScanCodes = <String, List<int>>{};
|
||||
for (final RegExpMatch match in keyEntry.allMatches(keyboardLayout)) {
|
||||
@@ -111,18 +116,23 @@ class PhysicalKeyData {
|
||||
// Skip undefined scan codes.
|
||||
continue;
|
||||
}
|
||||
androidNameToScanCodes.putIfAbsent(name, () => <int>[])
|
||||
.add(int.parse(match.namedGroup('id')!));
|
||||
androidNameToScanCodes
|
||||
.putIfAbsent(name, () => <int>[])
|
||||
.add(int.parse(match.namedGroup('id')!));
|
||||
}
|
||||
|
||||
// Cast Android dom map
|
||||
final Map<String, List<String>> nameToAndroidNames = (json.decode(nameMap) as Map<String, dynamic>)
|
||||
.cast<String, List<dynamic>>()
|
||||
.map<String, List<String>>((String key, List<dynamic> value) {
|
||||
return MapEntry<String, List<String>>(key, value.cast<String>());
|
||||
});
|
||||
final Map<String, List<String>> nameToAndroidNames = (json.decode(nameMap)
|
||||
as Map<String, dynamic>)
|
||||
.cast<String, List<dynamic>>()
|
||||
.map<String, List<String>>((String key, List<dynamic> value) {
|
||||
return MapEntry<String, List<String>>(key, value.cast<String>());
|
||||
});
|
||||
|
||||
final Map<String, List<int>> result = nameToAndroidNames.map((String name, List<String> androidNames) {
|
||||
final Map<String, List<int>> result = nameToAndroidNames.map((
|
||||
String name,
|
||||
List<String> androidNames,
|
||||
) {
|
||||
final Set<int> scanCodes = <int>{};
|
||||
for (final String androidName in androidNames) {
|
||||
scanCodes.addAll(androidNameToScanCodes[androidName] ?? <int>[]);
|
||||
@@ -179,14 +189,16 @@ class PhysicalKeyData {
|
||||
if (existing != null && existing.name != 'Fn') {
|
||||
// If it's an existing entry, the only thing we currently support is
|
||||
// to insert an extra DOMKey. The other entries must be empty.
|
||||
assert(evdevCode == 0
|
||||
&& xKbScanCode == 0
|
||||
&& windowsScanCode == 0
|
||||
&& macScanCode == 0xffff
|
||||
&& chromiumCode != null
|
||||
&& chromiumCode.isNotEmpty,
|
||||
'Duplicate usbHidCode ${existing.usbHidCode} of key ${existing.name} '
|
||||
'conflicts with existing ${entries[existing.usbHidCode]!.name}.');
|
||||
assert(
|
||||
evdevCode == 0 &&
|
||||
xKbScanCode == 0 &&
|
||||
windowsScanCode == 0 &&
|
||||
macScanCode == 0xffff &&
|
||||
chromiumCode != null &&
|
||||
chromiumCode.isNotEmpty,
|
||||
'Duplicate usbHidCode ${existing.usbHidCode} of key ${existing.name} '
|
||||
'conflicts with existing ${entries[existing.usbHidCode]!.name}.',
|
||||
);
|
||||
existing.otherWebCodes.add(chromiumCode!);
|
||||
continue;
|
||||
}
|
||||
@@ -203,8 +215,9 @@ class PhysicalKeyData {
|
||||
);
|
||||
entries[newEntry.usbHidCode] = newEntry;
|
||||
}
|
||||
return entries.map((int code, PhysicalKeyEntry entry) =>
|
||||
MapEntry<String, PhysicalKeyEntry>(entry.name, entry));
|
||||
return entries.map(
|
||||
(int code, PhysicalKeyEntry entry) => MapEntry<String, PhysicalKeyEntry>(entry.name, entry),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -250,24 +263,32 @@ class PhysicalKeyEntry {
|
||||
|
||||
/// The Evdev scan code of the key, from Chromium's header file.
|
||||
final int? evdevCode;
|
||||
|
||||
/// The XKb scan code of the key from Chromium's header file.
|
||||
final int? xKbScanCode;
|
||||
|
||||
/// The Windows scan code of the key from Chromium's header file.
|
||||
final int? windowsScanCode;
|
||||
|
||||
/// The macOS scan code of the key from Chromium's header file.
|
||||
final int? macOSScanCode;
|
||||
|
||||
/// The iOS scan code of the key from UIKey's documentation (USB Hid table)
|
||||
final int? iOSScanCode;
|
||||
|
||||
/// The list of Android scan codes matching this key, created by looking up
|
||||
/// the Android name in the Chromium data, and substituting the Android scan
|
||||
/// code value.
|
||||
final List<int> androidScanCodes;
|
||||
|
||||
/// The name of the key, mostly derived from the DomKey name in Chromium,
|
||||
/// but where there was no DomKey representation, derived from the Chromium
|
||||
/// symbol name.
|
||||
final String name;
|
||||
|
||||
/// The Chromium event code for the key.
|
||||
final String? chromiumCode;
|
||||
|
||||
/// Other codes used by Web besides chromiumCode.
|
||||
final List<String> otherWebCodes;
|
||||
|
||||
@@ -281,10 +302,7 @@ class PhysicalKeyEntry {
|
||||
/// Creates a JSON map from the key data.
|
||||
Map<String, dynamic> toJson() {
|
||||
return removeEmptyValues(<String, dynamic>{
|
||||
'names': <String, dynamic>{
|
||||
'name': name,
|
||||
'chromium': chromiumCode,
|
||||
},
|
||||
'names': <String, dynamic>{'name': name, 'chromium': chromiumCode},
|
||||
'otherWebCodes': otherWebCodes,
|
||||
'scanCodes': <String, dynamic>{
|
||||
'android': androidScanCodes,
|
||||
@@ -304,7 +322,9 @@ class PhysicalKeyEntry {
|
||||
RegExp(r'(Digit|Numpad|Lang|Button|Left|Right)([0-9]+)'),
|
||||
(Match match) => '${match.group(1)} ${match.group(2)}',
|
||||
);
|
||||
return upperCamel.replaceAllMapped(RegExp(r'([A-Z])'), (Match match) => ' ${match.group(1)}').trim();
|
||||
return upperCamel
|
||||
.replaceAllMapped(RegExp(r'([A-Z])'), (Match match) => ' ${match.group(1)}')
|
||||
.trim();
|
||||
}
|
||||
|
||||
/// Gets the name of the key suitable for placing in comments.
|
||||
@@ -320,26 +340,26 @@ class PhysicalKeyEntry {
|
||||
/// the name from the various different names available, making sure that the
|
||||
/// name isn't a Dart reserved word (if it is, then it adds the word "Key" to
|
||||
/// the end of the name).
|
||||
late final String constantName = (() {
|
||||
String? result;
|
||||
if (name.isEmpty) {
|
||||
// If it doesn't have a DomKey name then use the Chromium symbol name.
|
||||
result = chromiumCode;
|
||||
} else {
|
||||
result = upperCamelToLowerCamel(name);
|
||||
}
|
||||
result ??= 'Key${toHex(usbHidCode)}';
|
||||
if (kDartReservedWords.contains(result)) {
|
||||
return '${result}Key';
|
||||
}
|
||||
return result;
|
||||
})();
|
||||
late final String constantName =
|
||||
(() {
|
||||
String? result;
|
||||
if (name.isEmpty) {
|
||||
// If it doesn't have a DomKey name then use the Chromium symbol name.
|
||||
result = chromiumCode;
|
||||
} else {
|
||||
result = upperCamelToLowerCamel(name);
|
||||
}
|
||||
result ??= 'Key${toHex(usbHidCode)}';
|
||||
if (kDartReservedWords.contains(result)) {
|
||||
return '${result}Key';
|
||||
}
|
||||
return result;
|
||||
})();
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
final String otherWebStr = otherWebCodes.isEmpty
|
||||
? ''
|
||||
: ', otherWebCodes: [${otherWebCodes.join(', ')}]';
|
||||
final String otherWebStr =
|
||||
otherWebCodes.isEmpty ? '' : ', otherWebCodes: [${otherWebCodes.join(', ')}]';
|
||||
return """'$constantName': (name: "$name", usbHidCode: ${toHex(usbHidCode)}, """
|
||||
'linuxScanCode: ${toHex(evdevCode)}, xKbScanCode: ${toHex(xKbScanCode)}, '
|
||||
'windowsKeyCode: ${toHex(windowsScanCode)}, macOSScanCode: ${toHex(macOSScanCode)}, '
|
||||
|
||||
@@ -30,10 +30,16 @@ constexpr uint64_t kPhysical${_toUpperCamel(entry.constantName)} = ${toHex(entry
|
||||
|
||||
/// Gets the generated definitions of PhysicalKeyboardKeys.
|
||||
String get _logicalDefinitions {
|
||||
final OutputLines<int> lines = OutputLines<int>('Logical Key list', behavior: DeduplicateBehavior.kSkip);
|
||||
final OutputLines<int> lines = OutputLines<int>(
|
||||
'Logical Key list',
|
||||
behavior: DeduplicateBehavior.kSkip,
|
||||
);
|
||||
for (final LogicalKeyEntry entry in logicalData.entries) {
|
||||
lines.add(entry.value, '''
|
||||
constexpr uint64_t kLogical${_toUpperCamel(entry.constantName)} = ${toHex(entry.value, digits: 11)};''');
|
||||
lines.add(
|
||||
entry.value,
|
||||
'''
|
||||
constexpr uint64_t kLogical${_toUpperCamel(entry.constantName)} = ${toHex(entry.value, digits: 11)};''',
|
||||
);
|
||||
}
|
||||
return lines.sortedJoin().trimRight();
|
||||
}
|
||||
|
||||
@@ -11,18 +11,16 @@ import 'utils.dart';
|
||||
|
||||
String _toUpperSnake(String lowerCamel) {
|
||||
// Converts 'myTVFoo' to 'myTvFoo'.
|
||||
final String trueUpperCamel = lowerCamel.replaceAllMapped(
|
||||
RegExp(r'([A-Z]{3,})'),
|
||||
(Match match) {
|
||||
final String matched = match.group(1)!;
|
||||
return matched.substring(0, 1)
|
||||
+ matched.substring(1, matched.length - 2).toLowerCase()
|
||||
+ matched.substring(matched.length - 2, matched.length - 1);
|
||||
});
|
||||
final String trueUpperCamel = lowerCamel.replaceAllMapped(RegExp(r'([A-Z]{3,})'), (Match match) {
|
||||
final String matched = match.group(1)!;
|
||||
return matched.substring(0, 1) +
|
||||
matched.substring(1, matched.length - 2).toLowerCase() +
|
||||
matched.substring(matched.length - 2, matched.length - 1);
|
||||
});
|
||||
// Converts 'myTvFoo' to 'MY_TV_FOO'.
|
||||
return trueUpperCamel.replaceAllMapped(
|
||||
RegExp(r'([A-Z])'),
|
||||
(Match match) => '_${match.group(1)!}').toUpperCase();
|
||||
return trueUpperCamel
|
||||
.replaceAllMapped(RegExp(r'([A-Z])'), (Match match) => '_${match.group(1)!}')
|
||||
.toUpperCase();
|
||||
}
|
||||
|
||||
/// Generates the common/testing/key_codes.h based on the information in the key
|
||||
@@ -34,18 +32,27 @@ class KeyCodesJavaGenerator extends BaseCodeGenerator {
|
||||
String get _physicalDefinitions {
|
||||
final OutputLines<int> lines = OutputLines<int>('Physical Key list');
|
||||
for (final PhysicalKeyEntry entry in keyData.entries) {
|
||||
lines.add(entry.usbHidCode, '''
|
||||
public static final long PHYSICAL_${_toUpperSnake(entry.constantName)} = ${toHex(entry.usbHidCode)}L;''');
|
||||
lines.add(
|
||||
entry.usbHidCode,
|
||||
'''
|
||||
public static final long PHYSICAL_${_toUpperSnake(entry.constantName)} = ${toHex(entry.usbHidCode)}L;''',
|
||||
);
|
||||
}
|
||||
return lines.sortedJoin().trimRight();
|
||||
}
|
||||
|
||||
/// Gets the generated definitions of PhysicalKeyboardKeys.
|
||||
String get _logicalDefinitions {
|
||||
final OutputLines<int> lines = OutputLines<int>('Logical Key list', behavior: DeduplicateBehavior.kSkip);
|
||||
final OutputLines<int> lines = OutputLines<int>(
|
||||
'Logical Key list',
|
||||
behavior: DeduplicateBehavior.kSkip,
|
||||
);
|
||||
for (final LogicalKeyEntry entry in logicalData.entries) {
|
||||
lines.add(entry.value, '''
|
||||
public static final long LOGICAL_${_toUpperSnake(entry.constantName)} = ${toHex(entry.value, digits: 11)}L;''');
|
||||
lines.add(
|
||||
entry.value,
|
||||
'''
|
||||
public static final long LOGICAL_${_toUpperSnake(entry.constantName)} = ${toHex(entry.value, digits: 11)}L;''',
|
||||
);
|
||||
}
|
||||
return lines.sortedJoin().trimRight();
|
||||
}
|
||||
|
||||
@@ -12,7 +12,8 @@ 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 Directory flutterRoot =
|
||||
Directory(path.dirname(Platform.script.toFilePath())).parent.parent.parent.parent;
|
||||
String get dataRoot => testDataRoot ?? _dataRoot;
|
||||
String _dataRoot = path.join(flutterRoot.path, 'dev', 'tools', 'gen_keycodes', 'data');
|
||||
|
||||
@@ -169,14 +170,16 @@ Map<String, String> parseMapOfString(String jsonString) {
|
||||
|
||||
/// Read a Map<String, List<String>> out of its string representation in JSON.
|
||||
Map<String, List<String>> parseMapOfListOfString(String jsonString) {
|
||||
final Map<String, List<dynamic>> dynamicMap = (json.decode(jsonString) as Map<String, dynamic>).cast<String, List<dynamic>>();
|
||||
final Map<String, List<dynamic>> dynamicMap =
|
||||
(json.decode(jsonString) as Map<String, dynamic>).cast<String, List<dynamic>>();
|
||||
return dynamicMap.map<String, List<String>>((String key, List<dynamic> value) {
|
||||
return MapEntry<String, List<String>>(key, value.cast<String>());
|
||||
});
|
||||
}
|
||||
|
||||
Map<String, List<String?>> parseMapOfListOfNullableString(String jsonString) {
|
||||
final Map<String, List<dynamic>> dynamicMap = (json.decode(jsonString) as Map<String, dynamic>).cast<String, List<dynamic>>();
|
||||
final Map<String, List<dynamic>> dynamicMap =
|
||||
(json.decode(jsonString) as Map<String, dynamic>).cast<String, List<dynamic>>();
|
||||
return dynamicMap.map<String, List<String?>>((String key, List<dynamic> value) {
|
||||
return MapEntry<String, List<String?>>(key, value.cast<String?>());
|
||||
});
|
||||
@@ -187,7 +190,10 @@ Map<String, bool> parseMapOfBool(String jsonString) {
|
||||
}
|
||||
|
||||
/// Reverse the map of { fromValue -> list of toValue } to { toValue -> fromValue } and return.
|
||||
Map<String, String> reverseMapOfListOfString(Map<String, List<String>> inMap, void Function(String fromValue, String newToValue) onDuplicate) {
|
||||
Map<String, String> reverseMapOfListOfString(
|
||||
Map<String, List<String>> inMap,
|
||||
void Function(String fromValue, String newToValue) onDuplicate,
|
||||
) {
|
||||
final Map<String, String> result = <String, String>{};
|
||||
inMap.forEach((String fromValue, List<String> toValues) {
|
||||
for (final String toValue in toValues) {
|
||||
@@ -205,12 +211,14 @@ Map<String, String> reverseMapOfListOfString(Map<String, List<String>> inMap, vo
|
||||
///
|
||||
/// Will modify the input map.
|
||||
Map<String, dynamic> removeEmptyValues(Map<String, dynamic> map) {
|
||||
return map..removeWhere((String key, dynamic value) => switch (value) {
|
||||
null => true,
|
||||
Map<String, dynamic>() => removeEmptyValues(value).isEmpty,
|
||||
Iterable<dynamic>() => value.isEmpty,
|
||||
_ => false,
|
||||
});
|
||||
return map..removeWhere(
|
||||
(String key, dynamic value) => switch (value) {
|
||||
null => true,
|
||||
Map<String, dynamic>() => removeEmptyValues(value).isEmpty,
|
||||
Iterable<dynamic>() => value.isEmpty,
|
||||
_ => false,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
void addNameValue(List<String> names, List<int> values, String name, int value) {
|
||||
@@ -238,8 +246,7 @@ enum DeduplicateBehavior {
|
||||
|
||||
/// The information for a line used by [OutputLines].
|
||||
class OutputLine<T extends Comparable<Object>> {
|
||||
OutputLine(this.key, String value)
|
||||
: values = <String>[value];
|
||||
OutputLine(this.key, String value) : values = <String>[value];
|
||||
|
||||
final T key;
|
||||
final List<String> values;
|
||||
@@ -268,7 +275,9 @@ class OutputLines<T extends Comparable<Object>> {
|
||||
if (existing != null) {
|
||||
switch (behavior) {
|
||||
case DeduplicateBehavior.kWarn:
|
||||
print('Warn: Request to add $key to map "$mapName" as:\n $line\n but it already exists as:\n ${existing.values[0]}');
|
||||
print(
|
||||
'Warn: Request to add $key to map "$mapName" as:\n $line\n but it already exists as:\n ${existing.values[0]}',
|
||||
);
|
||||
return;
|
||||
case DeduplicateBehavior.kSkip:
|
||||
return;
|
||||
@@ -286,9 +295,9 @@ class OutputLines<T extends Comparable<Object>> {
|
||||
|
||||
String sortedJoin() {
|
||||
return (lines.values.toList()
|
||||
..sort((OutputLine<T> a, OutputLine<T> b) => a.key.compareTo(b.key)))
|
||||
.map((OutputLine<T> line) => line.values.join('\n'))
|
||||
.join('\n');
|
||||
..sort((OutputLine<T> a, OutputLine<T> b) => a.key.compareTo(b.key)))
|
||||
.map((OutputLine<T> line) => line.values.join('\n'))
|
||||
.join('\n');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,11 +13,8 @@ import 'utils.dart';
|
||||
/// Generates the key mapping for Web, based on the information in the key
|
||||
/// data structure given to it.
|
||||
class WebCodeGenerator extends PlatformCodeGenerator {
|
||||
WebCodeGenerator(
|
||||
super.keyData,
|
||||
super.logicalData,
|
||||
String logicalLocationMap,
|
||||
) : _logicalLocationMap = parseMapOfListOfNullableString(logicalLocationMap);
|
||||
WebCodeGenerator(super.keyData, super.logicalData, String logicalLocationMap)
|
||||
: _logicalLocationMap = parseMapOfListOfNullableString(logicalLocationMap);
|
||||
|
||||
/// This generates the map of Web KeyboardEvent codes to logical key ids.
|
||||
String get _webLogicalKeyCodeMap {
|
||||
@@ -38,8 +35,7 @@ class WebCodeGenerator extends PlatformCodeGenerator {
|
||||
final OutputLines<String> lines = OutputLines<String>('Web physical map');
|
||||
for (final PhysicalKeyEntry entry in keyData.entries) {
|
||||
for (final String webCode in entry.webCodes()) {
|
||||
lines.add(webCode,
|
||||
" '$webCode': ${toHex(entry.usbHidCode)}, // ${entry.constantName}");
|
||||
lines.add(webCode, " '$webCode': ${toHex(entry.usbHidCode)}, // ${entry.constantName}");
|
||||
}
|
||||
}
|
||||
return lines.sortedJoin().trimRight();
|
||||
@@ -49,24 +45,36 @@ class WebCodeGenerator extends PlatformCodeGenerator {
|
||||
String get _webLogicalLocationMap {
|
||||
final OutputLines<String> lines = OutputLines<String>('Web logical location map');
|
||||
_logicalLocationMap.forEach((String webKey, List<String?> locations) {
|
||||
final String valuesString = locations.map((String? value) {
|
||||
return value == null ? 'null' : toHex(logicalData.entryByName(value).value, digits: 11);
|
||||
}).join(', ');
|
||||
final String namesString = locations.map((String? value) {
|
||||
return value == null ? 'null' : logicalData.entryByName(value).constantName;
|
||||
}).join(', ');
|
||||
final String valuesString = locations
|
||||
.map((String? value) {
|
||||
return value == null ? 'null' : toHex(logicalData.entryByName(value).value, digits: 11);
|
||||
})
|
||||
.join(', ');
|
||||
final String namesString = locations
|
||||
.map((String? value) {
|
||||
return value == null ? 'null' : logicalData.entryByName(value).constantName;
|
||||
})
|
||||
.join(', ');
|
||||
lines.add(webKey, " '$webKey': <int?>[$valuesString], // $namesString");
|
||||
});
|
||||
return lines.sortedJoin().trimRight();
|
||||
}
|
||||
|
||||
final Map<String, List<String?>> _logicalLocationMap;
|
||||
|
||||
@override
|
||||
String get templatePath => path.join(dataRoot, 'web_key_map_dart.tmpl');
|
||||
|
||||
@override
|
||||
String outputPath(String platform) => path.join(PlatformCodeGenerator.engineRoot,
|
||||
'lib', 'web_ui', 'lib', 'src', 'engine', 'key_map.g.dart');
|
||||
String outputPath(String platform) => path.join(
|
||||
PlatformCodeGenerator.engineRoot,
|
||||
'lib',
|
||||
'web_ui',
|
||||
'lib',
|
||||
'src',
|
||||
'engine',
|
||||
'key_map.g.dart',
|
||||
);
|
||||
|
||||
@override
|
||||
Map<String, String> mappings() {
|
||||
|
||||
@@ -13,19 +13,18 @@ import 'utils.dart';
|
||||
/// Generates the key mapping for Windows, based on the information in the key
|
||||
/// data structure given to it.
|
||||
class WindowsCodeGenerator extends PlatformCodeGenerator {
|
||||
WindowsCodeGenerator(
|
||||
super.keyData,
|
||||
super.logicalData,
|
||||
String scancodeToLogical,
|
||||
) : _scancodeToLogical = parseMapOfString(scancodeToLogical);
|
||||
WindowsCodeGenerator(super.keyData, super.logicalData, String scancodeToLogical)
|
||||
: _scancodeToLogical = parseMapOfString(scancodeToLogical);
|
||||
|
||||
/// This generates the map of Windows scan codes to physical keys.
|
||||
String get _windowsScanCodeMap {
|
||||
final OutputLines<int> lines = OutputLines<int>('Windows scancode map');
|
||||
for (final PhysicalKeyEntry entry in keyData.entries) {
|
||||
if (entry.windowsScanCode != null) {
|
||||
lines.add(entry.windowsScanCode!,
|
||||
' {${toHex(entry.windowsScanCode)}, ${toHex(entry.usbHidCode)}}, // ${entry.constantName}');
|
||||
lines.add(
|
||||
entry.windowsScanCode!,
|
||||
' {${toHex(entry.windowsScanCode)}, ${toHex(entry.usbHidCode)}}, // ${entry.constantName}',
|
||||
);
|
||||
}
|
||||
}
|
||||
return lines.sortedJoin().trimRight();
|
||||
@@ -35,13 +34,13 @@ class WindowsCodeGenerator extends PlatformCodeGenerator {
|
||||
String get _windowsLogicalKeyCodeMap {
|
||||
final OutputLines<int> lines = OutputLines<int>('Windows logical map');
|
||||
for (final LogicalKeyEntry entry in logicalData.entries) {
|
||||
zipStrict(entry.windowsValues, entry.windowsNames,
|
||||
(int windowsValue, String windowsName) {
|
||||
lines.add(windowsValue,
|
||||
' {${toHex(windowsValue)}, ${toHex(entry.value, digits: 11)}}, '
|
||||
'// $windowsName -> ${entry.constantName}');
|
||||
},
|
||||
);
|
||||
zipStrict(entry.windowsValues, entry.windowsNames, (int windowsValue, String windowsName) {
|
||||
lines.add(
|
||||
windowsValue,
|
||||
' {${toHex(windowsValue)}, ${toHex(entry.value, digits: 11)}}, '
|
||||
'// $windowsName -> ${entry.constantName}',
|
||||
);
|
||||
});
|
||||
}
|
||||
return lines.sortedJoin().trimRight();
|
||||
}
|
||||
@@ -56,12 +55,15 @@ class WindowsCodeGenerator extends PlatformCodeGenerator {
|
||||
_scancodeToLogical.forEach((String scanCodeName, String logicalName) {
|
||||
final PhysicalKeyEntry physicalEntry = keyData.entryByName(scanCodeName);
|
||||
final LogicalKeyEntry logicalEntry = logicalData.entryByName(logicalName);
|
||||
lines.add(physicalEntry.windowsScanCode!,
|
||||
' {${toHex(physicalEntry.windowsScanCode)}, ${toHex(logicalEntry.value, digits: 11)}}, '
|
||||
'// ${physicalEntry.constantName} -> ${logicalEntry.constantName}');
|
||||
lines.add(
|
||||
physicalEntry.windowsScanCode!,
|
||||
' {${toHex(physicalEntry.windowsScanCode)}, ${toHex(logicalEntry.value, digits: 11)}}, '
|
||||
'// ${physicalEntry.constantName} -> ${logicalEntry.constantName}',
|
||||
);
|
||||
});
|
||||
return lines.sortedJoin().trimRight();
|
||||
}
|
||||
|
||||
final Map<String, String> _scancodeToLogical;
|
||||
|
||||
/// This generates the mask values for the part of a key code that defines its plane.
|
||||
@@ -73,7 +75,9 @@ class WindowsCodeGenerator extends PlatformCodeGenerator {
|
||||
kWindowsPlane,
|
||||
];
|
||||
for (final MaskConstant constant in maskConstants) {
|
||||
buffer.writeln('const uint64_t KeyboardKeyEmbedderHandler::${constant.lowerCamelName} = ${toHex(constant.value, digits: 11)};');
|
||||
buffer.writeln(
|
||||
'const uint64_t KeyboardKeyEmbedderHandler::${constant.lowerCamelName} = ${toHex(constant.value, digits: 11)};',
|
||||
);
|
||||
}
|
||||
return buffer.toString().trimRight();
|
||||
}
|
||||
@@ -82,8 +86,13 @@ class WindowsCodeGenerator extends PlatformCodeGenerator {
|
||||
String get templatePath => path.join(dataRoot, 'windows_flutter_key_map_cc.tmpl');
|
||||
|
||||
@override
|
||||
String outputPath(String platform) => path.join(PlatformCodeGenerator.engineRoot,
|
||||
'shell', 'platform', 'windows', 'flutter_key_map.g.cc');
|
||||
String outputPath(String platform) => path.join(
|
||||
PlatformCodeGenerator.engineRoot,
|
||||
'shell',
|
||||
'platform',
|
||||
'windows',
|
||||
'flutter_key_map.g.cc',
|
||||
);
|
||||
|
||||
@override
|
||||
Map<String, String> mappings() {
|
||||
|
||||
@@ -23,18 +23,19 @@ String readDataFile(String fileName) {
|
||||
}
|
||||
|
||||
final PhysicalKeyData physicalData = PhysicalKeyData.fromJson(
|
||||
json.decode(readDataFile('physical_key_data.g.json')) as Map<String, dynamic>);
|
||||
json.decode(readDataFile('physical_key_data.g.json')) as Map<String, dynamic>,
|
||||
);
|
||||
final LogicalKeyData logicalData = LogicalKeyData.fromJson(
|
||||
json.decode(readDataFile('logical_key_data.g.json')) as Map<String, dynamic>);
|
||||
final Map<String, bool> keyGoals = parseMapOfBool(
|
||||
readDataFile('layout_goals.json'));
|
||||
json.decode(readDataFile('logical_key_data.g.json')) as Map<String, dynamic>,
|
||||
);
|
||||
final Map<String, bool> keyGoals = parseMapOfBool(readDataFile('layout_goals.json'));
|
||||
|
||||
void main() {
|
||||
setUp(() {
|
||||
testDataRoot = path.canonicalize(path.join(Directory.current.absolute.path, 'data'));
|
||||
});
|
||||
|
||||
tearDown((){
|
||||
tearDown(() {
|
||||
testDataRoot = null;
|
||||
});
|
||||
|
||||
@@ -50,10 +51,7 @@ void main() {
|
||||
|
||||
test('Generate Keycodes for Android', () {
|
||||
const String platform = 'android';
|
||||
final PlatformCodeGenerator codeGenerator = AndroidCodeGenerator(
|
||||
physicalData,
|
||||
logicalData,
|
||||
);
|
||||
final PlatformCodeGenerator codeGenerator = AndroidCodeGenerator(physicalData, logicalData);
|
||||
final String output = codeGenerator.generate();
|
||||
|
||||
expect(codeGenerator.outputPath(platform), endsWith('KeyboardMap.java'));
|
||||
@@ -84,10 +82,7 @@ void main() {
|
||||
});
|
||||
test('Generate Keycodes for iOS', () {
|
||||
const String platform = 'ios';
|
||||
final PlatformCodeGenerator codeGenerator = IOSCodeGenerator(
|
||||
physicalData,
|
||||
logicalData,
|
||||
);
|
||||
final PlatformCodeGenerator codeGenerator = IOSCodeGenerator(physicalData, logicalData);
|
||||
final String output = codeGenerator.generate();
|
||||
|
||||
expect(codeGenerator.outputPath(platform), endsWith('KeyCodeMap.g.mm'));
|
||||
@@ -152,20 +147,12 @@ void main() {
|
||||
|
||||
// Regression tests for https://github.com/flutter/flutter/pull/87098
|
||||
|
||||
expect(
|
||||
entries.indexWhere((LogicalKeyEntry entry) => entry.name == 'ShiftLeft'),
|
||||
isNot(-1));
|
||||
expect(
|
||||
entries.indexWhere((LogicalKeyEntry entry) => entry.webNames.contains('ShiftLeft')),
|
||||
-1);
|
||||
expect(entries.indexWhere((LogicalKeyEntry entry) => entry.name == 'ShiftLeft'), isNot(-1));
|
||||
expect(entries.indexWhere((LogicalKeyEntry entry) => entry.webNames.contains('ShiftLeft')), -1);
|
||||
// 'Shift' maps to both 'ShiftLeft' and 'ShiftRight', and should be resolved
|
||||
// by other ways.
|
||||
expect(
|
||||
entries.indexWhere((LogicalKeyEntry entry) => entry.webNames.contains('Shift')),
|
||||
-1);
|
||||
expect(entries.indexWhere((LogicalKeyEntry entry) => entry.webNames.contains('Shift')), -1);
|
||||
// Printable keys must not be added with Web key of their names.
|
||||
expect(
|
||||
entries.indexWhere((LogicalKeyEntry entry) => entry.webNames.contains('Slash')),
|
||||
-1);
|
||||
expect(entries.indexWhere((LogicalKeyEntry entry) => entry.webNames.contains('Slash')), -1);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user