Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Web] Update modifier state when Meta key is seen as Process key #50779

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/web_ui/lib/src/engine/raw_keyboard.dart
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ class RawKeyboard {
} else if (event.key == 'Meta' && operatingSystem == OperatingSystem.linux) {
// On Chrome Linux, metaState can be wrong when a Meta key is pressed.
_lastMetaState |= _modifierMeta;
} else if (event.code == 'MetaLeft' && event.key == 'Process') {
// When Meta key is pressed, browsers can emit an event whose key is 'Process'.
// See https://github.com/flutter/flutter/issues/141186.
_lastMetaState |= _modifierMeta;
}
}
final Map<String, dynamic> eventData = <String, dynamic>{
Expand Down
34 changes: 33 additions & 1 deletion lib/web_ui/test/engine/raw_keyboard_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ void testMain() {
});

// Regression test for https://github.com/flutter/flutter/issues/125672.
test('updates meta state for Meta key and wrong DOM event metaKey value', () {
test('updates meta state for Meta key and wrong DOM event metaKey value (Linux)', () {
RawKeyboard.initialize();

Map<String, dynamic>? dataReceived;
Expand Down Expand Up @@ -181,6 +181,38 @@ void testMain() {
RawKeyboard.instance!.dispose();
}, skip: operatingSystem != OperatingSystem.linux);

// Regression test for https://github.com/flutter/flutter/issues/141186.
test('updates meta state for Meta key seen as "Process" key', () {
RawKeyboard.initialize();

Map<String, dynamic>? dataReceived;
ui.PlatformDispatcher.instance.onPlatformMessage = (String channel, ByteData? data,
ui.PlatformMessageResponseCallback? callback) {
dataReceived = const JSONMessageCodec().decodeMessage(data) as Map<String, dynamic>?;
};

// Purposely send a DOM event where Meta key is pressed but event.metaKey is not set to true.
// This can happen when the Meta key is seen as the 'Process' key.
final DomKeyboardEvent event = dispatchKeyboardEvent(
'keydown',
key: 'Process',
code: 'MetaLeft',
location: 1,
keyCode: 229,
);
expect(event.defaultPrevented, isFalse);
expect(dataReceived, <String, dynamic>{
'type': 'keydown',
'keymap': 'web',
'code': 'MetaLeft',
'key': 'Process',
'location': 1,
'metaState': 0x8,
'keyCode': 229,
});
RawKeyboard.instance!.dispose();
});

test('dispatches repeat events', () {
RawKeyboard.initialize();

Expand Down