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 { ...@@ -65,7 +65,7 @@ Future<String> getGlfwKeyCodes() async {
} }
Future<String> getGtkKeyCodes() 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); return http.read(keyCodesUri);
} }
......
...@@ -201,7 +201,6 @@ ...@@ -201,7 +201,6 @@
"NavigatePrevious": ["NAVIGATE_PREVIOUS"], "NavigatePrevious": ["NAVIGATE_PREVIOUS"],
"NewKey": ["NEW"], "NewKey": ["NEW"],
"NonConvert": ["MUHENKAN"], "NonConvert": ["MUHENKAN"],
"None": ["UNKNOWN"],
"Notification": ["NOTIFICATION"], "Notification": ["NOTIFICATION"],
"NumLock": ["NUM_LOCK"], "NumLock": ["NUM_LOCK"],
"NumberSign": ["POUND"], "NumberSign": ["POUND"],
......
...@@ -101,8 +101,6 @@ ...@@ -101,8 +101,6 @@
"IntlYen": ["yen"], "IntlYen": ["yen"],
"KanjiMode": ["Kanji"], "KanjiMode": ["Kanji"],
"Katakana": ["Katakana"], "Katakana": ["Katakana"],
"KbdIllumDown": ["KbdBrightnessDown"],
"KbdIllumUp": ["KbdBrightnessUp"],
"LaunchAudioBrowser": ["Music"], "LaunchAudioBrowser": ["Music"],
"LaunchCalendar": ["Calendar"], "LaunchCalendar": ["Calendar"],
"LaunchDocuments": ["Document"], "LaunchDocuments": ["Document"],
......
...@@ -166,10 +166,12 @@ class LogicalKeyboardKey extends KeyboardKey { ...@@ -166,10 +166,12 @@ class LogicalKeyboardKey extends KeyboardKey {
@override @override
bool operator ==(Object other) { bool operator ==(Object other) {
if (identical(this, other)) if (identical(this, other)) {
return true; return true;
if (other.runtimeType != runtimeType) }
if (other.runtimeType != runtimeType) {
return false; return false;
}
return other is LogicalKeyboardKey return other is LogicalKeyboardKey
&& other.keyId == keyId; && other.keyId == keyId;
} }
...@@ -348,10 +350,12 @@ class PhysicalKeyboardKey extends KeyboardKey { ...@@ -348,10 +350,12 @@ class PhysicalKeyboardKey extends KeyboardKey {
@override @override
bool operator ==(Object other) { bool operator ==(Object other) {
if (identical(this, other)) if (identical(this, other)) {
return true; return true;
if (other.runtimeType != runtimeType) }
if (other.runtimeType != runtimeType) {
return false; return false;
}
return other is PhysicalKeyboardKey return other is PhysicalKeyboardKey
&& other.usbHidUsage == usbHidUsage; && other.usbHidUsage == usbHidUsage;
} }
......
...@@ -305,8 +305,8 @@ class KeyboardMapsCodeGenerator extends BaseCodeGenerator { ...@@ -305,8 +305,8 @@ class KeyboardMapsCodeGenerator extends BaseCodeGenerator {
String get _webPhysicalKeyMap { String get _webPhysicalKeyMap {
final OutputLines<String> lines = OutputLines<String>('Web physical key map'); final OutputLines<String> lines = OutputLines<String>('Web physical key map');
for (final PhysicalKeyEntry entry in keyData.entries) { for (final PhysicalKeyEntry entry in keyData.entries) {
if (entry.name != null) { for (final String webCodes in entry.webCodes()) {
lines.add(entry.name, " '${entry.name}': PhysicalKeyboardKey.${entry.constantName},"); lines.add(entry.name, " '$webCodes': PhysicalKeyboardKey.${entry.constantName},");
} }
} }
return lines.sortedJoin().trimRight(); return lines.sortedJoin().trimRight();
......
...@@ -372,6 +372,9 @@ class LogicalKeyData { ...@@ -372,6 +372,9 @@ class LogicalKeyData {
glfwNameToKeyCode.forEach((String glfwName, int value) { glfwNameToKeyCode.forEach((String glfwName, int value) {
final String? name = nameToFlutterName[glfwName]; final String? name = nameToFlutterName[glfwName];
if (name == null) {
return;
}
final LogicalKeyEntry? entry = data[nameToFlutterName[glfwName]]; final LogicalKeyEntry? entry = data[nameToFlutterName[glfwName]];
if (entry == null) { if (entry == null) {
print('Invalid logical entry by name $name (from GLFW $glfwName)'); print('Invalid logical entry by name $name (from GLFW $glfwName)');
......
...@@ -259,6 +259,12 @@ class PhysicalKeyEntry { ...@@ -259,6 +259,12 @@ class PhysicalKeyEntry {
/// The Chromium event code for the key. /// The Chromium event code for the key.
final String? chromiumCode; final String? chromiumCode;
Iterable<String> webCodes() sync* {
if (chromiumCode != null) {
yield chromiumCode!;
}
}
/// Creates a JSON map from the key data. /// Creates a JSON map from the key data.
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
return removeEmptyValues(<String, dynamic>{ return removeEmptyValues(<String, dynamic>{
......
...@@ -35,7 +35,7 @@ class KeyCodesJavaGenerator extends BaseCodeGenerator { ...@@ -35,7 +35,7 @@ class KeyCodesJavaGenerator extends BaseCodeGenerator {
final OutputLines<int> lines = OutputLines<int>('Physical Key list'); final OutputLines<int> lines = OutputLines<int>('Physical Key list');
for (final PhysicalKeyEntry entry in keyData.entries) { for (final PhysicalKeyEntry entry in keyData.entries) {
lines.add(entry.usbHidCode, ''' 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(); return lines.sortedJoin().trimRight();
} }
...@@ -45,7 +45,7 @@ class KeyCodesJavaGenerator extends BaseCodeGenerator { ...@@ -45,7 +45,7 @@ class KeyCodesJavaGenerator extends BaseCodeGenerator {
final OutputLines<int> lines = OutputLines<int>('Logical Key list'); final OutputLines<int> lines = OutputLines<int>('Logical Key list');
for (final LogicalKeyEntry entry in logicalData.entries) { for (final LogicalKeyEntry entry in logicalData.entries) {
lines.add(entry.value, ''' 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(); return lines.sortedJoin().trimRight();
} }
......
...@@ -37,9 +37,9 @@ class WebCodeGenerator extends PlatformCodeGenerator { ...@@ -37,9 +37,9 @@ class WebCodeGenerator extends PlatformCodeGenerator {
String get _webPhysicalKeyCodeMap { String get _webPhysicalKeyCodeMap {
final OutputLines<String> lines = OutputLines<String>('Web physical map'); final OutputLines<String> lines = OutputLines<String>('Web physical map');
for (final PhysicalKeyEntry entry in keyData.entries) { for (final PhysicalKeyEntry entry in keyData.entries) {
if (entry.name != null) { for (final String webCode in entry.webCodes()) {
lines.add(entry.name, lines.add(webCode,
" '${entry.name}': ${toHex(entry.usbHidCode)}, // ${entry.constantName}"); " '$webCode': ${toHex(entry.usbHidCode)}, // ${entry.constantName}");
} }
} }
return lines.sortedJoin().trimRight(); return lines.sortedJoin().trimRight();
......
...@@ -2459,14 +2459,9 @@ const Map<String, PhysicalKeyboardKey> kWebToPhysicalKey = <String, PhysicalKeyb ...@@ -2459,14 +2459,9 @@ const Map<String, PhysicalKeyboardKey> kWebToPhysicalKey = <String, PhysicalKeyb
'Backquote': PhysicalKeyboardKey.backquote, 'Backquote': PhysicalKeyboardKey.backquote,
'Backslash': PhysicalKeyboardKey.backslash, 'Backslash': PhysicalKeyboardKey.backslash,
'Backspace': PhysicalKeyboardKey.backspace, 'Backspace': PhysicalKeyboardKey.backspace,
'BassBoost': PhysicalKeyboardKey.bassBoost,
'BracketLeft': PhysicalKeyboardKey.bracketLeft, 'BracketLeft': PhysicalKeyboardKey.bracketLeft,
'BracketRight': PhysicalKeyboardKey.bracketRight, 'BracketRight': PhysicalKeyboardKey.bracketRight,
'BrightnessAuto': PhysicalKeyboardKey.brightnessAuto,
'BrightnessDown': PhysicalKeyboardKey.brightnessDown, 'BrightnessDown': PhysicalKeyboardKey.brightnessDown,
'BrightnessMaximum': PhysicalKeyboardKey.brightnessMaximum,
'BrightnessMinimum': PhysicalKeyboardKey.brightnessMinimum,
'BrightnessToggle': PhysicalKeyboardKey.brightnessToggle,
'BrightnessUp': PhysicalKeyboardKey.brightnessUp, 'BrightnessUp': PhysicalKeyboardKey.brightnessUp,
'BrowserBack': PhysicalKeyboardKey.browserBack, 'BrowserBack': PhysicalKeyboardKey.browserBack,
'BrowserFavorites': PhysicalKeyboardKey.browserFavorites, 'BrowserFavorites': PhysicalKeyboardKey.browserFavorites,
...@@ -2476,10 +2471,6 @@ const Map<String, PhysicalKeyboardKey> kWebToPhysicalKey = <String, PhysicalKeyb ...@@ -2476,10 +2471,6 @@ const Map<String, PhysicalKeyboardKey> kWebToPhysicalKey = <String, PhysicalKeyb
'BrowserSearch': PhysicalKeyboardKey.browserSearch, 'BrowserSearch': PhysicalKeyboardKey.browserSearch,
'BrowserStop': PhysicalKeyboardKey.browserStop, 'BrowserStop': PhysicalKeyboardKey.browserStop,
'CapsLock': PhysicalKeyboardKey.capsLock, 'CapsLock': PhysicalKeyboardKey.capsLock,
'ChannelDown': PhysicalKeyboardKey.channelDown,
'ChannelUp': PhysicalKeyboardKey.channelUp,
'Close': PhysicalKeyboardKey.close,
'ClosedCaptionToggle': PhysicalKeyboardKey.closedCaptionToggle,
'Comma': PhysicalKeyboardKey.comma, 'Comma': PhysicalKeyboardKey.comma,
'ContextMenu': PhysicalKeyboardKey.contextMenu, 'ContextMenu': PhysicalKeyboardKey.contextMenu,
'ControlLeft': PhysicalKeyboardKey.controlLeft, 'ControlLeft': PhysicalKeyboardKey.controlLeft,
...@@ -2504,7 +2495,6 @@ const Map<String, PhysicalKeyboardKey> kWebToPhysicalKey = <String, PhysicalKeyb ...@@ -2504,7 +2495,6 @@ const Map<String, PhysicalKeyboardKey> kWebToPhysicalKey = <String, PhysicalKeyb
'Enter': PhysicalKeyboardKey.enter, 'Enter': PhysicalKeyboardKey.enter,
'Equal': PhysicalKeyboardKey.equal, 'Equal': PhysicalKeyboardKey.equal,
'Escape': PhysicalKeyboardKey.escape, 'Escape': PhysicalKeyboardKey.escape,
'Exit': PhysicalKeyboardKey.exit,
'F1': PhysicalKeyboardKey.f1, 'F1': PhysicalKeyboardKey.f1,
'F10': PhysicalKeyboardKey.f10, 'F10': PhysicalKeyboardKey.f10,
'F11': PhysicalKeyboardKey.f11, 'F11': PhysicalKeyboardKey.f11,
...@@ -2566,14 +2556,11 @@ const Map<String, PhysicalKeyboardKey> kWebToPhysicalKey = <String, PhysicalKeyb ...@@ -2566,14 +2556,11 @@ const Map<String, PhysicalKeyboardKey> kWebToPhysicalKey = <String, PhysicalKeyb
'Help': PhysicalKeyboardKey.help, 'Help': PhysicalKeyboardKey.help,
'Home': PhysicalKeyboardKey.home, 'Home': PhysicalKeyboardKey.home,
'Hyper': PhysicalKeyboardKey.hyper, 'Hyper': PhysicalKeyboardKey.hyper,
'Info': PhysicalKeyboardKey.info,
'Insert': PhysicalKeyboardKey.insert, 'Insert': PhysicalKeyboardKey.insert,
'IntlBackslash': PhysicalKeyboardKey.intlBackslash, 'IntlBackslash': PhysicalKeyboardKey.intlBackslash,
'IntlRo': PhysicalKeyboardKey.intlRo, 'IntlRo': PhysicalKeyboardKey.intlRo,
'IntlYen': PhysicalKeyboardKey.intlYen, 'IntlYen': PhysicalKeyboardKey.intlYen,
'KanaMode': PhysicalKeyboardKey.kanaMode, 'KanaMode': PhysicalKeyboardKey.kanaMode,
'KbdIllumDown': PhysicalKeyboardKey.kbdIllumDown,
'KbdIllumUp': PhysicalKeyboardKey.kbdIllumUp,
'KeyA': PhysicalKeyboardKey.keyA, 'KeyA': PhysicalKeyboardKey.keyA,
'KeyB': PhysicalKeyboardKey.keyB, 'KeyB': PhysicalKeyboardKey.keyB,
'KeyC': PhysicalKeyboardKey.keyC, 'KeyC': PhysicalKeyboardKey.keyC,
...@@ -2609,25 +2596,13 @@ const Map<String, PhysicalKeyboardKey> kWebToPhysicalKey = <String, PhysicalKeyb ...@@ -2609,25 +2596,13 @@ const Map<String, PhysicalKeyboardKey> kWebToPhysicalKey = <String, PhysicalKeyb
'LaunchApp1': PhysicalKeyboardKey.launchApp1, 'LaunchApp1': PhysicalKeyboardKey.launchApp1,
'LaunchApp2': PhysicalKeyboardKey.launchApp2, 'LaunchApp2': PhysicalKeyboardKey.launchApp2,
'LaunchAssistant': PhysicalKeyboardKey.launchAssistant, 'LaunchAssistant': PhysicalKeyboardKey.launchAssistant,
'LaunchAudioBrowser': PhysicalKeyboardKey.launchAudioBrowser,
'LaunchCalendar': PhysicalKeyboardKey.launchCalendar,
'LaunchContacts': PhysicalKeyboardKey.launchContacts,
'LaunchControlPanel': PhysicalKeyboardKey.launchControlPanel, 'LaunchControlPanel': PhysicalKeyboardKey.launchControlPanel,
'LaunchDocuments': PhysicalKeyboardKey.launchDocuments,
'LaunchInternetBrowser': PhysicalKeyboardKey.launchInternetBrowser,
'LaunchKeyboardLayout': PhysicalKeyboardKey.launchKeyboardLayout,
'LaunchMail': PhysicalKeyboardKey.launchMail, 'LaunchMail': PhysicalKeyboardKey.launchMail,
'LaunchPhone': PhysicalKeyboardKey.launchPhone,
'LaunchScreenSaver': PhysicalKeyboardKey.launchScreenSaver, 'LaunchScreenSaver': PhysicalKeyboardKey.launchScreenSaver,
'LaunchSpreadsheet': PhysicalKeyboardKey.launchSpreadsheet,
'LaunchWordProcessor': PhysicalKeyboardKey.launchWordProcessor,
'LockScreen': PhysicalKeyboardKey.lockScreen,
'LogOff': PhysicalKeyboardKey.logOff,
'MailForward': PhysicalKeyboardKey.mailForward, 'MailForward': PhysicalKeyboardKey.mailForward,
'MailReply': PhysicalKeyboardKey.mailReply, 'MailReply': PhysicalKeyboardKey.mailReply,
'MailSend': PhysicalKeyboardKey.mailSend, 'MailSend': PhysicalKeyboardKey.mailSend,
'MediaFastForward': PhysicalKeyboardKey.mediaFastForward, 'MediaFastForward': PhysicalKeyboardKey.mediaFastForward,
'MediaLast': PhysicalKeyboardKey.mediaLast,
'MediaPause': PhysicalKeyboardKey.mediaPause, 'MediaPause': PhysicalKeyboardKey.mediaPause,
'MediaPlay': PhysicalKeyboardKey.mediaPlay, 'MediaPlay': PhysicalKeyboardKey.mediaPlay,
'MediaPlayPause': PhysicalKeyboardKey.mediaPlayPause, 'MediaPlayPause': PhysicalKeyboardKey.mediaPlayPause,
...@@ -2641,7 +2616,6 @@ const Map<String, PhysicalKeyboardKey> kWebToPhysicalKey = <String, PhysicalKeyb ...@@ -2641,7 +2616,6 @@ const Map<String, PhysicalKeyboardKey> kWebToPhysicalKey = <String, PhysicalKeyb
'MetaRight': PhysicalKeyboardKey.metaRight, 'MetaRight': PhysicalKeyboardKey.metaRight,
'MicrophoneMuteToggle': PhysicalKeyboardKey.microphoneMuteToggle, 'MicrophoneMuteToggle': PhysicalKeyboardKey.microphoneMuteToggle,
'Minus': PhysicalKeyboardKey.minus, 'Minus': PhysicalKeyboardKey.minus,
'New': PhysicalKeyboardKey.newKey,
'NonConvert': PhysicalKeyboardKey.nonConvert, 'NonConvert': PhysicalKeyboardKey.nonConvert,
'NumLock': PhysicalKeyboardKey.numLock, 'NumLock': PhysicalKeyboardKey.numLock,
'Numpad0': PhysicalKeyboardKey.numpad0, 'Numpad0': PhysicalKeyboardKey.numpad0,
...@@ -2671,7 +2645,6 @@ const Map<String, PhysicalKeyboardKey> kWebToPhysicalKey = <String, PhysicalKeyb ...@@ -2671,7 +2645,6 @@ const Map<String, PhysicalKeyboardKey> kWebToPhysicalKey = <String, PhysicalKeyb
'NumpadMultiply': PhysicalKeyboardKey.numpadMultiply, 'NumpadMultiply': PhysicalKeyboardKey.numpadMultiply,
'NumpadParenLeft': PhysicalKeyboardKey.numpadParenLeft, 'NumpadParenLeft': PhysicalKeyboardKey.numpadParenLeft,
'NumpadParenRight': PhysicalKeyboardKey.numpadParenRight, 'NumpadParenRight': PhysicalKeyboardKey.numpadParenRight,
'NumpadSignChange': PhysicalKeyboardKey.numpadSignChange,
'NumpadSubtract': PhysicalKeyboardKey.numpadSubtract, 'NumpadSubtract': PhysicalKeyboardKey.numpadSubtract,
'Open': PhysicalKeyboardKey.open, 'Open': PhysicalKeyboardKey.open,
'PageDown': PhysicalKeyboardKey.pageDown, 'PageDown': PhysicalKeyboardKey.pageDown,
...@@ -2680,15 +2653,11 @@ const Map<String, PhysicalKeyboardKey> kWebToPhysicalKey = <String, PhysicalKeyb ...@@ -2680,15 +2653,11 @@ const Map<String, PhysicalKeyboardKey> kWebToPhysicalKey = <String, PhysicalKeyb
'Pause': PhysicalKeyboardKey.pause, 'Pause': PhysicalKeyboardKey.pause,
'Period': PhysicalKeyboardKey.period, 'Period': PhysicalKeyboardKey.period,
'Power': PhysicalKeyboardKey.power, 'Power': PhysicalKeyboardKey.power,
'Print': PhysicalKeyboardKey.print,
'PrintScreen': PhysicalKeyboardKey.printScreen, 'PrintScreen': PhysicalKeyboardKey.printScreen,
'PrivacyScreenToggle': PhysicalKeyboardKey.privacyScreenToggle, 'PrivacyScreenToggle': PhysicalKeyboardKey.privacyScreenToggle,
'ProgramGuide': PhysicalKeyboardKey.programGuide,
'Props': PhysicalKeyboardKey.props, 'Props': PhysicalKeyboardKey.props,
'Quote': PhysicalKeyboardKey.quote, 'Quote': PhysicalKeyboardKey.quote,
'Redo': PhysicalKeyboardKey.redo,
'Resume': PhysicalKeyboardKey.resume, 'Resume': PhysicalKeyboardKey.resume,
'Save': PhysicalKeyboardKey.save,
'ScrollLock': PhysicalKeyboardKey.scrollLock, 'ScrollLock': PhysicalKeyboardKey.scrollLock,
'Select': PhysicalKeyboardKey.select, 'Select': PhysicalKeyboardKey.select,
'SelectTask': PhysicalKeyboardKey.selectTask, 'SelectTask': PhysicalKeyboardKey.selectTask,
...@@ -2699,20 +2668,12 @@ const Map<String, PhysicalKeyboardKey> kWebToPhysicalKey = <String, PhysicalKeyb ...@@ -2699,20 +2668,12 @@ const Map<String, PhysicalKeyboardKey> kWebToPhysicalKey = <String, PhysicalKeyb
'Slash': PhysicalKeyboardKey.slash, 'Slash': PhysicalKeyboardKey.slash,
'Sleep': PhysicalKeyboardKey.sleep, 'Sleep': PhysicalKeyboardKey.sleep,
'Space': PhysicalKeyboardKey.space, 'Space': PhysicalKeyboardKey.space,
'SpeechInputToggle': PhysicalKeyboardKey.speechInputToggle,
'SpellCheck': PhysicalKeyboardKey.spellCheck,
'Super': PhysicalKeyboardKey.superKey, 'Super': PhysicalKeyboardKey.superKey,
'Suspend': PhysicalKeyboardKey.suspend, 'Suspend': PhysicalKeyboardKey.suspend,
'Tab': PhysicalKeyboardKey.tab, 'Tab': PhysicalKeyboardKey.tab,
'Turbo': PhysicalKeyboardKey.turbo, 'Turbo': PhysicalKeyboardKey.turbo,
'Undo': PhysicalKeyboardKey.undo, 'Undo': PhysicalKeyboardKey.undo,
'UsbErrorRollOver': PhysicalKeyboardKey.usbErrorRollOver,
'UsbErrorUndefined': PhysicalKeyboardKey.usbErrorUndefined,
'UsbPostFail': PhysicalKeyboardKey.usbPostFail,
'UsbReserved': PhysicalKeyboardKey.usbReserved,
'WakeUp': PhysicalKeyboardKey.wakeUp, 'WakeUp': PhysicalKeyboardKey.wakeUp,
'ZoomIn': PhysicalKeyboardKey.zoomIn,
'ZoomOut': PhysicalKeyboardKey.zoomOut,
'ZoomToggle': PhysicalKeyboardKey.zoomToggle, '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