Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
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
[Web] Synthesize modifiers key up based on known logical key
  • Loading branch information
bleroux committed Nov 7, 2022
commit 86eea35e7655a67ddabf9eaa5ac5350147e23d1a
1 change: 1 addition & 0 deletions lib/web_ui/lib/src/engine/key_map.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,7 @@ const Map<String, List<int?>> kWebLogicalLocationMap = <String, List<int?>>{
'8': <int?>[0x00000000038, null, null, 0x00200000238], // digit8, null, null, numpad8
'9': <int?>[0x00000000039, null, null, 0x00200000239], // digit9, null, null, numpad9
'Alt': <int?>[0x00200000104, 0x00200000104, 0x00200000105, null], // altLeft, altLeft, altRight, null
'AltGraph': <int?>[0x00100000103, null, 0x00100000103, null], // altGraph, null, altGraph, null
'ArrowDown': <int?>[0x00100000301, null, null, 0x00200000232], // arrowDown, null, null, numpad2
'ArrowLeft': <int?>[0x00100000302, null, null, 0x00200000234], // arrowLeft, null, null, numpad4
'ArrowRight': <int?>[0x00100000303, null, null, 0x00200000236], // arrowRight, null, null, numpad6
Expand Down
11 changes: 4 additions & 7 deletions lib/web_ui/lib/src/engine/keyboard_binding.dart
Original file line number Diff line number Diff line change
Expand Up @@ -584,31 +584,27 @@ class KeyboardConverter {
_kPhysicalAltLeft,
_kPhysicalAltRight,
_kLogicalAltLeft,
_kLogicalAltRight,
altPressed ? ui.KeyEventType.down : ui.KeyEventType.up,
eventTimestamp,
);
_synthesizeModifierIfNeeded(
_kPhysicalControlLeft,
_kPhysicalControlRight,
_kLogicalControlLeft,
_kLogicalControlRight,
controlPressed ? ui.KeyEventType.down : ui.KeyEventType.up,
eventTimestamp,
);
_synthesizeModifierIfNeeded(
_kPhysicalMetaLeft,
_kPhysicalMetaRight,
_kLogicalMetaLeft,
_kLogicalMetaRight,
metaPressed ? ui.KeyEventType.down : ui.KeyEventType.up,
eventTimestamp,
);
_synthesizeModifierIfNeeded(
_kPhysicalShiftLeft,
_kPhysicalShiftRight,
_kLogicalShiftLeft,
_kLogicalShiftRight,
shiftPressed ? ui.KeyEventType.down : ui.KeyEventType.up,
eventTimestamp,
);
Expand All @@ -618,7 +614,6 @@ class KeyboardConverter {
int physicalLeft,
int physicalRight,
int logicalLeft,
int logicalRight,
ui.KeyEventType type,
num domTimestamp,
) {
Expand All @@ -635,12 +630,14 @@ class KeyboardConverter {

// Synthesize an up event for left key if pressed
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems we can remove the logicalRight in the parameter list.

if (synthesizeUp && leftPressed) {
_synthesizeKeyUpEvent(domTimestamp, physicalLeft, logicalLeft);
final int knownLogicalKey = _pressingRecords[physicalLeft]!;
_synthesizeKeyUpEvent(domTimestamp, physicalLeft, knownLogicalKey);
}

// Synthesize an up event for right key if pressed
if (synthesizeUp && rightPressed) {
_synthesizeKeyUpEvent(domTimestamp, physicalRight, logicalRight);
final int knownLogicalKey = _pressingRecords[physicalRight]!;
_synthesizeKeyUpEvent(domTimestamp, physicalRight, knownLogicalKey);
}
}

Expand Down
35 changes: 35 additions & 0 deletions lib/web_ui/test/engine/pointer_binding_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,41 @@ void testMain() {
},
);

_testEach<_BasicEventContext>(
<_BasicEventContext>[
_PointerEventContext(),
_MouseEventContext(),
_TouchEventContext(),
],
'should synthesize modifier keys up event for AltGraph',
(_BasicEventContext context) {
PointerBinding.instance!.debugOverrideDetector(context);

final List<ui.KeyData> keyDataList = <ui.KeyData>[];
final KeyboardConverter keyboardConverter = createKeyboardConverter(keyDataList);
PointerBinding.instance!.debugOverrideKeyboardConverter(keyboardConverter);

final int physicalAltRight = kWebToPhysicalKey['AltRight']!;
final int logicalAltGraph = kWebLogicalLocationMap['AltGraph']![0]!;

// Simulate pressing `AltGr` key.
keyboardConverter.handleEvent(keyDownEvent('AltRight', 'AltGraph'));
expect(keyboardConverter.debugKeyIsPressed(physicalAltRight), true);
keyDataList.clear(); // Remove key data generated by handleEvent.

glassPane.dispatchEvent(context.primaryDown());
expect(keyDataList.length, 1);
expectKeyData(keyDataList.last,
type: ui.KeyEventType.up,
physical: physicalAltRight,
logical: logicalAltGraph,
character: null,
synthesized: true,
);
expect(keyboardConverter.debugKeyIsPressed(physicalAltRight), false);
},
);

_testEach<_ButtonedEventMixin>(
<_ButtonedEventMixin>[
if (!isIosSafari) _PointerEventContext(),
Expand Down