[gen_keycodes] Remove invalid Web code maps (#106074)

* Impl

* Test
This commit is contained in:
Tong Mu
2022-06-16 13:53:23 -07:00
committed by GitHub
parent 96813e9369
commit ddeb0b99c5
11 changed files with 41 additions and 54 deletions

View File

@@ -65,7 +65,7 @@ Future<String> getGlfwKeyCodes() async {
}
Future<String> getGtkKeyCodes() async {
final Uri keyCodesUri = Uri.parse('https://gitlab.gnome.org/GNOME/gtk/-/raw/master/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);
}

View File

@@ -201,7 +201,6 @@
"NavigatePrevious": ["NAVIGATE_PREVIOUS"],
"NewKey": ["NEW"],
"NonConvert": ["MUHENKAN"],
"None": ["UNKNOWN"],
"Notification": ["NOTIFICATION"],
"NumLock": ["NUM_LOCK"],
"NumberSign": ["POUND"],

View File

@@ -101,8 +101,6 @@
"IntlYen": ["yen"],
"KanjiMode": ["Kanji"],
"Katakana": ["Katakana"],
"KbdIllumDown": ["KbdBrightnessDown"],
"KbdIllumUp": ["KbdBrightnessUp"],
"LaunchAudioBrowser": ["Music"],
"LaunchCalendar": ["Calendar"],
"LaunchDocuments": ["Document"],

View File

@@ -166,10 +166,12 @@ class LogicalKeyboardKey extends KeyboardKey {
@override
bool operator ==(Object other) {
if (identical(this, other))
if (identical(this, other)) {
return true;
if (other.runtimeType != runtimeType)
}
if (other.runtimeType != runtimeType) {
return false;
}
return other is LogicalKeyboardKey
&& other.keyId == keyId;
}
@@ -348,10 +350,12 @@ class PhysicalKeyboardKey extends KeyboardKey {
@override
bool operator ==(Object other) {
if (identical(this, other))
if (identical(this, other)) {
return true;
if (other.runtimeType != runtimeType)
}
if (other.runtimeType != runtimeType) {
return false;
}
return other is PhysicalKeyboardKey
&& other.usbHidUsage == usbHidUsage;
}

View File

@@ -305,8 +305,8 @@ class KeyboardMapsCodeGenerator extends BaseCodeGenerator {
String get _webPhysicalKeyMap {
final OutputLines<String> lines = OutputLines<String>('Web physical key map');
for (final PhysicalKeyEntry entry in keyData.entries) {
if (entry.name != null) {
lines.add(entry.name, " '${entry.name}': PhysicalKeyboardKey.${entry.constantName},");
for (final String webCodes in entry.webCodes()) {
lines.add(entry.name, " '$webCodes': PhysicalKeyboardKey.${entry.constantName},");
}
}
return lines.sortedJoin().trimRight();

View File

@@ -372,6 +372,9 @@ class LogicalKeyData {
glfwNameToKeyCode.forEach((String glfwName, int value) {
final String? name = nameToFlutterName[glfwName];
if (name == null) {
return;
}
final LogicalKeyEntry? entry = data[nameToFlutterName[glfwName]];
if (entry == null) {
print('Invalid logical entry by name $name (from GLFW $glfwName)');

View File

@@ -259,6 +259,12 @@ class PhysicalKeyEntry {
/// The Chromium event code for the key.
final String? chromiumCode;
Iterable<String> webCodes() sync* {
if (chromiumCode != null) {
yield chromiumCode!;
}
}
/// Creates a JSON map from the key data.
Map<String, dynamic> toJson() {
return removeEmptyValues(<String, dynamic>{

View File

@@ -35,7 +35,7 @@ class KeyCodesJavaGenerator extends BaseCodeGenerator {
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;''');
public static final long PHYSICAL_${_toUpperSnake(entry.constantName)} = ${toHex(entry.usbHidCode)}L;''');
}
return lines.sortedJoin().trimRight();
}
@@ -45,7 +45,7 @@ class KeyCodesJavaGenerator extends BaseCodeGenerator {
final OutputLines<int> lines = OutputLines<int>('Logical Key list');
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;''');
public static final long LOGICAL_${_toUpperSnake(entry.constantName)} = ${toHex(entry.value, digits: 11)}L;''');
}
return lines.sortedJoin().trimRight();
}

View File

@@ -37,9 +37,9 @@ class WebCodeGenerator extends PlatformCodeGenerator {
String get _webPhysicalKeyCodeMap {
final OutputLines<String> lines = OutputLines<String>('Web physical map');
for (final PhysicalKeyEntry entry in keyData.entries) {
if (entry.name != null) {
lines.add(entry.name,
" '${entry.name}': ${toHex(entry.usbHidCode)}, // ${entry.constantName}");
for (final String webCode in entry.webCodes()) {
lines.add(webCode,
" '$webCode': ${toHex(entry.usbHidCode)}, // ${entry.constantName}");
}
}
return lines.sortedJoin().trimRight();