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
7 changes: 7 additions & 0 deletions shell/platform/common/accessibility_bridge.cc
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,13 @@ void AccessibilityBridge::SetIntAttributesFromFlutterUpdate(
: flags & FlutterSemanticsFlag::kFlutterSemanticsFlagIsChecked
? ax::mojom::CheckedState::kTrue
: ax::mojom::CheckedState::kFalse));
} else if (node_data.role == ax::mojom::Role::kToggleButton) {
node_data.AddIntAttribute(
ax::mojom::IntAttribute::kCheckedState,
static_cast<int32_t>(
flags & FlutterSemanticsFlag::kFlutterSemanticsFlagIsToggled
? ax::mojom::CheckedState::kTrue
: ax::mojom::CheckedState::kFalse));
}
}

Expand Down
101 changes: 99 additions & 2 deletions shell/platform/windows/flutter_windows_view_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ TEST(FlutterWindowsViewTest, CheckboxNativeState) {
VARIANT varchild = {};
varchild.vt = VT_I4;

// Verify the checkbox is checked.
// Verify the checkbox is unchecked.
varchild.lVal = CHILDID_SELF;
VARIANT native_state = {};
ASSERT_TRUE(SUCCEEDED(native_view->get_accState(varchild, &native_state)));
Expand Down Expand Up @@ -716,13 +716,110 @@ TEST(FlutterWindowsViewTest, CheckboxNativeState) {
VARIANT varchild = {};
varchild.vt = VT_I4;

// Verify the checkbox is checked.
// Verify the checkbox is mixed.
varchild.lVal = CHILDID_SELF;
VARIANT native_state = {};
ASSERT_TRUE(SUCCEEDED(native_view->get_accState(varchild, &native_state)));
EXPECT_TRUE(native_state.lVal & STATE_SYSTEM_MIXED);
}
}

// Ensure that switches have their toggle status set apropriately
TEST(FlutterWindowsViewTest, SwitchNativeState) {
std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine();
EngineModifier modifier(engine.get());
modifier.embedder_api().UpdateSemanticsEnabled =
[](FLUTTER_API_SYMBOL(FlutterEngine) engine, bool enabled) {
return kSuccess;
};

auto window_binding_handler =
std::make_unique<::testing::NiceMock<MockWindowBindingHandler>>();
FlutterWindowsView view(std::move(window_binding_handler));
view.SetEngine(std::move(engine));

// Enable semantics to instantiate accessibility bridge.
view.OnUpdateSemanticsEnabled(true);

auto bridge = view.GetEngine()->accessibility_bridge().lock();
ASSERT_TRUE(bridge);

FlutterSemanticsNode root{sizeof(FlutterSemanticsNode), 0};
root.id = 0;
root.label = "root";
root.hint = "";
root.value = "";
root.increased_value = "";
root.decreased_value = "";
root.child_count = 0;
root.custom_accessibility_actions_count = 0;
root.flags = static_cast<FlutterSemanticsFlag>(
FlutterSemanticsFlag::kFlutterSemanticsFlagHasToggledState |
FlutterSemanticsFlag::kFlutterSemanticsFlagIsToggled);
bridge->AddFlutterSemanticsNodeUpdate(&root);

bridge->CommitUpdates();

{
auto root_node = bridge
->GetFlutterPlatformNodeDelegateFromID(
AccessibilityBridge::kRootNodeId)
.lock();
EXPECT_EQ(root_node->GetData().role, ax::mojom::Role::kToggleButton);
EXPECT_EQ(root_node->GetData().GetCheckedState(),
ax::mojom::CheckedState::kTrue);

// Get the IAccessible for the root node.
IAccessible* native_view = root_node->GetNativeViewAccessible();
ASSERT_TRUE(native_view != nullptr);

// Look up against the node itself (not one of its children).
VARIANT varchild = {};
varchild.vt = VT_I4;

varchild.lVal = CHILDID_SELF;
VARIANT varrole = {};

// Verify the role of the switch is CHECKBUTTON
ASSERT_EQ(native_view->get_accRole(varchild, &varrole), S_OK);
ASSERT_EQ(varrole.lVal, ROLE_SYSTEM_CHECKBUTTON);

// Verify the switch is pressed.
VARIANT native_state = {};
ASSERT_TRUE(SUCCEEDED(native_view->get_accState(varchild, &native_state)));
EXPECT_TRUE(native_state.lVal & STATE_SYSTEM_PRESSED);
}

// Test unpressed too.
root.flags = static_cast<FlutterSemanticsFlag>(
FlutterSemanticsFlag::kFlutterSemanticsFlagHasToggledState);
bridge->AddFlutterSemanticsNodeUpdate(&root);
bridge->CommitUpdates();

{
auto root_node = bridge
->GetFlutterPlatformNodeDelegateFromID(
AccessibilityBridge::kRootNodeId)
.lock();
EXPECT_EQ(root_node->GetData().role, ax::mojom::Role::kToggleButton);
EXPECT_EQ(root_node->GetData().GetCheckedState(),
ax::mojom::CheckedState::kFalse);

// Get the IAccessible for the root node.
IAccessible* native_view = root_node->GetNativeViewAccessible();
ASSERT_TRUE(native_view != nullptr);

// Look up against the node itself (not one of its children).
VARIANT varchild = {};
varchild.vt = VT_I4;

// Verify the switch is not pressed.
varchild.lVal = CHILDID_SELF;
VARIANT native_state = {};
ASSERT_TRUE(SUCCEEDED(native_view->get_accState(varchild, &native_state)));
EXPECT_FALSE(native_state.lVal & STATE_SYSTEM_PRESSED);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible to also test its MSAARole is ROLE_SYSTEM_CHECKBUTTON?

}
}

} // namespace testing
} // namespace flutter
Original file line number Diff line number Diff line change
Expand Up @@ -3421,7 +3421,7 @@ int AXPlatformNodeWin::MSAARole() {
return ROLE_SYSTEM_TITLEBAR;

case ax::mojom::Role::kToggleButton:
return ROLE_SYSTEM_PUSHBUTTON;
return ROLE_SYSTEM_CHECKBUTTON;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is check button basically a check box? Why do we choose this over push button?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is the same role as for a checkbox. In #flutter/fluter/111525 we are currently of the opinion that it is the most appropriate role, as it is for interactable widgets with toggleable state, and the materials design guidelines recommend their use in place of checkboxes on mobile

Copy link
Contributor

Choose a reason for hiding this comment

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

thanks for explanation. SGTM


case ax::mojom::Role::kTextField:
case ax::mojom::Role::kSearchBox:
Expand Down