New scheme for keyboard logical key ID (#85121)

This PR updates the ID used by logical keyboard keys.

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

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

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

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

View File

@@ -7,6 +7,8 @@ import 'dart:io';
import 'package:path/path.dart' as path;
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;
@@ -221,32 +223,63 @@ void addNameValue(List<String> names, List<int> values, String name, int value)
}
}
/// The information for a line used by [OutputLines].
class OutputLine<T extends Comparable<Object>> {
const OutputLine(this.key, this.value);
final T key;
final String value;
}
/// A utility class to build join a number of lines in a sorted order.
///
/// Use [add] to add a line and associate it with an index. Use [sortedJoin] to
/// get the joined string of these lines joined sorting them in the order of the
/// index.
class OutputLines<T extends Comparable<Object>> {
OutputLines(this.mapName);
OutputLines(this.mapName, {this.checkDuplicate = true});
/// If true, then lines with duplicate keys will be warned and discarded.
///
/// Default to true.
final bool checkDuplicate;
/// The name for this map.
///
/// Used in warning messages.
final String mapName;
final Map<T, String> lines = <T, String>{};
final Set<T> keys = <T>{};
final List<OutputLine<T>> lines = <OutputLine<T>>[];
void add(T code, String line) {
if (lines.containsKey(code)) {
print('Warn: $mapName is requested to add line $code as:\n $line\n but it already exists as:\n ${lines[code]}');
if (checkDuplicate) {
if (keys.contains(code)) {
final OutputLine<T> existing = lines.firstWhere((OutputLine<T> line) => line.key == code);
print('Warn: $mapName is requested to add line $code as:\n $line\n but it already exists as:\n ${existing.value}');
return;
}
keys.add(code);
}
lines[code] = line;
lines.add(OutputLine<T>(code, line));
}
String join() {
return lines.map((OutputLine<T> line) => line.value).join('\n');
}
String sortedJoin() {
return (lines.entries.toList()
..sort((MapEntry<T, String> a, MapEntry<T, String> b) => a.key.compareTo(b.key)))
.map((MapEntry<T, String> entry) => entry.value)
return (lines.sublist(0)
..sort((OutputLine<T> a, OutputLine<T> b) => a.key.compareTo(b.key)))
.map((OutputLine<T> line) => line.value)
.join('\n');
}
}
int toPlane(int value, int plane) {
return (value & kValueMask.value) + (plane & kPlaneMask.value);
}
int getPlane(int value) {
return value & kPlaneMask.value;
}