mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Add repeatCount to RawKeyEventDataAndroid (#42861)
* Add repeatCount to RawKeyEventDataAndroid Adds a new field to RawKeyEventDataAndroid and sets it to the value passed from the engine. It is the value returned by KeyEvent.getRepeatCount(). This allows us to differentiate between events generated by a new keypress and repeated events when a key is held down. * Add test for RawKeyEventDataAndroid.repeatCount
This commit is contained in:
parent
bcab851b8f
commit
e458fd08d9
@ -102,6 +102,7 @@ class _HardwareKeyDemoState extends State<RawKeyboardDemo> {
|
||||
dataText.add(Text('vendorId: ${data.vendorId} (${_asHex(data.vendorId)})'));
|
||||
dataText.add(Text('productId: ${data.productId} (${_asHex(data.productId)})'));
|
||||
dataText.add(Text('flags: ${data.flags} (${_asHex(data.flags)})'));
|
||||
dataText.add(Text('repeatCount: ${data.repeatCount} (${_asHex(data.repeatCount)})'));
|
||||
} else if (data is RawKeyEventDataFuchsia) {
|
||||
dataText.add(Text('codePoint: ${data.codePoint} (${_asHex(data.codePoint)})'));
|
||||
dataText.add(Text('hidUsage: ${data.hidUsage} (${_asHex(data.hidUsage)})'));
|
||||
|
||||
@ -261,6 +261,7 @@ abstract class RawKeyEvent extends Diagnosticable {
|
||||
vendorId: message['vendorId'] ?? 0,
|
||||
productId: message['productId'] ?? 0,
|
||||
deviceId: message['deviceId'] ?? 0,
|
||||
repeatCount: message['repeatCount'] ?? 0,
|
||||
);
|
||||
break;
|
||||
case 'fuchsia':
|
||||
|
||||
@ -37,6 +37,7 @@ class RawKeyEventDataAndroid extends RawKeyEventData {
|
||||
this.vendorId = 0,
|
||||
this.productId = 0,
|
||||
this.deviceId = 0,
|
||||
this.repeatCount = 0,
|
||||
}) : assert(flags != null),
|
||||
assert(codePoint != null),
|
||||
assert(keyCode != null),
|
||||
@ -128,12 +129,17 @@ class RawKeyEventDataAndroid extends RawKeyEventData {
|
||||
/// for the numerical values of the `productId`.
|
||||
final int productId;
|
||||
|
||||
|
||||
/// The ID of the device that produced the event.
|
||||
///
|
||||
/// See https://developer.android.com/reference/android/view/InputDevice.html#getId()
|
||||
final int deviceId;
|
||||
|
||||
/// The repeat count of the event.
|
||||
///
|
||||
/// See <https://developer.android.com/reference/android/view/KeyEvent#getRepeatCount()>
|
||||
/// for more information.
|
||||
final int repeatCount;
|
||||
|
||||
// The source code that indicates that an event came from a joystick.
|
||||
// from https://developer.android.com/reference/android/view/InputDevice.html#SOURCE_JOYSTICK
|
||||
static const int _sourceJoystick = 0x01000010;
|
||||
|
||||
@ -225,6 +225,22 @@ void main() {
|
||||
final RawKeyEventDataAndroid data = joystickDpadCenter.data;
|
||||
expect(data.deviceId, equals(10));
|
||||
});
|
||||
test('Repeat count is passed correctly', () {
|
||||
final RawKeyEvent repeatCountEvent = RawKeyEvent.fromMessage(<String, dynamic>{
|
||||
'type': 'keydown',
|
||||
'keymap': 'android',
|
||||
'keyCode': 29,
|
||||
'plainCodePoint': 'a'.codeUnitAt(0),
|
||||
'codePoint': 'A'.codeUnitAt(0),
|
||||
'character': 'A',
|
||||
'scanCode': 30,
|
||||
'metaState': 0x0,
|
||||
'source': 0x101, // Keyboard source.
|
||||
'repeatCount': 42,
|
||||
});
|
||||
final RawKeyEventDataAndroid data = repeatCountEvent.data;
|
||||
expect(data.repeatCount, equals(42));
|
||||
});
|
||||
});
|
||||
group('RawKeyEventDataFuchsia', () {
|
||||
const Map<int, _ModifierCheck> modifierTests = <int, _ModifierCheck>{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user