Remove keyLabel and debugName from Logical/PhysicalKeyboardKey (#78263)
- Remove `LogicalKeyboardKey.keyLabel` - Make `Physical/LogicalKeyboardKey.debugName` getters - Make `Physical/LogicalKeyboardKey()` factory constructors, which cache non-predefined instances.
This commit is contained in:
@@ -6,6 +6,7 @@ import 'dart:io';
|
||||
|
||||
import 'package:flutter/foundation.dart' show kIsWeb;
|
||||
import 'package:flutter/services.dart';
|
||||
import 'key_labels.dart';
|
||||
import 'test_async_utils.dart';
|
||||
|
||||
// TODO(gspencergoog): Replace this with more robust key simulation code once
|
||||
@@ -13,6 +14,10 @@ import 'test_async_utils.dart';
|
||||
// https://github.com/flutter/flutter/issues/33521
|
||||
// This code can only simulate keys which appear in the key maps.
|
||||
|
||||
String _keyLabel(LogicalKeyboardKey key) {
|
||||
return logicalKeyLabels[key.keyId] ?? '';
|
||||
}
|
||||
|
||||
/// A class that serves as a namespace for a bunch of keyboard-key generation
|
||||
/// utilities.
|
||||
class KeyEventSimulator {
|
||||
@@ -206,7 +211,7 @@ class KeyEventSimulator {
|
||||
|
||||
if (kIsWeb) {
|
||||
result['code'] = _getWebKeyCode(key);
|
||||
result['key'] = key.keyLabel;
|
||||
result['key'] = _keyLabel(key);
|
||||
result['metaState'] = _getWebModifierFlags(key, isDown);
|
||||
return result;
|
||||
}
|
||||
@@ -214,17 +219,17 @@ class KeyEventSimulator {
|
||||
switch (platform) {
|
||||
case 'android':
|
||||
result['keyCode'] = keyCode;
|
||||
if (key.keyLabel.isNotEmpty) {
|
||||
result['codePoint'] = key.keyLabel.codeUnitAt(0);
|
||||
result['character'] = key.keyLabel;
|
||||
if (_keyLabel(key).isNotEmpty) {
|
||||
result['codePoint'] = _keyLabel(key).codeUnitAt(0);
|
||||
result['character'] = _keyLabel(key);
|
||||
}
|
||||
result['scanCode'] = scanCode;
|
||||
result['metaState'] = _getAndroidModifierFlags(key, isDown);
|
||||
break;
|
||||
case 'fuchsia':
|
||||
result['hidUsage'] = physicalKey.usbHidUsage;
|
||||
if (key.keyLabel.isNotEmpty) {
|
||||
result['codePoint'] = key.keyLabel.codeUnitAt(0);
|
||||
if (_keyLabel(key).isNotEmpty) {
|
||||
result['codePoint'] = _keyLabel(key).codeUnitAt(0);
|
||||
}
|
||||
result['modifiers'] = _getFuchsiaModifierFlags(key, isDown);
|
||||
break;
|
||||
@@ -233,32 +238,32 @@ class KeyEventSimulator {
|
||||
result['keyCode'] = keyCode;
|
||||
result['scanCode'] = scanCode;
|
||||
result['modifiers'] = _getGlfwModifierFlags(key, isDown);
|
||||
result['unicodeScalarValues'] = key.keyLabel.isNotEmpty ? key.keyLabel.codeUnitAt(0) : 0;
|
||||
result['unicodeScalarValues'] = _keyLabel(key).isNotEmpty ? _keyLabel(key).codeUnitAt(0) : 0;
|
||||
break;
|
||||
case 'macos':
|
||||
result['keyCode'] = scanCode;
|
||||
if (key.keyLabel.isNotEmpty) {
|
||||
result['characters'] = key.keyLabel;
|
||||
result['charactersIgnoringModifiers'] = key.keyLabel;
|
||||
if (_keyLabel(key).isNotEmpty) {
|
||||
result['characters'] = _keyLabel(key);
|
||||
result['charactersIgnoringModifiers'] = _keyLabel(key);
|
||||
}
|
||||
result['modifiers'] = _getMacOsModifierFlags(key, isDown);
|
||||
break;
|
||||
case 'ios':
|
||||
result['keyCode'] = scanCode;
|
||||
result['characters'] = key.keyLabel;
|
||||
result['charactersIgnoringModifiers'] = key.keyLabel;
|
||||
result['characters'] = _keyLabel(key);
|
||||
result['charactersIgnoringModifiers'] = _keyLabel(key);
|
||||
result['modifiers'] = _getIOSModifierFlags(key, isDown);
|
||||
break;
|
||||
case 'web':
|
||||
result['code'] = _getWebKeyCode(key);
|
||||
result['key'] = key.keyLabel;
|
||||
result['key'] = _keyLabel(key);
|
||||
result['metaState'] = _getWebModifierFlags(key, isDown);
|
||||
break;
|
||||
case 'windows':
|
||||
result['keyCode'] = keyCode;
|
||||
result['scanCode'] = scanCode;
|
||||
if (key.keyLabel.isNotEmpty) {
|
||||
result['characterCodePoint'] = key.keyLabel.codeUnitAt(0);
|
||||
if (_keyLabel(key).isNotEmpty) {
|
||||
result['characterCodePoint'] = _keyLabel(key).codeUnitAt(0);
|
||||
}
|
||||
result['modifiers'] = _getWindowsModifierFlags(key, isDown);
|
||||
}
|
||||
|
||||
83
packages/flutter_test/lib/src/key_labels.dart
Normal file
83
packages/flutter_test/lib/src/key_labels.dart
Normal file
@@ -0,0 +1,83 @@
|
||||
// Copyright 2014 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// DO NOT EDIT -- DO NOT EDIT -- DO NOT EDIT
|
||||
// This file is generated by dev/tools/gen_keycodes/bin/gen_keycodes.dart and
|
||||
// should not be edited directly.
|
||||
//
|
||||
// Edit the template dev/tools/gen_keycodes/data/key_labels.tmpl instead.
|
||||
// See dev/tools/gen_keycodes/README.md for more information.
|
||||
|
||||
/// The keyLabel corresponding to a logical key.
|
||||
///
|
||||
/// Used to generate simulated key events out of a logical key.
|
||||
const Map<int, String> logicalKeyLabels = <int, String>{
|
||||
0x00000000061: r'a',
|
||||
0x00000000062: r'b',
|
||||
0x00000000063: r'c',
|
||||
0x00000000064: r'd',
|
||||
0x00000000065: r'e',
|
||||
0x00000000066: r'f',
|
||||
0x00000000067: r'g',
|
||||
0x00000000068: r'h',
|
||||
0x00000000069: r'i',
|
||||
0x0000000006a: r'j',
|
||||
0x0000000006b: r'k',
|
||||
0x0000000006c: r'l',
|
||||
0x0000000006d: r'm',
|
||||
0x0000000006e: r'n',
|
||||
0x0000000006f: r'o',
|
||||
0x00000000070: r'p',
|
||||
0x00000000071: r'q',
|
||||
0x00000000072: r'r',
|
||||
0x00000000073: r's',
|
||||
0x00000000074: r't',
|
||||
0x00000000075: r'u',
|
||||
0x00000000076: r'v',
|
||||
0x00000000077: r'w',
|
||||
0x00000000078: r'x',
|
||||
0x00000000079: r'y',
|
||||
0x0000000007a: r'z',
|
||||
0x00000000031: r'1',
|
||||
0x00000000032: r'2',
|
||||
0x00000000033: r'3',
|
||||
0x00000000034: r'4',
|
||||
0x00000000035: r'5',
|
||||
0x00000000036: r'6',
|
||||
0x00000000037: r'7',
|
||||
0x00000000038: r'8',
|
||||
0x00000000039: r'9',
|
||||
0x00000000030: r'0',
|
||||
0x00000000020: r' ',
|
||||
0x0000000002d: r'-',
|
||||
0x0000000003d: r'=',
|
||||
0x0000000005b: r'[',
|
||||
0x0000000005d: r']',
|
||||
0x0000000005c: r'\',
|
||||
0x0000000003b: r';',
|
||||
0x00000000027: r"'",
|
||||
0x00000000060: r'`',
|
||||
0x0000000002c: r',',
|
||||
0x0000000002e: r'.',
|
||||
0x0000000002f: r'/',
|
||||
0x00100070054: r'/',
|
||||
0x00100070055: r'*',
|
||||
0x00100070056: r'-',
|
||||
0x00100070057: r'+',
|
||||
0x00100070059: r'1',
|
||||
0x0010007005a: r'2',
|
||||
0x0010007005b: r'3',
|
||||
0x0010007005c: r'4',
|
||||
0x0010007005d: r'5',
|
||||
0x0010007005e: r'6',
|
||||
0x0010007005f: r'7',
|
||||
0x00100070060: r'8',
|
||||
0x00100070061: r'9',
|
||||
0x00100070062: r'0',
|
||||
0x00100070063: r'.',
|
||||
0x00100070067: r'=',
|
||||
0x00100070085: r',',
|
||||
0x001000700b6: r'(',
|
||||
0x001000700b7: r')',
|
||||
};
|
||||
Reference in New Issue
Block a user