Impl & test (flutter/engine#32061)
This commit is contained in:
@@ -475,20 +475,25 @@ class KeyboardConverter {
|
|||||||
|
|
||||||
// After updating _pressingRecords, synchronize modifier states. The
|
// After updating _pressingRecords, synchronize modifier states. The
|
||||||
// `event.***Key` fields can be used to reduce some omitted modifier key
|
// `event.***Key` fields can be used to reduce some omitted modifier key
|
||||||
// events. We can deduce key cancel events if they are false. Key sync
|
// events. We can synthesize key up events if they are false. Key down
|
||||||
// events can not be deduced since we don't know which physical key they
|
// events can not be synthesized since we don't know which physical key they
|
||||||
// represent.
|
// represent.
|
||||||
_kLogicalKeyToModifierGetter.forEach((int logicalKey, _ModifierGetter getModifier) {
|
_kLogicalKeyToModifierGetter.forEach((int testeeLogicalKey, _ModifierGetter getModifier) {
|
||||||
if (_pressingRecords.containsValue(logicalKey) && !getModifier(event)) {
|
// Do not synthesize for the key of the current event. The event is the
|
||||||
|
// ground truth.
|
||||||
|
if (logicalKey == testeeLogicalKey) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (_pressingRecords.containsValue(testeeLogicalKey) && !getModifier(event)) {
|
||||||
_pressingRecords.removeWhere((int physicalKey, int logicalRecord) {
|
_pressingRecords.removeWhere((int physicalKey, int logicalRecord) {
|
||||||
if (logicalRecord != logicalKey)
|
if (logicalRecord != testeeLogicalKey)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
_dispatchKeyData!(ui.KeyData(
|
_dispatchKeyData!(ui.KeyData(
|
||||||
timeStamp: timeStamp,
|
timeStamp: timeStamp,
|
||||||
type: ui.KeyEventType.up,
|
type: ui.KeyEventType.up,
|
||||||
physical: physicalKey,
|
physical: physicalKey,
|
||||||
logical: logicalKey,
|
logical: testeeLogicalKey,
|
||||||
character: null,
|
character: null,
|
||||||
synthesized: true,
|
synthesized: true,
|
||||||
));
|
));
|
||||||
|
|||||||
@@ -996,6 +996,60 @@ void testMain() {
|
|||||||
character: 'a',
|
character: 'a',
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Regression test for https://github.com/flutter/flutter/issues/99297.
|
||||||
|
//
|
||||||
|
// On Linux Chrome, when holding ShiftLeft and pressing MetaLeft (Win key),
|
||||||
|
// the MetaLeft down event has metaKey true, while the Meta up event has
|
||||||
|
// metaKey false. This violates the definition of metaKey, and does not happen
|
||||||
|
// in nearly any other cases for any other keys.
|
||||||
|
test('Ignore inconsistent modifier flag of the current modifier', () {
|
||||||
|
final List<ui.KeyData> keyDataList = <ui.KeyData>[];
|
||||||
|
final KeyboardConverter converter = KeyboardConverter((ui.KeyData key) {
|
||||||
|
keyDataList.add(key);
|
||||||
|
return true;
|
||||||
|
}, onMacOs: false);
|
||||||
|
|
||||||
|
converter.handleEvent(keyDownEvent('ShiftLeft', 'Shift', kShift, kLocationLeft));
|
||||||
|
expectKeyData(keyDataList.last,
|
||||||
|
type: ui.KeyEventType.down,
|
||||||
|
physical: kPhysicalShiftLeft,
|
||||||
|
logical: kLogicalShiftLeft,
|
||||||
|
character: null,
|
||||||
|
);
|
||||||
|
keyDataList.clear();
|
||||||
|
|
||||||
|
converter.handleEvent(keyDownEvent('MetaLeft', 'Meta', kShift /* No kMeta here! */, kLocationLeft));
|
||||||
|
// Only a MetaLeft down event, no synthesized MetaLeft up events.
|
||||||
|
expect(keyDataList, hasLength(1));
|
||||||
|
expectKeyData(keyDataList.first,
|
||||||
|
type: ui.KeyEventType.down,
|
||||||
|
physical: kPhysicalMetaLeft,
|
||||||
|
logical: kLogicalMetaLeft,
|
||||||
|
character: null,
|
||||||
|
);
|
||||||
|
keyDataList.clear();
|
||||||
|
|
||||||
|
converter.handleEvent(keyUpEvent('MetaLeft', 'Meta', kShift | kMeta /* Yes, kMeta here! */, kLocationLeft));
|
||||||
|
// Only a MetaLeft down event, no synthesized MetaLeft up events.
|
||||||
|
expect(keyDataList, hasLength(1));
|
||||||
|
expectKeyData(keyDataList.first,
|
||||||
|
type: ui.KeyEventType.up,
|
||||||
|
physical: kPhysicalMetaLeft,
|
||||||
|
logical: kLogicalMetaLeft,
|
||||||
|
character: null,
|
||||||
|
);
|
||||||
|
keyDataList.clear();
|
||||||
|
|
||||||
|
converter.handleEvent(keyUpEvent('ShiftLeft', 'Shift', 0, kLocationLeft));
|
||||||
|
expectKeyData(keyDataList.last,
|
||||||
|
type: ui.KeyEventType.up,
|
||||||
|
physical: kPhysicalShiftLeft,
|
||||||
|
logical: kLogicalShiftLeft,
|
||||||
|
character: null,
|
||||||
|
);
|
||||||
|
keyDataList.clear();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
class MockKeyboardEvent implements FlutterHtmlKeyboardEvent {
|
class MockKeyboardEvent implements FlutterHtmlKeyboardEvent {
|
||||||
|
|||||||
Reference in New Issue
Block a user