RawKeyboardMacos accepts a new field "specifiedLogicalKey" (#100803)

This commit is contained in:
Tong Mu
2022-04-14 11:24:11 -07:00
committed by GitHub
parent 08e467dde7
commit c5e3e1cf5f
6 changed files with 63 additions and 3 deletions

View File

@@ -83,9 +83,9 @@ class LogicalKeyboardKey extends KeyboardKey {
const int valueMaskWidth = 32;
// Equivalent to assert(divisorForValueMask == (1 << valueMaskWidth)).
const int _firstDivisorWidth = 28;
const int firstDivisorWidth = 28;
assert(divisorForValueMask ==
(1 << _firstDivisorWidth) * (1 << (valueMaskWidth - _firstDivisorWidth)));
(1 << firstDivisorWidth) * (1 << (valueMaskWidth - firstDivisorWidth)));
// JS only supports up to 2^53 - 1, therefore non-value bits can only
// contain (maxSafeIntegerWidth - valueMaskWidth) bits.

View File

@@ -4,7 +4,7 @@
#import <Cocoa/Cocoa.h>
#import <Foundation/Foundation.h>
#include "./KeyCodeMap_internal.h"
#include "./KeyCodeMap_Internal.h"
// DO NOT EDIT -- DO NOT EDIT -- DO NOT EDIT
// This file is generated by
@@ -17,6 +17,8 @@
//
// See flutter/flutter:dev/tools/gen_keycodes/README.md for more information.
namespace flutter {
@@@MASK_CONSTANTS@@@
const NSDictionary* keyCodeToPhysicalKey = @{
@@ -36,3 +38,9 @@ const NSDictionary* modifierFlagToKeyCode = @{
};
@@@SPECIAL_KEY_CONSTANTS@@@
const std::vector<LayoutGoal> layoutGoals = {
@@@LAYOUT_GOALS@@@
};
} // namespace flutter

View File

@@ -96,6 +96,27 @@ class MacOSCodeGenerator extends PlatformCodeGenerator {
return specialKeyConstants.toString().trimRight();
}
String get _layoutGoals {
final OutputLines<int> lines = OutputLines<int>('macOS layout goals');
final Iterable<LogicalKeyEntry> asciiEntries = logicalData.entries.where(
(LogicalKeyEntry entry) => entry.value <= 128);
for (final LogicalKeyEntry logicalEntry in asciiEntries) {
final int value = logicalEntry.value;
final PhysicalKeyEntry? physicalEntry = keyData.tryEntryByName(logicalEntry.name);
if (physicalEntry == null) {
continue;
}
final bool mandatory = (value >= '0'.codeUnitAt(0) && value <= '9'.codeUnitAt(0))
|| (value >= 'a'.codeUnitAt(0) && value <= 'z'.codeUnitAt(0));
lines.add(value,
' LayoutGoal{${toHex(physicalEntry.macOSScanCode, digits: 2)}, '
'${toHex(value, digits: 2)}, '
'${mandatory ? 'true}, ' : 'false},'}'
' // ${logicalEntry.name}');
}
return lines.sortedJoin().trimRight();
}
@override
String get templatePath => path.join(dataRoot, 'macos_key_code_map_cc.tmpl');
@@ -115,6 +136,7 @@ class MacOSCodeGenerator extends PlatformCodeGenerator {
'KEYCODE_TO_MODIFIER_FLAG_MAP': _keyToModifierFlagMap,
'MODIFIER_FLAG_TO_KEYCODE_MAP': _modifierFlagToKeyMap,
'SPECIAL_KEY_CONSTANTS': _specialKeyConstants,
'LAYOUT_GOALS': _layoutGoals,
};
}
}