forked from firka/flutter
[Web] Synthesize modifiers key up based on known logical key (flutter/engine#37280)
Co-authored-by: Bruno Leroux <bruno.leroux@gmail.com>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -584,7 +584,6 @@ class KeyboardConverter {
|
||||
_kPhysicalAltLeft,
|
||||
_kPhysicalAltRight,
|
||||
_kLogicalAltLeft,
|
||||
_kLogicalAltRight,
|
||||
altPressed ? ui.KeyEventType.down : ui.KeyEventType.up,
|
||||
eventTimestamp,
|
||||
);
|
||||
@@ -592,7 +591,6 @@ class KeyboardConverter {
|
||||
_kPhysicalControlLeft,
|
||||
_kPhysicalControlRight,
|
||||
_kLogicalControlLeft,
|
||||
_kLogicalControlRight,
|
||||
controlPressed ? ui.KeyEventType.down : ui.KeyEventType.up,
|
||||
eventTimestamp,
|
||||
);
|
||||
@@ -600,7 +598,6 @@ class KeyboardConverter {
|
||||
_kPhysicalMetaLeft,
|
||||
_kPhysicalMetaRight,
|
||||
_kLogicalMetaLeft,
|
||||
_kLogicalMetaRight,
|
||||
metaPressed ? ui.KeyEventType.down : ui.KeyEventType.up,
|
||||
eventTimestamp,
|
||||
);
|
||||
@@ -608,7 +605,6 @@ class KeyboardConverter {
|
||||
_kPhysicalShiftLeft,
|
||||
_kPhysicalShiftRight,
|
||||
_kLogicalShiftLeft,
|
||||
_kLogicalShiftRight,
|
||||
shiftPressed ? ui.KeyEventType.down : ui.KeyEventType.up,
|
||||
eventTimestamp,
|
||||
);
|
||||
@@ -618,7 +614,6 @@ class KeyboardConverter {
|
||||
int physicalLeft,
|
||||
int physicalRight,
|
||||
int logicalLeft,
|
||||
int logicalRight,
|
||||
ui.KeyEventType type,
|
||||
num domTimestamp,
|
||||
) {
|
||||
@@ -635,12 +630,14 @@ class KeyboardConverter {
|
||||
|
||||
// Synthesize an up event for left key if pressed
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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(),
|
||||
|
||||
Reference in New Issue
Block a user