Unverified Commit 6b087c74 authored by Greg Spencer's avatar Greg Spencer Committed by GitHub

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.
parent 62d00c6d
......@@ -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<void> main(List<String> rawArguments) async {
physicalData,
logicalData,
),
'macos': MacOsCodeGenerator(
'macos': MacOSCodeGenerator(
physicalData,
logicalData,
),
'ios': IOSCodeGenerator(
physicalData,
logicalData,
),
......
......@@ -5,11 +5,15 @@
#include <map>
// 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<int, int> g_fuchsia_to_logical_key = {
......
......@@ -5,11 +5,15 @@
#include <map>
// 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<int, int> g_glfw_to_logical_key = {
......
// 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 <map>
#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<uint32_t, uint32_t> keyCodeToPhysicalKey = {
@@@IOS_SCAN_CODE_MAP@@@
};
const std::map<uint32_t, uint32_t> keyCodeToLogicalKey = {
@@@IOS_KEYCODE_LOGICAL_MAP@@@
};
const std::map<uint32_t, uint32_t> keyCodeToModifierFlag = {
@@@KEYCODE_TO_MODIFIER_FLAG_MAP@@@
};
const std::map<uint32_t, uint32_t> modifierFlagToKeyCode = {
@@@MODIFIER_FLAG_TO_KEYCODE_MAP@@@
};
@@@SPECIAL_KEY_CONSTANTS@@@
\ No newline at end of file
......@@ -5,13 +5,16 @@
#include <map>
// 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<int, int> g_ios_to_physical_key = {
......
......@@ -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@@@
......
......@@ -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 {
......
// 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<String> kModifiersOfInterest = <String>[
'ShiftLeft',
'ShiftRight',
'ControlLeft',
'ControlRight',
'AltLeft',
'AltRight',
'MetaLeft',
'MetaRight',
];
// The name of keys that require special attention.
const List<String> kSpecialPhysicalKeys = <String>['CapsLock'];
const List<String> kSpecialLogicalKeys = <String>['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<String, String> 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 <String, String>{
'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,
};
}
}
......@@ -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<int> lines = OutputLines<int>('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<int> lines = OutputLines<int>('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<int> lines = OutputLines<int>('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<int> lines = OutputLines<int>('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,
......
......@@ -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 = <String>[],
macOsKeyCodeNames = <String>[],
macOsKeyCodeValues = <int>[],
iosKeyCodeNames = <String>[],
iosKeyCodeValues = <int>[],
macOSKeyCodeNames = <String>[],
macOSKeyCodeValues = <int>[],
iOSKeyCodeNames = <String>[],
iOSKeyCodeValues = <int>[],
gtkNames = <String>[],
gtkValues = <int>[],
windowsNames = <String>[],
......@@ -441,10 +441,10 @@ class LogicalKeyEntry {
: value = map['value'] as int,
name = map['name'] as String,
webNames = _toNonEmptyArray<String>(map['names']['web']),
macOsKeyCodeNames = _toNonEmptyArray<String>(map['names']['macOs']),
macOsKeyCodeValues = _toNonEmptyArray<int>(map['values']?['macOs']),
iosKeyCodeNames = _toNonEmptyArray<String>(map['names']['ios']),
iosKeyCodeValues = _toNonEmptyArray<int>(map['values']?['ios']),
macOSKeyCodeNames = _toNonEmptyArray<String>(map['names']['macos']),
macOSKeyCodeValues = _toNonEmptyArray<int>(map['values']?['macos']),
iOSKeyCodeNames = _toNonEmptyArray<String>(map['names']['ios']),
iOSKeyCodeValues = _toNonEmptyArray<int>(map['values']?['ios']),
gtkNames = _toNonEmptyArray<String>(map['names']['gtk']),
gtkValues = _toNonEmptyArray<int>(map['values']?['gtk']),
windowsNames = _toNonEmptyArray<String>(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<String> macOsKeyCodeNames;
final List<String> 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<int> macOsKeyCodeValues;
final List<int> macOSKeyCodeValues;
/// The names of the key codes that corresponds to this logical key on iOS,
/// created from the corresponding physical keys.
final List<String> iosKeyCodeNames;
final List<String> 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<int> iosKeyCodeValues;
final List<int> 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': <String, dynamic>{
'web': webNames,
'macOs': macOsKeyCodeNames,
'ios': iosKeyCodeNames,
'macos': macOSKeyCodeNames,
'ios': iOSKeyCodeNames,
'gtk': gtkNames,
'windows': windowsNames,
'android': androidNames,
},
'values': <String, List<int>>{
'macOs': macOsKeyCodeValues,
'ios': iosKeyCodeValues,
'macos': macOSKeyCodeValues,
'ios': iOSKeyCodeValues,
'gtk': gtkValues,
'windows': windowsValues,
'android': androidValues,
......
......@@ -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();
}
......
......@@ -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<dynamic>?)?.cast<int>() ?? <int>[],
);
}
......@@ -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': <String, List<int>>{
'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) =>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment