Skip to content

Commit

Permalink
Split SemanticsFlags.isDisabled into two (flutter#4517)
Browse files Browse the repository at this point in the history
  • Loading branch information
goderbauer authored Jan 4, 2018
1 parent 4332773 commit 12e0e38
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 13 deletions.
27 changes: 18 additions & 9 deletions lib/ui/semantics.dart
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ 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;
static const int _kHasEnabledStateIndex = 1 << 6;
static const int _kIsEnabledIndex = 1 << 7;

const SemanticsFlags._(this.index);

Expand Down Expand Up @@ -194,15 +195,20 @@ 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.
/// The semantics node has the quality of either being "enabled" or
/// "disabled".
///
/// For example, a button can be enabled or disabled and therefore has an
/// "enabled" state. Static text is usually neither enabled nor disabled and
/// therefore does not have an "enabled" state.
static const SemanticsFlags hasEnabledState = const SemanticsFlags._(_kHasEnabledStateIndex);

/// Whether a semantic node that [hasEnabledState] is currently enabled.
///
/// 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);
static const SemanticsFlags isEnabled = const SemanticsFlags._(_kIsEnabledIndex);

/// The possible semantics flags.
///
Expand All @@ -214,7 +220,8 @@ class SemanticsFlags {
_kIsButtonIndex: isButton,
_kIsTextFieldIndex: isTextField,
_kIsFocusedIndex: isFocused,
_kIsDisabledIndex: isDisabled,
_kHasEnabledStateIndex: hasEnabledState,
_kIsEnabledIndex: isEnabled,
};

@override
Expand All @@ -232,8 +239,10 @@ class SemanticsFlags {
return 'SemanticsFlags.isTextField';
case _kIsFocusedIndex:
return 'SemanticsFlags.isFocused';
case _kIsDisabledIndex:
return 'SemanticsFlags.isDisabled';
case _kHasEnabledStateIndex:
return 'SemanticsFlags.hasEnabledState';
case _kIsEnabledIndex:
return 'SemanticsFlags.isEnabled';
}
return null;
}
Expand Down
3 changes: 2 additions & 1 deletion lib/ui/semantics/semantics_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ enum class SemanticsFlags : int32_t {
kIsButton = 1 << 3,
kIsTextField = 1 << 4,
kIsFocused = 1 << 5,
kIsDisabled = 1 << 6,
kHasEnabledState = 1 << 6,
kIsEnabled = 1 << 7,
};

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

Flag(int value) {
this.value = value;
Expand Down Expand Up @@ -158,7 +159,8 @@ public AccessibilityNodeInfo createAccessibilityNodeInfo(int virtualViewId) {
}
result.setBoundsInScreen(bounds);
result.setVisibleToUser(true);
result.setEnabled(!object.hasFlag(Flag.IS_DISABLED));
result.setEnabled(!object.hasFlag(Flag.HAS_ENABLED_STATE) ||
object.hasFlag(Flag.IS_ENABLED));

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,7 +194,8 @@ - (UIAccessibilityTraits)accessibilityTraits {
if (_node.HasFlag(blink::SemanticsFlags::kIsButton)) {
traits |= UIAccessibilityTraitButton;
}
if (_node.HasFlag(blink::SemanticsFlags::kIsDisabled)) {
if (_node.HasFlag(blink::SemanticsFlags::kHasEnabledState) &&
!_node.HasFlag(blink::SemanticsFlags::kIsEnabled)) {
traits |= UIAccessibilityTraitNotEnabled;
}
return traits;
Expand Down

0 comments on commit 12e0e38

Please sign in to comment.