Unverified Commit ddeb0b99 authored by Tong Mu's avatar Tong Mu Committed by GitHub

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

* Impl

* Test
parent 96813e93
......@@ -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);
}
......
......@@ -201,7 +201,6 @@
"NavigatePrevious": ["NAVIGATE_PREVIOUS"],
"NewKey": ["NEW"],
"NonConvert": ["MUHENKAN"],
"None": ["UNKNOWN"],
"Notification": ["NOTIFICATION"],
"NumLock": ["NUM_LOCK"],
"NumberSign": ["POUND"],
......
......@@ -101,8 +101,6 @@
"IntlYen": ["yen"],
"KanjiMode": ["Kanji"],
"Katakana": ["Katakana"],
"KbdIllumDown": ["KbdBrightnessDown"],
"KbdIllumUp": ["KbdBrightnessUp"],
"LaunchAudioBrowser": ["Music"],
"LaunchCalendar": ["Calendar"],
"LaunchDocuments": ["Document"],
......
......@@ -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;
}
......
......@@ -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();
......
......@@ -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)');
......
......@@ -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>{
......
......@@ -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();
}
......
......@@ -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();
......
......@@ -2459,14 +2459,9 @@ const Map<String, PhysicalKeyboardKey> kWebToPhysicalKey = <String, PhysicalKeyb
'Backquote': PhysicalKeyboardKey.backquote,
'Backslash': PhysicalKeyboardKey.backslash,
'Backspace': PhysicalKeyboardKey.backspace,
'BassBoost': PhysicalKeyboardKey.bassBoost,
'BracketLeft': PhysicalKeyboardKey.bracketLeft,
'BracketRight': PhysicalKeyboardKey.bracketRight,
'BrightnessAuto': PhysicalKeyboardKey.brightnessAuto,
'BrightnessDown': PhysicalKeyboardKey.brightnessDown,
'BrightnessMaximum': PhysicalKeyboardKey.brightnessMaximum,
'BrightnessMinimum': PhysicalKeyboardKey.brightnessMinimum,
'BrightnessToggle': PhysicalKeyboardKey.brightnessToggle,
'BrightnessUp': PhysicalKeyboardKey.brightnessUp,
'BrowserBack': PhysicalKeyboardKey.browserBack,
'BrowserFavorites': PhysicalKeyboardKey.browserFavorites,
......@@ -2476,10 +2471,6 @@ const Map<String, PhysicalKeyboardKey> kWebToPhysicalKey = <String, PhysicalKeyb
'BrowserSearch': PhysicalKeyboardKey.browserSearch,
'BrowserStop': PhysicalKeyboardKey.browserStop,
'CapsLock': PhysicalKeyboardKey.capsLock,
'ChannelDown': PhysicalKeyboardKey.channelDown,
'ChannelUp': PhysicalKeyboardKey.channelUp,
'Close': PhysicalKeyboardKey.close,
'ClosedCaptionToggle': PhysicalKeyboardKey.closedCaptionToggle,
'Comma': PhysicalKeyboardKey.comma,
'ContextMenu': PhysicalKeyboardKey.contextMenu,
'ControlLeft': PhysicalKeyboardKey.controlLeft,
......@@ -2504,7 +2495,6 @@ const Map<String, PhysicalKeyboardKey> kWebToPhysicalKey = <String, PhysicalKeyb
'Enter': PhysicalKeyboardKey.enter,
'Equal': PhysicalKeyboardKey.equal,
'Escape': PhysicalKeyboardKey.escape,
'Exit': PhysicalKeyboardKey.exit,
'F1': PhysicalKeyboardKey.f1,
'F10': PhysicalKeyboardKey.f10,
'F11': PhysicalKeyboardKey.f11,
......@@ -2566,14 +2556,11 @@ const Map<String, PhysicalKeyboardKey> kWebToPhysicalKey = <String, PhysicalKeyb
'Help': PhysicalKeyboardKey.help,
'Home': PhysicalKeyboardKey.home,
'Hyper': PhysicalKeyboardKey.hyper,
'Info': PhysicalKeyboardKey.info,
'Insert': PhysicalKeyboardKey.insert,
'IntlBackslash': PhysicalKeyboardKey.intlBackslash,
'IntlRo': PhysicalKeyboardKey.intlRo,
'IntlYen': PhysicalKeyboardKey.intlYen,
'KanaMode': PhysicalKeyboardKey.kanaMode,
'KbdIllumDown': PhysicalKeyboardKey.kbdIllumDown,
'KbdIllumUp': PhysicalKeyboardKey.kbdIllumUp,
'KeyA': PhysicalKeyboardKey.keyA,
'KeyB': PhysicalKeyboardKey.keyB,
'KeyC': PhysicalKeyboardKey.keyC,
......@@ -2609,25 +2596,13 @@ const Map<String, PhysicalKeyboardKey> kWebToPhysicalKey = <String, PhysicalKeyb
'LaunchApp1': PhysicalKeyboardKey.launchApp1,
'LaunchApp2': PhysicalKeyboardKey.launchApp2,
'LaunchAssistant': PhysicalKeyboardKey.launchAssistant,
'LaunchAudioBrowser': PhysicalKeyboardKey.launchAudioBrowser,
'LaunchCalendar': PhysicalKeyboardKey.launchCalendar,
'LaunchContacts': PhysicalKeyboardKey.launchContacts,
'LaunchControlPanel': PhysicalKeyboardKey.launchControlPanel,
'LaunchDocuments': PhysicalKeyboardKey.launchDocuments,
'LaunchInternetBrowser': PhysicalKeyboardKey.launchInternetBrowser,
'LaunchKeyboardLayout': PhysicalKeyboardKey.launchKeyboardLayout,
'LaunchMail': PhysicalKeyboardKey.launchMail,
'LaunchPhone': PhysicalKeyboardKey.launchPhone,
'LaunchScreenSaver': PhysicalKeyboardKey.launchScreenSaver,
'LaunchSpreadsheet': PhysicalKeyboardKey.launchSpreadsheet,
'LaunchWordProcessor': PhysicalKeyboardKey.launchWordProcessor,
'LockScreen': PhysicalKeyboardKey.lockScreen,
'LogOff': PhysicalKeyboardKey.logOff,
'MailForward': PhysicalKeyboardKey.mailForward,
'MailReply': PhysicalKeyboardKey.mailReply,
'MailSend': PhysicalKeyboardKey.mailSend,
'MediaFastForward': PhysicalKeyboardKey.mediaFastForward,
'MediaLast': PhysicalKeyboardKey.mediaLast,
'MediaPause': PhysicalKeyboardKey.mediaPause,
'MediaPlay': PhysicalKeyboardKey.mediaPlay,
'MediaPlayPause': PhysicalKeyboardKey.mediaPlayPause,
......@@ -2641,7 +2616,6 @@ const Map<String, PhysicalKeyboardKey> kWebToPhysicalKey = <String, PhysicalKeyb
'MetaRight': PhysicalKeyboardKey.metaRight,
'MicrophoneMuteToggle': PhysicalKeyboardKey.microphoneMuteToggle,
'Minus': PhysicalKeyboardKey.minus,
'New': PhysicalKeyboardKey.newKey,
'NonConvert': PhysicalKeyboardKey.nonConvert,
'NumLock': PhysicalKeyboardKey.numLock,
'Numpad0': PhysicalKeyboardKey.numpad0,
......@@ -2671,7 +2645,6 @@ const Map<String, PhysicalKeyboardKey> kWebToPhysicalKey = <String, PhysicalKeyb
'NumpadMultiply': PhysicalKeyboardKey.numpadMultiply,
'NumpadParenLeft': PhysicalKeyboardKey.numpadParenLeft,
'NumpadParenRight': PhysicalKeyboardKey.numpadParenRight,
'NumpadSignChange': PhysicalKeyboardKey.numpadSignChange,
'NumpadSubtract': PhysicalKeyboardKey.numpadSubtract,
'Open': PhysicalKeyboardKey.open,
'PageDown': PhysicalKeyboardKey.pageDown,
......@@ -2680,15 +2653,11 @@ const Map<String, PhysicalKeyboardKey> kWebToPhysicalKey = <String, PhysicalKeyb
'Pause': PhysicalKeyboardKey.pause,
'Period': PhysicalKeyboardKey.period,
'Power': PhysicalKeyboardKey.power,
'Print': PhysicalKeyboardKey.print,
'PrintScreen': PhysicalKeyboardKey.printScreen,
'PrivacyScreenToggle': PhysicalKeyboardKey.privacyScreenToggle,
'ProgramGuide': PhysicalKeyboardKey.programGuide,
'Props': PhysicalKeyboardKey.props,
'Quote': PhysicalKeyboardKey.quote,
'Redo': PhysicalKeyboardKey.redo,
'Resume': PhysicalKeyboardKey.resume,
'Save': PhysicalKeyboardKey.save,
'ScrollLock': PhysicalKeyboardKey.scrollLock,
'Select': PhysicalKeyboardKey.select,
'SelectTask': PhysicalKeyboardKey.selectTask,
......@@ -2699,20 +2668,12 @@ const Map<String, PhysicalKeyboardKey> kWebToPhysicalKey = <String, PhysicalKeyb
'Slash': PhysicalKeyboardKey.slash,
'Sleep': PhysicalKeyboardKey.sleep,
'Space': PhysicalKeyboardKey.space,
'SpeechInputToggle': PhysicalKeyboardKey.speechInputToggle,
'SpellCheck': PhysicalKeyboardKey.spellCheck,
'Super': PhysicalKeyboardKey.superKey,
'Suspend': PhysicalKeyboardKey.suspend,
'Tab': PhysicalKeyboardKey.tab,
'Turbo': PhysicalKeyboardKey.turbo,
'Undo': PhysicalKeyboardKey.undo,
'UsbErrorRollOver': PhysicalKeyboardKey.usbErrorRollOver,
'UsbErrorUndefined': PhysicalKeyboardKey.usbErrorUndefined,
'UsbPostFail': PhysicalKeyboardKey.usbPostFail,
'UsbReserved': PhysicalKeyboardKey.usbReserved,
'WakeUp': PhysicalKeyboardKey.wakeUp,
'ZoomIn': PhysicalKeyboardKey.zoomIn,
'ZoomOut': PhysicalKeyboardKey.zoomOut,
'ZoomToggle': PhysicalKeyboardKey.zoomToggle,
};
......
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
test('The Web physical key mapping do not have entries without a Chrome code.', () {
// Regression test for https://github.com/flutter/flutter/pull/106074.
// There is an entry called KBD_ILLUM_DOWN in dom_code_data.inc, but it
// has an empty "Code" column. This entry should not be present in the
// web mapping.
expect(kWebToPhysicalKey['KbdIllumDown'], isNull);
});
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment