-
Notifications
You must be signed in to change notification settings - Fork 6k
Honor mixed state of tristate Checkbox in Semantics #35868
Honor mixed state of tristate Checkbox in Semantics #35868
Conversation
cbracken
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall this approach lgtm. Adding @chunhtai for general a11y review.
|
I am going to need to push an interim PR to flutter/flutter to circumvent some tests that this change would break so that this change can be merged, which is necessary for those tests to be updated to be compatible with it. |
lib/ui/semantics.dart
Outdated
|
|
||
| /// Whether a tristate checkbox is in its mixed state. | ||
| /// | ||
| /// Should only be true when the checkbox has [tristate] = true. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this can still be false if [tristate] = true?
Also this comment is too specific, people who reading this doc may not know what tristate is.
Maybe
If this is true, the check box this semantics node represents is in a mixed state. For example, a [Checkbox] with [Checkbox.tristate] set to true can have checked, unchecked, or mixed state.
lib/web_ui/lib/semantics.dart
Outdated
| static const SemanticsFlag hasToggledState = SemanticsFlag._(_kHasToggledStateIndex); | ||
| static const SemanticsFlag isToggled = SemanticsFlag._(_kIsToggledIndex); | ||
| static const SemanticsFlag hasImplicitScrolling = SemanticsFlag._(_kHasImplicitScrollingIndex); | ||
| static const SemanticsFlag isMixedCheck = SemanticsFlag._(_kIsMixedCheckIndex); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We may need a better name. maybe isCheckStateMixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe isMixedCheckState? But it's a bit at odds with existing naming convention typically hasFooState and isFoo.
lib/ui/semantics.dart
Outdated
| /// can have checked, unchecked, or mixed state. | ||
| /// | ||
| /// Should be false when the checkbox is either checked or unchecked. | ||
| /// |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| /// |
| EXPECT_FALSE(native_state.lVal & STATE_SYSTEM_CHECKED); | ||
| } | ||
|
|
||
| // Now check mixed state |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Super pedantic nit: end with a period (here and below). Look like at least one comment above was already missing one :/
Ref: https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#use-correct-grammar
| // Now check mixed state | |
| // Now check mixed state. |
| IAccessible* native_view = root_node->GetNativeViewAccessible(); | ||
| ASSERT_TRUE(native_view != nullptr); | ||
|
|
||
| // Look up against the node itself (not one of its children) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| // Look up against the node itself (not one of its children) | |
| // Look up against the node itself (not one of its children). |
| IAccessible* native_view = root_node->GetNativeViewAccessible(); | ||
| ASSERT_TRUE(native_view != nullptr); | ||
|
|
||
| // Look up against the node itself (not one of its children) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quick fix of existing comment:
| // Look up against the node itself (not one of its children) | |
| // Look up against the node itself (not one of its children). |
| EXPECT_TRUE(native_state.lVal & STATE_SYSTEM_CHECKED); | ||
| } | ||
|
|
||
| // Test unchecked too |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quick fix of existing comment. Sadly, github won't let me fix the one on line 653/654.
| // Test unchecked too | |
| // Test unchecked too. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
chunhtai
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
lib/ui/semantics.dart
Outdated
| /// For example, a [Checkbox] with [Checkbox.tristate] set to true | ||
| /// can have checked, unchecked, or mixed state. | ||
| /// | ||
| /// Should be false when the checkbox is either checked or unchecked. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| /// Should be false when the checkbox is either checked or unchecked. | |
| /// Must be false when the checkbox is either checked or unchecked. |
* Honor mixed state * Add to unit test * Add state enums * Fix delimiter * Add enums * Scope subtests, rename enum * Rename enums * Comment specification * Tidy up comments * Rename java enum * Trailing whitespace

Flutter already supports tristate checkboxes that can have a mixed or half-checked state, but the semantics do not. Where the checked/unchecked state of a checkbox is passed to the Semantics node, a mixed state is not. This adds support for the mixed-state semantics flag to the engine. In conjunction with a PR to Flutter, we will be able to support the mixed state in semantics for checkboxes.
Addresses flutter/flutter#110107
Pre-launch Checklist
writing and running engine tests.
///).If you need help, consider asking for advice on the #hackers-new channel on Discord.