Skip to content

Commit

Permalink
A11y enabled state (flutter#48653)
Browse files Browse the repository at this point in the history
Sets enabled state in Fuchsia a11y via the accessibility bridge.

This was added in Fuchsia API v15, which Flutter is updated to use after
flutter#48233.

b/261482081

## 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 `///`).
- [x] I signed the [CLA].
- [x] All existing and new tests are passing.
  • Loading branch information
jrwang authored Dec 5, 2023
1 parent 184cdef commit cfdaecc
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
8 changes: 8 additions & 0 deletions shell/platform/fuchsia/flutter/accessibility_bridge.cc
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,14 @@ fuchsia::accessibility::semantics::States AccessibilityBridge::GetNodeStates(
: fuchsia::accessibility::semantics::CheckedState::UNCHECKED);
}

// Set enabled state.
if (node.HasFlag(flutter::SemanticsFlags::kHasEnabledState)) {
states.set_enabled_state(
node.HasFlag(flutter::SemanticsFlags::kIsEnabled)
? fuchsia::accessibility::semantics::EnabledState::ENABLED
: fuchsia::accessibility::semantics::EnabledState::DISABLED);
}

// Set selected state.
states.set_selected(node.HasFlag(flutter::SemanticsFlags::kIsSelected));

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 @@ -483,6 +483,36 @@ TEST_F(AccessibilityBridgeTest, PopulatesToggledState) {
EXPECT_FALSE(semantics_manager_.UpdateOverflowed());
}

TEST_F(AccessibilityBridgeTest, PopulatesEnabledState) {
flutter::SemanticsNode node0;
node0.id = 0;
// HasEnabledState = true
// IsEnabled = true
node0.flags |= static_cast<int>(flutter::SemanticsFlags::kHasEnabledState);
node0.flags |= static_cast<int>(flutter::SemanticsFlags::kIsEnabled);
node0.value = "value";

accessibility_bridge_->AddSemanticsNodeUpdate({{0, node0}}, 1.f);
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.node_id(), static_cast<unsigned int>(node0.id));
EXPECT_TRUE(fuchsia_node.has_states());
const auto& states = fuchsia_node.states();
EXPECT_TRUE(states.has_enabled_state());
EXPECT_EQ(states.enabled_state(),
fuchsia::accessibility::semantics::EnabledState::ENABLED);
EXPECT_TRUE(states.has_value());
EXPECT_EQ(states.value(), node0.value);

EXPECT_FALSE(semantics_manager_.DeleteOverflowed());
EXPECT_FALSE(semantics_manager_.UpdateOverflowed());
}

TEST_F(AccessibilityBridgeTest, ApplyViewPixelRatioToRoot) {
flutter::SemanticsNode node0;
node0.id = 0;
Expand Down

0 comments on commit cfdaecc

Please sign in to comment.