Add SemanticsFlag.isDisabled (flutter/engine#4503)

This commit is contained in:
Michael Goderbauer
2018-01-02 15:57:52 -08:00
committed by GitHub
parent f461782e0a
commit e863618c08
4 changed files with 21 additions and 2 deletions

View File

@@ -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);
@@ -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.
@@ -203,6 +214,7 @@ class SemanticsFlags {
_kIsButtonIndex: isButton,
_kIsTextFieldIndex: isTextField,
_kIsFocusedIndex: isFocused,
_kIsDisabledIndex: isDisabled,
};
@override
@@ -220,6 +232,8 @@ class SemanticsFlags {
return 'SemanticsFlags.isTextField';
case _kIsFocusedIndex:
return 'SemanticsFlags.isFocused';
case _kIsDisabledIndex:
return 'SemanticsFlags.isDisabled';
}
return null;
}

View File

@@ -41,6 +41,7 @@ enum class SemanticsFlags : int32_t {
kIsButton = 1 << 3,
kIsTextField = 1 << 4,
kIsFocused = 1 << 5,
kIsDisabled = 1 << 6,
};
struct SemanticsNode {

View File

@@ -65,7 +65,8 @@ class AccessibilityBridge extends AccessibilityNodeProvider implements BasicMess
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;
@@ -157,7 +158,7 @@ class AccessibilityBridge extends AccessibilityNodeProvider implements BasicMess
}
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);

View File

@@ -194,6 +194,9 @@ bool GeometryComparator(SemanticsObject* a, SemanticsObject* b) {
if (_node.HasFlag(blink::SemanticsFlags::kIsButton)) {
traits |= UIAccessibilityTraitButton;
}
if (_node.HasFlag(blink::SemanticsFlags::kIsDisabled)) {
traits |= UIAccessibilityTraitNotEnabled;
}
return traits;
}