From 1787c3fb1e8670d626794e2533e4be6a71aa2ca8 Mon Sep 17 00:00:00 2001 From: Michael Goderbauer Date: Fri, 9 Jun 2017 15:58:30 -0700 Subject: [PATCH] Adding SemanticsFlag.isSelected (#3764) * Adding SemanticsFlag.isSelected * typo --- lib/ui/semantics.dart | 13 +++++++++++++ lib/ui/semantics/semantics_node.h | 1 + .../io/flutter/view/AccessibilityBridge.java | 2 ++ .../ios/framework/Source/accessibility_bridge.mm | 4 ++++ 4 files changed, 20 insertions(+) diff --git a/lib/ui/semantics.dart b/lib/ui/semantics.dart index 725804254..fde5f6be8 100644 --- a/lib/ui/semantics.dart +++ b/lib/ui/semantics.dart @@ -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); @@ -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 values = const { _kHasCheckedStateIndex: hasCheckedState, _kIsCheckedIndex: isChecked, + _kIsSelectedIndex: isSelected, }; @override @@ -148,6 +159,8 @@ class SemanticsFlags { return 'SemanticsFlags.hasCheckedState'; case _kIsCheckedIndex: return 'SemanticsFlags.isChecked'; + case _kIsSelectedIndex: + return 'SemanticsFlags.isSelected'; } return null; } diff --git a/lib/ui/semantics/semantics_node.h b/lib/ui/semantics/semantics_node.h index e221d3173..0dd6e3dd3 100644 --- a/lib/ui/semantics/semantics_node.h +++ b/lib/ui/semantics/semantics_node.h @@ -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 { diff --git a/shell/platform/android/io/flutter/view/AccessibilityBridge.java b/shell/platform/android/io/flutter/view/AccessibilityBridge.java index 9336f1a45..77d894d19 100644 --- a/shell/platform/android/io/flutter/view/AccessibilityBridge.java +++ b/shell/platform/android/io/flutter/view/AccessibilityBridge.java @@ -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; @@ -119,6 +120,7 @@ class AccessibilityBridge extends AccessibilityNodeProvider { 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 diff --git a/shell/platform/darwin/ios/framework/Source/accessibility_bridge.mm b/shell/platform/darwin/ios/framework/Source/accessibility_bridge.mm index 6c65644eb..6feeaa27c 100644 --- a/shell/platform/darwin/ios/framework/Source/accessibility_bridge.mm +++ b/shell/platform/darwin/ios/framework/Source/accessibility_bridge.mm @@ -116,6 +116,10 @@ blink::SemanticsAction GetSemanticsActionForScrollDirection( _node.HasAction(blink::SemanticsAction::kDecrease)) { traits |= UIAccessibilityTraitAdjustable; } + if (_node.HasFlag(blink::SemanticsFlags::kIsSelected) || + _node.HasFlag(blink::SemanticsFlags::kIsChecked)) { + traits |= UIAccessibilityTraitSelected; + } return traits; } -- GitLab