[Keyboard, iOS] Generate iOS's special key mapping (#106909)

This commit is contained in:
Tong Mu
2022-07-13 15:40:06 -07:00
committed by GitHub
parent cadb264d26
commit d87faf921d
7 changed files with 99 additions and 29 deletions

View File

@@ -48,4 +48,9 @@ const std::set<uint32_t> functionKeyCodes = {
@@@IOS_FUNCTION_KEY_SET@@@
};
API_AVAILABLE(ios(13.4))
NSDictionary<NSString*, NSNumber*>* specialKeyMapping = [[NSDictionary alloc] initWithDictionary:@{
@@@SPECIAL_KEY_MAPPING@@@
}];
@@@SPECIAL_KEY_CONSTANTS@@@

View File

@@ -78,6 +78,15 @@ const Map<int, PhysicalKeyboardKey> kIosToPhysicalKey = <int, PhysicalKeyboardKe
@@@IOS_SCAN_CODE_MAP@@@
};
/// Maps iOS specific string values of nonvisible keys to logical keys
///
/// Some unprintable keys on iOS has literal names on their key label, such as
/// "UIKeyInputEscape". See:
/// https://developer.apple.com/documentation/uikit/uikeycommand/input_strings_for_special_keys?language=objc
const Map<String, LogicalKeyboardKey> kIosSpecialLogicalMap = <String, LogicalKeyboardKey>{
@@@IOS_SPECIAL_MAP@@@
};
/// A map of iOS 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.

View File

@@ -0,0 +1,30 @@
// 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.
/// Maps iOS's special key labels to logical key names.
///
/// See https://developer.apple.com/documentation/uikit/uikeycommand/input_strings_for_special_keys?language=objc
const Map<String, String> kIosSpecialKeyMapping = <String, String>{
'UIKeyInputEscape': 'Escape',
'UIKeyInputF1': 'F1',
'UIKeyInputF2': 'F2',
'UIKeyInputF3': 'F3',
'UIKeyInputF4': 'F4',
'UIKeyInputF5': 'F5',
'UIKeyInputF6': 'F6',
'UIKeyInputF7': 'F7',
'UIKeyInputF8': 'F8',
'UIKeyInputF9': 'F9',
'UIKeyInputF10': 'F10',
'UIKeyInputF11': 'F11',
'UIKeyInputF12': 'F12',
'UIKeyInputUpArrow': 'ArrowUp',
'UIKeyInputDownArrow': 'ArrowDown',
'UIKeyInputLeftArrow': 'ArrowLeft',
'UIKeyInputRightArrow': 'ArrowRight',
'UIKeyInputHome': 'Home',
'UIKeyInputEnd': 'Enter',
'UIKeyInputPageUp': 'PageUp',
'UIKeyInputPageDown': 'PageDown',
};

View File

@@ -6,6 +6,7 @@ import 'package:path/path.dart' as path;
import 'base_code_gen.dart';
import 'constants.dart';
import 'data.dart';
import 'logical_key_data.dart';
import 'physical_key_data.dart';
import 'utils.dart';
@@ -105,6 +106,15 @@ class IOSCodeGenerator extends PlatformCodeGenerator {
return modifierKeyMap.toString().trimRight();
}
String get _specialKeyMapping {
final OutputLines<int> lines = OutputLines<int>('iOS special key mapping');
kIosSpecialKeyMapping.forEach((String key, String logicalName) {
final int value = logicalData.entryByName(logicalName).value;
lines.add(value, ' @"$key" : @(${toHex(value)}),');
});
return lines.join().trimRight();
}
/// This generates some keys that needs special attention.
String get _specialKeyConstants {
final StringBuffer specialKeyConstants = StringBuffer();
@@ -137,6 +147,7 @@ class IOSCodeGenerator extends PlatformCodeGenerator {
'KEYCODE_TO_MODIFIER_FLAG_MAP': _keyToModifierFlagMap,
'MODIFIER_FLAG_TO_KEYCODE_MAP': _modifierFlagToKeyMap,
'SPECIAL_KEY_CONSTANTS': _specialKeyConstants,
'SPECIAL_KEY_MAPPING': _specialKeyMapping,
};
}
}

View File

@@ -7,6 +7,7 @@ import 'dart:io';
import 'package:path/path.dart' as path;
import 'base_code_gen.dart';
import 'data.dart';
import 'logical_key_data.dart';
import 'physical_key_data.dart';
import 'utils.dart';
@@ -246,6 +247,16 @@ class KeyboardMapsCodeGenerator extends BaseCodeGenerator {
return lines.sortedJoin().trimRight();
}
/// This generates the map of iOS key label to logical keys for special keys.
String get _iOSSpecialMap {
final OutputLines<int> lines = OutputLines<int>('iOS special key mapping');
kIosSpecialKeyMapping.forEach((String key, String logicalName) {
final LogicalKeyEntry entry = logicalData.entryByName(logicalName);
lines.add(entry.value, " '$key': LogicalKeyboardKey.${entry.constantName},");
});
return lines.join().trimRight();
}
/// This generates the map of iOS number pad key codes to logical keys.
String get _iOSNumpadMap {
final OutputLines<int> lines = OutputLines<int>('iOS numpad map');
@@ -353,6 +364,7 @@ class KeyboardMapsCodeGenerator extends BaseCodeGenerator {
'MACOS_FUNCTION_KEY_MAP': _macOSFunctionKeyMap,
'MACOS_KEY_CODE_MAP': _macOSKeyCodeMap,
'IOS_SCAN_CODE_MAP': _iOSScanCodeMap,
'IOS_SPECIAL_MAP': _iOSSpecialMap,
'IOS_NUMPAD_MAP': _iOSNumpadMap,
'IOS_KEY_CODE_MAP': _iOSKeyCodeMap,
'GLFW_KEY_CODE_MAP': _glfwKeyCodeMap,