From 179876fe94edb09c6912ddadb8e1ff7d2c411281 Mon Sep 17 00:00:00 2001 From: moko256 Date: Tue, 8 Mar 2022 06:29:48 +0900 Subject: [PATCH] Web: treat modifier key without location (generate key map from flutter/flutter#98460) (flutter/engine#31550) --- .../lib/web_ui/lib/src/engine/key_map.dart | 8 +- .../web_ui/test/keyboard_converter_test.dart | 77 +++++++++++++++++++ 2 files changed, 81 insertions(+), 4 deletions(-) diff --git a/engine/src/flutter/lib/web_ui/lib/src/engine/key_map.dart b/engine/src/flutter/lib/web_ui/lib/src/engine/key_map.dart index 5841e8adc5..6d473540d0 100644 --- a/engine/src/flutter/lib/web_ui/lib/src/engine/key_map.dart +++ b/engine/src/flutter/lib/web_ui/lib/src/engine/key_map.dart @@ -609,20 +609,20 @@ const Map> kWebLogicalLocationMap = >{ '7': [0x00000000037, null, null, 0x00200000237], // digit7, null, null, numpad7 '8': [0x00000000038, null, null, 0x00200000238], // digit8, null, null, numpad8 '9': [0x00000000039, null, null, 0x00200000239], // digit9, null, null, numpad9 - 'Alt': [null, 0x00200000104, 0x00200000105, null], // null, altLeft, altRight, null + 'Alt': [0x00200000104, 0x00200000104, 0x00200000105, null], // altLeft, altLeft, altRight, null 'ArrowDown': [0x00100000301, null, null, 0x00200000232], // arrowDown, null, null, numpad2 'ArrowLeft': [0x00100000302, null, null, 0x00200000234], // arrowLeft, null, null, numpad4 'ArrowRight': [0x00100000303, null, null, 0x00200000236], // arrowRight, null, null, numpad6 'ArrowUp': [0x00100000304, null, null, 0x00200000238], // arrowUp, null, null, numpad8 'Clear': [0x00100000401, null, null, 0x00200000235], // clear, null, null, numpad5 - 'Control': [null, 0x00200000100, 0x00200000101, null], // null, controlLeft, controlRight, null + 'Control': [0x00200000100, 0x00200000100, 0x00200000101, null], // controlLeft, controlLeft, controlRight, null 'Delete': [0x0010000007f, null, null, 0x0020000022e], // delete, null, null, numpadDecimal 'End': [0x00100000305, null, null, 0x00200000231], // end, null, null, numpad1 'Enter': [0x0010000000d, null, null, 0x0020000020d], // enter, null, null, numpadEnter 'Home': [0x00100000306, null, null, 0x00200000237], // home, null, null, numpad7 'Insert': [0x00100000407, null, null, 0x00200000230], // insert, null, null, numpad0 - 'Meta': [null, 0x00200000106, 0x00200000107, null], // null, metaLeft, metaRight, null + 'Meta': [0x00200000106, 0x00200000106, 0x00200000107, null], // metaLeft, metaLeft, metaRight, null 'PageDown': [0x00100000307, null, null, 0x00200000233], // pageDown, null, null, numpad3 'PageUp': [0x00100000308, null, null, 0x00200000239], // pageUp, null, null, numpad9 - 'Shift': [null, 0x00200000102, 0x00200000103, null], // null, shiftLeft, shiftRight, null + 'Shift': [0x00200000102, 0x00200000102, 0x00200000103, null], // shiftLeft, shiftLeft, shiftRight, null }; diff --git a/engine/src/flutter/lib/web_ui/test/keyboard_converter_test.dart b/engine/src/flutter/lib/web_ui/test/keyboard_converter_test.dart index aafcbabcfe..3391a703c4 100644 --- a/engine/src/flutter/lib/web_ui/test/keyboard_converter_test.dart +++ b/engine/src/flutter/lib/web_ui/test/keyboard_converter_test.dart @@ -9,6 +9,7 @@ import 'package:test/test.dart'; import 'package:ui/src/engine.dart'; import 'package:ui/ui.dart' as ui; +const int kLocationStandard = 0; const int kLocationLeft = 1; const int kLocationRight = 2; const int kLocationNumpad = 3; @@ -24,6 +25,8 @@ final int kPhysicalMetaLeft = kWebToPhysicalKey['MetaLeft']!; final int kPhysicalTab = kWebToPhysicalKey['Tab']!; final int kPhysicalCapsLock = kWebToPhysicalKey['CapsLock']!; final int kPhysicalScrollLock = kWebToPhysicalKey['ScrollLock']!; +// A web-specific physical key when code is empty. +const int kPhysicalEmptyCode = 0x1700000000; const int kLogicalKeyA = 0x00000000061; const int kLogicalKeyU = 0x00000000075; @@ -31,6 +34,8 @@ const int kLogicalDigit1 = 0x00000000031; final int kLogicalNumpad1 = kWebLogicalLocationMap['1']![kLocationNumpad]!; final int kLogicalShiftLeft = kWebLogicalLocationMap['Shift']![kLocationLeft]!; final int kLogicalShiftRight = kWebLogicalLocationMap['Shift']![kLocationRight]!; +final int kLogicalCtrlLeft = kWebLogicalLocationMap['Control']![kLocationLeft]!; +final int kLogicalAltLeft = kWebLogicalLocationMap['Alt']![kLocationLeft]!; final int kLogicalMetaLeft = kWebLogicalLocationMap['Meta']![kLocationLeft]!; const int kLogicalTab = 0x0000000009; final int kLogicalCapsLock = kWebToLogicalKey['CapsLock']!; @@ -264,6 +269,78 @@ void testMain() { ); }); + test('Treat modifiers at standard locations as if at left', () { + final List keyDataList = []; + final KeyboardConverter converter = KeyboardConverter((ui.KeyData key) { + keyDataList.add(key); + return true; + }); + + converter.handleEvent(keyDownEvent('', 'Shift', kShift, kLocationStandard)); + expectKeyData(keyDataList.last, + type: ui.KeyEventType.down, + physical: kPhysicalEmptyCode, + logical: kLogicalShiftLeft, + character: null, + ); + + converter.handleEvent(keyUpEvent('', 'Shift', kShift, kLocationStandard)); + expectKeyData(keyDataList.last, + type: ui.KeyEventType.up, + physical: kPhysicalEmptyCode, + logical: kLogicalShiftLeft, + character: null, + ); + + converter.handleEvent(keyDownEvent('', 'Control', kCtrl, kLocationStandard)); + expectKeyData(keyDataList.last, + type: ui.KeyEventType.down, + physical: kPhysicalEmptyCode, + logical: kLogicalCtrlLeft, + character: null, + ); + + converter.handleEvent(keyUpEvent('', 'Control', kCtrl, kLocationStandard)); + expectKeyData(keyDataList.last, + type: ui.KeyEventType.up, + physical: kPhysicalEmptyCode, + logical: kLogicalCtrlLeft, + character: null, + ); + + converter.handleEvent(keyDownEvent('', 'Alt', kAlt, kLocationStandard)); + expectKeyData(keyDataList.last, + type: ui.KeyEventType.down, + physical: kPhysicalEmptyCode, + logical: kLogicalAltLeft, + character: null, + ); + + converter.handleEvent(keyUpEvent('', 'Alt', kAlt, kLocationStandard)); + expectKeyData(keyDataList.last, + type: ui.KeyEventType.up, + physical: kPhysicalEmptyCode, + logical: kLogicalAltLeft, + character: null, + ); + + converter.handleEvent(keyDownEvent('', 'Meta', kMeta, kLocationStandard)); + expectKeyData(keyDataList.last, + type: ui.KeyEventType.down, + physical: kPhysicalEmptyCode, + logical: kLogicalMetaLeft, + character: null, + ); + + converter.handleEvent(keyUpEvent('', 'Meta', kMeta, kLocationStandard)); + expectKeyData(keyDataList.last, + type: ui.KeyEventType.up, + physical: kPhysicalEmptyCode, + logical: kLogicalMetaLeft, + character: null, + ); + }); + test('Distinguish between normal and numpad digits', () { final List keyDataList = []; final KeyboardConverter converter = KeyboardConverter((ui.KeyData key) {