From 6b087c74e2f5c15e302acd8b727f560eb18b53e7 Mon Sep 17 00:00:00 2001 From: Greg Spencer Date: Tue, 25 May 2021 17:18:06 -0700 Subject: [PATCH] Add iOS key map generation, make macOS var naming consistent with repo (#83146) This adds iOS key map generation that uses std::maps. It uses std::maps because on iOS if we use NSDictionaries, then when XCode loads the dylib, the initialization of those status NSDictionaries hasn't yet occurred, and it crashes the app. std::maps have a well-defined static behavior, and are correctly initialized. I also made the naming of variables, fields, etc. consistent for macOS. We variously had macosFoo, macOSFoo, and macOsFoo. I eliminated macOsFoo and macosFoo, since the rest of the repo uses macOSFoo for lowerCamelCase names (with only a few exceptions). I used iOSFoo for iOS. --- dev/tools/gen_keycodes/bin/gen_keycodes.dart | 7 +- .../data/fuchsia_keyboard_map_cc.tmpl | 12 +- .../data/glfw_keyboard_map_cc.tmpl | 12 +- .../data/ios_key_code_map_cc.tmpl | 39 +++ .../data/ios_keyboard_map_cc.tmpl | 13 +- .../gen_keycodes/data/logical_key_data.json | 284 +++++++++--------- .../data/macos_key_code_map_cc.tmpl | 12 +- .../data/windows_flutter_key_map_cc.tmpl | 9 +- dev/tools/gen_keycodes/lib/ios_code_gen.dart | 125 ++++++++ .../lib/keyboard_maps_code_gen.dart | 64 ++-- .../gen_keycodes/lib/logical_key_data.dart | 46 +-- .../gen_keycodes/lib/macos_code_gen.dart | 16 +- .../gen_keycodes/lib/physical_key_data.dart | 24 +- 13 files changed, 425 insertions(+), 238 deletions(-) create mode 100644 dev/tools/gen_keycodes/data/ios_key_code_map_cc.tmpl create mode 100644 dev/tools/gen_keycodes/lib/ios_code_gen.dart diff --git a/dev/tools/gen_keycodes/bin/gen_keycodes.dart b/dev/tools/gen_keycodes/bin/gen_keycodes.dart index c9a69f6ef6..4c1d3aecc5 100644 --- a/dev/tools/gen_keycodes/bin/gen_keycodes.dart +++ b/dev/tools/gen_keycodes/bin/gen_keycodes.dart @@ -9,6 +9,7 @@ import 'package:args/args.dart'; import 'package:gen_keycodes/android_code_gen.dart'; import 'package:gen_keycodes/base_code_gen.dart'; import 'package:gen_keycodes/gtk_code_gen.dart'; +import 'package:gen_keycodes/ios_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/logical_key_data.dart'; @@ -210,7 +211,11 @@ Future main(List rawArguments) async { physicalData, logicalData, ), - 'macos': MacOsCodeGenerator( + 'macos': MacOSCodeGenerator( + physicalData, + logicalData, + ), + 'ios': IOSCodeGenerator( physicalData, logicalData, ), diff --git a/dev/tools/gen_keycodes/data/fuchsia_keyboard_map_cc.tmpl b/dev/tools/gen_keycodes/data/fuchsia_keyboard_map_cc.tmpl index 47aa41ea2a..668d517d46 100644 --- a/dev/tools/gen_keycodes/data/fuchsia_keyboard_map_cc.tmpl +++ b/dev/tools/gen_keycodes/data/fuchsia_keyboard_map_cc.tmpl @@ -5,11 +5,15 @@ #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. +// 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/fuchsia_keyboard_map_cc.tmpl instead. -// See dev/tools/gen_keycodes/README.md for more information. +// Edit the template +// flutter/flutter:dev/tools/gen_keycodes/data/fuchsia_keyboard_map_cc.tmpl +// instead. +// +// See flutter/flutter:dev/tools/gen_keycodes/README.md for more information. /// Maps Fuchsia-specific IDs to the matching LogicalKeyboardKey. const std::map g_fuchsia_to_logical_key = { diff --git a/dev/tools/gen_keycodes/data/glfw_keyboard_map_cc.tmpl b/dev/tools/gen_keycodes/data/glfw_keyboard_map_cc.tmpl index 21bbf2fa5f..17e61e3742 100644 --- a/dev/tools/gen_keycodes/data/glfw_keyboard_map_cc.tmpl +++ b/dev/tools/gen_keycodes/data/glfw_keyboard_map_cc.tmpl @@ -5,11 +5,15 @@ #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. +// 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/glfw_keyboard_map_cc.tmpl instead. -// See dev/tools/gen_keycodes/README.md for more information. +// Edit the template +// flutter/flutter:dev/tools/gen_keycodes/data/glfw_keyboard_map_cc.tmpl +// instead. +// +// See flutter/flutter:dev/tools/gen_keycodes/README.md for more information. /// Maps GLFW-specific key codes to the matching [LogicalKeyboardKey]. const std::map g_glfw_to_logical_key = { diff --git a/dev/tools/gen_keycodes/data/ios_key_code_map_cc.tmpl b/dev/tools/gen_keycodes/data/ios_key_code_map_cc.tmpl new file mode 100644 index 0000000000..feaa9aaefb --- /dev/null +++ b/dev/tools/gen_keycodes/data/ios_key_code_map_cc.tmpl @@ -0,0 +1,39 @@ +// 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 +#include "./KeyCodeMap_internal.h" + +// 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 +// flutter/flutter:dev/tools/gen_keycodes/data/ios_key_code_map_cc.tmpl instead. +// +// See flutter/flutter:dev/tools/gen_keycodes/README.md for more information. + +@@@MASK_CONSTANTS@@@ + +// Maps iOS-specific key code values representing [PhysicalKeyboardKey]. +// +// iOS doesn't provide a scan code, but a virtual keycode to represent a physical key. +const std::map keyCodeToPhysicalKey = { +@@@IOS_SCAN_CODE_MAP@@@ +}; + +const std::map keyCodeToLogicalKey = { +@@@IOS_KEYCODE_LOGICAL_MAP@@@ +}; + +const std::map keyCodeToModifierFlag = { +@@@KEYCODE_TO_MODIFIER_FLAG_MAP@@@ +}; + +const std::map modifierFlagToKeyCode = { +@@@MODIFIER_FLAG_TO_KEYCODE_MAP@@@ +}; + +@@@SPECIAL_KEY_CONSTANTS@@@ \ No newline at end of file diff --git a/dev/tools/gen_keycodes/data/ios_keyboard_map_cc.tmpl b/dev/tools/gen_keycodes/data/ios_keyboard_map_cc.tmpl index b36a967142..439d90a423 100644 --- a/dev/tools/gen_keycodes/data/ios_keyboard_map_cc.tmpl +++ b/dev/tools/gen_keycodes/data/ios_keyboard_map_cc.tmpl @@ -5,13 +5,16 @@ #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. +// 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/ios_keyboard_map_cc.tmpl instead. -// See dev/tools/gen_keycodes/README.md for more information. +// Edit the template +// flutter/flutter:dev/tools/gen_keycodes/data/ios_keyboard_map_cc.tmpl instead. +// +// See flutter/flutter:dev/tools/gen_keycodes/README.md for more information. -// Maps macOS-specific key code values representing [PhysicalKeyboardKey]. +// Maps iOS-specific key code values representing [PhysicalKeyboardKey]. // // iOS doesn't provide a scan code, but a virtual keycode to represent a physical key. const std::map g_ios_to_physical_key = { diff --git a/dev/tools/gen_keycodes/data/logical_key_data.json b/dev/tools/gen_keycodes/data/logical_key_data.json index 16b10799eb..8595ca63ad 100644 --- a/dev/tools/gen_keycodes/data/logical_key_data.json +++ b/dev/tools/gen_keycodes/data/logical_key_data.json @@ -1338,7 +1338,7 @@ "web": [ "Backspace" ], - "macOs": [ + "macos": [ "Backspace" ], "ios": [ @@ -1355,7 +1355,7 @@ ] }, "values": { - "macOs": [ + "macos": [ 51 ], "ios": [ @@ -1383,7 +1383,7 @@ "web": [ "Tab" ], - "macOs": [ + "macos": [ "Tab" ], "ios": [ @@ -1402,7 +1402,7 @@ ] }, "values": { - "macOs": [ + "macos": [ 48 ], "ios": [ @@ -1432,7 +1432,7 @@ "web": [ "Enter" ], - "macOs": [ + "macos": [ "Enter" ], "ios": [ @@ -1451,7 +1451,7 @@ ] }, "values": { - "macOs": [ + "macos": [ 36 ], "ios": [ @@ -1481,7 +1481,7 @@ "web": [ "Escape" ], - "macOs": [ + "macos": [ "Escape" ], "ios": [ @@ -1498,7 +1498,7 @@ ] }, "values": { - "macOs": [ + "macos": [ 53 ], "ios": [ @@ -1526,7 +1526,7 @@ "web": [ "Delete" ], - "macOs": [ + "macos": [ "Delete" ], "ios": [ @@ -1543,7 +1543,7 @@ ] }, "values": { - "macOs": [ + "macos": [ 117 ], "ios": [ @@ -1588,7 +1588,7 @@ "web": [ "CapsLock" ], - "macOs": [ + "macos": [ "CapsLock" ], "ios": [ @@ -1605,7 +1605,7 @@ ] }, "values": { - "macOs": [ + "macos": [ 57 ], "ios": [ @@ -1632,7 +1632,7 @@ "web": [ "Fn" ], - "macOs": [ + "macos": [ "Fn" ], "android": [ @@ -1640,7 +1640,7 @@ ] }, "values": { - "macOs": [ + "macos": [ 63 ], "android": [ @@ -1694,7 +1694,7 @@ "web": [ "NumLock" ], - "macOs": [ + "macos": [ "NumLock" ], "ios": [ @@ -1711,7 +1711,7 @@ ] }, "values": { - "macOs": [ + "macos": [ 71 ], "ios": [ @@ -1827,7 +1827,7 @@ "web": [ "ArrowDown" ], - "macOs": [ + "macos": [ "ArrowDown" ], "ios": [ @@ -1844,7 +1844,7 @@ ] }, "values": { - "macOs": [ + "macos": [ 125 ], "ios": [ @@ -1871,7 +1871,7 @@ "web": [ "ArrowLeft" ], - "macOs": [ + "macos": [ "ArrowLeft" ], "ios": [ @@ -1888,7 +1888,7 @@ ] }, "values": { - "macOs": [ + "macos": [ 123 ], "ios": [ @@ -1915,7 +1915,7 @@ "web": [ "ArrowRight" ], - "macOs": [ + "macos": [ "ArrowRight" ], "ios": [ @@ -1932,7 +1932,7 @@ ] }, "values": { - "macOs": [ + "macos": [ 124 ], "ios": [ @@ -1959,7 +1959,7 @@ "web": [ "ArrowUp" ], - "macOs": [ + "macos": [ "ArrowUp" ], "ios": [ @@ -1976,7 +1976,7 @@ ] }, "values": { - "macOs": [ + "macos": [ 126 ], "ios": [ @@ -2003,7 +2003,7 @@ "web": [ "End" ], - "macOs": [ + "macos": [ "End" ], "ios": [ @@ -2020,7 +2020,7 @@ ] }, "values": { - "macOs": [ + "macos": [ 119 ], "ios": [ @@ -2047,7 +2047,7 @@ "web": [ "Home" ], - "macOs": [ + "macos": [ "Home" ], "ios": [ @@ -2064,7 +2064,7 @@ ] }, "values": { - "macOs": [ + "macos": [ 115 ], "ios": [ @@ -2091,7 +2091,7 @@ "web": [ "PageDown" ], - "macOs": [ + "macos": [ "PageDown" ], "ios": [ @@ -2108,7 +2108,7 @@ ] }, "values": { - "macOs": [ + "macos": [ 121 ], "ios": [ @@ -2135,7 +2135,7 @@ "web": [ "PageUp" ], - "macOs": [ + "macos": [ "PageUp" ], "ios": [ @@ -2152,7 +2152,7 @@ ] }, "values": { - "macOs": [ + "macos": [ 116 ], "ios": [ @@ -2305,7 +2305,7 @@ "web": [ "Insert" ], - "macOs": [ + "macos": [ "Insert" ], "ios": [ @@ -2322,7 +2322,7 @@ ] }, "values": { - "macOs": [ + "macos": [ 114 ], "ios": [ @@ -2492,7 +2492,7 @@ "web": [ "ContextMenu" ], - "macOs": [ + "macos": [ "ContextMenu" ], "ios": [ @@ -2509,7 +2509,7 @@ ] }, "values": { - "macOs": [ + "macos": [ 110 ], "ios": [ @@ -3504,7 +3504,7 @@ "web": [ "F1" ], - "macOs": [ + "macos": [ "F1" ], "ios": [ @@ -3522,7 +3522,7 @@ ] }, "values": { - "macOs": [ + "macos": [ 122 ], "ios": [ @@ -3550,7 +3550,7 @@ "web": [ "F2" ], - "macOs": [ + "macos": [ "F2" ], "ios": [ @@ -3568,7 +3568,7 @@ ] }, "values": { - "macOs": [ + "macos": [ 120 ], "ios": [ @@ -3596,7 +3596,7 @@ "web": [ "F3" ], - "macOs": [ + "macos": [ "F3" ], "ios": [ @@ -3614,7 +3614,7 @@ ] }, "values": { - "macOs": [ + "macos": [ 99 ], "ios": [ @@ -3642,7 +3642,7 @@ "web": [ "F4" ], - "macOs": [ + "macos": [ "F4" ], "ios": [ @@ -3660,7 +3660,7 @@ ] }, "values": { - "macOs": [ + "macos": [ 118 ], "ios": [ @@ -3688,7 +3688,7 @@ "web": [ "F5" ], - "macOs": [ + "macos": [ "F5" ], "ios": [ @@ -3705,7 +3705,7 @@ ] }, "values": { - "macOs": [ + "macos": [ 96 ], "ios": [ @@ -3732,7 +3732,7 @@ "web": [ "F6" ], - "macOs": [ + "macos": [ "F6" ], "ios": [ @@ -3749,7 +3749,7 @@ ] }, "values": { - "macOs": [ + "macos": [ 97 ], "ios": [ @@ -3776,7 +3776,7 @@ "web": [ "F7" ], - "macOs": [ + "macos": [ "F7" ], "ios": [ @@ -3793,7 +3793,7 @@ ] }, "values": { - "macOs": [ + "macos": [ 98 ], "ios": [ @@ -3820,7 +3820,7 @@ "web": [ "F8" ], - "macOs": [ + "macos": [ "F8" ], "ios": [ @@ -3837,7 +3837,7 @@ ] }, "values": { - "macOs": [ + "macos": [ 100 ], "ios": [ @@ -3864,7 +3864,7 @@ "web": [ "F9" ], - "macOs": [ + "macos": [ "F9" ], "ios": [ @@ -3881,7 +3881,7 @@ ] }, "values": { - "macOs": [ + "macos": [ 101 ], "ios": [ @@ -3908,7 +3908,7 @@ "web": [ "F10" ], - "macOs": [ + "macos": [ "F10" ], "ios": [ @@ -3925,7 +3925,7 @@ ] }, "values": { - "macOs": [ + "macos": [ 109 ], "ios": [ @@ -3952,7 +3952,7 @@ "web": [ "F11" ], - "macOs": [ + "macos": [ "F11" ], "ios": [ @@ -3969,7 +3969,7 @@ ] }, "values": { - "macOs": [ + "macos": [ 103 ], "ios": [ @@ -3996,7 +3996,7 @@ "web": [ "F12" ], - "macOs": [ + "macos": [ "F12" ], "ios": [ @@ -4013,7 +4013,7 @@ ] }, "values": { - "macOs": [ + "macos": [ 111 ], "ios": [ @@ -4040,7 +4040,7 @@ "web": [ "F13" ], - "macOs": [ + "macos": [ "F13" ], "ios": [ @@ -4054,7 +4054,7 @@ ] }, "values": { - "macOs": [ + "macos": [ 105 ], "ios": [ @@ -4078,7 +4078,7 @@ "web": [ "F14" ], - "macOs": [ + "macos": [ "F14" ], "ios": [ @@ -4092,7 +4092,7 @@ ] }, "values": { - "macOs": [ + "macos": [ 107 ], "ios": [ @@ -4116,7 +4116,7 @@ "web": [ "F15" ], - "macOs": [ + "macos": [ "F15" ], "ios": [ @@ -4130,7 +4130,7 @@ ] }, "values": { - "macOs": [ + "macos": [ 113 ], "ios": [ @@ -4154,7 +4154,7 @@ "web": [ "F16" ], - "macOs": [ + "macos": [ "F16" ], "ios": [ @@ -4168,7 +4168,7 @@ ] }, "values": { - "macOs": [ + "macos": [ 106 ], "ios": [ @@ -4192,7 +4192,7 @@ "web": [ "F17" ], - "macOs": [ + "macos": [ "F17" ], "ios": [ @@ -4206,7 +4206,7 @@ ] }, "values": { - "macOs": [ + "macos": [ 64 ], "ios": [ @@ -4230,7 +4230,7 @@ "web": [ "F18" ], - "macOs": [ + "macos": [ "F18" ], "ios": [ @@ -4244,7 +4244,7 @@ ] }, "values": { - "macOs": [ + "macos": [ 79 ], "ios": [ @@ -4268,7 +4268,7 @@ "web": [ "F19" ], - "macOs": [ + "macos": [ "F19" ], "ios": [ @@ -4282,7 +4282,7 @@ ] }, "values": { - "macOs": [ + "macos": [ 80 ], "ios": [ @@ -4306,7 +4306,7 @@ "web": [ "F20" ], - "macOs": [ + "macos": [ "F20" ], "ios": [ @@ -4320,7 +4320,7 @@ ] }, "values": { - "macOs": [ + "macos": [ 90 ], "ios": [ @@ -4822,7 +4822,7 @@ "web": [ "AudioVolumeDown" ], - "macOs": [ + "macos": [ "AudioVolumeDown" ], "ios": [ @@ -4839,7 +4839,7 @@ ] }, "values": { - "macOs": [ + "macos": [ 73 ], "ios": [ @@ -4866,7 +4866,7 @@ "web": [ "AudioVolumeUp" ], - "macOs": [ + "macos": [ "AudioVolumeUp" ], "ios": [ @@ -4883,7 +4883,7 @@ ] }, "values": { - "macOs": [ + "macos": [ 72 ], "ios": [ @@ -4910,7 +4910,7 @@ "web": [ "AudioVolumeMute" ], - "macOs": [ + "macos": [ "AudioVolumeMute" ], "ios": [ @@ -4927,7 +4927,7 @@ ] }, "values": { - "macOs": [ + "macos": [ 74 ], "ios": [ @@ -8077,7 +8077,7 @@ "web": [ "IntlRo" ], - "macOs": [ + "macos": [ "IntlRo" ], "ios": [ @@ -8088,7 +8088,7 @@ ] }, "values": { - "macOs": [ + "macos": [ 94 ], "ios": [ @@ -8109,7 +8109,7 @@ "web": [ "IntlYen" ], - "macOs": [ + "macos": [ "IntlYen" ], "ios": [ @@ -8123,7 +8123,7 @@ ] }, "values": { - "macOs": [ + "macos": [ 93 ], "ios": [ @@ -8147,7 +8147,7 @@ "web": [ "Lang1" ], - "macOs": [ + "macos": [ "Lang1" ], "ios": [ @@ -8158,7 +8158,7 @@ ] }, "values": { - "macOs": [ + "macos": [ 104 ], "ios": [ @@ -8179,7 +8179,7 @@ "web": [ "Lang2" ], - "macOs": [ + "macos": [ "Lang2" ], "ios": [ @@ -8187,7 +8187,7 @@ ] }, "values": { - "macOs": [ + "macos": [ 102 ], "ios": [ @@ -8279,7 +8279,7 @@ "web": [ "AltLeft" ], - "macOs": [ + "macos": [ "AltLeft" ], "ios": [ @@ -8296,7 +8296,7 @@ ] }, "values": { - "macOs": [ + "macos": [ 58 ], "ios": [ @@ -8323,7 +8323,7 @@ "web": [ "ControlLeft" ], - "macOs": [ + "macos": [ "ControlLeft" ], "ios": [ @@ -8341,7 +8341,7 @@ ] }, "values": { - "macOs": [ + "macos": [ 59 ], "ios": [ @@ -8369,7 +8369,7 @@ "web": [ "MetaLeft" ], - "macOs": [ + "macos": [ "MetaLeft" ], "ios": [ @@ -8386,7 +8386,7 @@ ] }, "values": { - "macOs": [ + "macos": [ 55 ], "ios": [ @@ -8413,7 +8413,7 @@ "web": [ "ShiftLeft" ], - "macOs": [ + "macos": [ "ShiftLeft" ], "ios": [ @@ -8431,7 +8431,7 @@ ] }, "values": { - "macOs": [ + "macos": [ 56 ], "ios": [ @@ -8459,7 +8459,7 @@ "web": [ "AltRight" ], - "macOs": [ + "macos": [ "AltRight" ], "ios": [ @@ -8477,7 +8477,7 @@ ] }, "values": { - "macOs": [ + "macos": [ 61 ], "ios": [ @@ -8505,7 +8505,7 @@ "web": [ "ControlRight" ], - "macOs": [ + "macos": [ "ControlRight" ], "ios": [ @@ -8522,7 +8522,7 @@ ] }, "values": { - "macOs": [ + "macos": [ 62 ], "ios": [ @@ -8549,7 +8549,7 @@ "web": [ "MetaRight" ], - "macOs": [ + "macos": [ "MetaRight" ], "ios": [ @@ -8566,7 +8566,7 @@ ] }, "values": { - "macOs": [ + "macos": [ 54 ], "ios": [ @@ -8593,7 +8593,7 @@ "web": [ "ShiftRight" ], - "macOs": [ + "macos": [ "ShiftRight" ], "ios": [ @@ -8610,7 +8610,7 @@ ] }, "values": { - "macOs": [ + "macos": [ 60 ], "ios": [ @@ -8637,7 +8637,7 @@ "web": [ "NumpadEnter" ], - "macOs": [ + "macos": [ "NumpadEnter" ], "ios": [ @@ -8651,7 +8651,7 @@ ] }, "values": { - "macOs": [ + "macos": [ 76 ], "ios": [ @@ -8715,7 +8715,7 @@ "web": [ "NumpadMultiply" ], - "macOs": [ + "macos": [ "NumpadMultiply" ], "ios": [ @@ -8732,7 +8732,7 @@ ] }, "values": { - "macOs": [ + "macos": [ 67 ], "ios": [ @@ -8759,7 +8759,7 @@ "web": [ "NumpadAdd" ], - "macOs": [ + "macos": [ "NumpadAdd" ], "ios": [ @@ -8776,7 +8776,7 @@ ] }, "values": { - "macOs": [ + "macos": [ 69 ], "ios": [ @@ -8803,7 +8803,7 @@ "web": [ "NumpadComma" ], - "macOs": [ + "macos": [ "NumpadComma" ], "ios": [ @@ -8814,7 +8814,7 @@ ] }, "values": { - "macOs": [ + "macos": [ 95 ], "ios": [ @@ -8835,7 +8835,7 @@ "web": [ "NumpadSubtract" ], - "macOs": [ + "macos": [ "NumpadSubtract" ], "ios": [ @@ -8852,7 +8852,7 @@ ] }, "values": { - "macOs": [ + "macos": [ 78 ], "ios": [ @@ -8879,7 +8879,7 @@ "web": [ "NumpadDecimal" ], - "macOs": [ + "macos": [ "NumpadDecimal" ], "ios": [ @@ -8896,7 +8896,7 @@ ] }, "values": { - "macOs": [ + "macos": [ 65 ], "ios": [ @@ -8923,7 +8923,7 @@ "web": [ "NumpadDivide" ], - "macOs": [ + "macos": [ "NumpadDivide" ], "ios": [ @@ -8940,7 +8940,7 @@ ] }, "values": { - "macOs": [ + "macos": [ 75 ], "ios": [ @@ -8967,7 +8967,7 @@ "web": [ "Numpad0" ], - "macOs": [ + "macos": [ "Numpad0" ], "ios": [ @@ -8985,7 +8985,7 @@ ] }, "values": { - "macOs": [ + "macos": [ 82 ], "ios": [ @@ -9013,7 +9013,7 @@ "web": [ "Numpad1" ], - "macOs": [ + "macos": [ "Numpad1" ], "ios": [ @@ -9031,7 +9031,7 @@ ] }, "values": { - "macOs": [ + "macos": [ 83 ], "ios": [ @@ -9059,7 +9059,7 @@ "web": [ "Numpad2" ], - "macOs": [ + "macos": [ "Numpad2" ], "ios": [ @@ -9077,7 +9077,7 @@ ] }, "values": { - "macOs": [ + "macos": [ 84 ], "ios": [ @@ -9105,7 +9105,7 @@ "web": [ "Numpad3" ], - "macOs": [ + "macos": [ "Numpad3" ], "ios": [ @@ -9123,7 +9123,7 @@ ] }, "values": { - "macOs": [ + "macos": [ 85 ], "ios": [ @@ -9151,7 +9151,7 @@ "web": [ "Numpad4" ], - "macOs": [ + "macos": [ "Numpad4" ], "ios": [ @@ -9169,7 +9169,7 @@ ] }, "values": { - "macOs": [ + "macos": [ 86 ], "ios": [ @@ -9197,7 +9197,7 @@ "web": [ "Numpad5" ], - "macOs": [ + "macos": [ "Numpad5" ], "ios": [ @@ -9214,7 +9214,7 @@ ] }, "values": { - "macOs": [ + "macos": [ 87 ], "ios": [ @@ -9241,7 +9241,7 @@ "web": [ "Numpad6" ], - "macOs": [ + "macos": [ "Numpad6" ], "ios": [ @@ -9259,7 +9259,7 @@ ] }, "values": { - "macOs": [ + "macos": [ 88 ], "ios": [ @@ -9287,7 +9287,7 @@ "web": [ "Numpad7" ], - "macOs": [ + "macos": [ "Numpad7" ], "ios": [ @@ -9305,7 +9305,7 @@ ] }, "values": { - "macOs": [ + "macos": [ 89 ], "ios": [ @@ -9333,7 +9333,7 @@ "web": [ "Numpad8" ], - "macOs": [ + "macos": [ "Numpad8" ], "ios": [ @@ -9351,7 +9351,7 @@ ] }, "values": { - "macOs": [ + "macos": [ 91 ], "ios": [ @@ -9379,7 +9379,7 @@ "web": [ "Numpad9" ], - "macOs": [ + "macos": [ "Numpad9" ], "ios": [ @@ -9397,7 +9397,7 @@ ] }, "values": { - "macOs": [ + "macos": [ 92 ], "ios": [ @@ -9425,7 +9425,7 @@ "web": [ "NumpadEqual" ], - "macOs": [ + "macos": [ "NumpadEqual" ], "ios": [ @@ -9442,7 +9442,7 @@ ] }, "values": { - "macOs": [ + "macos": [ 81 ], "ios": [ diff --git a/dev/tools/gen_keycodes/data/macos_key_code_map_cc.tmpl b/dev/tools/gen_keycodes/data/macos_key_code_map_cc.tmpl index 876d5806ce..27cc3151f7 100644 --- a/dev/tools/gen_keycodes/data/macos_key_code_map_cc.tmpl +++ b/dev/tools/gen_keycodes/data/macos_key_code_map_cc.tmpl @@ -7,11 +7,15 @@ #include "./KeyCodeMap_internal.h" // 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. +// 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_map_macos_cc.tmpl instead. -// See dev/tools/gen_keycodes/README.md for more information. +// Edit the template +// flutter/flutter:dev/tools/gen_keycodes/data/keyboard_map_macos_cc.tmpl +// instead. +// +// See flutter/flutter:dev/tools/gen_keycodes/README.md for more information. @@@MASK_CONSTANTS@@@ diff --git a/dev/tools/gen_keycodes/data/windows_flutter_key_map_cc.tmpl b/dev/tools/gen_keycodes/data/windows_flutter_key_map_cc.tmpl index 302fe8f30e..97f3621a1d 100644 --- a/dev/tools/gen_keycodes/data/windows_flutter_key_map_cc.tmpl +++ b/dev/tools/gen_keycodes/data/windows_flutter_key_map_cc.tmpl @@ -11,11 +11,14 @@ // 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 +// flutter/flutter:dev/tools/gen_keycodes/bin/gen_keycodes.dart and should not // be edited directly. // -// Edit the template dev/tools/gen_keycodes/data/windows_flutter_key_map_cc.tmpl -// instead. See dev/tools/gen_keycodes/README.md for more information. +// Edit the template +// flutter/flutter:dev/tools/gen_keycodes/data/windows_flutter_key_map_cc.tmpl +// instead. +// +// See flutter/flutter:dev/tools/gen_keycodes/README.md for more information. namespace flutter { diff --git a/dev/tools/gen_keycodes/lib/ios_code_gen.dart b/dev/tools/gen_keycodes/lib/ios_code_gen.dart new file mode 100644 index 0000000000..5a631becd7 --- /dev/null +++ b/dev/tools/gen_keycodes/lib/ios_code_gen.dart @@ -0,0 +1,125 @@ +// 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 'constants.dart'; +import 'logical_key_data.dart'; +import 'physical_key_data.dart'; +import 'utils.dart'; + +const List kModifiersOfInterest = [ + 'ShiftLeft', + 'ShiftRight', + 'ControlLeft', + 'ControlRight', + 'AltLeft', + 'AltRight', + 'MetaLeft', + 'MetaRight', +]; + +// The name of keys that require special attention. +const List kSpecialPhysicalKeys = ['CapsLock']; +const List kSpecialLogicalKeys = ['CapsLock']; + +String _toConstantVariableName(String variableName) { + return 'k${variableName[0].toUpperCase()}${variableName.substring(1)}'; +} + +/// Generates the key mapping for iOS, based on the information in the key +/// data structure given to it. +class IOSCodeGenerator extends PlatformCodeGenerator { + IOSCodeGenerator(PhysicalKeyData keyData, LogicalKeyData logicalData) + : super(keyData, logicalData); + + /// This generates the map of iOS key codes to physical keys. + String get _scanCodeMap { + final StringBuffer scanCodeMap = StringBuffer(); + for (final PhysicalKeyEntry entry in keyData.entries) { + if (entry.iOSScanCode != null) { + scanCodeMap.writeln(' {${toHex(entry.iOSScanCode)}, ${toHex(entry.usbHidCode)}}, // ${entry.constantName}'); + } + } + return scanCodeMap.toString().trimRight(); + } + + String get _keyCodeToLogicalMap { + final StringBuffer result = StringBuffer(); + for (final LogicalKeyEntry entry in logicalData.entries) { + zipStrict(entry.iOSKeyCodeValues, entry.iOSKeyCodeNames, (int iOSValue, String iOSName) { + result.writeln(' {${toHex(iOSValue)}, ${toHex(entry.value, digits: 11)}}, // $iOSName'); + }); + } + return result.toString().trimRight(); + } + + /// This generates the mask values for the part of a key code that defines its plane. + String get _maskConstants { + final StringBuffer buffer = StringBuffer(); + for (final MaskConstant constant in maskConstants) { + buffer.writeln('/**'); + buffer.write(constant.description + .map((String line) => wrapString(line, prefix: ' * ')) + .join(' *\n')); + buffer.writeln(' */'); + buffer.writeln('const uint64_t ${_toConstantVariableName(constant.name)} = ${toHex(constant.value, digits: 11)};'); + buffer.writeln(''); + } + return buffer.toString().trimRight(); + } + + /// This generates a map from the key code to a modifier flag. + String get _keyToModifierFlagMap { + final StringBuffer modifierKeyMap = StringBuffer(); + for (final String name in kModifiersOfInterest) { + modifierKeyMap.writeln(' {${toHex(logicalData.entryByName(name).iOSKeyCodeValues[0])}, kModifierFlag${lowerCamelToUpperCamel(name)}},'); + } + return modifierKeyMap.toString().trimRight(); + } + + /// This generates a map from the modifier flag to the key code. + String get _modifierFlagToKeyMap { + final StringBuffer modifierKeyMap = StringBuffer(); + for (final String name in kModifiersOfInterest) { + modifierKeyMap.writeln(' {kModifierFlag${lowerCamelToUpperCamel(name)}, ${toHex(logicalData.entryByName(name).iOSKeyCodeValues[0])}},'); + } + return modifierKeyMap.toString().trimRight(); + } + + /// This generates some keys that needs special attention. + String get _specialKeyConstants { + final StringBuffer specialKeyConstants = StringBuffer(); + for (final String keyName in kSpecialPhysicalKeys) { + specialKeyConstants.writeln('const uint64_t k${keyName}PhysicalKey = ${toHex(keyData.entryByName(keyName).usbHidCode)};'); + } + for (final String keyName in kSpecialLogicalKeys) { + specialKeyConstants.writeln('const uint64_t k${lowerCamelToUpperCamel(keyName)}LogicalKey = ${toHex(logicalData.entryByName(keyName).value)};'); + } + return specialKeyConstants.toString().trimRight(); + } + + @override + String get templatePath => path.join(dataRoot, 'ios_key_code_map_cc.tmpl'); + + @override + String outputPath(String platform) => path.join(PlatformCodeGenerator.engineRoot, + 'shell', 'platform', 'darwin', 'ios', 'framework', 'Source', 'KeyCodeMap.mm'); + + @override + Map mappings() { + // There is no iOS keycode map since iOS uses keycode to represent a physical key. + // The LogicalKeyboardKey is generated by raw_keyboard_ios.dart from the unmodified characters + // from NSEvent. + return { + 'MASK_CONSTANTS': _maskConstants, + 'IOS_SCAN_CODE_MAP': _scanCodeMap, + 'IOS_KEYCODE_LOGICAL_MAP': _keyCodeToLogicalMap, + 'KEYCODE_TO_MODIFIER_FLAG_MAP': _keyToModifierFlagMap, + 'MODIFIER_FLAG_TO_KEYCODE_MAP': _modifierFlagToKeyMap, + 'SPECIAL_KEY_CONSTANTS': _specialKeyConstants, + }; + } +} diff --git a/dev/tools/gen_keycodes/lib/keyboard_maps_code_gen.dart b/dev/tools/gen_keycodes/lib/keyboard_maps_code_gen.dart index bdf44ce748..5f8e49b510 100644 --- a/dev/tools/gen_keycodes/lib/keyboard_maps_code_gen.dart +++ b/dev/tools/gen_keycodes/lib/keyboard_maps_code_gen.dart @@ -180,42 +180,42 @@ class KeyboardMapsCodeGenerator extends BaseCodeGenerator { } /// This generates the map of macOS key codes to physical keys. - String get _macOsScanCodeMap { - final StringBuffer macOsScanCodeMap = StringBuffer(); + String get _macOSScanCodeMap { + final StringBuffer macOSScanCodeMap = StringBuffer(); for (final PhysicalKeyEntry entry in keyData.entries) { - if (entry.macOsScanCode != null) { - macOsScanCodeMap.writeln(' ${toHex(entry.macOsScanCode)}: PhysicalKeyboardKey.${entry.constantName},'); + if (entry.macOSScanCode != null) { + macOSScanCodeMap.writeln(' ${toHex(entry.macOSScanCode)}: PhysicalKeyboardKey.${entry.constantName},'); } } - return macOsScanCodeMap.toString().trimRight(); + return macOSScanCodeMap.toString().trimRight(); } /// This generates the map of macOS number pad key codes to logical keys. - String get _macOsNumpadMap { - final StringBuffer macOsNumPadMap = StringBuffer(); + String get _macOSNumpadMap { + final StringBuffer macOSNumPadMap = StringBuffer(); for (final PhysicalKeyEntry entry in _numpadKeyData) { - if (entry.macOsScanCode != null) { - macOsNumPadMap.writeln(' ${toHex(entry.macOsScanCode)}: LogicalKeyboardKey.${entry.constantName},'); + if (entry.macOSScanCode != null) { + macOSNumPadMap.writeln(' ${toHex(entry.macOSScanCode)}: LogicalKeyboardKey.${entry.constantName},'); } } - return macOsNumPadMap.toString().trimRight(); + return macOSNumPadMap.toString().trimRight(); } - String get _macOsFunctionKeyMap { - final StringBuffer macOsFunctionKeyMap = StringBuffer(); + String get _macOSFunctionKeyMap { + final StringBuffer macOSFunctionKeyMap = StringBuffer(); for (final PhysicalKeyEntry entry in _functionKeyData) { - if (entry.macOsScanCode != null) { - macOsFunctionKeyMap.writeln(' ${toHex(entry.macOsScanCode)}: LogicalKeyboardKey.${entry.constantName},'); + if (entry.macOSScanCode != null) { + macOSFunctionKeyMap.writeln(' ${toHex(entry.macOSScanCode)}: LogicalKeyboardKey.${entry.constantName},'); } } - return macOsFunctionKeyMap.toString().trimRight(); + return macOSFunctionKeyMap.toString().trimRight(); } /// This generates the map of macOS key codes to physical keys. - String get _macOsKeyCodeMap { + String get _macOSKeyCodeMap { final OutputLines lines = OutputLines('MacOS key code map'); for (final LogicalKeyEntry entry in logicalData.entries) { - for (final int code in entry.macOsKeyCodeValues) { + for (final int code in entry.macOSKeyCodeValues) { lines.add(code, ' $code: LogicalKeyboardKey.${entry.constantName},'); } } @@ -223,32 +223,32 @@ class KeyboardMapsCodeGenerator extends BaseCodeGenerator { } /// This generates the map of iOS key codes to physical keys. - String get _iosScanCodeMap { + String get _iOSScanCodeMap { final OutputLines lines = OutputLines('iOS scancode map'); for (final PhysicalKeyEntry entry in keyData.entries) { - if (entry.iosScanCode != null) { - lines.add(entry.iosScanCode!, ' ${toHex(entry.iosScanCode)}: PhysicalKeyboardKey.${entry.constantName},'); + if (entry.iOSScanCode != null) { + lines.add(entry.iOSScanCode!, ' ${toHex(entry.iOSScanCode)}: PhysicalKeyboardKey.${entry.constantName},'); } } return lines.sortedJoin().trimRight(); } /// This generates the map of iOS number pad key codes to logical keys. - String get _iosNumpadMap { + String get _iOSNumpadMap { final OutputLines lines = OutputLines('iOS numpad map'); for (final PhysicalKeyEntry entry in _numpadKeyData) { - if (entry.iosScanCode != null) { - lines.add(entry.iosScanCode!,' ${toHex(entry.iosScanCode)}: LogicalKeyboardKey.${entry.constantName},'); + if (entry.iOSScanCode != null) { + lines.add(entry.iOSScanCode!,' ${toHex(entry.iOSScanCode)}: LogicalKeyboardKey.${entry.constantName},'); } } return lines.sortedJoin().trimRight(); } /// This generates the map of macOS key codes to physical keys. - String get _iosKeyCodeMap { + String get _iOSKeyCodeMap { final OutputLines lines = OutputLines('iOS key code map'); for (final LogicalKeyEntry entry in logicalData.entries) { - for (final int code in entry.iosKeyCodeValues) { + for (final int code in entry.iOSKeyCodeValues) { lines.add(code, ' $code: LogicalKeyboardKey.${entry.constantName},'); } } @@ -335,13 +335,13 @@ class KeyboardMapsCodeGenerator extends BaseCodeGenerator { '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, - 'MACOS_KEY_CODE_MAP': _macOsKeyCodeMap, - 'IOS_SCAN_CODE_MAP': _iosScanCodeMap, - 'IOS_NUMPAD_MAP': _iosNumpadMap, - 'IOS_KEY_CODE_MAP': _iosKeyCodeMap, + 'MACOS_SCAN_CODE_MAP': _macOSScanCodeMap, + 'MACOS_NUMPAD_MAP': _macOSNumpadMap, + 'MACOS_FUNCTION_KEY_MAP': _macOSFunctionKeyMap, + 'MACOS_KEY_CODE_MAP': _macOSKeyCodeMap, + 'IOS_SCAN_CODE_MAP': _iOSScanCodeMap, + 'IOS_NUMPAD_MAP': _iOSNumpadMap, + 'IOS_KEY_CODE_MAP': _iOSKeyCodeMap, 'GLFW_KEY_CODE_MAP': _glfwKeyCodeMap, 'GLFW_NUMPAD_MAP': _glfwNumpadMap, 'GTK_KEY_CODE_MAP': _gtkKeyCodeMap, diff --git a/dev/tools/gen_keycodes/lib/logical_key_data.dart b/dev/tools/gen_keycodes/lib/logical_key_data.dart index f2d2ecfe83..96921d7830 100644 --- a/dev/tools/gen_keycodes/lib/logical_key_data.dart +++ b/dev/tools/gen_keycodes/lib/logical_key_data.dart @@ -207,13 +207,13 @@ class LogicalKeyData { physicalToLogical.forEach((String physicalKeyName, String logicalKeyName) { final PhysicalKeyEntry physicalEntry = physicalKeyData.entryByName(physicalKeyName); - assert(physicalEntry.macOsScanCode != null, - 'Physical entry $physicalKeyName does not have a macOsScanCode.'); + assert(physicalEntry.macOSScanCode != null, + 'Physical entry $physicalKeyName does not have a macOSScanCode.'); final LogicalKeyEntry? logicalEntry = data[logicalKeyName]; assert(logicalEntry != null, 'Unable to find logical entry by name $logicalKeyName.'); - logicalEntry!.macOsKeyCodeNames.add(physicalEntry.name); - logicalEntry.macOsKeyCodeValues.add(physicalEntry.macOsScanCode!); + logicalEntry!.macOSKeyCodeNames.add(physicalEntry.name); + logicalEntry.macOSKeyCodeValues.add(physicalEntry.macOSScanCode!); }); } @@ -227,13 +227,13 @@ class LogicalKeyData { physicalToLogical.forEach((String physicalKeyName, String logicalKeyName) { final PhysicalKeyEntry physicalEntry = physicalKeyData.entryByName(physicalKeyName); - assert(physicalEntry.iosScanCode != null, + assert(physicalEntry.iOSScanCode != null, 'Physical entry $physicalKeyName does not have an iosScanCode.'); final LogicalKeyEntry? logicalEntry = data[logicalKeyName]; assert(logicalEntry != null, 'Unable to find logical entry by name $logicalKeyName.'); - logicalEntry!.iosKeyCodeNames.add(physicalEntry.name); - logicalEntry.iosKeyCodeValues.add(physicalEntry.iosScanCode!); + logicalEntry!.iOSKeyCodeNames.add(physicalEntry.name); + logicalEntry.iOSKeyCodeValues.add(physicalEntry.iOSScanCode!); }); } @@ -414,10 +414,10 @@ class LogicalKeyEntry { required this.name, this.keyLabel, }) : webNames = [], - macOsKeyCodeNames = [], - macOsKeyCodeValues = [], - iosKeyCodeNames = [], - iosKeyCodeValues = [], + macOSKeyCodeNames = [], + macOSKeyCodeValues = [], + iOSKeyCodeNames = [], + iOSKeyCodeValues = [], gtkNames = [], gtkValues = [], windowsNames = [], @@ -441,10 +441,10 @@ class LogicalKeyEntry { : value = map['value'] as int, name = map['name'] as String, webNames = _toNonEmptyArray(map['names']['web']), - macOsKeyCodeNames = _toNonEmptyArray(map['names']['macOs']), - macOsKeyCodeValues = _toNonEmptyArray(map['values']?['macOs']), - iosKeyCodeNames = _toNonEmptyArray(map['names']['ios']), - iosKeyCodeValues = _toNonEmptyArray(map['values']?['ios']), + macOSKeyCodeNames = _toNonEmptyArray(map['names']['macos']), + macOSKeyCodeValues = _toNonEmptyArray(map['values']?['macos']), + iOSKeyCodeNames = _toNonEmptyArray(map['names']['ios']), + iOSKeyCodeValues = _toNonEmptyArray(map['values']?['ios']), gtkNames = _toNonEmptyArray(map['names']['gtk']), gtkValues = _toNonEmptyArray(map['values']?['gtk']), windowsNames = _toNonEmptyArray(map['names']['windows']), @@ -470,19 +470,19 @@ class LogicalKeyEntry { /// The names of the key codes that corresponds to this logical key on macOS, /// created from the corresponding physical keys. - final List macOsKeyCodeNames; + final List macOSKeyCodeNames; /// The key codes that corresponds to this logical key on macOS, created from /// the physical key list substituted with the key mapping. - final List macOsKeyCodeValues; + final List macOSKeyCodeValues; /// The names of the key codes that corresponds to this logical key on iOS, /// created from the corresponding physical keys. - final List iosKeyCodeNames; + final List iOSKeyCodeNames; /// The key codes that corresponds to this logical key on iOS, created from the /// physical key list substituted with the key mapping. - final List iosKeyCodeValues; + final List iOSKeyCodeValues; /// The list of names that GTK gives to this key (symbol names minus the /// prefix). @@ -528,15 +528,15 @@ class LogicalKeyEntry { 'keyLabel': keyLabel, 'names': { 'web': webNames, - 'macOs': macOsKeyCodeNames, - 'ios': iosKeyCodeNames, + 'macos': macOSKeyCodeNames, + 'ios': iOSKeyCodeNames, 'gtk': gtkNames, 'windows': windowsNames, 'android': androidNames, }, 'values': >{ - 'macOs': macOsKeyCodeValues, - 'ios': iosKeyCodeValues, + 'macos': macOSKeyCodeValues, + 'ios': iOSKeyCodeValues, 'gtk': gtkValues, 'windows': windowsValues, 'android': androidValues, diff --git a/dev/tools/gen_keycodes/lib/macos_code_gen.dart b/dev/tools/gen_keycodes/lib/macos_code_gen.dart index b482aedde6..85c09cb87d 100644 --- a/dev/tools/gen_keycodes/lib/macos_code_gen.dart +++ b/dev/tools/gen_keycodes/lib/macos_code_gen.dart @@ -31,16 +31,16 @@ String _toConstantVariableName(String variableName) { /// Generates the key mapping for macOS, based on the information in the key /// data structure given to it. -class MacOsCodeGenerator extends PlatformCodeGenerator { - MacOsCodeGenerator(PhysicalKeyData keyData, LogicalKeyData logicalData) +class MacOSCodeGenerator extends PlatformCodeGenerator { + MacOSCodeGenerator(PhysicalKeyData keyData, LogicalKeyData logicalData) : super(keyData, logicalData); /// This generates the map of macOS key codes to physical keys. String get _scanCodeMap { final StringBuffer scanCodeMap = StringBuffer(); for (final PhysicalKeyEntry entry in keyData.entries) { - if (entry.macOsScanCode != null) { - scanCodeMap.writeln(' @${toHex(entry.macOsScanCode)} : @${toHex(entry.usbHidCode)}, // ${entry.constantName}'); + if (entry.macOSScanCode != null) { + scanCodeMap.writeln(' @${toHex(entry.macOSScanCode)} : @${toHex(entry.usbHidCode)}, // ${entry.constantName}'); } } return scanCodeMap.toString().trimRight(); @@ -49,8 +49,8 @@ class MacOsCodeGenerator extends PlatformCodeGenerator { String get _keyCodeToLogicalMap { final StringBuffer result = StringBuffer(); for (final LogicalKeyEntry entry in logicalData.entries) { - zipStrict(entry.macOsKeyCodeValues, entry.macOsKeyCodeNames, (int macOsValue, String macOsName) { - result.writeln(' @${toHex(macOsValue)} : @${toHex(entry.value, digits: 11)}, // $macOsName'); + zipStrict(entry.macOSKeyCodeValues, entry.macOSKeyCodeNames, (int macOSValue, String macOSName) { + result.writeln(' @${toHex(macOSValue)} : @${toHex(entry.value, digits: 11)}, // $macOSName'); }); } return result.toString().trimRight(); @@ -75,7 +75,7 @@ class MacOsCodeGenerator extends PlatformCodeGenerator { String get _keyToModifierFlagMap { final StringBuffer modifierKeyMap = StringBuffer(); for (final String name in kModifiersOfInterest) { - modifierKeyMap.writeln(' @${toHex(logicalData.entryByName(name).macOsKeyCodeValues[0])} : @(kModifierFlag${lowerCamelToUpperCamel(name)}),'); + modifierKeyMap.writeln(' @${toHex(logicalData.entryByName(name).macOSKeyCodeValues[0])} : @(kModifierFlag${lowerCamelToUpperCamel(name)}),'); } return modifierKeyMap.toString().trimRight(); } @@ -84,7 +84,7 @@ class MacOsCodeGenerator extends PlatformCodeGenerator { String get _modifierFlagToKeyMap { final StringBuffer modifierKeyMap = StringBuffer(); for (final String name in kModifiersOfInterest) { - modifierKeyMap.writeln(' @(kModifierFlag${lowerCamelToUpperCamel(name)}) : @${toHex(logicalData.entryByName(name).macOsKeyCodeValues[0])},'); + modifierKeyMap.writeln(' @(kModifierFlag${lowerCamelToUpperCamel(name)}) : @${toHex(logicalData.entryByName(name).macOSKeyCodeValues[0])},'); } return modifierKeyMap.toString().trimRight(); } diff --git a/dev/tools/gen_keycodes/lib/physical_key_data.dart b/dev/tools/gen_keycodes/lib/physical_key_data.dart index 1e4d88ccdc..3fefe84f81 100644 --- a/dev/tools/gen_keycodes/lib/physical_key_data.dart +++ b/dev/tools/gen_keycodes/lib/physical_key_data.dart @@ -231,8 +231,8 @@ class PhysicalKeyData { linuxScanCode: linuxScanCode == 0 ? null : linuxScanCode, xKbScanCode: xKbScanCode == 0 ? null : xKbScanCode, windowsScanCode: windowsScanCode == 0 ? null : windowsScanCode, - macOsScanCode: macScanCode == 0xffff ? null : macScanCode, - iosScanCode: (usbHidCode & 0x070000) == 0x070000 ? (usbHidCode ^ 0x070000) : null, + macOSScanCode: macScanCode == 0xffff ? null : macScanCode, + iOSScanCode: (usbHidCode & 0x070000) == 0x070000 ? (usbHidCode ^ 0x070000) : null, name: name, chromiumCode: chromiumCode, ); @@ -267,8 +267,8 @@ class PhysicalKeyEntry { required this.linuxScanCode, required this.xKbScanCode, required this.windowsScanCode, - required this.macOsScanCode, - required this.iosScanCode, + required this.macOSScanCode, + required this.iOSScanCode, required this.chromiumCode, required this.glfwKeyCodes, }); @@ -283,8 +283,8 @@ class PhysicalKeyEntry { linuxScanCode: map['scanCodes']['linux'] as int?, xKbScanCode: map['scanCodes']['xkb'] as int?, windowsScanCode: map['scanCodes']['windows'] as int?, - macOsScanCode: map['scanCodes']['macos'] as int?, - iosScanCode: map['scanCodes']['ios'] as int?, + macOSScanCode: map['scanCodes']['macos'] as int?, + iOSScanCode: map['scanCodes']['ios'] as int?, glfwKeyCodes: (map['keyCodes']?['glfw'] as List?)?.cast() ?? [], ); } @@ -299,9 +299,9 @@ class PhysicalKeyEntry { /// The Windows scan code of the key from Chromium's header file. final int? windowsScanCode; /// The macOS scan code of the key from Chromium's header file. - final int? macOsScanCode; + final int? macOSScanCode; /// The iOS scan code of the key from UIKey's documentation (USB Hid table) - final int? iosScanCode; + final int? iOSScanCode; /// The list of Android scan codes matching this key, created by looking up /// the Android name in the Chromium data, and substituting the Android scan /// code value. @@ -330,8 +330,8 @@ class PhysicalKeyEntry { 'linux': linuxScanCode, 'xkb': xKbScanCode, 'windows': windowsScanCode, - 'macos': macOsScanCode, - 'ios': iosScanCode, + 'macos': macOSScanCode, + 'ios': iOSScanCode, }, 'keyCodes': >{ 'glfw': glfwKeyCodes, @@ -380,9 +380,9 @@ class PhysicalKeyEntry { String toString() { return """'$constantName': (name: "$name", usbHidCode: ${toHex(usbHidCode)}, """ 'linuxScanCode: ${toHex(linuxScanCode)}, xKbScanCode: ${toHex(xKbScanCode)}, ' - 'windowsKeyCode: ${toHex(windowsScanCode)}, macOsScanCode: ${toHex(macOsScanCode)}, ' + 'windowsKeyCode: ${toHex(windowsScanCode)}, macOSScanCode: ${toHex(macOSScanCode)}, ' 'windowsScanCode: ${toHex(windowsScanCode)}, chromiumSymbolName: $chromiumCode ' - 'iOSScanCode: ${toHex(iosScanCode)})'; + 'iOSScanCode: ${toHex(iOSScanCode)})'; } static int compareByUsbHidCode(PhysicalKeyEntry a, PhysicalKeyEntry b) =>