diff --git a/lib/web_ui/lib/src/engine/raw_keyboard.dart b/lib/web_ui/lib/src/engine/raw_keyboard.dart index d4aa87b6bbc90..54ba7ae93c04d 100644 --- a/lib/web_ui/lib/src/engine/raw_keyboard.dart +++ b/lib/web_ui/lib/src/engine/raw_keyboard.dart @@ -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 eventData = { diff --git a/lib/web_ui/test/engine/raw_keyboard_test.dart b/lib/web_ui/test/engine/raw_keyboard_test.dart index 7c7ff009767d9..cece887b99149 100644 --- a/lib/web_ui/test/engine/raw_keyboard_test.dart +++ b/lib/web_ui/test/engine/raw_keyboard_test.dart @@ -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? dataReceived; @@ -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? dataReceived; + ui.PlatformDispatcher.instance.onPlatformMessage = (String channel, ByteData? data, + ui.PlatformMessageResponseCallback? callback) { + dataReceived = const JSONMessageCodec().decodeMessage(data) as Map?; + }; + + // 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, { + 'type': 'keydown', + 'keymap': 'web', + 'code': 'MetaLeft', + 'key': 'Process', + 'location': 1, + 'metaState': 0x8, + 'keyCode': 229, + }); + RawKeyboard.instance!.dispose(); + }); + test('dispatches repeat events', () { RawKeyboard.initialize();