Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions shell/platform/fuchsia/flutter/accessibility_bridge.cc
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,36 @@ fuchsia::accessibility::semantics::States AccessibilityBridge::GetNodeStates(
return states;
}

std::vector<fuchsia::accessibility::semantics::Action>
AccessibilityBridge::GetNodeActions(const flutter::SemanticsNode& node,
size_t* additional_size) const {
std::vector<fuchsia::accessibility::semantics::Action> node_actions;

if (node.HasAction(flutter::SemanticsAction::kTap)) {
node_actions.push_back(fuchsia::accessibility::semantics::Action::DEFAULT);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is more a FYI. For a lack of a better name, we are thinking adding a semantics action that call DefaultAction to support ios magic tap. https://developer.apple.com/documentation/objectivec/nsobject/1615137-accessibilityperformmagictap?language=objc.

I am not sure how should they overlap here. Is the Action::DEFAULT always referring to tap in fuchsia?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the heads-up. Based on the description in that link, it looks like Action::Default is the most appropriate mapping for SemanticsAction::kTap.

}
if (node.HasAction(flutter::SemanticsAction::kLongPress)) {
node_actions.push_back(
fuchsia::accessibility::semantics::Action::SECONDARY);
}
if (node.HasAction(flutter::SemanticsAction::kShowOnScreen)) {
node_actions.push_back(
fuchsia::accessibility::semantics::Action::SHOW_ON_SCREEN);
}
if (node.HasAction(flutter::SemanticsAction::kIncrease)) {
node_actions.push_back(
fuchsia::accessibility::semantics::Action::INCREMENT);
}
if (node.HasAction(flutter::SemanticsAction::kDecrease)) {
node_actions.push_back(
fuchsia::accessibility::semantics::Action::DECREMENT);
}

*additional_size +=
node_actions.size() * sizeof(fuchsia::accessibility::semantics::Action);
return node_actions;
}

std::unordered_set<int32_t> AccessibilityBridge::GetDescendants(
int32_t node_id) const {
std::unordered_set<int32_t> descendents;
Expand Down Expand Up @@ -227,6 +257,7 @@ void AccessibilityBridge::AddSemanticsNodeUpdate(
.set_transform(GetNodeTransform(flutter_node))
.set_attributes(GetNodeAttributes(flutter_node, &this_node_size))
.set_states(GetNodeStates(flutter_node, &this_node_size))
.set_actions(GetNodeActions(flutter_node, &this_node_size))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not familiar with fuchsia code. Do you know where are these APIs defined?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah I see, thanks for the link

.set_child_ids(child_ids);
this_node_size +=
kNodeIdSize * flutter_node.childrenInTraversalOrder.size();
Expand Down
6 changes: 6 additions & 0 deletions shell/platform/fuchsia/flutter/accessibility_bridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,12 @@ class AccessibilityBridge
const flutter::SemanticsNode& node,
size_t* additional_size) const;

// Derives the set of supported actions for a Fuchsia semantics node from
// a Flutter semantics node.
std::vector<fuchsia::accessibility::semantics::Action> GetNodeActions(
const flutter::SemanticsNode& node,
size_t* additional_size) const;

// Gets the set of reachable descendants from the given node id.
std::unordered_set<int32_t> GetDescendants(int32_t node_id) const;

Expand Down
30 changes: 30 additions & 0 deletions shell/platform/fuchsia/flutter/accessibility_bridge_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,36 @@ TEST_F(AccessibilityBridgeTest, PopulatesHiddenState) {
EXPECT_FALSE(semantics_manager_.UpdateOverflowed());
}

TEST_F(AccessibilityBridgeTest, PopulatesActions) {
flutter::SemanticsNode node0;
node0.id = 0;
node0.actions |= static_cast<int>(flutter::SemanticsAction::kTap);
node0.actions |= static_cast<int>(flutter::SemanticsAction::kLongPress);
node0.actions |= static_cast<int>(flutter::SemanticsAction::kShowOnScreen);
node0.actions |= static_cast<int>(flutter::SemanticsAction::kIncrease);
node0.actions |= static_cast<int>(flutter::SemanticsAction::kDecrease);

accessibility_bridge_->AddSemanticsNodeUpdate({{0, node0}});
RunLoopUntilIdle();

EXPECT_EQ(0, semantics_manager_.DeleteCount());
EXPECT_EQ(1, semantics_manager_.UpdateCount());
EXPECT_EQ(1, semantics_manager_.CommitCount());
EXPECT_EQ(1u, semantics_manager_.LastUpdatedNodes().size());
const auto& fuchsia_node = semantics_manager_.LastUpdatedNodes().at(0u);
EXPECT_EQ(fuchsia_node.actions().size(), 5u);
EXPECT_EQ(fuchsia_node.actions().at(0u),
fuchsia::accessibility::semantics::Action::DEFAULT);
EXPECT_EQ(fuchsia_node.actions().at(1u),
fuchsia::accessibility::semantics::Action::SECONDARY);
EXPECT_EQ(fuchsia_node.actions().at(2u),
fuchsia::accessibility::semantics::Action::SHOW_ON_SCREEN);
EXPECT_EQ(fuchsia_node.actions().at(3u),
fuchsia::accessibility::semantics::Action::INCREMENT);
EXPECT_EQ(fuchsia_node.actions().at(4u),
fuchsia::accessibility::semantics::Action::DECREMENT);
}

TEST_F(AccessibilityBridgeTest, TruncatesLargeLabel) {
// Test that labels which are too long are truncated.
flutter::SemanticsNode node0;
Expand Down