Desktop: Support a11y slider widgets (flutter/engine#30322)

Adds support to the common desktop accessibility bridge for widgets that
include a semantics node with the `isSlider` flag set.

Issue: https://github.com/flutter/flutter/issues/77838
This commit is contained in:
Chris Bracken
2021-12-14 11:20:16 -08:00
committed by GitHub
parent aaaf467b08
commit a2d82caeab
2 changed files with 27 additions and 0 deletions

View File

@@ -257,6 +257,10 @@ void AccessibilityBridge::SetRoleFromFlutterUpdate(ui::AXNodeData& node_data,
node_data.role = ax::mojom::Role::kToggleButton;
return;
}
if (flags & kFlutterSemanticsFlagIsSlider) {
node_data.role = ax::mojom::Role::kSlider;
return;
}
// If the state cannot be derived from the flutter flags, we fallback to group
// or static text.
if (node.children_in_traversal_order.size() == 0) {

View File

@@ -314,5 +314,28 @@ TEST(AccessibilityBridgeTest, ToggleHasToggleButtonRole) {
EXPECT_EQ(root_node->GetData().role, ax::mojom::Role::kToggleButton);
}
TEST(AccessibilityBridgeTest, SliderHasSliderRole) {
std::shared_ptr<AccessibilityBridge> bridge =
std::make_shared<AccessibilityBridge>(
std::make_unique<TestAccessibilityBridgeDelegate>());
FlutterSemanticsNode root{.id = 0};
root.flags = static_cast<FlutterSemanticsFlag>(
FlutterSemanticsFlag::kFlutterSemanticsFlagIsSlider |
FlutterSemanticsFlag::kFlutterSemanticsFlagHasEnabledState |
FlutterSemanticsFlag::kFlutterSemanticsFlagIsEnabled |
FlutterSemanticsFlag::kFlutterSemanticsFlagIsFocusable);
root.actions = static_cast<FlutterSemanticsAction>(0);
root.text_selection_base = -1;
root.text_selection_extent = -1;
root.label = "root";
root.child_count = 0;
root.custom_accessibility_actions_count = 0;
bridge->AddFlutterSemanticsNodeUpdate(&root);
bridge->CommitUpdates();
auto root_node = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
EXPECT_EQ(root_node->GetData().role, ax::mojom::Role::kSlider);
}
} // namespace testing
} // namespace flutter