[a11y] Flutter sends node roles as part of Fuchsia semantics updates. (flutter/engine#21329)
This commit is contained in:
@@ -145,6 +145,28 @@ AccessibilityBridge::GetNodeActions(const flutter::SemanticsNode& node,
|
||||
return node_actions;
|
||||
}
|
||||
|
||||
fuchsia::accessibility::semantics::Role AccessibilityBridge::GetNodeRole(
|
||||
const flutter::SemanticsNode& node) const {
|
||||
if (node.HasFlag(flutter::SemanticsFlags::kIsButton)) {
|
||||
return fuchsia::accessibility::semantics::Role::BUTTON;
|
||||
}
|
||||
if (node.HasFlag(flutter::SemanticsFlags::kIsHeader)) {
|
||||
return fuchsia::accessibility::semantics::Role::HEADER;
|
||||
}
|
||||
if (node.HasFlag(flutter::SemanticsFlags::kIsImage)) {
|
||||
return fuchsia::accessibility::semantics::Role::IMAGE;
|
||||
}
|
||||
// If a flutter node supports the kIncrease or kDecrease actions, it can be
|
||||
// treated as a slider control by assistive technology. This is important
|
||||
// because users have special gestures to deal with sliders, and Fuchsia API
|
||||
// requires nodes that can receive this kind of action to be a slider control.
|
||||
if (node.HasAction(flutter::SemanticsAction::kIncrease) ||
|
||||
node.HasAction(flutter::SemanticsAction::kDecrease)) {
|
||||
return fuchsia::accessibility::semantics::Role::SLIDER;
|
||||
}
|
||||
return fuchsia::accessibility::semantics::Role::UNKNOWN;
|
||||
}
|
||||
|
||||
std::unordered_set<int32_t> AccessibilityBridge::GetDescendants(
|
||||
int32_t node_id) const {
|
||||
std::unordered_set<int32_t> descendents;
|
||||
@@ -253,6 +275,7 @@ void AccessibilityBridge::AddSemanticsNodeUpdate(
|
||||
child_ids.push_back(FlutterIdToFuchsiaId(flutter_child_id));
|
||||
}
|
||||
fuchsia_node.set_node_id(flutter_node.id)
|
||||
.set_role(GetNodeRole(flutter_node))
|
||||
.set_location(GetNodeLocation(flutter_node))
|
||||
.set_transform(GetNodeTransform(flutter_node))
|
||||
.set_attributes(GetNodeAttributes(flutter_node, &this_node_size))
|
||||
|
||||
@@ -151,6 +151,11 @@ class AccessibilityBridge
|
||||
const flutter::SemanticsNode& node,
|
||||
size_t* additional_size) const;
|
||||
|
||||
// Derives the role for a Fuchsia semantics node from a Flutter
|
||||
// semantics node.
|
||||
fuchsia::accessibility::semantics::Role GetNodeRole(
|
||||
const flutter::SemanticsNode& node) const;
|
||||
|
||||
// Gets the set of reachable descendants from the given node id.
|
||||
std::unordered_set<int32_t> GetDescendants(int32_t node_id) const;
|
||||
|
||||
|
||||
@@ -137,6 +137,70 @@ TEST_F(AccessibilityBridgeTest, DeletesChildrenTransitively) {
|
||||
EXPECT_FALSE(semantics_manager_.UpdateOverflowed());
|
||||
}
|
||||
|
||||
TEST_F(AccessibilityBridgeTest, PopulatesRoleButton) {
|
||||
flutter::SemanticsNode node0;
|
||||
node0.id = 0;
|
||||
node0.flags = static_cast<int>(flutter::SemanticsFlags::kIsButton);
|
||||
|
||||
accessibility_bridge_->AddSemanticsNodeUpdate({{0, node0}});
|
||||
RunLoopUntilIdle();
|
||||
|
||||
EXPECT_EQ(1U, semantics_manager_.LastUpdatedNodes().size());
|
||||
const auto& fuchsia_node = semantics_manager_.LastUpdatedNodes().at(0u);
|
||||
EXPECT_EQ(fuchsia_node.node_id(), static_cast<unsigned int>(node0.id));
|
||||
EXPECT_TRUE(fuchsia_node.has_role());
|
||||
EXPECT_EQ(fuchsia_node.role(),
|
||||
fuchsia::accessibility::semantics::Role::BUTTON);
|
||||
}
|
||||
|
||||
TEST_F(AccessibilityBridgeTest, PopulatesRoleImage) {
|
||||
flutter::SemanticsNode node0;
|
||||
node0.id = 0;
|
||||
node0.flags = static_cast<int>(flutter::SemanticsFlags::kIsImage);
|
||||
|
||||
accessibility_bridge_->AddSemanticsNodeUpdate({{0, node0}});
|
||||
RunLoopUntilIdle();
|
||||
|
||||
EXPECT_EQ(1U, semantics_manager_.LastUpdatedNodes().size());
|
||||
const auto& fuchsia_node = semantics_manager_.LastUpdatedNodes().at(0u);
|
||||
EXPECT_EQ(fuchsia_node.node_id(), static_cast<unsigned int>(node0.id));
|
||||
EXPECT_TRUE(fuchsia_node.has_role());
|
||||
EXPECT_EQ(fuchsia_node.role(),
|
||||
fuchsia::accessibility::semantics::Role::IMAGE);
|
||||
}
|
||||
|
||||
TEST_F(AccessibilityBridgeTest, PopulatesRoleSlider) {
|
||||
flutter::SemanticsNode node0;
|
||||
node0.id = 0;
|
||||
node0.actions |= static_cast<int>(flutter::SemanticsAction::kIncrease);
|
||||
|
||||
accessibility_bridge_->AddSemanticsNodeUpdate({{0, node0}});
|
||||
RunLoopUntilIdle();
|
||||
|
||||
EXPECT_EQ(1U, semantics_manager_.LastUpdatedNodes().size());
|
||||
const auto& fuchsia_node = semantics_manager_.LastUpdatedNodes().at(0u);
|
||||
EXPECT_EQ(fuchsia_node.node_id(), static_cast<unsigned int>(node0.id));
|
||||
EXPECT_TRUE(fuchsia_node.has_role());
|
||||
EXPECT_EQ(fuchsia_node.role(),
|
||||
fuchsia::accessibility::semantics::Role::SLIDER);
|
||||
}
|
||||
|
||||
TEST_F(AccessibilityBridgeTest, PopulatesRoleHeader) {
|
||||
flutter::SemanticsNode node0;
|
||||
node0.id = 0;
|
||||
node0.flags = static_cast<int>(flutter::SemanticsFlags::kIsHeader);
|
||||
|
||||
accessibility_bridge_->AddSemanticsNodeUpdate({{0, node0}});
|
||||
RunLoopUntilIdle();
|
||||
|
||||
EXPECT_EQ(1U, semantics_manager_.LastUpdatedNodes().size());
|
||||
const auto& fuchsia_node = semantics_manager_.LastUpdatedNodes().at(0u);
|
||||
EXPECT_EQ(fuchsia_node.node_id(), static_cast<unsigned int>(node0.id));
|
||||
EXPECT_TRUE(fuchsia_node.has_role());
|
||||
EXPECT_EQ(fuchsia_node.role(),
|
||||
fuchsia::accessibility::semantics::Role::HEADER);
|
||||
}
|
||||
|
||||
TEST_F(AccessibilityBridgeTest, PopulatesCheckedState) {
|
||||
flutter::SemanticsNode node0;
|
||||
node0.id = 0;
|
||||
|
||||
Reference in New Issue
Block a user