Skip to content

Commit 09598f6

Browse files
authored
Introduce SemanticsFlag.hasSelectedState to the engine API (#55780)
Introduce `SemanticsFlag.hasSelectedState` to the engine API. At this point the flag is not backed by any engine functionality. See also: #66673 (comment) | ⚠️ WARNING | |:----------------------------| | Submit _AFTER_ #157017 and #157061 land in the framework | A step towards #66673
1 parent bf8530e commit 09598f6

7 files changed

Lines changed: 44 additions & 12 deletions

File tree

lib/ui/semantics.dart

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -342,15 +342,27 @@ class SemanticsFlag {
342342
static const int _kIsCheckStateMixedIndex = 1 << 25;
343343
static const int _kHasExpandedStateIndex = 1 << 26;
344344
static const int _kIsExpandedIndex = 1 << 27;
345-
// READ THIS: if you add a flag here, you MUST update the numSemanticsFlags
346-
// value in testing/dart/semantics_test.dart and
347-
// lib/web_ui/test/engine/semantics/semantics_api_test.dart, or tests will
348-
// fail. Also, please update the Flag enum in
349-
// flutter/shell/platform/android/io/flutter/view/AccessibilityBridge.java,
350-
// and the SemanticsFlag class in lib/web_ui/lib/semantics.dart. If the new flag
351-
// affects the visibility of a [SemanticsNode] to accessibility services,
352-
// `flutter_test/controller.dart#SemanticsController._importantFlags`
353-
// must be updated as well.
345+
static const int _kHasSelectedStateIndex = 1 << 28;
346+
// READ THIS: if you add a flag here, you MUST update the following:
347+
//
348+
// - Add an appropriately named and documented `static const SemanticsFlag`
349+
// field to this class.
350+
// - Add the new flag to `_kFlagById` in this file.
351+
// - Make changes in lib/web_ui/lib/semantics.dart in the web engine that mirror
352+
// the changes in this file (i.e. `_k*Index`, `static const SemanticsFlag`,
353+
// `_kFlagById`).
354+
// - Increment the `numSemanticsFlags` value in testing/dart/semantics_test.dart
355+
// and in lib/web_ui/test/engine/semantics/semantics_api_test.dart.
356+
// - Add the new flag to platform-specific enums:
357+
// - The `Flag` enum in flutter/shell/platform/android/io/flutter/view/AccessibilityBridge.java.
358+
// - The `SemanticsFlags` enum in lib/ui/semantics/semantics_node.h.
359+
// - The `FlutterSemanticsFlag` enum in shell/platform/embedder/embedder.h.
360+
// - If the new flag affects the visibility of a [SemanticsNode] to accessibility services,
361+
// update `flutter_test/controller.dart#SemanticsController._importantFlags`
362+
// accordingly.
363+
// - If the new flag affects focusability of a semantics node, also update the
364+
// value of `AccessibilityBridge.FOCUSABLE_FLAGS` in
365+
// flutter/shell/platform/android/io/flutter/view/AccessibilityBridge.java.
354366

355367
/// The semantics node has the quality of either being "checked" or "unchecked".
356368
///
@@ -386,9 +398,20 @@ class SemanticsFlag {
386398
/// Must be false when the checkbox is either checked or unchecked.
387399
static const SemanticsFlag isCheckStateMixed = SemanticsFlag._(_kIsCheckStateMixedIndex, 'isCheckStateMixed');
388400

401+
/// The semantics node has the quality of either being "selected" or "unselected".
402+
///
403+
/// Whether the widget corresponding to this node is currently selected or not
404+
/// is determined by the [isSelected] flag.
405+
///
406+
/// When this flag is not set, the corresponding widget cannot be selected by
407+
/// the user, and the presence or the lack of [isSelected] does not carry any
408+
/// meaning.
409+
static const SemanticsFlag hasSelectedState = SemanticsFlag._(_kHasSelectedStateIndex, 'hasSelectedState');
389410

390411
/// Whether a semantics node is selected.
391412
///
413+
/// This flag only has meaning in nodes that have [hasSelectedState] flag set.
414+
///
392415
/// If true, the semantics node is "selected". If false, the semantics node is
393416
/// "unselected".
394417
///
@@ -614,6 +637,7 @@ class SemanticsFlag {
614637
static const Map<int, SemanticsFlag> _kFlagById = <int, SemanticsFlag>{
615638
_kHasCheckedStateIndex: hasCheckedState,
616639
_kIsCheckedIndex: isChecked,
640+
_kHasSelectedStateIndex: hasSelectedState,
617641
_kIsSelectedIndex: isSelected,
618642
_kIsButtonIndex: isButton,
619643
_kIsTextFieldIndex: isTextField,

lib/ui/semantics/semantics_node.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ enum class SemanticsFlags : int32_t {
9191
kIsCheckStateMixed = 1 << 25,
9292
kHasExpandedState = 1 << 26,
9393
kIsExpanded = 1 << 27,
94+
kHasSelectedState = 1 << 28,
9495
};
9596

9697
const int kScrollableSemanticsFlags =

lib/web_ui/lib/semantics.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,11 @@ class SemanticsFlag {
126126
static const int _kIsCheckStateMixedIndex = 1 << 25;
127127
static const int _kHasExpandedStateIndex = 1 << 26;
128128
static const int _kIsExpandedIndex = 1 << 27;
129+
static const int _kHasSelectedStateIndex = 1 << 28;
129130

130131
static const SemanticsFlag hasCheckedState = SemanticsFlag._(_kHasCheckedStateIndex, 'hasCheckedState');
131132
static const SemanticsFlag isChecked = SemanticsFlag._(_kIsCheckedIndex, 'isChecked');
133+
static const SemanticsFlag hasSelectedState = SemanticsFlag._(_kHasSelectedStateIndex, 'hasSelectedState');
132134
static const SemanticsFlag isSelected = SemanticsFlag._(_kIsSelectedIndex, 'isSelected');
133135
static const SemanticsFlag isButton = SemanticsFlag._(_kIsButtonIndex, 'isButton');
134136
static const SemanticsFlag isTextField = SemanticsFlag._(_kIsTextFieldIndex, 'isTextField');
@@ -159,6 +161,7 @@ class SemanticsFlag {
159161
static const Map<int, SemanticsFlag> _kFlagById = <int, SemanticsFlag>{
160162
_kHasCheckedStateIndex: hasCheckedState,
161163
_kIsCheckedIndex: isChecked,
164+
_kHasSelectedStateIndex: hasSelectedState,
162165
_kIsSelectedIndex: isSelected,
163166
_kIsButtonIndex: isButton,
164167
_kIsTextFieldIndex: isTextField,

lib/web_ui/test/engine/semantics/semantics_api_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ void main() {
1818

1919
void testMain() {
2020
// This must match the number of flags in lib/ui/semantics.dart
21-
const int numSemanticsFlags = 28;
21+
const int numSemanticsFlags = 29;
2222
test('SemanticsFlag.values refers to all flags.', () async {
2323
expect(SemanticsFlag.values.length, equals(numSemanticsFlags));
2424
for (int index = 0; index < numSemanticsFlags; ++index) {

shell/platform/android/io/flutter/view/AccessibilityBridge.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2158,7 +2158,8 @@ public enum Action {
21582158
IS_KEYBOARD_KEY(1 << 24),
21592159
IS_CHECK_STATE_MIXED(1 << 25),
21602160
HAS_EXPANDED_STATE(1 << 26),
2161-
IS_EXPANDED(1 << 27);
2161+
IS_EXPANDED(1 << 27),
2162+
HAS_SELECTED_STATE(1 << 28);
21622163

21632164
final int value;
21642165

shell/platform/embedder/embedder.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,9 @@ typedef enum {
243243
kFlutterSemanticsFlagHasExpandedState = 1 << 26,
244244
/// Whether a semantic node that hasExpandedState is currently expanded.
245245
kFlutterSemanticsFlagIsExpanded = 1 << 27,
246+
/// The semantics node has the quality of either being "selected" or
247+
/// "not selected".
248+
kFlutterSemanticsFlagHasSelectedState = 1 << 28,
246249
} FlutterSemanticsFlag;
247250

248251
typedef enum {

testing/dart/semantics_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import 'package:test/test.dart';
1111

1212
void main() {
1313
// This must match the number of flags in lib/ui/semantics.dart
14-
const int numSemanticsFlags = 28;
14+
const int numSemanticsFlags = 29;
1515
test('SemanticsFlag.values refers to all flags.', () async {
1616
expect(SemanticsFlag.values.length, equals(numSemanticsFlags));
1717
for (int index = 0; index < numSemanticsFlags; ++index) {

0 commit comments

Comments
 (0)