Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 91f60e7

Browse files
committed
[Web] Synthesize modifiers key up based on known logical key
1 parent 138aceb commit 91f60e7

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

lib/web_ui/lib/src/engine/key_map.g.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,7 @@ const Map<String, List<int?>> kWebLogicalLocationMap = <String, List<int?>>{
574574
'8': <int?>[0x00000000038, null, null, 0x00200000238], // digit8, null, null, numpad8
575575
'9': <int?>[0x00000000039, null, null, 0x00200000239], // digit9, null, null, numpad9
576576
'Alt': <int?>[0x00200000104, 0x00200000104, 0x00200000105, null], // altLeft, altLeft, altRight, null
577+
'AltGraph': <int?>[0x00100000103, null, 0x00100000103, null], // altGraph, null, altGraph, null
577578
'ArrowDown': <int?>[0x00100000301, null, null, 0x00200000232], // arrowDown, null, null, numpad2
578579
'ArrowLeft': <int?>[0x00100000302, null, null, 0x00200000234], // arrowLeft, null, null, numpad4
579580
'ArrowRight': <int?>[0x00100000303, null, null, 0x00200000236], // arrowRight, null, null, numpad6

lib/web_ui/lib/src/engine/keyboard_binding.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -635,12 +635,14 @@ class KeyboardConverter {
635635

636636
// Synthesize an up event for left key if pressed
637637
if (synthesizeUp && leftPressed) {
638-
_synthesizeKeyUpEvent(domTimestamp, physicalLeft, logicalLeft);
638+
final int knownLogicalKey = _pressingRecords[physicalLeft]!;
639+
_synthesizeKeyUpEvent(domTimestamp, physicalLeft, knownLogicalKey);
639640
}
640641

641642
// Synthesize an up event for right key if pressed
642643
if (synthesizeUp && rightPressed) {
643-
_synthesizeKeyUpEvent(domTimestamp, physicalRight, logicalRight);
644+
final int knownLogicalKey = _pressingRecords[physicalRight]!;
645+
_synthesizeKeyUpEvent(domTimestamp, physicalRight, knownLogicalKey);
644646
}
645647
}
646648

lib/web_ui/test/engine/pointer_binding_test.dart

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -760,6 +760,41 @@ void testMain() {
760760
},
761761
);
762762

763+
_testEach<_BasicEventContext>(
764+
<_BasicEventContext>[
765+
_PointerEventContext(),
766+
_MouseEventContext(),
767+
_TouchEventContext(),
768+
],
769+
'should synthesize modifier keys up event using known pressed logical key',
770+
(_BasicEventContext context) {
771+
PointerBinding.instance!.debugOverrideDetector(context);
772+
773+
final List<ui.KeyData> keyDataList = <ui.KeyData>[];
774+
final KeyboardConverter keyboardConverter = createKeyboardConverter(keyDataList);
775+
PointerBinding.instance!.debugOverrideKeyboardConverter(keyboardConverter);
776+
777+
final int physicalAltRight = kWebToPhysicalKey['AltRight']!;
778+
final int logicalAltGraph = kWebLogicalLocationMap['AltGraph']![0]!;
779+
780+
// Simulate pressing `AltGr` key.
781+
keyboardConverter.handleEvent(keyDownEvent('AltRight', 'AltGraph'));
782+
expect(keyboardConverter.debugKeyIsPressed(physicalAltRight), true);
783+
keyDataList.clear(); // Remove key data generated by handleEvent.
784+
785+
glassPane.dispatchEvent(context.primaryDown());
786+
expect(keyDataList.length, 1);
787+
expectKeyData(keyDataList.last,
788+
type: ui.KeyEventType.up,
789+
physical: physicalAltRight,
790+
logical: logicalAltGraph,
791+
character: null,
792+
synthesized: true,
793+
);
794+
expect(keyboardConverter.debugKeyIsPressed(physicalAltRight), false);
795+
},
796+
);
797+
763798
_testEach<_ButtonedEventMixin>(
764799
<_ButtonedEventMixin>[
765800
if (!isIosSafari) _PointerEventContext(),

0 commit comments

Comments
 (0)