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

Commit 86eea35

Browse files
committed
[Web] Synthesize modifiers key up based on known logical key
1 parent ee48c03 commit 86eea35

File tree

3 files changed

+40
-7
lines changed

3 files changed

+40
-7
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 & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -584,31 +584,27 @@ class KeyboardConverter {
584584
_kPhysicalAltLeft,
585585
_kPhysicalAltRight,
586586
_kLogicalAltLeft,
587-
_kLogicalAltRight,
588587
altPressed ? ui.KeyEventType.down : ui.KeyEventType.up,
589588
eventTimestamp,
590589
);
591590
_synthesizeModifierIfNeeded(
592591
_kPhysicalControlLeft,
593592
_kPhysicalControlRight,
594593
_kLogicalControlLeft,
595-
_kLogicalControlRight,
596594
controlPressed ? ui.KeyEventType.down : ui.KeyEventType.up,
597595
eventTimestamp,
598596
);
599597
_synthesizeModifierIfNeeded(
600598
_kPhysicalMetaLeft,
601599
_kPhysicalMetaRight,
602600
_kLogicalMetaLeft,
603-
_kLogicalMetaRight,
604601
metaPressed ? ui.KeyEventType.down : ui.KeyEventType.up,
605602
eventTimestamp,
606603
);
607604
_synthesizeModifierIfNeeded(
608605
_kPhysicalShiftLeft,
609606
_kPhysicalShiftRight,
610607
_kLogicalShiftLeft,
611-
_kLogicalShiftRight,
612608
shiftPressed ? ui.KeyEventType.down : ui.KeyEventType.up,
613609
eventTimestamp,
614610
);
@@ -618,7 +614,6 @@ class KeyboardConverter {
618614
int physicalLeft,
619615
int physicalRight,
620616
int logicalLeft,
621-
int logicalRight,
622617
ui.KeyEventType type,
623618
num domTimestamp,
624619
) {
@@ -635,12 +630,14 @@ class KeyboardConverter {
635630

636631
// Synthesize an up event for left key if pressed
637632
if (synthesizeUp && leftPressed) {
638-
_synthesizeKeyUpEvent(domTimestamp, physicalLeft, logicalLeft);
633+
final int knownLogicalKey = _pressingRecords[physicalLeft]!;
634+
_synthesizeKeyUpEvent(domTimestamp, physicalLeft, knownLogicalKey);
639635
}
640636

641637
// Synthesize an up event for right key if pressed
642638
if (synthesizeUp && rightPressed) {
643-
_synthesizeKeyUpEvent(domTimestamp, physicalRight, logicalRight);
639+
final int knownLogicalKey = _pressingRecords[physicalRight]!;
640+
_synthesizeKeyUpEvent(domTimestamp, physicalRight, knownLogicalKey);
644641
}
645642
}
646643

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 for AltGraph',
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)