From c177db172d4cbb7246e9122496b9a76ca695b8e5 Mon Sep 17 00:00:00 2001 From: Tong Mu Date: Wed, 29 Jul 2020 13:20:07 -0700 Subject: [PATCH] Refactor gen_keycode: Split generators (#61916) * Split gen_keycode to make maintenance easier. --- dev/tools/gen_keycodes/bin/gen_keycodes.dart | 61 ++- dev/tools/gen_keycodes/data/keyboard_key.tmpl | 4 + .../data/keyboard_map_gtk_cc.tmpl | 24 - .../gen_keycodes/data/keyboard_maps.tmpl | 2 + .../gen_keycodes/lib/android_code_gen.dart | 67 +++ dev/tools/gen_keycodes/lib/base_code_gen.dart | 71 +++ dev/tools/gen_keycodes/lib/dart_code_gen.dart | 481 ------------------ .../gen_keycodes/lib/fuchsia_code_gen.dart | 49 ++ dev/tools/gen_keycodes/lib/glfw_code_gen.dart | 53 ++ dev/tools/gen_keycodes/lib/gtk_code_gen.dart | 37 ++ .../lib/keyboard_keys_code_gen.dart | 152 ++++++ ...e_gen.dart => keyboard_maps_code_gen.dart} | 156 +++--- .../gen_keycodes/lib/macos_code_gen.dart | 63 +++ dev/tools/gen_keycodes/lib/web_code_gen.dart | 64 +++ .../gen_keycodes/lib/windows_code_gen.dart | 63 +++ .../lib/src/services/keyboard_key.dart | 26 + .../lib/src/services/keyboard_maps.dart | 10 + 17 files changed, 771 insertions(+), 612 deletions(-) delete mode 100644 dev/tools/gen_keycodes/data/keyboard_map_gtk_cc.tmpl create mode 100644 dev/tools/gen_keycodes/lib/android_code_gen.dart create mode 100644 dev/tools/gen_keycodes/lib/base_code_gen.dart delete mode 100644 dev/tools/gen_keycodes/lib/dart_code_gen.dart create mode 100644 dev/tools/gen_keycodes/lib/fuchsia_code_gen.dart create mode 100644 dev/tools/gen_keycodes/lib/glfw_code_gen.dart create mode 100644 dev/tools/gen_keycodes/lib/gtk_code_gen.dart create mode 100644 dev/tools/gen_keycodes/lib/keyboard_keys_code_gen.dart rename dev/tools/gen_keycodes/lib/{cc_code_gen.dart => keyboard_maps_code_gen.dart} (57%) create mode 100644 dev/tools/gen_keycodes/lib/macos_code_gen.dart create mode 100644 dev/tools/gen_keycodes/lib/web_code_gen.dart create mode 100644 dev/tools/gen_keycodes/lib/windows_code_gen.dart diff --git a/dev/tools/gen_keycodes/bin/gen_keycodes.dart b/dev/tools/gen_keycodes/bin/gen_keycodes.dart index 25164c15ec..83a41978a3 100644 --- a/dev/tools/gen_keycodes/bin/gen_keycodes.dart +++ b/dev/tools/gen_keycodes/bin/gen_keycodes.dart @@ -7,11 +7,19 @@ import 'dart:convert'; import 'dart:io' hide Platform; import 'package:args/args.dart'; -import 'package:gen_keycodes/cc_code_gen.dart'; import 'package:http/http.dart' as http; import 'package:path/path.dart' as path; -import 'package:gen_keycodes/dart_code_gen.dart'; +import 'package:gen_keycodes/android_code_gen.dart'; +import 'package:gen_keycodes/base_code_gen.dart'; +import 'package:gen_keycodes/macos_code_gen.dart'; +import 'package:gen_keycodes/fuchsia_code_gen.dart'; +import 'package:gen_keycodes/glfw_code_gen.dart'; +import 'package:gen_keycodes/gtk_code_gen.dart'; +import 'package:gen_keycodes/windows_code_gen.dart'; +import 'package:gen_keycodes/web_code_gen.dart'; +import 'package:gen_keycodes/keyboard_keys_code_gen.dart'; +import 'package:gen_keycodes/keyboard_maps_code_gen.dart'; import 'package:gen_keycodes/key_data.dart'; import 'package:gen_keycodes/utils.dart'; @@ -235,30 +243,49 @@ Future main(List rawArguments) async { if (!codeFile.existsSync()) { codeFile.createSync(recursive: true); } + print('Writing ${'key codes'.padRight(15)}${codeFile.absolute}'); + await codeFile.writeAsString(KeyboardKeysCodeGenerator(data).generate()); final File mapsFile = File(parsedArguments['maps'] as String); if (!mapsFile.existsSync()) { mapsFile.createSync(recursive: true); } + print('Writing ${'key maps'.padRight(15)}${mapsFile.absolute}'); + await mapsFile.writeAsString(KeyboardMapsCodeGenerator(data).generate()); - final DartCodeGenerator generator = DartCodeGenerator(data); - await codeFile.writeAsString(generator.generateKeyboardKeys()); - await mapsFile.writeAsString(generator.generateKeyboardMaps()); + for (final String platform in ['android', 'darwin', 'glfw', 'fuchsia', 'linux', 'windows', 'web']) { + PlatformCodeGenerator codeGenerator; + switch (platform) { + case 'glfw': + codeGenerator = GlfwCodeGenerator(data); + break; + case 'fuchsia': + codeGenerator = FuchsiaCodeGenerator(data); + break; + case 'android': + codeGenerator = AndroidCodeGenerator(data); + break; + case 'darwin': + codeGenerator = MacOsCodeGenerator(data); + break; + case 'windows': + codeGenerator = WindowsCodeGenerator(data); + break; + case 'linux': + codeGenerator = GtkCodeGenerator(data); + break; + case 'web': + codeGenerator = WebCodeGenerator(data); + break; + default: + assert(false); + } - final CcCodeGenerator ccCodeGenerator = CcCodeGenerator(data); - for (final String platform in ['android', 'darwin', 'glfw', 'gtk', 'fuchsia', 'linux', 'windows']) { - final File platformFile = File(path.join(flutterRoot.path, '..', path.join('engine', 'src', 'flutter', 'shell', 'platform', platform, 'keycodes', 'keyboard_map_$platform.h'))); + final File platformFile = File(codeGenerator.outputPath(platform)); if (!platformFile.existsSync()) { platformFile.createSync(recursive: true); } - print('Writing map ${platformFile.absolute}'); - await platformFile.writeAsString(ccCodeGenerator.generateKeyboardMaps(platform)); + print('Writing ${'$platform map'.padRight(15)}${platformFile.absolute}'); + await platformFile.writeAsString(codeGenerator.generate()); } - - final File webPlatformFile = File(path.join(flutterRoot.path, '..', 'engine', 'src', 'flutter', path.join('lib', 'web_ui', 'lib', 'src', 'engine', 'keycodes', 'keyboard_map_web.dart'))); - if (!webPlatformFile.existsSync()) { - webPlatformFile.createSync(recursive: true); - } - print('Writing map ${webPlatformFile.absolute}'); - await webPlatformFile.writeAsString(generator.generateWebKeyboardMap()); } diff --git a/dev/tools/gen_keycodes/data/keyboard_key.tmpl b/dev/tools/gen_keycodes/data/keyboard_key.tmpl index a20cc98fc9..559d3a12cb 100644 --- a/dev/tools/gen_keycodes/data/keyboard_key.tmpl +++ b/dev/tools/gen_keycodes/data/keyboard_key.tmpl @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +// @dart = 2.8 + // DO NOT EDIT -- DO NOT EDIT -- DO NOT EDIT // This file is generated by dev/tools/gen_keycodes/bin/gen_keycodes.dart and // should not be edited directly. @@ -121,6 +123,7 @@ abstract class KeyboardKey with Diagnosticable { /// to keyboard events. /// * [RawKeyboardListener], a widget used to listen to and supply handlers for /// keyboard events. +@immutable class LogicalKeyboardKey extends KeyboardKey { /// Creates a LogicalKeyboardKey object with an optional key label and debug /// name. @@ -402,6 +405,7 @@ class LogicalKeyboardKey extends KeyboardKey { /// to keyboard events. /// * [RawKeyboardListener], a widget used to listen to and supply handlers for /// keyboard events. +@immutable class PhysicalKeyboardKey extends KeyboardKey { /// Creates a PhysicalKeyboardKey object with an optional debug name. /// diff --git a/dev/tools/gen_keycodes/data/keyboard_map_gtk_cc.tmpl b/dev/tools/gen_keycodes/data/keyboard_map_gtk_cc.tmpl deleted file mode 100644 index 9645a22090..0000000000 --- a/dev/tools/gen_keycodes/data/keyboard_map_gtk_cc.tmpl +++ /dev/null @@ -1,24 +0,0 @@ -// 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. - -#include - -// DO NOT EDIT -- DO NOT EDIT -- DO NOT EDIT -// This file is generated by flutter/flutter@dev/tools/gen_keycodes/bin/gen_keycodes.dart and -// should not be edited directly. -// -// Edit the template dev/tools/gen_keycodes/data/keyboard_maps_gtk_cxx.tmpl instead. -// See dev/tools/gen_keycodes/README.md for more information. - -/// Maps GTK-specific key codes to the matching [LogicalKeyboardKey]. -const std::map g_gtk_to_logical_key = { -@@@GTK_KEY_CODE_MAP@@@ -}; - -/// A map of GTK key codes which have printable representations, but appear -/// on the number pad. Used to provide different key objects for keys like -/// KEY_EQUALS and NUMPAD_EQUALS. -const std::map g_gtk_numpad_map = { -@@@GTK_NUMPAD_MAP@@@ -}; diff --git a/dev/tools/gen_keycodes/data/keyboard_maps.tmpl b/dev/tools/gen_keycodes/data/keyboard_maps.tmpl index 498f636fb7..182ebbf297 100644 --- a/dev/tools/gen_keycodes/data/keyboard_maps.tmpl +++ b/dev/tools/gen_keycodes/data/keyboard_maps.tmpl @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +// @dart = 2.8 + // DO NOT EDIT -- DO NOT EDIT -- DO NOT EDIT // This file is generated by dev/tools/gen_keycodes/bin/gen_keycodes.dart and // should not be edited directly. diff --git a/dev/tools/gen_keycodes/lib/android_code_gen.dart b/dev/tools/gen_keycodes/lib/android_code_gen.dart new file mode 100644 index 0000000000..89de4de0f7 --- /dev/null +++ b/dev/tools/gen_keycodes/lib/android_code_gen.dart @@ -0,0 +1,67 @@ +// 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:path/path.dart' as path; + +import 'base_code_gen.dart'; +import 'key_data.dart'; +import 'utils.dart'; + + +/// Generates the key mapping of Android, based on the information in the key +/// data structure given to it. +class AndroidCodeGenerator extends PlatformCodeGenerator { + AndroidCodeGenerator(KeyData keyData) : super(keyData); + + /// This generates the map of Android key codes to logical keys. + String get _androidKeyCodeMap { + final StringBuffer androidKeyCodeMap = StringBuffer(); + for (final Key entry in keyData.data) { + if (entry.androidKeyCodes != null) { + for (final int code in entry.androidKeyCodes.cast()) { + androidKeyCodeMap.writeln(' { $code, ${toHex(entry.flutterId, digits: 10)} }, // ${entry.constantName}'); + } + } + } + return androidKeyCodeMap.toString().trimRight(); + } + + /// This generates the map of Android number pad key codes to logical keys. + String get _androidNumpadMap { + final StringBuffer androidKeyCodeMap = StringBuffer(); + for (final Key entry in numpadKeyData) { + if (entry.androidKeyCodes != null) { + for (final int code in entry.androidKeyCodes.cast()) { + androidKeyCodeMap.writeln(' { $code, ${toHex(entry.flutterId, digits: 10)} }, // ${entry.constantName}'); + } + } + } + return androidKeyCodeMap.toString().trimRight(); + } + + /// This generates the map of Android scan codes to physical keys. + String get _androidScanCodeMap { + final StringBuffer androidScanCodeMap = StringBuffer(); + for (final Key entry in keyData.data) { + if (entry.androidScanCodes != null) { + for (final int code in entry.androidScanCodes.cast()) { + androidScanCodeMap.writeln(' { $code, ${toHex(entry.usbHidCode)} }, // ${entry.constantName}'); + } + } + } + return androidScanCodeMap.toString().trimRight(); + } + + @override + String get templatePath => path.join(flutterRoot.path, 'dev', 'tools', 'gen_keycodes', 'data', 'keyboard_map_android_cc.tmpl'); + + @override + Map mappings() { + return { + 'ANDROID_SCAN_CODE_MAP': _androidScanCodeMap, + 'ANDROID_KEY_CODE_MAP': _androidKeyCodeMap, + 'ANDROID_NUMPAD_MAP': _androidNumpadMap, + }; + } +} diff --git a/dev/tools/gen_keycodes/lib/base_code_gen.dart b/dev/tools/gen_keycodes/lib/base_code_gen.dart new file mode 100644 index 0000000000..162de81a47 --- /dev/null +++ b/dev/tools/gen_keycodes/lib/base_code_gen.dart @@ -0,0 +1,71 @@ +// 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 'dart:io'; +import 'package:path/path.dart' as path; + +import 'key_data.dart'; +import 'utils.dart'; + +String _injectDictionary(String template, Map dictionary) { + String result = template; + for (final String key in dictionary.keys) { + result = result.replaceAll('@@@$key@@@', dictionary[key]); + } + return result; +} + +/// Generates a file based on the information in the key data structure given to +/// it. +/// +/// [BaseCodeGenerator] finds tokens in the template file that has the form of +/// `@@@TOKEN@@@`, and replace them by looking up the key `TOKEN` from the map +/// returned by [mappings]. +/// +/// Subclasses must implement [templatePath] and [mappings]. +abstract class BaseCodeGenerator { + /// Create a code generator while providing [keyData] to be used in [mappings]. + BaseCodeGenerator(this.keyData); + + /// Absolute path to the template file that this file is generated on. + String get templatePath; + + /// A mapping from tokens to be replaced in the template to the result string. + Map mappings(); + + /// Substitutes the various platform specific maps into the template file for + /// keyboard_maps.dart. + String generate() { + final String template = File(templatePath).readAsStringSync(); + return _injectDictionary(template, mappings()); + } + + /// The database of keys loaded from disk. + final KeyData keyData; +} + +/// A code generator which also defines platform-based behavior. +abstract class PlatformCodeGenerator extends BaseCodeGenerator { + PlatformCodeGenerator(KeyData keyData) : super(keyData); + + // Used by platform code generators. + List get numpadKeyData { + return keyData.data.where((Key entry) { + return entry.constantName.startsWith('numpad') && entry.keyLabel != null; + }).toList(); + } + + // Used by platform code generators. + List get functionKeyData { + final RegExp functionKeyRe = RegExp(r'^f[0-9]+$'); + return keyData.data.where((Key entry) { + return functionKeyRe.hasMatch(entry.constantName); + }).toList(); + } + + /// Absolute path to the output file. + /// + /// How this value will be used is based on the callee. + String outputPath(String platform) => path.join(flutterRoot.path, '..', path.join('engine', 'src', 'flutter', 'shell', 'platform', platform, 'keycodes', 'keyboard_map_$platform.h')); +} diff --git a/dev/tools/gen_keycodes/lib/dart_code_gen.dart b/dev/tools/gen_keycodes/lib/dart_code_gen.dart deleted file mode 100644 index c27ddc79d5..0000000000 --- a/dev/tools/gen_keycodes/lib/dart_code_gen.dart +++ /dev/null @@ -1,481 +0,0 @@ -// 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 'dart:io'; -import 'package:path/path.dart' as path; - -import 'package:gen_keycodes/key_data.dart'; -import 'package:gen_keycodes/utils.dart'; - -/// Generates the keyboard_keys.dart and keyboard_maps.dart files, based on the -/// information in the key data structure given to it. -class DartCodeGenerator { - DartCodeGenerator(this.keyData); - - /// Given an [input] string, wraps the text at 80 characters and prepends each - /// line with the [prefix] string. Use for generated comments. - String wrapString(String input, {String prefix = ' /// '}) { - final int wrapWidth = 80 - prefix.length; - final StringBuffer result = StringBuffer(); - final List words = input.split(RegExp(r'\s+')); - String currentLine = words.removeAt(0); - for (final String word in words) { - if ((currentLine.length + word.length) < wrapWidth) { - currentLine += ' $word'; - } else { - result.writeln('$prefix$currentLine'); - currentLine = word; - } - } - if (currentLine.isNotEmpty) { - result.writeln('$prefix$currentLine'); - } - return result.toString(); - } - - /// Gets the generated definitions of PhysicalKeyboardKeys. - String get physicalDefinitions { - final StringBuffer definitions = StringBuffer(); - for (final Key entry in keyData.data) { - final String firstComment = wrapString('Represents the location of the ' - '"${entry.commentName}" key on a generalized keyboard.'); - final String otherComments = wrapString('See the function ' - '[RawKeyEvent.physicalKey] for more information.'); - definitions.write(''' - -$firstComment /// -$otherComments static const PhysicalKeyboardKey ${entry.constantName} = PhysicalKeyboardKey(${toHex(entry.usbHidCode, digits: 8)}, debugName: kReleaseMode ? null : '${entry.commentName}'); -'''); - } - return definitions.toString(); - } - - /// Gets the generated definitions of LogicalKeyboardKeys. - String get logicalDefinitions { - String escapeLabel(String label) => label.contains("'") ? 'r"$label"' : "r'$label'"; - final StringBuffer definitions = StringBuffer(); - void printKey(int flutterId, String keyLabel, String constantName, String commentName, {String otherComments}) { - final String firstComment = wrapString('Represents the logical "$commentName" key on the keyboard.'); - otherComments ??= wrapString('See the function [RawKeyEvent.logicalKey] for more information.'); - if (keyLabel == null) { - definitions.write(''' - -$firstComment /// -$otherComments static const LogicalKeyboardKey $constantName = LogicalKeyboardKey(${toHex(flutterId, digits: 11)}, debugName: kReleaseMode ? null : '$commentName'); -'''); - } else { - definitions.write(''' - -$firstComment /// -$otherComments static const LogicalKeyboardKey $constantName = LogicalKeyboardKey(${toHex(flutterId, digits: 11)}, keyLabel: ${escapeLabel(keyLabel)}, debugName: kReleaseMode ? null : '$commentName'); -'''); - } - } - - for (final Key entry in keyData.data) { - printKey( - entry.flutterId, - entry.keyLabel, - entry.constantName, - entry.commentName, - ); - } - for (final String name in Key.synonyms.keys) { - // Use the first item in the synonyms as a template for the ID to use. - // It won't end up being the same value because it'll be in the pseudo-key - // plane. - final Key entry = keyData.data.firstWhere((Key item) => item.name == Key.synonyms[name][0]); - final Set unionNames = Key.synonyms[name].map((dynamic name) { - return upperCamelToLowerCamel(name as String); - }).toSet(); - printKey(Key.synonymPlane | entry.flutterId, entry.keyLabel, name, Key.getCommentName(name), - otherComments: wrapString('This key represents the union of the keys ' - '$unionNames when comparing keys. This key will never be generated ' - 'directly, its main use is in defining key maps.')); - } - return definitions.toString(); - } - - String get logicalSynonyms { - final StringBuffer synonyms = StringBuffer(); - for (final String name in Key.synonyms.keys) { - for (final String synonym in Key.synonyms[name].cast()) { - final String keyName = upperCamelToLowerCamel(synonym); - synonyms.writeln(' $keyName: $name,'); - } - } - return synonyms.toString(); - } - - List get numpadKeyData { - return keyData.data.where((Key entry) { - return entry.constantName.startsWith('numpad') && entry.keyLabel != null; - }).toList(); - } - - List get functionKeyData { - final RegExp functionKeyRe = RegExp(r'^f[0-9]+$'); - return keyData.data.where((Key entry) { - return functionKeyRe.hasMatch(entry.constantName); - }).toList(); - } - - /// This generates the map of USB HID codes to physical keys. - String get predefinedHidCodeMap { - final StringBuffer scanCodeMap = StringBuffer(); - for (final Key entry in keyData.data) { - scanCodeMap.writeln(' ${toHex(entry.usbHidCode)}: ${entry.constantName},'); - } - return scanCodeMap.toString().trimRight(); - } - - /// This generates the map of Flutter key codes to logical keys. - String get predefinedKeyCodeMap { - final StringBuffer keyCodeMap = StringBuffer(); - for (final Key entry in keyData.data) { - keyCodeMap.writeln(' ${toHex(entry.flutterId, digits: 10)}: ${entry.constantName},'); - } - for (final String entry in Key.synonyms.keys) { - // Use the first item in the synonyms as a template for the ID to use. - // It won't end up being the same value because it'll be in the pseudo-key - // plane. - final Key primaryKey = keyData.data.firstWhere((Key item) { - return item.name == Key.synonyms[entry][0]; - }, orElse: () => null); - assert(primaryKey != null); - keyCodeMap.writeln(' ${toHex(Key.synonymPlane | primaryKey.flutterId, digits: 10)}: $entry,'); - } - return keyCodeMap.toString().trimRight(); - } - - /// This generates the map of GLFW number pad key codes to logical keys. - String get glfwNumpadMap { - final StringBuffer glfwNumpadMap = StringBuffer(); - for (final Key entry in numpadKeyData) { - if (entry.glfwKeyCodes != null) { - for (final int code in entry.glfwKeyCodes.cast()) { - glfwNumpadMap.writeln(' $code: LogicalKeyboardKey.${entry.constantName},'); - } - } - } - return glfwNumpadMap.toString().trimRight(); - } - - /// This generates the map of GLFW key codes to logical keys. - String get glfwKeyCodeMap { - final StringBuffer glfwKeyCodeMap = StringBuffer(); - for (final Key entry in keyData.data) { - if (entry.glfwKeyCodes != null) { - for (final int code in entry.glfwKeyCodes.cast()) { - glfwKeyCodeMap.writeln(' $code: LogicalKeyboardKey.${entry.constantName},'); - } - } - } - return glfwKeyCodeMap.toString().trimRight(); - } - - /// This generates the map of GTK number pad key codes to logical keys. - String get gtkNumpadMap { - final StringBuffer gtkNumpadMap = StringBuffer(); - for (final Key entry in numpadKeyData) { - if (entry.gtkKeyCodes != null) { - for (final int code in entry.gtkKeyCodes.cast()) { - gtkNumpadMap.writeln(' $code: LogicalKeyboardKey.${entry.constantName},'); - } - } - } - return gtkNumpadMap.toString().trimRight(); - } - - /// This generates the map of GTK key codes to logical keys. - String get gtkKeyCodeMap { - final StringBuffer gtkKeyCodeMap = StringBuffer(); - for (final Key entry in keyData.data) { - if (entry.gtkKeyCodes != null) { - for (final int code in entry.gtkKeyCodes.cast()) { - gtkKeyCodeMap.writeln(' $code: LogicalKeyboardKey.${entry.constantName},'); - } - } - } - return gtkKeyCodeMap.toString().trimRight(); - } - - /// This generates the map of XKB USB HID codes to physical keys. - String get xkbScanCodeMap { - final StringBuffer xkbScanCodeMap = StringBuffer(); - for (final Key entry in keyData.data) { - if (entry.xKbScanCode != null) { - xkbScanCodeMap.writeln(' ${toHex(entry.xKbScanCode)}: PhysicalKeyboardKey.${entry.constantName},'); - } - } - return xkbScanCodeMap.toString().trimRight(); - } - - /// This generates the map of Android key codes to logical keys. - String get androidKeyCodeMap { - final StringBuffer androidKeyCodeMap = StringBuffer(); - for (final Key entry in keyData.data) { - if (entry.androidKeyCodes != null) { - for (final int code in entry.androidKeyCodes.cast()) { - androidKeyCodeMap.writeln(' $code: LogicalKeyboardKey.${entry.constantName},'); - } - } - } - return androidKeyCodeMap.toString().trimRight(); - } - - /// This generates the map of Android number pad key codes to logical keys. - String get androidNumpadMap { - final StringBuffer androidKeyCodeMap = StringBuffer(); - for (final Key entry in numpadKeyData) { - if (entry.androidKeyCodes != null) { - for (final int code in entry.androidKeyCodes.cast()) { - androidKeyCodeMap.writeln(' $code: LogicalKeyboardKey.${entry.constantName},'); - } - } - } - return androidKeyCodeMap.toString().trimRight(); - } - - /// This generates the map of Android scan codes to physical keys. - String get androidScanCodeMap { - final StringBuffer androidScanCodeMap = StringBuffer(); - for (final Key entry in keyData.data) { - if (entry.androidScanCodes != null) { - for (final int code in entry.androidScanCodes.cast()) { - androidScanCodeMap.writeln(' $code: PhysicalKeyboardKey.${entry.constantName},'); - } - } - } - return androidScanCodeMap.toString().trimRight(); - } - - /// This generates the map of Windows scan codes to physical keys. - String get windowsScanCodeMap { - final StringBuffer windowsScanCodeMap = StringBuffer(); - for (final Key entry in keyData.data) { - if (entry.windowsScanCode != null) { - windowsScanCodeMap.writeln(' ${toHex(entry.windowsScanCode)}: PhysicalKeyboardKey.${entry.constantName},'); - } - } - return windowsScanCodeMap.toString().trimRight(); - } - - /// This generates the map of Windows number pad key codes to logical keys. - String get windowsNumpadMap { - final StringBuffer windowsNumPadMap = StringBuffer(); - for (final Key entry in numpadKeyData) { - if (entry.windowsKeyCodes != null){ - for (final int code in entry.windowsKeyCodes) { - windowsNumPadMap.writeln(' $code: LogicalKeyboardKey.${entry.constantName},'); - } - } - } - return windowsNumPadMap.toString().trimRight(); - } - - /// This generates the map of Windows key codes to logical keys. - String get windowsKeyCodeMap { - final StringBuffer windowsKeyCodeMap = StringBuffer(); - for (final Key entry in keyData.data) { - if (entry.windowsKeyCodes != null) { - for (final int code in entry.windowsKeyCodes) { - windowsKeyCodeMap.writeln(' $code: LogicalKeyboardKey.${entry.constantName},'); - } - } - } - return windowsKeyCodeMap.toString().trimRight(); - } - - /// This generates the map of macOS key codes to physical keys. - String get macOsScanCodeMap { - final StringBuffer macOsScanCodeMap = StringBuffer(); - for (final Key entry in keyData.data) { - if (entry.macOsScanCode != null) { - macOsScanCodeMap.writeln(' ${toHex(entry.macOsScanCode)}: PhysicalKeyboardKey.${entry.constantName},'); - } - } - return macOsScanCodeMap.toString().trimRight(); - } - - /// This generates the map of macOS number pad key codes to logical keys. - String get macOsNumpadMap { - final StringBuffer macOsNumPadMap = StringBuffer(); - for (final Key entry in numpadKeyData) { - if (entry.macOsScanCode != null) { - macOsNumPadMap.writeln(' ${toHex(entry.macOsScanCode)}: LogicalKeyboardKey.${entry.constantName},'); - } - } - return macOsNumPadMap.toString().trimRight(); - } - - String get macOsFunctionKeyMap { - final StringBuffer macOsFunctionKeyMap = StringBuffer(); - for (final Key entry in functionKeyData) { - if (entry.macOsScanCode != null) { - macOsFunctionKeyMap.writeln(' ${toHex(entry.macOsScanCode)}: LogicalKeyboardKey.${entry.constantName},'); - } - } - return macOsFunctionKeyMap.toString().trimRight(); - } - - /// This generates the map of Fuchsia key codes to logical keys. - String get fuchsiaKeyCodeMap { - final StringBuffer fuchsiaKeyCodeMap = StringBuffer(); - for (final Key entry in keyData.data) { - if (entry.usbHidCode != null) { - fuchsiaKeyCodeMap.writeln(' ${toHex(entry.flutterId)}: LogicalKeyboardKey.${entry.constantName},'); - } - } - return fuchsiaKeyCodeMap.toString().trimRight(); - } - - /// This generates the map of Fuchsia USB HID codes to physical keys. - String get fuchsiaHidCodeMap { - final StringBuffer fuchsiaScanCodeMap = StringBuffer(); - for (final Key entry in keyData.data) { - if (entry.usbHidCode != null) { - fuchsiaScanCodeMap.writeln(' ${toHex(entry.usbHidCode)}: PhysicalKeyboardKey.${entry.constantName},'); - } - } - return fuchsiaScanCodeMap.toString().trimRight(); - } - - /// This generates the map of Web KeyboardEvent codes to logical keys. - String get webLogicalKeyMap { - final StringBuffer result = StringBuffer(); - for (final Key entry in keyData.data) { - if (entry.name != null) { - result.writeln(" '${entry.name}': LogicalKeyboardKey.${entry.constantName},"); - } - } - return result.toString().trimRight(); - } - - /// This generates the map of Web KeyboardEvent codes to physical keys. - String get webPhysicalKeyMap { - final StringBuffer result = StringBuffer(); - for (final Key entry in keyData.data) { - if (entry.name != null) { - result.writeln(" '${entry.name}': PhysicalKeyboardKey.${entry.constantName},"); - } - } - return result.toString().trimRight(); - } - - /// This generates the map of Web number pad codes to logical keys. - String get webNumpadMap { - final StringBuffer result = StringBuffer(); - for (final Key entry in numpadKeyData) { - if (entry.name != null) { - result.writeln(" '${entry.name}': LogicalKeyboardKey.${entry.constantName},"); - } - } - return result.toString().trimRight(); - } - - /// This generates the map of Web KeyboardEvent codes to logical key ids. - String get webLogicalKeyCodeMap { - final StringBuffer result = StringBuffer(); - for (final Key entry in keyData.data) { - if (entry.name != null) { - result.writeln(" '${entry.name}': ${toHex(entry.flutterId, digits: 10)},"); - } - } - return result.toString().trimRight(); - } - - /// This generates the map of Web KeyboardEvent codes to physical key USB HID codes. - String get webPhysicalKeyCodeMap { - final StringBuffer result = StringBuffer(); - for (final Key entry in keyData.data) { - if (entry.name != null) { - result.writeln(" '${entry.name}': ${toHex(entry.usbHidCode)},"); - } - } - return result.toString().trimRight(); - } - - /// This generates the map of Web number pad codes to logical key ids. - String get webNumpadCodeMap { - final StringBuffer result = StringBuffer(); - for (final Key entry in numpadKeyData) { - if (entry.name != null) { - result.writeln(" '${entry.name}': ${toHex(entry.flutterId, digits: 10)},"); - } - } - return result.toString().trimRight(); - } - - /// Substitutes the various maps and definitions into the template file for - /// keyboard_key.dart. - String generateKeyboardKeys() { - final Map mappings = { - 'PHYSICAL_KEY_MAP': predefinedHidCodeMap, - 'LOGICAL_KEY_MAP': predefinedKeyCodeMap, - 'LOGICAL_KEY_DEFINITIONS': logicalDefinitions, - 'LOGICAL_KEY_SYNONYMS': logicalSynonyms, - 'PHYSICAL_KEY_DEFINITIONS': physicalDefinitions, - }; - - final String template = File(path.join(flutterRoot.path, 'dev', 'tools', 'gen_keycodes', 'data', 'keyboard_key.tmpl')).readAsStringSync(); - return _injectDictionary(template, mappings); - } - - /// Substitutes the various platform specific maps into the template file for - /// keyboard_maps.dart. - String generateKeyboardMaps() { - // There is no macOS keycode map since macOS uses keycode to represent a physical key. - // The LogicalKeyboardKey is generated by raw_keyboard_macos.dart from the unmodified characters - // from NSEvent. - final Map mappings = { - 'ANDROID_SCAN_CODE_MAP': androidScanCodeMap, - 'ANDROID_KEY_CODE_MAP': androidKeyCodeMap, - 'ANDROID_NUMPAD_MAP': androidNumpadMap, - 'FUCHSIA_SCAN_CODE_MAP': fuchsiaHidCodeMap, - 'FUCHSIA_KEY_CODE_MAP': fuchsiaKeyCodeMap, - 'MACOS_SCAN_CODE_MAP': macOsScanCodeMap, - 'MACOS_NUMPAD_MAP': macOsNumpadMap, - 'MACOS_FUNCTION_KEY_MAP': macOsFunctionKeyMap, - 'GLFW_KEY_CODE_MAP': glfwKeyCodeMap, - 'GLFW_NUMPAD_MAP': glfwNumpadMap, - 'GTK_KEY_CODE_MAP': gtkKeyCodeMap, - 'GTK_NUMPAD_MAP': gtkNumpadMap, - 'XKB_SCAN_CODE_MAP': xkbScanCodeMap, - 'WEB_LOGICAL_KEY_MAP': webLogicalKeyMap, - 'WEB_PHYSICAL_KEY_MAP': webPhysicalKeyMap, - 'WEB_NUMPAD_MAP': webNumpadMap, - 'WINDOWS_LOGICAL_KEY_MAP': windowsKeyCodeMap, - 'WINDOWS_PHYSICAL_KEY_MAP': windowsScanCodeMap, - 'WINDOWS_NUMPAD_MAP': windowsNumpadMap, - }; - - final String template = File(path.join(flutterRoot.path, 'dev', 'tools', 'gen_keycodes', 'data', 'keyboard_maps.tmpl')).readAsStringSync(); - return _injectDictionary(template, mappings); - } - - /// Substitutes the web specific maps into the template file for - /// keyboard_map_web.dart in the engine. - String generateWebKeyboardMap() { - final Map mappings = { - 'WEB_LOGICAL_KEY_CODE_MAP': webLogicalKeyCodeMap, - 'WEB_PHYSICAL_KEY_CODE_MAP': webPhysicalKeyCodeMap, - 'WEB_NUMPAD_CODE_MAP': webNumpadCodeMap, - }; - - final String template = File(path.join(flutterRoot.path, 'dev', 'tools', 'gen_keycodes', 'data', 'keyboard_map_web.tmpl')).readAsStringSync(); - return _injectDictionary(template, mappings); - } - - /// The database of keys loaded from disk. - final KeyData keyData; - - static String _injectDictionary(String template, Map dictionary) { - String result = template; - for (final String key in dictionary.keys) { - result = result.replaceAll('@@@$key@@@', dictionary[key]); - } - return result; - } -} diff --git a/dev/tools/gen_keycodes/lib/fuchsia_code_gen.dart b/dev/tools/gen_keycodes/lib/fuchsia_code_gen.dart new file mode 100644 index 0000000000..fe4404e660 --- /dev/null +++ b/dev/tools/gen_keycodes/lib/fuchsia_code_gen.dart @@ -0,0 +1,49 @@ +// 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:path/path.dart' as path; + +import 'base_code_gen.dart'; +import 'key_data.dart'; +import 'utils.dart'; + + +/// Generates the key mapping of Fuchsia, based on the information in the key +/// data structure given to it. +class FuchsiaCodeGenerator extends PlatformCodeGenerator { + FuchsiaCodeGenerator(KeyData keyData) : super(keyData); + + /// This generates the map of Fuchsia key codes to logical keys. + String get _fuchsiaKeyCodeMap { + final StringBuffer fuchsiaKeyCodeMap = StringBuffer(); + for (final Key entry in keyData.data) { + if (entry.usbHidCode != null) { + fuchsiaKeyCodeMap.writeln(' { ${toHex(entry.flutterId)}, ${toHex(entry.flutterId, digits: 10)} }, // ${entry.constantName}'); + } + } + return fuchsiaKeyCodeMap.toString().trimRight(); + } + + /// This generates the map of Fuchsia USB HID codes to physical keys. + String get _fuchsiaHidCodeMap { + final StringBuffer fuchsiaScanCodeMap = StringBuffer(); + for (final Key entry in keyData.data) { + if (entry.usbHidCode != null) { + fuchsiaScanCodeMap.writeln(' { ${toHex(entry.usbHidCode)}, ${toHex(entry.usbHidCode)} }, // ${entry.constantName}'); + } + } + return fuchsiaScanCodeMap.toString().trimRight(); + } + + @override + String get templatePath => path.join(flutterRoot.path, 'dev', 'tools', 'gen_keycodes', 'data', 'keyboard_map_fuchsia_cc.tmpl'); + + @override + Map mappings() { + return { + 'FUCHSIA_SCAN_CODE_MAP': _fuchsiaHidCodeMap, + 'FUCHSIA_KEY_CODE_MAP': _fuchsiaKeyCodeMap, + }; + } +} diff --git a/dev/tools/gen_keycodes/lib/glfw_code_gen.dart b/dev/tools/gen_keycodes/lib/glfw_code_gen.dart new file mode 100644 index 0000000000..5667d64230 --- /dev/null +++ b/dev/tools/gen_keycodes/lib/glfw_code_gen.dart @@ -0,0 +1,53 @@ +// 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:path/path.dart' as path; + +import 'base_code_gen.dart'; +import 'key_data.dart'; +import 'utils.dart'; + + +/// Generates the key mapping of GLFW, based on the information in the key +/// data structure given to it. +class GlfwCodeGenerator extends PlatformCodeGenerator { + GlfwCodeGenerator(KeyData keyData) : super(keyData); + + /// This generates the map of GLFW number pad key codes to logical keys. + String get _glfwNumpadMap { + final StringBuffer glfwNumpadMap = StringBuffer(); + for (final Key entry in numpadKeyData) { + if (entry.glfwKeyCodes != null) { + for (final int code in entry.glfwKeyCodes.cast()) { + glfwNumpadMap.writeln(' { $code, ${toHex(entry.flutterId, digits: 10)} }, // ${entry.constantName}'); + } + } + } + return glfwNumpadMap.toString().trimRight(); + } + + /// This generates the map of GLFW key codes to logical keys. + String get _glfwKeyCodeMap { + final StringBuffer glfwKeyCodeMap = StringBuffer(); + for (final Key entry in keyData.data) { + if (entry.glfwKeyCodes != null) { + for (final int code in entry.glfwKeyCodes.cast()) { + glfwKeyCodeMap.writeln(' { $code, ${toHex(entry.flutterId, digits: 10)} }, // ${entry.constantName}'); + } + } + } + return glfwKeyCodeMap.toString().trimRight(); + } + + @override + String get templatePath => path.join(flutterRoot.path, 'dev', 'tools', 'gen_keycodes', 'data', 'keyboard_map_glfw_cc.tmpl'); + + @override + Map mappings() { + return { + 'GLFW_KEY_CODE_MAP': _glfwKeyCodeMap, + 'GLFW_NUMPAD_MAP': _glfwNumpadMap, + }; + } +} diff --git a/dev/tools/gen_keycodes/lib/gtk_code_gen.dart b/dev/tools/gen_keycodes/lib/gtk_code_gen.dart new file mode 100644 index 0000000000..1c5ede8fc8 --- /dev/null +++ b/dev/tools/gen_keycodes/lib/gtk_code_gen.dart @@ -0,0 +1,37 @@ +// 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:path/path.dart' as path; + +import 'base_code_gen.dart'; +import 'key_data.dart'; +import 'utils.dart'; + + +/// Generates the key mapping of GTK, based on the information in the key +/// data structure given to it. +class GtkCodeGenerator extends PlatformCodeGenerator { + GtkCodeGenerator(KeyData keyData) : super(keyData); + + /// This generates the map of XKB scan codes to USB HID codes. + String get xkbScanCodeMap { + final StringBuffer xkbScanCodeMap = StringBuffer(); + for (final Key entry in keyData.data) { + if (entry.xKbScanCode != null) { + xkbScanCodeMap.writeln(' { ${toHex(entry.xKbScanCode)}, ${toHex(entry.usbHidCode)} }, // ${entry.constantName}'); + } + } + return xkbScanCodeMap.toString().trimRight(); + } + + @override + String get templatePath => path.join(flutterRoot.path, 'dev', 'tools', 'gen_keycodes', 'data', 'keyboard_map_linux_cc.tmpl'); + + @override + Map mappings() { + return { + 'XKB_SCAN_CODE_MAP': xkbScanCodeMap, + }; + } +} diff --git a/dev/tools/gen_keycodes/lib/keyboard_keys_code_gen.dart b/dev/tools/gen_keycodes/lib/keyboard_keys_code_gen.dart new file mode 100644 index 0000000000..3e82d3ee2f --- /dev/null +++ b/dev/tools/gen_keycodes/lib/keyboard_keys_code_gen.dart @@ -0,0 +1,152 @@ +// 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:path/path.dart' as path; + +import 'base_code_gen.dart'; +import 'key_data.dart'; +import 'utils.dart'; + +/// Given an [input] string, wraps the text at 80 characters and prepends each +/// line with the [prefix] string. Use for generated comments. +String _wrapString(String input, {String prefix = ' /// '}) { + final int wrapWidth = 80 - prefix.length; + final StringBuffer result = StringBuffer(); + final List words = input.split(RegExp(r'\s+')); + String currentLine = words.removeAt(0); + for (final String word in words) { + if ((currentLine.length + word.length) < wrapWidth) { + currentLine += ' $word'; + } else { + result.writeln('$prefix$currentLine'); + currentLine = word; + } + } + if (currentLine.isNotEmpty) { + result.writeln('$prefix$currentLine'); + } + return result.toString(); +} + +/// Generates the keyboard_keys.dart based on the information in the key data +/// structure given to it. +class KeyboardKeysCodeGenerator extends BaseCodeGenerator { + KeyboardKeysCodeGenerator(KeyData keyData) : super(keyData); + + /// Gets the generated definitions of PhysicalKeyboardKeys. + String get _physicalDefinitions { + final StringBuffer definitions = StringBuffer(); + for (final Key entry in keyData.data) { + final String firstComment = _wrapString('Represents the location of the ' + '"${entry.commentName}" key on a generalized keyboard.'); + final String otherComments = _wrapString('See the function ' + '[RawKeyEvent.physicalKey] for more information.'); + definitions.write(''' + +$firstComment /// +$otherComments static const PhysicalKeyboardKey ${entry.constantName} = PhysicalKeyboardKey(${toHex(entry.usbHidCode, digits: 8)}, debugName: kReleaseMode ? null : '${entry.commentName}'); +'''); + } + return definitions.toString(); + } + + /// Gets the generated definitions of LogicalKeyboardKeys. + String get _logicalDefinitions { + String escapeLabel(String label) => label.contains("'") ? 'r"$label"' : "r'$label'"; + final StringBuffer definitions = StringBuffer(); + void printKey(int flutterId, String keyLabel, String constantName, String commentName, {String otherComments}) { + final String firstComment = _wrapString('Represents the logical "$commentName" key on the keyboard.'); + otherComments ??= _wrapString('See the function [RawKeyEvent.logicalKey] for more information.'); + if (keyLabel == null) { + definitions.write(''' + +$firstComment /// +$otherComments static const LogicalKeyboardKey $constantName = LogicalKeyboardKey(${toHex(flutterId, digits: 11)}, debugName: kReleaseMode ? null : '$commentName'); +'''); + } else { + definitions.write(''' + +$firstComment /// +$otherComments static const LogicalKeyboardKey $constantName = LogicalKeyboardKey(${toHex(flutterId, digits: 11)}, keyLabel: ${escapeLabel(keyLabel)}, debugName: kReleaseMode ? null : '$commentName'); +'''); + } + } + + for (final Key entry in keyData.data) { + printKey( + entry.flutterId, + entry.keyLabel, + entry.constantName, + entry.commentName, + ); + } + for (final String name in Key.synonyms.keys) { + // Use the first item in the synonyms as a template for the ID to use. + // It won't end up being the same value because it'll be in the pseudo-key + // plane. + final Key entry = keyData.data.firstWhere((Key item) => item.name == Key.synonyms[name][0]); + final Set unionNames = Key.synonyms[name].map((dynamic name) { + return upperCamelToLowerCamel(name as String); + }).toSet(); + printKey(Key.synonymPlane | entry.flutterId, entry.keyLabel, name, Key.getCommentName(name), + otherComments: _wrapString('This key represents the union of the keys ' + '$unionNames when comparing keys. This key will never be generated ' + 'directly, its main use is in defining key maps.')); + } + return definitions.toString(); + } + + String get _logicalSynonyms { + final StringBuffer synonyms = StringBuffer(); + for (final String name in Key.synonyms.keys) { + for (final String synonym in Key.synonyms[name].cast()) { + final String keyName = upperCamelToLowerCamel(synonym); + synonyms.writeln(' $keyName: $name,'); + } + } + return synonyms.toString(); + } + + /// This generates the map of USB HID codes to physical keys. + String get _predefinedHidCodeMap { + final StringBuffer scanCodeMap = StringBuffer(); + for (final Key entry in keyData.data) { + scanCodeMap.writeln(' ${toHex(entry.usbHidCode)}: ${entry.constantName},'); + } + return scanCodeMap.toString().trimRight(); + } + + /// This generates the map of Flutter key codes to logical keys. + String get _predefinedKeyCodeMap { + final StringBuffer keyCodeMap = StringBuffer(); + for (final Key entry in keyData.data) { + keyCodeMap.writeln(' ${toHex(entry.flutterId, digits: 10)}: ${entry.constantName},'); + } + for (final String entry in Key.synonyms.keys) { + // Use the first item in the synonyms as a template for the ID to use. + // It won't end up being the same value because it'll be in the pseudo-key + // plane. + final Key primaryKey = keyData.data.firstWhere((Key item) { + return item.name == Key.synonyms[entry][0]; + }, orElse: () => null); + assert(primaryKey != null); + keyCodeMap.writeln(' ${toHex(Key.synonymPlane | primaryKey.flutterId, digits: 10)}: $entry,'); + } + return keyCodeMap.toString().trimRight(); + } + + @override + String get templatePath => path.join(flutterRoot.path, 'dev', 'tools', 'gen_keycodes', 'data', 'keyboard_key.tmpl'); + + @override + Map mappings() { + return { + 'PHYSICAL_KEY_MAP': _predefinedHidCodeMap, + 'LOGICAL_KEY_MAP': _predefinedKeyCodeMap, + 'LOGICAL_KEY_DEFINITIONS': _logicalDefinitions, + 'LOGICAL_KEY_SYNONYMS': _logicalSynonyms, + 'PHYSICAL_KEY_DEFINITIONS': _physicalDefinitions, + }; + } +} diff --git a/dev/tools/gen_keycodes/lib/cc_code_gen.dart b/dev/tools/gen_keycodes/lib/keyboard_maps_code_gen.dart similarity index 57% rename from dev/tools/gen_keycodes/lib/cc_code_gen.dart rename to dev/tools/gen_keycodes/lib/keyboard_maps_code_gen.dart index 341403a999..17398ef37e 100644 --- a/dev/tools/gen_keycodes/lib/cc_code_gen.dart +++ b/dev/tools/gen_keycodes/lib/keyboard_maps_code_gen.dart @@ -2,37 +2,17 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'dart:io'; import 'package:path/path.dart' as path; -import 'package:gen_keycodes/key_data.dart'; -import 'package:gen_keycodes/utils.dart'; +import 'base_code_gen.dart'; +import 'key_data.dart'; +import 'utils.dart'; -/// Generates the keyboard_keys.dart and keyboard_maps.dart files, based on the -/// information in the key data structure given to it. -class CcCodeGenerator { - CcCodeGenerator(this.keyData); - /// Given an [input] string, wraps the text at 80 characters and prepends each - /// line with the [prefix] string. Use for generated comments. - String wrapString(String input, {String prefix = ' // '}) { - final int wrapWidth = 80 - prefix.length; - final StringBuffer result = StringBuffer(); - final List words = input.split(RegExp(r'\s+')); - String currentLine = words.removeAt(0); - for (final String word in words) { - if ((currentLine.length + word.length) < wrapWidth) { - currentLine += ' $word'; - } else { - result.writeln('$prefix$currentLine'); - currentLine = word; - } - } - if (currentLine.isNotEmpty) { - result.writeln('$prefix$currentLine'); - } - return result.toString(); - } +/// Generates the keyboard_maps.dart files, based on the information in the key +/// data structure given to it. +class KeyboardMapsCodeGenerator extends BaseCodeGenerator { + KeyboardMapsCodeGenerator(KeyData keyData) : super(keyData); List get numpadKeyData { return keyData.data.where((Key entry) { @@ -47,32 +27,13 @@ class CcCodeGenerator { }).toList(); } - /// This generates the map of Flutter key codes to logical keys. - String get predefinedKeyCodeMap { - final StringBuffer keyCodeMap = StringBuffer(); - for (final Key entry in keyData.data) { - keyCodeMap.writeln(' ${toHex(entry.flutterId, digits: 10)}: ${entry.constantName},'); - } - for (final String entry in Key.synonyms.keys) { - // Use the first item in the synonyms as a template for the ID to use. - // It won't end up being the same value because it'll be in the pseudo-key - // plane. - final Key primaryKey = keyData.data.firstWhere((Key item) { - return item.name == Key.synonyms[entry][0]; - }, orElse: () => null); - assert(primaryKey != null); - keyCodeMap.writeln(' ${toHex(Key.synonymPlane | primaryKey.flutterId, digits: 10)}: $entry,'); - } - return keyCodeMap.toString().trimRight(); - } - /// This generates the map of GLFW number pad key codes to logical keys. String get glfwNumpadMap { final StringBuffer glfwNumpadMap = StringBuffer(); for (final Key entry in numpadKeyData) { if (entry.glfwKeyCodes != null) { for (final int code in entry.glfwKeyCodes.cast()) { - glfwNumpadMap.writeln(' { $code, ${toHex(entry.flutterId, digits: 10)} }, // ${entry.constantName}'); + glfwNumpadMap.writeln(' $code: LogicalKeyboardKey.${entry.constantName},'); } } } @@ -85,19 +46,45 @@ class CcCodeGenerator { for (final Key entry in keyData.data) { if (entry.glfwKeyCodes != null) { for (final int code in entry.glfwKeyCodes.cast()) { - glfwKeyCodeMap.writeln(' { $code, ${toHex(entry.flutterId, digits: 10)} }, // ${entry.constantName}'); + glfwKeyCodeMap.writeln(' $code: LogicalKeyboardKey.${entry.constantName},'); } } } return glfwKeyCodeMap.toString().trimRight(); } - /// This generates the map of XKB scan codes to USB HID codes. + /// This generates the map of GTK number pad key codes to logical keys. + String get gtkNumpadMap { + final StringBuffer gtkNumpadMap = StringBuffer(); + for (final Key entry in numpadKeyData) { + if (entry.gtkKeyCodes != null) { + for (final int code in entry.gtkKeyCodes.cast()) { + gtkNumpadMap.writeln(' $code: LogicalKeyboardKey.${entry.constantName},'); + } + } + } + return gtkNumpadMap.toString().trimRight(); + } + + /// This generates the map of GTK key codes to logical keys. + String get gtkKeyCodeMap { + final StringBuffer gtkKeyCodeMap = StringBuffer(); + for (final Key entry in keyData.data) { + if (entry.gtkKeyCodes != null) { + for (final int code in entry.gtkKeyCodes.cast()) { + gtkKeyCodeMap.writeln(' $code: LogicalKeyboardKey.${entry.constantName},'); + } + } + } + return gtkKeyCodeMap.toString().trimRight(); + } + + /// This generates the map of XKB USB HID codes to physical keys. String get xkbScanCodeMap { final StringBuffer xkbScanCodeMap = StringBuffer(); for (final Key entry in keyData.data) { if (entry.xKbScanCode != null) { - xkbScanCodeMap.writeln(' { ${toHex(entry.xKbScanCode)}, ${toHex(entry.usbHidCode)} }, // ${entry.constantName}'); + xkbScanCodeMap.writeln(' ${toHex(entry.xKbScanCode)}: PhysicalKeyboardKey.${entry.constantName},'); } } return xkbScanCodeMap.toString().trimRight(); @@ -109,7 +96,7 @@ class CcCodeGenerator { for (final Key entry in keyData.data) { if (entry.androidKeyCodes != null) { for (final int code in entry.androidKeyCodes.cast()) { - androidKeyCodeMap.writeln(' { $code, ${toHex(entry.flutterId, digits: 10)} }, // ${entry.constantName}'); + androidKeyCodeMap.writeln(' $code: LogicalKeyboardKey.${entry.constantName},'); } } } @@ -122,7 +109,7 @@ class CcCodeGenerator { for (final Key entry in numpadKeyData) { if (entry.androidKeyCodes != null) { for (final int code in entry.androidKeyCodes.cast()) { - androidKeyCodeMap.writeln(' { $code, ${toHex(entry.flutterId, digits: 10)} }, // ${entry.constantName}'); + androidKeyCodeMap.writeln(' $code: LogicalKeyboardKey.${entry.constantName},'); } } } @@ -135,7 +122,7 @@ class CcCodeGenerator { for (final Key entry in keyData.data) { if (entry.androidScanCodes != null) { for (final int code in entry.androidScanCodes.cast()) { - androidScanCodeMap.writeln(' { $code, ${toHex(entry.usbHidCode)} }, // ${entry.constantName}'); + androidScanCodeMap.writeln(' $code: PhysicalKeyboardKey.${entry.constantName},'); } } } @@ -147,7 +134,7 @@ class CcCodeGenerator { final StringBuffer windowsScanCodeMap = StringBuffer(); for (final Key entry in keyData.data) { if (entry.windowsScanCode != null) { - windowsScanCodeMap.writeln(' { ${entry.windowsScanCode}, ${toHex(entry.usbHidCode)} }, // ${entry.constantName}'); + windowsScanCodeMap.writeln(' ${toHex(entry.windowsScanCode)}: PhysicalKeyboardKey.${entry.constantName},'); } } return windowsScanCodeMap.toString().trimRight(); @@ -157,20 +144,22 @@ class CcCodeGenerator { String get windowsNumpadMap { final StringBuffer windowsNumPadMap = StringBuffer(); for (final Key entry in numpadKeyData) { - if (entry.windowsScanCode != null) { - windowsNumPadMap.writeln(' { ${toHex(entry.windowsScanCode)}, ${toHex(entry.flutterId, digits: 10)} }, // ${entry.constantName}'); + if (entry.windowsKeyCodes != null){ + for (final int code in entry.windowsKeyCodes) { + windowsNumPadMap.writeln(' $code: LogicalKeyboardKey.${entry.constantName},'); + } } } return windowsNumPadMap.toString().trimRight(); } - /// This generates the map of Android key codes to logical keys. + /// This generates the map of Windows key codes to logical keys. String get windowsKeyCodeMap { final StringBuffer windowsKeyCodeMap = StringBuffer(); for (final Key entry in keyData.data) { if (entry.windowsKeyCodes != null) { - for (final int code in entry.windowsKeyCodes.cast()) { - windowsKeyCodeMap.writeln(' { $code, ${toHex(entry.flutterId, digits: 10)} }, // ${entry.constantName}'); + for (final int code in entry.windowsKeyCodes) { + windowsKeyCodeMap.writeln(' $code: LogicalKeyboardKey.${entry.constantName},'); } } } @@ -182,7 +171,7 @@ class CcCodeGenerator { final StringBuffer macOsScanCodeMap = StringBuffer(); for (final Key entry in keyData.data) { if (entry.macOsScanCode != null) { - macOsScanCodeMap.writeln(' { ${toHex(entry.macOsScanCode)}, ${toHex(entry.usbHidCode)} }, // ${entry.constantName}'); + macOsScanCodeMap.writeln(' ${toHex(entry.macOsScanCode)}: PhysicalKeyboardKey.${entry.constantName},'); } } return macOsScanCodeMap.toString().trimRight(); @@ -193,7 +182,7 @@ class CcCodeGenerator { final StringBuffer macOsNumPadMap = StringBuffer(); for (final Key entry in numpadKeyData) { if (entry.macOsScanCode != null) { - macOsNumPadMap.writeln(' { ${toHex(entry.macOsScanCode)}, ${toHex(entry.flutterId, digits: 10)} }, // ${entry.constantName}'); + macOsNumPadMap.writeln(' ${toHex(entry.macOsScanCode)}: LogicalKeyboardKey.${entry.constantName},'); } } return macOsNumPadMap.toString().trimRight(); @@ -203,7 +192,7 @@ class CcCodeGenerator { final StringBuffer macOsFunctionKeyMap = StringBuffer(); for (final Key entry in functionKeyData) { if (entry.macOsScanCode != null) { - macOsFunctionKeyMap.writeln(' { ${toHex(entry.macOsScanCode)}, ${toHex(entry.flutterId, digits: 10)} }, // ${entry.constantName}'); + macOsFunctionKeyMap.writeln(' ${toHex(entry.macOsScanCode)}: LogicalKeyboardKey.${entry.constantName},'); } } return macOsFunctionKeyMap.toString().trimRight(); @@ -214,7 +203,7 @@ class CcCodeGenerator { final StringBuffer fuchsiaKeyCodeMap = StringBuffer(); for (final Key entry in keyData.data) { if (entry.usbHidCode != null) { - fuchsiaKeyCodeMap.writeln(' { ${toHex(entry.flutterId)}, ${toHex(entry.flutterId, digits: 10)} }, // ${entry.constantName}'); + fuchsiaKeyCodeMap.writeln(' ${toHex(entry.flutterId)}: LogicalKeyboardKey.${entry.constantName},'); } } return fuchsiaKeyCodeMap.toString().trimRight(); @@ -225,7 +214,7 @@ class CcCodeGenerator { final StringBuffer fuchsiaScanCodeMap = StringBuffer(); for (final Key entry in keyData.data) { if (entry.usbHidCode != null) { - fuchsiaScanCodeMap.writeln(' { ${toHex(entry.usbHidCode)}, ${toHex(entry.usbHidCode)} }, // ${entry.constantName}'); + fuchsiaScanCodeMap.writeln(' ${toHex(entry.usbHidCode)}: PhysicalKeyboardKey.${entry.constantName},'); } } return fuchsiaScanCodeMap.toString().trimRight(); @@ -236,7 +225,7 @@ class CcCodeGenerator { final StringBuffer result = StringBuffer(); for (final Key entry in keyData.data) { if (entry.name != null) { - result.writeln(" '${entry.name}': ${toHex(entry.flutterId, digits: 10)}, // ${entry.constantName}"); + result.writeln(" '${entry.name}': LogicalKeyboardKey.${entry.constantName},"); } } return result.toString().trimRight(); @@ -247,7 +236,7 @@ class CcCodeGenerator { final StringBuffer result = StringBuffer(); for (final Key entry in keyData.data) { if (entry.name != null) { - result.writeln(" '${entry.name}': ${toHex(entry.usbHidCode)}, // ${entry.constantName}"); + result.writeln(" '${entry.name}': PhysicalKeyboardKey.${entry.constantName},"); } } return result.toString().trimRight(); @@ -258,19 +247,18 @@ class CcCodeGenerator { final StringBuffer result = StringBuffer(); for (final Key entry in numpadKeyData) { if (entry.name != null) { - result.writeln(" '${entry.name}': ${toHex(entry.flutterId, digits: 10)}, // ${entry.constantName}"); + result.writeln(" '${entry.name}': LogicalKeyboardKey.${entry.constantName},"); } } return result.toString().trimRight(); } - /// Substitutes the various platform specific maps into the template file for - /// keyboard_maps.dart. - String generateKeyboardMaps(String platform) { - // There is no macOS keycode map since macOS uses keycode to represent a physical key. - // The LogicalKeyboardKey is generated by raw_keyboard_macos.dart from the unmodified characters - // from NSEvent. - final Map mappings = { + @override + String get templatePath => path.join(flutterRoot.path, 'dev', 'tools', 'gen_keycodes', 'data', 'keyboard_maps.tmpl'); + + @override + Map mappings() { + return { 'ANDROID_SCAN_CODE_MAP': androidScanCodeMap, 'ANDROID_KEY_CODE_MAP': androidKeyCodeMap, 'ANDROID_NUMPAD_MAP': androidNumpadMap, @@ -281,27 +269,15 @@ class CcCodeGenerator { 'MACOS_FUNCTION_KEY_MAP': macOsFunctionKeyMap, 'GLFW_KEY_CODE_MAP': glfwKeyCodeMap, 'GLFW_NUMPAD_MAP': glfwNumpadMap, + 'GTK_KEY_CODE_MAP': gtkKeyCodeMap, + 'GTK_NUMPAD_MAP': gtkNumpadMap, 'XKB_SCAN_CODE_MAP': xkbScanCodeMap, 'WEB_LOGICAL_KEY_MAP': webLogicalKeyMap, 'WEB_PHYSICAL_KEY_MAP': webPhysicalKeyMap, 'WEB_NUMPAD_MAP': webNumpadMap, - 'WINDOWS_SCAN_CODE_MAP': windowsScanCodeMap, + 'WINDOWS_LOGICAL_KEY_MAP': windowsKeyCodeMap, + 'WINDOWS_PHYSICAL_KEY_MAP': windowsScanCodeMap, 'WINDOWS_NUMPAD_MAP': windowsNumpadMap, - 'WINDOWS_KEY_CODE_MAP': windowsKeyCodeMap, }; - - final String template = File(path.join(flutterRoot.path, 'dev', 'tools', 'gen_keycodes', 'data', 'keyboard_map_${platform}_cc.tmpl')).readAsStringSync(); - return _injectDictionary(template, mappings); - } - - /// The database of keys loaded from disk. - final KeyData keyData; - - static String _injectDictionary(String template, Map dictionary) { - String result = template; - for (final String key in dictionary.keys) { - result = result.replaceAll('@@@$key@@@', dictionary[key]); - } - return result; } } diff --git a/dev/tools/gen_keycodes/lib/macos_code_gen.dart b/dev/tools/gen_keycodes/lib/macos_code_gen.dart new file mode 100644 index 0000000000..731e93f4b0 --- /dev/null +++ b/dev/tools/gen_keycodes/lib/macos_code_gen.dart @@ -0,0 +1,63 @@ +// 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:path/path.dart' as path; + +import 'base_code_gen.dart'; +import 'key_data.dart'; +import 'utils.dart'; + + +/// Generates the key mapping of macOS, based on the information in the key +/// data structure given to it. +class MacOsCodeGenerator extends PlatformCodeGenerator { + MacOsCodeGenerator(KeyData keyData) : super(keyData); + + /// This generates the map of macOS key codes to physical keys. + String get _macOsScanCodeMap { + final StringBuffer macOsScanCodeMap = StringBuffer(); + for (final Key entry in keyData.data) { + if (entry.macOsScanCode != null) { + macOsScanCodeMap.writeln(' { ${toHex(entry.macOsScanCode)}, ${toHex(entry.usbHidCode)} }, // ${entry.constantName}'); + } + } + return macOsScanCodeMap.toString().trimRight(); + } + + /// This generates the map of macOS number pad key codes to logical keys. + String get _macOsNumpadMap { + final StringBuffer macOsNumPadMap = StringBuffer(); + for (final Key entry in numpadKeyData) { + if (entry.macOsScanCode != null) { + macOsNumPadMap.writeln(' { ${toHex(entry.macOsScanCode)}, ${toHex(entry.flutterId, digits: 10)} }, // ${entry.constantName}'); + } + } + return macOsNumPadMap.toString().trimRight(); + } + + String get _macOsFunctionKeyMap { + final StringBuffer macOsFunctionKeyMap = StringBuffer(); + for (final Key entry in functionKeyData) { + if (entry.macOsScanCode != null) { + macOsFunctionKeyMap.writeln(' { ${toHex(entry.macOsScanCode)}, ${toHex(entry.flutterId, digits: 10)} }, // ${entry.constantName}'); + } + } + return macOsFunctionKeyMap.toString().trimRight(); + } + + @override + String get templatePath => path.join(flutterRoot.path, 'dev', 'tools', 'gen_keycodes', 'data', 'keyboard_map_darwin_cc.tmpl'); + + @override + Map mappings() { + // There is no macOS keycode map since macOS uses keycode to represent a physical key. + // The LogicalKeyboardKey is generated by raw_keyboard_macos.dart from the unmodified characters + // from NSEvent. + return { + 'MACOS_SCAN_CODE_MAP': _macOsScanCodeMap, + 'MACOS_NUMPAD_MAP': _macOsNumpadMap, + 'MACOS_FUNCTION_KEY_MAP': _macOsFunctionKeyMap, + }; + } +} diff --git a/dev/tools/gen_keycodes/lib/web_code_gen.dart b/dev/tools/gen_keycodes/lib/web_code_gen.dart new file mode 100644 index 0000000000..662af7a34d --- /dev/null +++ b/dev/tools/gen_keycodes/lib/web_code_gen.dart @@ -0,0 +1,64 @@ +// 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:path/path.dart' as path; + +import 'base_code_gen.dart'; +import 'key_data.dart'; +import 'utils.dart'; + + +/// Generates the key mapping of Web, based on the information in the key +/// data structure given to it. +class WebCodeGenerator extends PlatformCodeGenerator { + WebCodeGenerator(KeyData keyData) : super(keyData); + + /// This generates the map of Web KeyboardEvent codes to logical key ids. + String get _webLogicalKeyCodeMap { + final StringBuffer result = StringBuffer(); + for (final Key entry in keyData.data) { + if (entry.name != null) { + result.writeln(" '${entry.name}': ${toHex(entry.flutterId, digits: 10)},"); + } + } + return result.toString().trimRight(); + } + + /// This generates the map of Web KeyboardEvent codes to physical key USB HID codes. + String get _webPhysicalKeyCodeMap { + final StringBuffer result = StringBuffer(); + for (final Key entry in keyData.data) { + if (entry.name != null) { + result.writeln(" '${entry.name}': ${toHex(entry.usbHidCode)},"); + } + } + return result.toString().trimRight(); + } + + /// This generates the map of Web number pad codes to logical key ids. + String get _webNumpadCodeMap { + final StringBuffer result = StringBuffer(); + for (final Key entry in numpadKeyData) { + if (entry.name != null) { + result.writeln(" '${entry.name}': ${toHex(entry.flutterId, digits: 10)},"); + } + } + return result.toString().trimRight(); + } + + @override + String get templatePath => path.join(flutterRoot.path, 'dev', 'tools', 'gen_keycodes', 'data', 'keyboard_map_web.tmpl'); + + @override + String outputPath(String platform) => path.join(flutterRoot.path, '..', 'engine', 'src', 'flutter', path.join('lib', 'web_ui', 'lib', 'src', 'engine', 'keycodes', 'keyboard_map_web.dart')); + + @override + Map mappings() { + return { + 'WEB_LOGICAL_KEY_CODE_MAP': _webLogicalKeyCodeMap, + 'WEB_PHYSICAL_KEY_CODE_MAP': _webPhysicalKeyCodeMap, + 'WEB_NUMPAD_CODE_MAP': _webNumpadCodeMap, + }; + } +} diff --git a/dev/tools/gen_keycodes/lib/windows_code_gen.dart b/dev/tools/gen_keycodes/lib/windows_code_gen.dart new file mode 100644 index 0000000000..a79a3c4c76 --- /dev/null +++ b/dev/tools/gen_keycodes/lib/windows_code_gen.dart @@ -0,0 +1,63 @@ +// 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:path/path.dart' as path; + +import 'base_code_gen.dart'; +import 'key_data.dart'; +import 'utils.dart'; + + +/// Generates the key mapping of Windows, based on the information in the key +/// data structure given to it. +class WindowsCodeGenerator extends PlatformCodeGenerator { + WindowsCodeGenerator(KeyData keyData) : super(keyData); + + /// This generates the map of Windows scan codes to physical keys. + String get _windowsScanCodeMap { + final StringBuffer windowsScanCodeMap = StringBuffer(); + for (final Key entry in keyData.data) { + if (entry.windowsScanCode != null) { + windowsScanCodeMap.writeln(' { ${entry.windowsScanCode}, ${toHex(entry.usbHidCode)} }, // ${entry.constantName}'); + } + } + return windowsScanCodeMap.toString().trimRight(); + } + + /// This generates the map of Windows number pad key codes to logical keys. + String get _windowsNumpadMap { + final StringBuffer windowsNumPadMap = StringBuffer(); + for (final Key entry in numpadKeyData) { + if (entry.windowsScanCode != null) { + windowsNumPadMap.writeln(' { ${toHex(entry.windowsScanCode)}, ${toHex(entry.flutterId, digits: 10)} }, // ${entry.constantName}'); + } + } + return windowsNumPadMap.toString().trimRight(); + } + + /// This generates the map of Android key codes to logical keys. + String get _windowsKeyCodeMap { + final StringBuffer windowsKeyCodeMap = StringBuffer(); + for (final Key entry in keyData.data) { + if (entry.windowsKeyCodes != null) { + for (final int code in entry.windowsKeyCodes.cast()) { + windowsKeyCodeMap.writeln(' { $code, ${toHex(entry.flutterId, digits: 10)} }, // ${entry.constantName}'); + } + } + } + return windowsKeyCodeMap.toString().trimRight(); + } + + @override + String get templatePath => path.join(flutterRoot.path, 'dev', 'tools', 'gen_keycodes', 'data', 'keyboard_map_windows_cc.tmpl'); + + @override + Map mappings() { + return { + 'WINDOWS_SCAN_CODE_MAP': _windowsScanCodeMap, + 'WINDOWS_NUMPAD_MAP': _windowsNumpadMap, + 'WINDOWS_KEY_CODE_MAP': _windowsKeyCodeMap, + }; + } +} diff --git a/packages/flutter/lib/src/services/keyboard_key.dart b/packages/flutter/lib/src/services/keyboard_key.dart index b3deb38bc9..860198beec 100644 --- a/packages/flutter/lib/src/services/keyboard_key.dart +++ b/packages/flutter/lib/src/services/keyboard_key.dart @@ -1193,6 +1193,16 @@ class LogicalKeyboardKey extends KeyboardKey { /// See the function [RawKeyEvent.logicalKey] for more information. static const LogicalKeyboardKey brightnessAuto = LogicalKeyboardKey(0x001000c0075, debugName: kReleaseMode ? null : 'Brightness Auto'); + /// Represents the logical "Kbd Illum Up" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey kbdIllumUp = LogicalKeyboardKey(0x001000c0079, debugName: kReleaseMode ? null : 'Kbd Illum Up'); + + /// Represents the logical "Kbd Illum Down" key on the keyboard. + /// + /// See the function [RawKeyEvent.logicalKey] for more information. + static const LogicalKeyboardKey kbdIllumDown = LogicalKeyboardKey(0x001000c007a, debugName: kReleaseMode ? null : 'Kbd Illum Down'); + /// Represents the logical "Media Last" key on the keyboard. /// /// See the function [RawKeyEvent.logicalKey] for more information. @@ -1847,6 +1857,8 @@ class LogicalKeyboardKey extends KeyboardKey { 0x01000c0073: brightnessMinimum, 0x01000c0074: brightnessMaximum, 0x01000c0075: brightnessAuto, + 0x01000c0079: kbdIllumUp, + 0x01000c007a: kbdIllumDown, 0x01000c0083: mediaLast, 0x01000c008c: launchPhone, 0x01000c008d: programGuide, @@ -3038,6 +3050,18 @@ class PhysicalKeyboardKey extends KeyboardKey { /// See the function [RawKeyEvent.physicalKey] for more information. static const PhysicalKeyboardKey brightnessAuto = PhysicalKeyboardKey(0x000c0075, debugName: kReleaseMode ? null : 'Brightness Auto'); + /// Represents the location of the "Kbd Illum Up" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey kbdIllumUp = PhysicalKeyboardKey(0x000c0079, debugName: kReleaseMode ? null : 'Kbd Illum Up'); + + /// Represents the location of the "Kbd Illum Down" key on a generalized + /// keyboard. + /// + /// See the function [RawKeyEvent.physicalKey] for more information. + static const PhysicalKeyboardKey kbdIllumDown = PhysicalKeyboardKey(0x000c007a, debugName: kReleaseMode ? null : 'Kbd Illum Down'); + /// Represents the location of the "Media Last" key on a generalized keyboard. /// /// See the function [RawKeyEvent.physicalKey] for more information. @@ -3735,6 +3759,8 @@ class PhysicalKeyboardKey extends KeyboardKey { 0x000c0073: brightnessMinimum, 0x000c0074: brightnessMaximum, 0x000c0075: brightnessAuto, + 0x000c0079: kbdIllumUp, + 0x000c007a: kbdIllumDown, 0x000c0083: mediaLast, 0x000c008c: launchPhone, 0x000c008d: programGuide, diff --git a/packages/flutter/lib/src/services/keyboard_maps.dart b/packages/flutter/lib/src/services/keyboard_maps.dart index 8eaaf17a63..a1da1ba392 100644 --- a/packages/flutter/lib/src/services/keyboard_maps.dart +++ b/packages/flutter/lib/src/services/keyboard_maps.dart @@ -636,6 +636,8 @@ const Map kFuchsiaToLogicalKey = kFuchsiaToPhysicalKey = kGtkToLogicalKey = { 57: LogicalKeyboardKey.digit9, 48: LogicalKeyboardKey.digit0, 65293: LogicalKeyboardKey.enter, + 65076: LogicalKeyboardKey.enter, 65307: LogicalKeyboardKey.escape, 65288: LogicalKeyboardKey.backspace, 65289: LogicalKeyboardKey.tab, 65417: LogicalKeyboardKey.tab, + 65056: LogicalKeyboardKey.tab, 32: LogicalKeyboardKey.space, 65408: LogicalKeyboardKey.space, 45: LogicalKeyboardKey.minus, @@ -1470,6 +1476,8 @@ const Map kGtkToLogicalKey = { 65512: LogicalKeyboardKey.metaRight, 269025026: LogicalKeyboardKey.brightnessUp, 269025027: LogicalKeyboardKey.brightnessDown, + 269025029: LogicalKeyboardKey.kbdIllumUp, + 269025030: LogicalKeyboardKey.kbdIllumDown, 269025134: LogicalKeyboardKey.launchPhone, 269025044: LogicalKeyboardKey.mediaPlay, 64790: LogicalKeyboardKey.mediaPlay, @@ -1688,6 +1696,8 @@ const Map kLinuxToPhysicalKey =