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
fe052394
Unverified
Commit
fe052394
authored
Jan 12, 2022
by
b-luk
Committed by
GitHub
Jan 12, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Expose keyCode field in RawKeyEventDataWeb. (#96483)
parent
5ac97140
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
3 deletions
+30
-3
raw_keyboard.dart
packages/flutter/lib/src/services/raw_keyboard.dart
+1
-0
raw_keyboard_web.dart
packages/flutter/lib/src/services/raw_keyboard_web.dart
+11
-1
raw_keyboard_test.dart
packages/flutter/test/services/raw_keyboard_test.dart
+18
-2
No files found.
packages/flutter/lib/src/services/raw_keyboard.dart
View file @
fe052394
...
...
@@ -300,6 +300,7 @@ abstract class RawKeyEvent with Diagnosticable {
key:
key
??
''
,
location:
message
[
'location'
]
as
int
?
??
0
,
metaState:
message
[
'metaState'
]
as
int
?
??
0
,
keyCode:
message
[
'keyCode'
]
as
int
?
??
0
,
);
}
...
...
packages/flutter/lib/src/services/raw_keyboard_web.dart
View file @
fe052394
...
...
@@ -32,6 +32,7 @@ class RawKeyEventDataWeb extends RawKeyEventData {
required
this
.
key
,
this
.
location
=
0
,
this
.
metaState
=
modifierNone
,
this
.
keyCode
=
0
,
})
:
assert
(
code
!=
null
),
assert
(
metaState
!=
null
);
...
...
@@ -80,6 +81,12 @@ class RawKeyEventDataWeb extends RawKeyEventData {
/// * [isMetaPressed], to see if a META key is pressed.
final
int
metaState
;
/// The `KeyboardEvent.keyCode` corresponding to this event.
///
/// See <https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keyCode>
/// for more information.
final
int
keyCode
;
@override
String
get
keyLabel
=>
key
==
'Unidentified'
?
''
:
_unicodeChar
(
key
)
??
''
;
...
...
@@ -156,6 +163,7 @@ class RawKeyEventDataWeb extends RawKeyEventData {
properties
.
add
(
DiagnosticsProperty
<
String
>(
'key'
,
key
));
properties
.
add
(
DiagnosticsProperty
<
int
>(
'location'
,
location
));
properties
.
add
(
DiagnosticsProperty
<
int
>(
'metaState'
,
metaState
));
properties
.
add
(
DiagnosticsProperty
<
int
>(
'keyCode'
,
keyCode
));
}
@override
...
...
@@ -168,7 +176,8 @@ class RawKeyEventDataWeb extends RawKeyEventData {
&&
other
.
code
==
code
&&
other
.
key
==
key
&&
other
.
location
==
location
&&
other
.
metaState
==
metaState
;
&&
other
.
metaState
==
metaState
&&
other
.
keyCode
==
keyCode
;
}
@override
...
...
@@ -177,6 +186,7 @@ class RawKeyEventDataWeb extends RawKeyEventData {
key
,
location
,
metaState
,
keyCode
,
);
// Modifier key masks.
...
...
packages/flutter/test/services/raw_keyboard_test.dart
View file @
fe052394
...
...
@@ -2547,11 +2547,13 @@ void main() {
'key'
:
'a'
,
'location'
:
0
,
'metaState'
:
0x0
,
'keyCode'
:
0x41
,
});
final
RawKeyEventDataWeb
data
=
keyAEvent
.
data
as
RawKeyEventDataWeb
;
expect
(
data
.
physicalKey
,
equals
(
PhysicalKeyboardKey
.
keyA
));
expect
(
data
.
logicalKey
,
equals
(
LogicalKeyboardKey
.
keyA
));
expect
(
data
.
keyLabel
,
equals
(
'a'
));
expect
(
data
.
keyCode
,
equals
(
0x41
));
});
test
(
'Upper letter keys are correctly translated'
,
()
{
...
...
@@ -2562,11 +2564,13 @@ void main() {
'key'
:
'A'
,
'location'
:
0
,
'metaState'
:
0x1
,
// Shift
'keyCode'
:
0x41
,
});
final
RawKeyEventDataWeb
data
=
keyAEvent
.
data
as
RawKeyEventDataWeb
;
expect
(
data
.
physicalKey
,
equals
(
PhysicalKeyboardKey
.
keyA
));
expect
(
data
.
logicalKey
,
equals
(
LogicalKeyboardKey
.
keyA
));
expect
(
data
.
keyLabel
,
equals
(
'A'
));
expect
(
data
.
keyCode
,
equals
(
0x41
));
});
test
(
'Control keyboard keys are correctly translated'
,
()
{
...
...
@@ -2577,11 +2581,13 @@ void main() {
'key'
:
'Escape'
,
'location'
:
0
,
'metaState'
:
0x0
,
'keyCode'
:
0x1B
,
});
final
RawKeyEventDataWeb
data
=
escapeKeyEvent
.
data
as
RawKeyEventDataWeb
;
expect
(
data
.
physicalKey
,
equals
(
PhysicalKeyboardKey
.
escape
));
expect
(
data
.
logicalKey
,
equals
(
LogicalKeyboardKey
.
escape
));
expect
(
data
.
keyLabel
,
isEmpty
);
expect
(
data
.
keyCode
,
equals
(
0x1B
));
});
test
(
'Modifier keyboard keys are correctly translated'
,
()
{
...
...
@@ -2592,11 +2598,13 @@ void main() {
'key'
:
'Shift'
,
'location'
:
1
,
'metaState'
:
RawKeyEventDataWeb
.
modifierShift
,
'keyCode'
:
0x10
,
});
final
RawKeyEventDataWeb
data
=
shiftKeyEvent
.
data
as
RawKeyEventDataWeb
;
expect
(
data
.
physicalKey
,
equals
(
PhysicalKeyboardKey
.
shiftLeft
));
expect
(
data
.
logicalKey
,
equals
(
LogicalKeyboardKey
.
shiftLeft
));
expect
(
data
.
keyLabel
,
isEmpty
);
expect
(
data
.
keyCode
,
equals
(
0x10
));
});
test
(
'Arrow keys from a keyboard give correct physical key mappings'
,
()
{
...
...
@@ -2607,11 +2615,13 @@ void main() {
'key'
:
'ArrowDown'
,
'location'
:
0
,
'metaState'
:
0x0
,
'keyCode'
:
0x28
,
});
final
RawKeyEventDataWeb
data
=
arrowKeyDown
.
data
as
RawKeyEventDataWeb
;
expect
(
data
.
physicalKey
,
equals
(
PhysicalKeyboardKey
.
arrowDown
));
expect
(
data
.
logicalKey
,
equals
(
LogicalKeyboardKey
.
arrowDown
));
expect
(
data
.
keyLabel
,
isEmpty
);
expect
(
data
.
keyCode
,
equals
(
0x28
));
});
test
(
'Unrecognized keys are mapped to Web plane'
,
()
{
...
...
@@ -2631,6 +2641,7 @@ void main() {
expect
(
data
.
logicalKey
.
keyId
,
greaterThan
(
0x01700000000
));
expect
(
data
.
logicalKey
.
keyId
,
lessThan
(
0x01800000000
));
expect
(
data
.
keyLabel
,
isEmpty
);
expect
(
data
.
keyCode
,
equals
(
0
));
});
test
(
'data.toString'
,
()
{
...
...
@@ -2641,8 +2652,9 @@ void main() {
'key'
:
'a'
,
'location'
:
2
,
'metaState'
:
0x10
,
'keyCode'
:
0x41
,
}).
data
.
toString
(),
equalsIgnoringHashCodes
(
'RawKeyEventDataWeb#00000(code: KeyA, key: a, location: 2, metaState: 16)'
));
'RawKeyEventDataWeb#00000(code: KeyA, key: a, location: 2, metaState: 16
, keyCode: 65
)'
));
// Without location
expect
(
RawKeyEvent
.
fromMessage
(
const
<
String
,
Object
?>{
...
...
@@ -2651,8 +2663,9 @@ void main() {
'code'
:
'KeyA'
,
'key'
:
'a'
,
'metaState'
:
0x10
,
'keyCode'
:
0x41
,
}).
data
.
toString
(),
equalsIgnoringHashCodes
(
'RawKeyEventDataWeb#00000(code: KeyA, key: a, location: 0, metaState: 16)'
));
'RawKeyEventDataWeb#00000(code: KeyA, key: a, location: 0, metaState: 16
, keyCode: 65
)'
));
});
test
(
'data.equality'
,
()
{
...
...
@@ -2663,11 +2676,13 @@ void main() {
'key'
:
'a'
,
'location'
:
2
,
'metaState'
:
0x10
,
'keyCode'
:
0x41
,
}).
data
,
const
RawKeyEventDataWeb
(
key:
'a'
,
code:
'KeyA'
,
location:
2
,
metaState:
0x10
,
keyCode:
0x41
));
expect
(
RawKeyEvent
.
fromMessage
(
const
<
String
,
Object
?>{
...
...
@@ -2677,6 +2692,7 @@ void main() {
'key'
:
'a'
,
'location'
:
2
,
'metaState'
:
0x10
,
'keyCode'
:
0x41
,
}).
data
,
isNot
(
equals
(
const
RawKeyEventDataWeb
(
code:
'KeyA'
,
key:
'a'
))));
});
});
...
...
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