Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions lib/ui/semantics.dart
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ class SemanticsAction {
class SemanticsFlags {
static const int _kHasCheckedStateIndex = 1 << 0;
static const int _kIsCheckedIndex = 1 << 1;
static const int _kIsSelectedIndex = 1 << 2;

const SemanticsFlags._(this.index);

Expand All @@ -133,12 +134,22 @@ class SemanticsFlags {
/// For example, if a checkbox has a visible checkmark, [isChecked] is true.
static const SemanticsFlags isChecked = const SemanticsFlags._(_kIsCheckedIndex);


/// Whether a semantics node is selected.
///
/// If true, the semantics node is "selected". If false, the semantics node is
/// "unselected".
///
/// For example, the active tab in a tab bar has [isSelected] set to true.
static const SemanticsFlags isSelected = const SemanticsFlags._(_kIsSelectedIndex);

/// The possible semantics flags.
///
/// The map's key is the [index] of the flag and the value is the flag itself.
static final Map<int, SemanticsFlags> values = const <int, SemanticsFlags>{
_kHasCheckedStateIndex: hasCheckedState,
_kIsCheckedIndex: isChecked,
_kIsSelectedIndex: isSelected,
};

@override
Expand All @@ -148,6 +159,8 @@ class SemanticsFlags {
return 'SemanticsFlags.hasCheckedState';
case _kIsCheckedIndex:
return 'SemanticsFlags.isChecked';
case _kIsSelectedIndex:
return 'SemanticsFlags.isSelected';
}
return null;
}
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 @@ -31,6 +31,7 @@ enum class SemanticsAction : int32_t {
enum class SemanticsFlags : int32_t {
kHasCheckedState = 1 << 0,
kIsChecked = 1 << 1,
kIsSelected = 1 << 2,
};

struct SemanticsNode {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class AccessibilityBridge extends AccessibilityNodeProvider {

private static final int SEMANTICS_FLAG_HAS_CHECKED_STATE = 1 << 0;
private static final int SEMANTICS_FLAG_IS_CHECKED = 1 << 1;
private static final int SEMANTICS_FLAG_IS_SELECTED = 1 << 2;

AccessibilityBridge(FlutterView owner) {
assert owner != null;
Expand Down Expand Up @@ -119,6 +120,7 @@ public AccessibilityNodeInfo createAccessibilityNodeInfo(int virtualViewId) {

result.setCheckable((object.flags & SEMANTICS_FLAG_HAS_CHECKED_STATE) != 0);
result.setChecked((object.flags & SEMANTICS_FLAG_IS_CHECKED) != 0);
result.setSelected((object.flags & SEMANTICS_FLAG_IS_SELECTED) != 0);
result.setText(object.label);

// TODO(ianh): use setTraversalBefore/setTraversalAfter to set
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ - (UIAccessibilityTraits)accessibilityTraits {
_node.HasAction(blink::SemanticsAction::kDecrease)) {
traits |= UIAccessibilityTraitAdjustable;
}
if (_node.HasFlag(blink::SemanticsFlags::kIsSelected) ||
_node.HasFlag(blink::SemanticsFlags::kIsChecked)) {
traits |= UIAccessibilityTraitSelected;
}
return traits;
}

Expand Down