mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00

This PR updates the ID used by logical keyboard keys. The logical key ID is still composed of 2 parts: 32 bits of value, and 8 bits of plane. But the assignment of planes has been drastically changed. HID plane is removed, and unprintable plane and Flutter plane are added. This is to reflect the new generation method for logical key IDs. Now keys that are defined by Flutter but not by dom_key_data are placed into the Flutter plane, including numpad keys, sided modifier keys, and gamepad keys. The values for platform planes have also been adjusted. The generation script and README have been updated accordingly as well. A new file, test_utils/key_codes.h is now generated to assist engine unit testing. All lists generated by the script are now sorted by the key.
52 lines
1.8 KiB
Dart
52 lines
1.8 KiB
Dart
// 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 'logical_key_data.dart';
|
|
import 'physical_key_data.dart';
|
|
import 'utils.dart';
|
|
|
|
String _toUpperCammel(String lowerCammel) {
|
|
return lowerCammel.substring(0, 1).toUpperCase() + lowerCammel.substring(1);
|
|
}
|
|
|
|
/// Generates the common/testing/key_codes.h based on the information in the key
|
|
/// data structure given to it.
|
|
class KeyCodesCcGenerator extends BaseCodeGenerator {
|
|
KeyCodesCcGenerator(PhysicalKeyData keyData, LogicalKeyData logicalData) : super(keyData, logicalData);
|
|
|
|
/// Gets the generated definitions of PhysicalKeyboardKeys.
|
|
String get _physicalDefinitions {
|
|
final OutputLines<int> lines = OutputLines<int>('Physical Key list');
|
|
for (final PhysicalKeyEntry entry in keyData.entries) {
|
|
lines.add(entry.usbHidCode, '''
|
|
constexpr uint64_t kPhysical${_toUpperCammel(entry.constantName)} = ${toHex(entry.usbHidCode, digits: 8)};''');
|
|
}
|
|
return lines.sortedJoin().trimRight();
|
|
}
|
|
|
|
/// Gets the generated definitions of PhysicalKeyboardKeys.
|
|
String get _logicalDefinitions {
|
|
final OutputLines<int> lines = OutputLines<int>('Logical Key list');
|
|
for (final LogicalKeyEntry entry in logicalData.entries) {
|
|
lines.add(entry.value, '''
|
|
constexpr uint64_t kLogical${_toUpperCammel(entry.constantName)} = ${toHex(entry.value, digits: 11)};''');
|
|
}
|
|
return lines.sortedJoin().trimRight();
|
|
}
|
|
|
|
@override
|
|
String get templatePath => path.join(dataRoot, 'key_codes_h.tmpl');
|
|
|
|
@override
|
|
Map<String, String> mappings() {
|
|
return <String, String>{
|
|
'LOGICAL_KEY_DEFINITIONS': _logicalDefinitions,
|
|
'PHYSICAL_KEY_DEFINITIONS': _physicalDefinitions,
|
|
};
|
|
}
|
|
}
|