Skip to content

Commit

Permalink
[fuchsia][a11y] Adds isKeyboardKey semantics flag. (flutter#25167)
Browse files Browse the repository at this point in the history
This change introduces a semantics flag to indicate whether a node
represents a virtual keyboard key.
  • Loading branch information
abrush21 authored Mar 30, 2021
1 parent 352a50f commit 70af54f
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 2 deletions.
7 changes: 7 additions & 0 deletions lib/ui/semantics.dart
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ class SemanticsFlag {
static const int _kIsFocusableIndex = 1 << 21;
static const int _kIsLinkIndex = 1 << 22;
static const int _kIsSliderIndex = 1 << 23;
static const int _kIsKeyboardKeyIndex = 1 << 24;
// READ THIS: if you add a flag here, you MUST update the numSemanticsFlags
// value in testing/dart/semantics_test.dart, or tests will fail. Also,
// please update the Flag enum in
Expand Down Expand Up @@ -374,6 +375,9 @@ class SemanticsFlag {
/// Whether the semantic node represents a slider.
static const SemanticsFlag isSlider = SemanticsFlag._(_kIsSliderIndex);

/// Whether the semantic node represents a keyboard key.
static const SemanticsFlag isKeyboardKey = SemanticsFlag._(_kIsKeyboardKeyIndex);

/// Whether the semantic node is read only.
///
/// Only applicable when [isTextField] is true.
Expand Down Expand Up @@ -575,6 +579,7 @@ class SemanticsFlag {
_kIsFocusableIndex: isFocusable,
_kIsLinkIndex: isLink,
_kIsSliderIndex: isSlider,
_kIsKeyboardKeyIndex: isKeyboardKey,
};

@override
Expand Down Expand Up @@ -628,6 +633,8 @@ class SemanticsFlag {
return 'SemanticsFlag.isLink';
case _kIsSliderIndex:
return 'SemanticsFlag.isSlider';
case _kIsKeyboardKeyIndex:
return 'SemanticsFlag.isKeyboardKey';
}
assert(false, 'Unhandled index: $index');
return '';
Expand Down
1 change: 1 addition & 0 deletions lib/ui/semantics/semantics_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ enum class SemanticsFlags : int32_t {
kIsFocusable = 1 << 21,
kIsLink = 1 << 22,
kIsSlider = 1 << 23,
kIsKeyboardKey = 1 << 24,
};

const int kScrollableSemanticsFlags =
Expand Down
5 changes: 5 additions & 0 deletions lib/web_ui/lib/src/ui/semantics.dart
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ class SemanticsFlag {
static const int _kIsFocusableIndex = 1 << 21;
static const int _kIsLinkIndex = 1 << 22;
static const int _kIsSliderIndex = 1 << 23;
static const int _kIsKeyboardKeyIndex = 1 << 24;

const SemanticsFlag._(this.index) : assert(index != null); // ignore: unnecessary_null_comparison
final int index;
Expand Down Expand Up @@ -189,6 +190,7 @@ class SemanticsFlag {
static const SemanticsFlag hasImplicitScrolling = SemanticsFlag._(_kHasImplicitScrollingIndex);
static const SemanticsFlag isMultiline = SemanticsFlag._(_kIsMultilineIndex);
static const SemanticsFlag isSlider = SemanticsFlag._(_kIsSliderIndex);
static const SemanticsFlag isKeyboardKey = SemanticsFlag._(_kIsKeyboardKeyIndex);
static const Map<int, SemanticsFlag> values = <int, SemanticsFlag>{
_kHasCheckedStateIndex: hasCheckedState,
_kIsCheckedIndex: isChecked,
Expand All @@ -214,6 +216,7 @@ class SemanticsFlag {
_kHasImplicitScrollingIndex: hasImplicitScrolling,
_kIsMultilineIndex: isMultiline,
_kIsReadOnlyIndex: isReadOnly,
_kIsKeyboardKeyIndex: isKeyboardKey,
};

@override
Expand Down Expand Up @@ -265,6 +268,8 @@ class SemanticsFlag {
return 'SemanticsFlag.isMultiline';
case _kIsReadOnlyIndex:
return 'SemanticsFlag.isReadOnly';
case _kIsKeyboardKeyIndex:
return 'SemanticsFlag.isKeyboardKey';
}
assert(false, 'Unhandled index: $index');
return '';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1910,7 +1910,9 @@ public enum Action {
// IS_MULTILINE(1 << 19);
IS_READ_ONLY(1 << 20),
IS_FOCUSABLE(1 << 21),
IS_LINK(1 << 22);
IS_LINK(1 << 22),
IS_SLIDER(1 << 23),
IS_KEYBOARD_KEY(1 << 24);

final int value;

Expand Down
2 changes: 1 addition & 1 deletion testing/dart/semantics_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import 'package:test/test.dart' hide TypeMatcher, isInstanceOf;
/// Verifies Semantics flags and actions.
void main() {
// This must match the number of flags in lib/ui/semantics.dart
const int numSemanticsFlags = 24;
const int numSemanticsFlags = 25;
test('SemanticsFlag.values refers to all flags.', () async {
expect(SemanticsFlag.values.length, equals(numSemanticsFlags));
for (int index = 0; index < numSemanticsFlags; ++index) {
Expand Down

0 comments on commit 70af54f

Please sign in to comment.