From e8c2d9b35fb43ca7966a5d038238e3a0ea46742f Mon Sep 17 00:00:00 2001 From: schectman Date: Thu, 15 Sep 2022 15:12:43 -0400 Subject: [PATCH 1/2] Switch semantics --- shell/platform/common/accessibility_bridge.cc | 7 ++ .../windows/flutter_windows_view_unittests.cc | 95 ++++++++++++++++++- .../ax/platform/ax_platform_node_win.cc | 2 +- 3 files changed, 101 insertions(+), 3 deletions(-) diff --git a/shell/platform/common/accessibility_bridge.cc b/shell/platform/common/accessibility_bridge.cc index 0c831104023e9..3a050a5a415f9 100644 --- a/shell/platform/common/accessibility_bridge.cc +++ b/shell/platform/common/accessibility_bridge.cc @@ -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( + flags & FlutterSemanticsFlag::kFlutterSemanticsFlagIsToggled + ? ax::mojom::CheckedState::kTrue + : ax::mojom::CheckedState::kFalse)); } } diff --git a/shell/platform/windows/flutter_windows_view_unittests.cc b/shell/platform/windows/flutter_windows_view_unittests.cc index 58b5cc7015ac7..48eac6175ebec 100644 --- a/shell/platform/windows/flutter_windows_view_unittests.cc +++ b/shell/platform/windows/flutter_windows_view_unittests.cc @@ -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,96 @@ TEST(FlutterWindowsViewTest, CheckboxNativeState) { } } +// Ensure that switches have their toggle status set apropriately +TEST(FlutterWindowsViewTest, SwitchNativeState) { + std::unique_ptr 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>(); + 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::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; + + // Verify the switch is pressed. + varchild.lVal = CHILDID_SELF; + 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::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 diff --git a/third_party/accessibility/ax/platform/ax_platform_node_win.cc b/third_party/accessibility/ax/platform/ax_platform_node_win.cc index f56c0a3737270..1e649877a800d 100644 --- a/third_party/accessibility/ax/platform/ax_platform_node_win.cc +++ b/third_party/accessibility/ax/platform/ax_platform_node_win.cc @@ -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: From 88402bd705f027bc2619dd5b4f8fb28a50317663 Mon Sep 17 00:00:00 2001 From: schectman Date: Thu, 15 Sep 2022 16:04:31 -0400 Subject: [PATCH 2/2] Test native role --- shell/platform/windows/flutter_windows_view_unittests.cc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/shell/platform/windows/flutter_windows_view_unittests.cc b/shell/platform/windows/flutter_windows_view_unittests.cc index 48eac6175ebec..766d36af8972b 100644 --- a/shell/platform/windows/flutter_windows_view_unittests.cc +++ b/shell/platform/windows/flutter_windows_view_unittests.cc @@ -777,8 +777,14 @@ TEST(FlutterWindowsViewTest, SwitchNativeState) { VARIANT varchild = {}; varchild.vt = VT_I4; - // Verify the switch is pressed. 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);