Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
5d372062
Unverified
Commit
5d372062
authored
Dec 15, 2021
by
Tong Mu
Committed by
GitHub
Dec 15, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[RawKeyboard, Web, macOS] Upper keys should generate lower logical keys (#94827)
parent
f47ca955
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
45 additions
and
6 deletions
+45
-6
raw_keyboard_macos.dart
packages/flutter/lib/src/services/raw_keyboard_macos.dart
+11
-1
raw_keyboard_web.dart
packages/flutter/lib/src/services/raw_keyboard_web.dart
+1
-1
raw_keyboard_test.dart
packages/flutter/test/services/raw_keyboard_test.dart
+33
-4
No files found.
packages/flutter/lib/src/services/raw_keyboard_macos.dart
View file @
5d372062
...
@@ -10,6 +10,16 @@ import 'keyboard_key.dart';
...
@@ -10,6 +10,16 @@ import 'keyboard_key.dart';
import
'keyboard_maps.dart'
;
import
'keyboard_maps.dart'
;
import
'raw_keyboard.dart'
;
import
'raw_keyboard.dart'
;
/// Convert a UTF32 rune to its lower case.
int
runeToLowerCase
(
int
rune
)
{
// Assume only Basic Multilingual Plane runes have lower and upper cases.
// For other characters, return them as is.
const
int
utf16BmpUpperBound
=
0xD7FF
;
if
(
rune
>
utf16BmpUpperBound
)
return
rune
;
return
String
.
fromCharCode
(
rune
).
toLowerCase
().
codeUnitAt
(
0
);
}
/// Platform-specific key event data for macOS.
/// Platform-specific key event data for macOS.
///
///
/// This object contains information about key events obtained from macOS's
/// This object contains information about key events obtained from macOS's
...
@@ -99,7 +109,7 @@ class RawKeyEventDataMacOs extends RawKeyEventData {
...
@@ -99,7 +109,7 @@ class RawKeyEventDataMacOs extends RawKeyEventData {
// only tests BMP, it is fine to test keyLabel instead.
// only tests BMP, it is fine to test keyLabel instead.
!
LogicalKeyboardKey
.
isControlCharacter
(
keyLabel
)
&&
!
LogicalKeyboardKey
.
isControlCharacter
(
keyLabel
)
&&
!
_isUnprintableKey
(
keyLabel
))
{
!
_isUnprintableKey
(
keyLabel
))
{
character
=
codePoints
[
0
]
;
character
=
runeToLowerCase
(
codePoints
[
0
])
;
}
}
}
}
if
(
character
!=
null
)
{
if
(
character
!=
null
)
{
...
...
packages/flutter/lib/src/services/raw_keyboard_web.dart
View file @
5d372062
...
@@ -104,7 +104,7 @@ class RawKeyEventDataWeb extends RawKeyEventData {
...
@@ -104,7 +104,7 @@ class RawKeyEventDataWeb extends RawKeyEventData {
final
bool
isPrintable
=
key
.
length
==
1
;
final
bool
isPrintable
=
key
.
length
==
1
;
if
(
isPrintable
)
if
(
isPrintable
)
return
LogicalKeyboardKey
(
key
.
codeUnitAt
(
0
));
return
LogicalKeyboardKey
(
key
.
toLowerCase
().
codeUnitAt
(
0
));
// This is a non-printable key that we don't know about, so we mint a new
// This is a non-printable key that we don't know about, so we mint a new
// key from `code`. Don't mint with `key`, because the `key` will always be
// key from `code`. Don't mint with `key`, because the `key` will always be
...
...
packages/flutter/test/services/raw_keyboard_test.dart
View file @
5d372062
...
@@ -1415,14 +1415,13 @@ void main() {
...
@@ -1415,14 +1415,13 @@ void main() {
}
}
});
});
test
(
'Printable keyboard keys are correctly translated'
,
()
{
test
(
'Lower letter keys are correctly translated'
,
()
{
const
String
unmodifiedCharacter
=
'a'
;
final
RawKeyEvent
keyAEvent
=
RawKeyEvent
.
fromMessage
(
const
<
String
,
dynamic
>{
final
RawKeyEvent
keyAEvent
=
RawKeyEvent
.
fromMessage
(
const
<
String
,
dynamic
>{
'type'
:
'keydown'
,
'type'
:
'keydown'
,
'keymap'
:
'macos'
,
'keymap'
:
'macos'
,
'keyCode'
:
0x00000000
,
'keyCode'
:
0x00000000
,
'characters'
:
'a'
,
'characters'
:
'a'
,
'charactersIgnoringModifiers'
:
unmodifiedCharacter
,
'charactersIgnoringModifiers'
:
'a'
,
'modifiers'
:
0x0
,
'modifiers'
:
0x0
,
});
});
final
RawKeyEventDataMacOs
data
=
keyAEvent
.
data
as
RawKeyEventDataMacOs
;
final
RawKeyEventDataMacOs
data
=
keyAEvent
.
data
as
RawKeyEventDataMacOs
;
...
@@ -1431,6 +1430,21 @@ void main() {
...
@@ -1431,6 +1430,21 @@ void main() {
expect
(
data
.
keyLabel
,
equals
(
'a'
));
expect
(
data
.
keyLabel
,
equals
(
'a'
));
});
});
test
(
'Upper letter keys are correctly translated'
,
()
{
final
RawKeyEvent
keyAEvent
=
RawKeyEvent
.
fromMessage
(
const
<
String
,
dynamic
>{
'type'
:
'keydown'
,
'keymap'
:
'macos'
,
'keyCode'
:
0x00000000
,
'characters'
:
'A'
,
'charactersIgnoringModifiers'
:
'A'
,
'modifiers'
:
0x20002
,
});
final
RawKeyEventDataMacOs
data
=
keyAEvent
.
data
as
RawKeyEventDataMacOs
;
expect
(
data
.
physicalKey
,
equals
(
PhysicalKeyboardKey
.
keyA
));
expect
(
data
.
logicalKey
,
equals
(
LogicalKeyboardKey
.
keyA
));
expect
(
data
.
keyLabel
,
equals
(
'A'
));
});
test
(
'Control keyboard keys are correctly translated'
,
()
{
test
(
'Control keyboard keys are correctly translated'
,
()
{
final
RawKeyEvent
escapeKeyEvent
=
RawKeyEvent
.
fromMessage
(
const
<
String
,
dynamic
>{
final
RawKeyEvent
escapeKeyEvent
=
RawKeyEvent
.
fromMessage
(
const
<
String
,
dynamic
>{
'type'
:
'keydown'
,
'type'
:
'keydown'
,
...
@@ -2482,7 +2496,7 @@ void main() {
...
@@ -2482,7 +2496,7 @@ void main() {
}
}
});
});
test
(
'
Printable keyboard
keys are correctly translated'
,
()
{
test
(
'
Lower letter
keys are correctly translated'
,
()
{
final
RawKeyEvent
keyAEvent
=
RawKeyEvent
.
fromMessage
(
const
<
String
,
Object
?>{
final
RawKeyEvent
keyAEvent
=
RawKeyEvent
.
fromMessage
(
const
<
String
,
Object
?>{
'type'
:
'keydown'
,
'type'
:
'keydown'
,
'keymap'
:
'web'
,
'keymap'
:
'web'
,
...
@@ -2497,6 +2511,21 @@ void main() {
...
@@ -2497,6 +2511,21 @@ void main() {
expect
(
data
.
keyLabel
,
equals
(
'a'
));
expect
(
data
.
keyLabel
,
equals
(
'a'
));
});
});
test
(
'Upper letter keys are correctly translated'
,
()
{
final
RawKeyEvent
keyAEvent
=
RawKeyEvent
.
fromMessage
(
const
<
String
,
Object
?>{
'type'
:
'keydown'
,
'keymap'
:
'web'
,
'code'
:
'KeyA'
,
'key'
:
'A'
,
'location'
:
0
,
'metaState'
:
0x1
,
// Shift
});
final
RawKeyEventDataWeb
data
=
keyAEvent
.
data
as
RawKeyEventDataWeb
;
expect
(
data
.
physicalKey
,
equals
(
PhysicalKeyboardKey
.
keyA
));
expect
(
data
.
logicalKey
,
equals
(
LogicalKeyboardKey
.
keyA
));
expect
(
data
.
keyLabel
,
equals
(
'A'
));
});
test
(
'Control keyboard keys are correctly translated'
,
()
{
test
(
'Control keyboard keys are correctly translated'
,
()
{
final
RawKeyEvent
escapeKeyEvent
=
RawKeyEvent
.
fromMessage
(
const
<
String
,
Object
?>{
final
RawKeyEvent
escapeKeyEvent
=
RawKeyEvent
.
fromMessage
(
const
<
String
,
Object
?>{
'type'
:
'keydown'
,
'type'
:
'keydown'
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment