Assign mojom kSwitch role to switches (flutter/engine#48146)

We have previously been using the `kToggleButton` role for any widget
that has a toggled state. Our AX library does not expect this role to be
used for switches, and so would not assign the checked state to switches
for MSAA. As far as I can tell, the `Switch` is the only widget that
uses the `toggled` semantic property (`ToggleButtons`, ironically, does
not), so we ought to be able to swap in the `kSwitch` role, for which
the proper states are presented. This will allow screen readers to
announce the state of a switch.

https://github.com/flutter/flutter/issues/138500

## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide] and the [C++,
Objective-C, Java style guides].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [x] I added new tests to check the change I am making or feature I am
adding, or the PR is [test-exempt]. See [testing the engine] for
instructions on writing and running engine tests.
- [x] I updated/added relevant documentation (doc comments with `///`).
- [ ] I signed the [CLA].
- [x] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#overview
[Tree Hygiene]: https://github.com/flutter/flutter/wiki/Tree-hygiene
[test-exempt]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo
[C++, Objective-C, Java style guides]:
https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
[testing the engine]:
https://github.com/flutter/flutter/wiki/Testing-the-engine
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#handling-breaking-changes
[Discord]: https://github.com/flutter/flutter/wiki/Chat
This commit is contained in:
yaakovschectman
2023-11-17 14:21:23 -05:00
committed by GitHub
parent 3e7fea4e4f
commit bb97ac1d3b
3 changed files with 8 additions and 6 deletions

View File

@@ -333,7 +333,7 @@ void AccessibilityBridge::SetRoleFromFlutterUpdate(ui::AXNodeData& node_data,
return;
}
if (flags & kFlutterSemanticsFlagHasToggledState) {
node_data.role = ax::mojom::Role::kToggleButton;
node_data.role = ax::mojom::Role::kSwitch;
return;
}
if (flags & kFlutterSemanticsFlagIsSlider) {
@@ -477,7 +477,7 @@ void AccessibilityBridge::SetIntAttributesFromFlutterUpdate(
: flags & FlutterSemanticsFlag::kFlutterSemanticsFlagIsChecked
? ax::mojom::CheckedState::kTrue
: ax::mojom::CheckedState::kFalse));
} else if (node_data.role == ax::mojom::Role::kToggleButton) {
} else if (node_data.role == ax::mojom::Role::kSwitch) {
node_data.AddIntAttribute(
ax::mojom::IntAttribute::kCheckedState,
static_cast<int32_t>(

View File

@@ -253,7 +253,7 @@ TEST(AccessibilityBridgeTest, DoesNotAssignEditableRootToSelectableText) {
ax::mojom::BoolAttribute::kEditableRoot));
}
TEST(AccessibilityBridgeTest, ToggleHasToggleButtonRole) {
TEST(AccessibilityBridgeTest, SwitchHasSwitchRole) {
std::shared_ptr<TestAccessibilityBridge> bridge =
std::make_shared<TestAccessibilityBridge>();
FlutterSemanticsNode2 root = CreateSemanticsNode(0, "root");
@@ -265,7 +265,7 @@ TEST(AccessibilityBridgeTest, ToggleHasToggleButtonRole) {
bridge->CommitUpdates();
auto root_node = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
EXPECT_EQ(root_node->GetData().role, ax::mojom::Role::kToggleButton);
EXPECT_EQ(root_node->GetData().role, ax::mojom::Role::kSwitch);
}
TEST(AccessibilityBridgeTest, SliderHasSliderRole) {

View File

@@ -1081,7 +1081,7 @@ TEST(FlutterWindowsViewTest, SwitchNativeState) {
{
auto root_node = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
EXPECT_EQ(root_node->GetData().role, ax::mojom::Role::kToggleButton);
EXPECT_EQ(root_node->GetData().role, ax::mojom::Role::kSwitch);
EXPECT_EQ(root_node->GetData().GetCheckedState(),
ax::mojom::CheckedState::kTrue);
@@ -1104,6 +1104,7 @@ TEST(FlutterWindowsViewTest, SwitchNativeState) {
VARIANT native_state = {};
ASSERT_TRUE(SUCCEEDED(native_view->get_accState(varchild, &native_state)));
EXPECT_TRUE(native_state.lVal & STATE_SYSTEM_PRESSED);
EXPECT_TRUE(native_state.lVal & STATE_SYSTEM_CHECKED);
// Test similarly on UIA node.
IRawElementProviderSimple* uia_node;
@@ -1129,7 +1130,7 @@ TEST(FlutterWindowsViewTest, SwitchNativeState) {
{
auto root_node = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
EXPECT_EQ(root_node->GetData().role, ax::mojom::Role::kToggleButton);
EXPECT_EQ(root_node->GetData().role, ax::mojom::Role::kSwitch);
EXPECT_EQ(root_node->GetData().GetCheckedState(),
ax::mojom::CheckedState::kFalse);
@@ -1146,6 +1147,7 @@ TEST(FlutterWindowsViewTest, SwitchNativeState) {
VARIANT native_state = {};
ASSERT_TRUE(SUCCEEDED(native_view->get_accState(varchild, &native_state)));
EXPECT_FALSE(native_state.lVal & STATE_SYSTEM_PRESSED);
EXPECT_FALSE(native_state.lVal & STATE_SYSTEM_CHECKED);
// Test similarly on UIA node.
IRawElementProviderSimple* uia_node;