Skip to content

Commit

Permalink
Add SemanticsFlag.isDisabled (flutter#4503)
Browse files Browse the repository at this point in the history
  • Loading branch information
goderbauer authored Jan 2, 2018
1 parent 3778965 commit 26010cf
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
14 changes: 14 additions & 0 deletions lib/ui/semantics.dart
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ class SemanticsFlags {
static const int _kIsButtonIndex = 1 << 3;
static const int _kIsTextFieldIndex = 1 << 4;
static const int _kIsFocusedIndex = 1 << 5;
static const int _kIsDisabledIndex = 1 << 6;

const SemanticsFlags._(this.index);

Expand Down Expand Up @@ -193,6 +194,16 @@ class SemanticsFlags {
/// The focused element is usually the current receiver of keyboard inputs.
static const SemanticsFlags isFocused = const SemanticsFlags._(_kIsFocusedIndex);

/// Whether the semantic node is currently disabled.
///
/// A disabled element does not respond to user interaction. For example, a
/// button that currently does not respond to user interaction should be
/// marked as disabled.
///
/// Elements, that never respond to user interactions (e.g. static text)
/// should not be marked as disabled.
static const SemanticsFlags isDisabled = const SemanticsFlags._(_kIsDisabledIndex);

/// The possible semantics flags.
///
/// The map's key is the [index] of the flag and the value is the flag itself.
Expand All @@ -203,6 +214,7 @@ class SemanticsFlags {
_kIsButtonIndex: isButton,
_kIsTextFieldIndex: isTextField,
_kIsFocusedIndex: isFocused,
_kIsDisabledIndex: isDisabled,
};

@override
Expand All @@ -220,6 +232,8 @@ class SemanticsFlags {
return 'SemanticsFlags.isTextField';
case _kIsFocusedIndex:
return 'SemanticsFlags.isFocused';
case _kIsDisabledIndex:
return 'SemanticsFlags.isDisabled';
}
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 @@ -41,6 +41,7 @@ enum class SemanticsFlags : int32_t {
kIsButton = 1 << 3,
kIsTextField = 1 << 4,
kIsFocused = 1 << 5,
kIsDisabled = 1 << 6,
};

struct SemanticsNode {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ enum Flag {
IS_SELECTED(1 << 2),
IS_BUTTON(1 << 3),
IS_TEXT_FIELD(1 << 4),
IS_FOCUSED(1 << 5);
IS_FOCUSED(1 << 5),
IS_DISABLED(1 << 6);

Flag(int value) {
this.value = value;
Expand Down Expand Up @@ -157,7 +158,7 @@ public AccessibilityNodeInfo createAccessibilityNodeInfo(int virtualViewId) {
}
result.setBoundsInScreen(bounds);
result.setVisibleToUser(true);
result.setEnabled(true); // TODO(ianh): Expose disabled subtrees
result.setEnabled(!object.hasFlag(Flag.IS_DISABLED));

if (object.hasAction(Action.TAP)) {
result.addAction(AccessibilityNodeInfo.ACTION_CLICK);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,9 @@ - (UIAccessibilityTraits)accessibilityTraits {
if (_node.HasFlag(blink::SemanticsFlags::kIsButton)) {
traits |= UIAccessibilityTraitButton;
}
if (_node.HasFlag(blink::SemanticsFlags::kIsDisabled)) {
traits |= UIAccessibilityTraitNotEnabled;
}
return traits;
}

Expand Down

0 comments on commit 26010cf

Please sign in to comment.