Unverified Commit 31e2618b authored by Tong Mu's avatar Tong Mu Committed by GitHub

[RawKeyboard] Allow inconsistent modifiers for iOS and Android (#108926)

parent 23d17e30
...@@ -836,10 +836,13 @@ class RawKeyboard { ...@@ -836,10 +836,13 @@ class RawKeyboard {
// exist in the modifier list. Enforce the pressing state. // exist in the modifier list. Enforce the pressing state.
if (event is RawKeyDownEvent && thisKeyModifier != null if (event is RawKeyDownEvent && thisKeyModifier != null
&& !_keysPressed.containsKey(event.physicalKey)) { && !_keysPressed.containsKey(event.physicalKey)) {
// So far this inconsistancy is only found on Linux GTK for AltRight in a // This inconsistancy is found on Linux GTK for AltRight:
// rare case. (See https://github.com/flutter/flutter/issues/93278 .) In // https://github.com/flutter/flutter/issues/93278
// other cases, this inconsistancy will be caught by an assertion later. // And also on Android and iOS:
if (event.data is RawKeyEventDataLinux && event.physicalKey == PhysicalKeyboardKey.altRight) { // https://github.com/flutter/flutter/issues/101090
if ((event.data is RawKeyEventDataLinux && event.physicalKey == PhysicalKeyboardKey.altRight)
|| event.data is RawKeyEventDataIos
|| event.data is RawKeyEventDataAndroid) {
final LogicalKeyboardKey? logicalKey = _allModifiersExceptFn[event.physicalKey]; final LogicalKeyboardKey? logicalKey = _allModifiersExceptFn[event.physicalKey];
if (logicalKey != null) { if (logicalKey != null) {
_keysPressed[event.physicalKey] = logicalKey; _keysPressed[event.physicalKey] = logicalKey;
......
...@@ -759,12 +759,11 @@ void main() { ...@@ -759,12 +759,11 @@ void main() {
} else { } else {
keyEventMessage = const <String, dynamic>{ keyEventMessage = const <String, dynamic>{
'type': 'keydown', 'type': 'keydown',
'keymap': 'android', 'keymap': 'windows',
'keyCode': 0x3b, // Left shift key keyCode 'keyCode': 16, // Left shift key keyCode
'scanCode': 0x2a, 'characterCodePoint': 0,
'metaState': 0x0, // No shift key metaState set! 'scanCode': 42,
'source': 0x101, 'modifiers': 0x0, // No shift key metaState set!
'deviceId': 1,
}; };
} }
...@@ -784,6 +783,65 @@ void main() { ...@@ -784,6 +783,65 @@ void main() {
); );
}); });
testWidgets('Allows inconsistent modifier for iOS', (WidgetTester _) async {
// Use `testWidgets` for clean-ups.
final List<RawKeyEvent> events = <RawKeyEvent>[];
RawKeyboard.instance.addListener(events.add);
addTearDown(() {
RawKeyboard.instance.removeListener(events.add);
});
await TestDefaultBinaryMessengerBinding.instance!.defaultBinaryMessenger.handlePlatformMessage(
SystemChannels.keyEvent.name,
SystemChannels.keyEvent.codec.encodeMessage(const <String, dynamic>{
'type': 'keydown',
'keymap': 'ios',
'keyCode': 0x00000039,
'characters': '',
'charactersIgnoringModifiers': '',
'modifiers': 0,
}),
(ByteData? data) { },
);
expect(events, hasLength(1));
final RawKeyEvent capsLockKey = events[0];
final RawKeyEventDataIos data = capsLockKey.data as RawKeyEventDataIos;
expect(data.physicalKey, equals(PhysicalKeyboardKey.capsLock));
expect(data.logicalKey, equals(LogicalKeyboardKey.capsLock));
expect(RawKeyboard.instance.keysPressed, contains(LogicalKeyboardKey.capsLock));
}, skip: isBrowser); // [intended] This is an iOS-specific group.
testWidgets('Allows inconsistent modifier for Android', (WidgetTester _) async {
// Use `testWidgets` for clean-ups.
final List<RawKeyEvent> events = <RawKeyEvent>[];
RawKeyboard.instance.addListener(events.add);
addTearDown(() {
RawKeyboard.instance.removeListener(events.add);
});
await TestDefaultBinaryMessengerBinding.instance!.defaultBinaryMessenger.handlePlatformMessage(
SystemChannels.keyEvent.name,
SystemChannels.keyEvent.codec.encodeMessage(const <String, dynamic>{
'type': 'keydown',
'keymap': 'android',
'keyCode': 115,
'plainCodePoint': 0,
'codePoint': 0,
'scanCode': 58,
'metaState': 0,
'source': 0x101,
'deviceId': 1,
}),
(ByteData? data) { },
);
expect(events, hasLength(1));
final RawKeyEvent capsLockKey = events[0];
final RawKeyEventDataAndroid data = capsLockKey.data as RawKeyEventDataAndroid;
expect(data.physicalKey, equals(PhysicalKeyboardKey.capsLock));
expect(data.logicalKey, equals(LogicalKeyboardKey.capsLock));
expect(RawKeyboard.instance.keysPressed, contains(LogicalKeyboardKey.capsLock));
}, skip: isBrowser); // [intended] This is an Android-specific group.
testWidgets('Dispatch events to all handlers', (WidgetTester tester) async { testWidgets('Dispatch events to all handlers', (WidgetTester tester) async {
final FocusNode focusNode = FocusNode(); final FocusNode focusNode = FocusNode();
final List<int> logs = <int>[]; final List<int> logs = <int>[];
......
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