Communicate switch status to semantics on Windows (flutter/engine#36177)

* Switch semantics

* Test native role
This commit is contained in:
yaakovschectman
2022-09-15 18:02:12 -04:00
committed by GitHub
parent 88b1dab12c
commit ef3bc43183
3 changed files with 107 additions and 3 deletions

View File

@@ -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));
}
}

View File

@@ -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)));
@@ -716,7 +716,7 @@ 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)));
@@ -724,5 +724,102 @@ TEST(FlutterWindowsViewTest, CheckboxNativeState) {
}
}
// 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);
}
}
} // namespace testing
} // namespace flutter

View File

@@ -3421,7 +3421,7 @@ int AXPlatformNodeWin::MSAARole() {
return ROLE_SYSTEM_TITLEBAR;
case ax::mojom::Role::kToggleButton:
return ROLE_SYSTEM_PUSHBUTTON;
return ROLE_SYSTEM_CHECKBUTTON;
case ax::mojom::Role::kTextField:
case ax::mojom::Role::kSearchBox: