Skip to content

Commit

Permalink
[gen_keycodes] Remove invalid Web code maps (#106074)
Browse files Browse the repository at this point in the history
* Impl

* Test
  • Loading branch information
dkwingsmt committed Jun 16, 2022
1 parent 96813e9 commit ddeb0b9
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 54 deletions.
2 changes: 1 addition & 1 deletion dev/tools/gen_keycodes/bin/gen_keycodes.dart
Expand Up @@ -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);
}

Expand Down
1 change: 0 additions & 1 deletion dev/tools/gen_keycodes/data/android_key_name_to_name.json
Expand Up @@ -201,7 +201,6 @@
"NavigatePrevious": ["NAVIGATE_PREVIOUS"],
"NewKey": ["NEW"],
"NonConvert": ["MUHENKAN"],
"None": ["UNKNOWN"],
"Notification": ["NOTIFICATION"],
"NumLock": ["NUM_LOCK"],
"NumberSign": ["POUND"],
Expand Down
2 changes: 0 additions & 2 deletions dev/tools/gen_keycodes/data/gtk_logical_name_mapping.json
Expand Up @@ -101,8 +101,6 @@
"IntlYen": ["yen"],
"KanjiMode": ["Kanji"],
"Katakana": ["Katakana"],
"KbdIllumDown": ["KbdBrightnessDown"],
"KbdIllumUp": ["KbdBrightnessUp"],
"LaunchAudioBrowser": ["Music"],
"LaunchCalendar": ["Calendar"],
"LaunchDocuments": ["Document"],
Expand Down
12 changes: 8 additions & 4 deletions dev/tools/gen_keycodes/data/keyboard_key.tmpl
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions dev/tools/gen_keycodes/lib/keyboard_maps_code_gen.dart
Expand Up @@ -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();
Expand Down
3 changes: 3 additions & 0 deletions dev/tools/gen_keycodes/lib/logical_key_data.dart
Expand Up @@ -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)');
Expand Down
6 changes: 6 additions & 0 deletions dev/tools/gen_keycodes/lib/physical_key_data.dart
Expand Up @@ -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>{
Expand Down
4 changes: 2 additions & 2 deletions dev/tools/gen_keycodes/lib/testing_key_codes_java_gen.dart
Expand Up @@ -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();
}
Expand All @@ -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();
}
Expand Down
6 changes: 3 additions & 3 deletions dev/tools/gen_keycodes/lib/web_code_gen.dart
Expand Up @@ -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();
Expand Down
39 changes: 0 additions & 39 deletions packages/flutter/lib/src/services/keyboard_maps.dart
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
};

Expand Down
16 changes: 16 additions & 0 deletions packages/flutter/test/services/keyboard_maps_test.dart
@@ -0,0 +1,16 @@
// 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);
});
}

0 comments on commit ddeb0b9

Please sign in to comment.