Skip to content

Commit

Permalink
Add a semantic isButton flag (flutter#4254)
Browse files Browse the repository at this point in the history
  • Loading branch information
amirh authored Oct 20, 2017
1 parent c39124d commit 3d01338
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
8 changes: 8 additions & 0 deletions lib/ui/semantics.dart
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ class SemanticsFlags {
static const int _kHasCheckedStateIndex = 1 << 0;
static const int _kIsCheckedIndex = 1 << 1;
static const int _kIsSelectedIndex = 1 << 2;
static const int _kIsButton = 1 << 3;

const SemanticsFlags._(this.index);

Expand Down Expand Up @@ -153,6 +154,13 @@ class SemanticsFlags {
/// For example, the active tab in a tab bar has [isSelected] set to true.
static const SemanticsFlags isSelected = const SemanticsFlags._(_kIsSelectedIndex);

/// Whether the semantic node represents a button.
///
/// Platforms has special handling for buttons, for example Android's TalkBack
/// and iOS's VoiceOver provides an additional hint when the focused object is
/// a button.
static const SemanticsFlags isButton = const SemanticsFlags._(_kIsButton);

/// The possible semantics flags.
///
/// The map's key is the [index] of the flag and the value is the flag itself.
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 @@ -38,6 +38,7 @@ enum class SemanticsFlags : int32_t {
kHasCheckedState = 1 << 0,
kIsChecked = 1 << 1,
kIsSelected = 1 << 2,
kIsButton = 1 << 3,
};

struct SemanticsNode {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class AccessibilityBridge extends AccessibilityNodeProvider implements BasicMess
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;
private static final int SEMANTICS_FLAG_IS_BUTTON = 1 << 3;

AccessibilityBridge(FlutterView owner) {
assert owner != null;
Expand Down Expand Up @@ -159,6 +160,10 @@ public AccessibilityNodeInfo createAccessibilityNodeInfo(int virtualViewId) {
result.setSelected((object.flags & SEMANTICS_FLAG_IS_SELECTED) != 0);
result.setText(object.label);

if ((object.flags & SEMANTICS_FLAG_IS_BUTTON) != 0) {
result.setClassName("android.widget.Button");
}

// Accessibility Focus
if (mFocusedObject != null && mFocusedObject.id == virtualViewId) {
result.addAction(AccessibilityNodeInfo.ACTION_CLEAR_ACCESSIBILITY_FOCUS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,6 @@ - (NSString*)accessibilityLabel {

- (UIAccessibilityTraits)accessibilityTraits {
UIAccessibilityTraits traits = UIAccessibilityTraitNone;
if (_node.HasAction(blink::SemanticsAction::kTap)) {
traits |= UIAccessibilityTraitButton;
}
if (_node.HasAction(blink::SemanticsAction::kIncrease) ||
_node.HasAction(blink::SemanticsAction::kDecrease)) {
traits |= UIAccessibilityTraitAdjustable;
Expand All @@ -175,6 +172,9 @@ - (UIAccessibilityTraits)accessibilityTraits {
_node.HasFlag(blink::SemanticsFlags::kIsChecked)) {
traits |= UIAccessibilityTraitSelected;
}
if (_node.HasFlag(blink::SemanticsFlags::kIsButton)) {
traits |= UIAccessibilityTraitButton;
}
return traits;
}

Expand Down

0 comments on commit 3d01338

Please sign in to comment.