Support toggle buttons for desktop accessibility (flutter/engine#30297)

This commit is contained in:
Chris Bracken
2021-12-13 11:04:05 -08:00
committed by GitHub
parent 4b41bad357
commit a9722681ef
3 changed files with 29 additions and 1 deletions

View File

@@ -253,6 +253,10 @@ void AccessibilityBridge::SetRoleFromFlutterUpdate(ui::AXNodeData& node_data,
node_data.role = ax::mojom::Role::kCheckBox;
return;
}
if (flags & kFlutterSemanticsFlagHasToggledState) {
node_data.role = ax::mojom::Role::kToggleButton;
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

@@ -292,5 +292,27 @@ TEST(AccessibilityBridgeTest, doesNotAssignEditableRootToSelectableText) {
ax::mojom::BoolAttribute::kEditableRoot));
}
TEST(AccessibilityBridgeTest, ToggleHasToggleButtonRole) {
std::shared_ptr<AccessibilityBridge> bridge =
std::make_shared<AccessibilityBridge>(
std::make_unique<TestAccessibilityBridgeDelegate>());
FlutterSemanticsNode root{.id = 0};
root.flags = static_cast<FlutterSemanticsFlag>(
FlutterSemanticsFlag::kFlutterSemanticsFlagHasToggledState |
FlutterSemanticsFlag::kFlutterSemanticsFlagHasEnabledState |
FlutterSemanticsFlag::kFlutterSemanticsFlagIsEnabled);
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::kToggleButton);
}
} // namespace testing
} // namespace flutter

View File

@@ -34,6 +34,9 @@ void AccessibilityBridgeDelegateWin32::OnAccessibilityEvent(
case ui::AXEventGenerator::Event::ALERT:
DispatchWinAccessibilityEvent(win_delegate, EVENT_SYSTEM_ALERT);
break;
case ui::AXEventGenerator::Event::CHECKED_STATE_CHANGED:
DispatchWinAccessibilityEvent(win_delegate, EVENT_OBJECT_VALUECHANGE);
break;
case ui::AXEventGenerator::Event::CHILDREN_CHANGED:
DispatchWinAccessibilityEvent(win_delegate, EVENT_OBJECT_REORDER);
break;
@@ -83,7 +86,6 @@ void AccessibilityBridgeDelegateWin32::OnAccessibilityEvent(
case ui::AXEventGenerator::Event::ATOMIC_CHANGED:
case ui::AXEventGenerator::Event::AUTO_COMPLETE_CHANGED:
case ui::AXEventGenerator::Event::BUSY_CHANGED:
case ui::AXEventGenerator::Event::CHECKED_STATE_CHANGED:
case ui::AXEventGenerator::Event::CLASS_NAME_CHANGED:
case ui::AXEventGenerator::Event::COLLAPSED:
case ui::AXEventGenerator::Event::CONTROLS_CHANGED: