diff --git a/engine/src/flutter/lib/ui/semantics.dart b/engine/src/flutter/lib/ui/semantics.dart index ff168c8ae8..e18aff4d63 100644 --- a/engine/src/flutter/lib/ui/semantics.dart +++ b/engine/src/flutter/lib/ui/semantics.dart @@ -319,6 +319,7 @@ class SemanticsFlag { static const int _kIsLinkIndex = 1 << 22; static const int _kIsSliderIndex = 1 << 23; static const int _kIsKeyboardKeyIndex = 1 << 24; + static const int _kIsCheckStateMixedIndex = 1 << 25; // READ THIS: if you add a flag here, you MUST update the numSemanticsFlags // value in testing/dart/semantics_test.dart, or tests will fail. Also, // please update the Flag enum in @@ -348,6 +349,17 @@ class SemanticsFlag { /// * [SemanticsFlag.hasCheckedState], which enables a checked state. static const SemanticsFlag isChecked = SemanticsFlag._(_kIsCheckedIndex); + /// Whether a tristate checkbox is in its mixed state. + /// + /// If this is true, the check box this semantics node represents + /// is in a mixed state. + /// + /// For example, a [Checkbox] with [Checkbox.tristate] set to true + /// can have checked, unchecked, or mixed state. + /// + /// Must be false when the checkbox is either checked or unchecked. + static const SemanticsFlag isCheckStateMixed = SemanticsFlag._(_kIsCheckStateMixedIndex); + /// Whether a semantics node is selected. /// @@ -578,6 +590,7 @@ class SemanticsFlag { _kIsLinkIndex: isLink, _kIsSliderIndex: isSlider, _kIsKeyboardKeyIndex: isKeyboardKey, + _kIsCheckStateMixedIndex: isCheckStateMixed, }; @override @@ -633,6 +646,8 @@ class SemanticsFlag { return 'SemanticsFlag.isSlider'; case _kIsKeyboardKeyIndex: return 'SemanticsFlag.isKeyboardKey'; + case _kIsCheckStateMixedIndex: + return 'SemanticsFlag.isCheckStateMixed'; } assert(false, 'Unhandled index: $index (0x${index.toRadixString(8).padLeft(4, "0")})'); return ''; diff --git a/engine/src/flutter/lib/ui/semantics/semantics_node.h b/engine/src/flutter/lib/ui/semantics/semantics_node.h index cede05943a..3fad29b844 100644 --- a/engine/src/flutter/lib/ui/semantics/semantics_node.h +++ b/engine/src/flutter/lib/ui/semantics/semantics_node.h @@ -87,6 +87,7 @@ enum class SemanticsFlags : int32_t { kIsLink = 1 << 22, kIsSlider = 1 << 23, kIsKeyboardKey = 1 << 24, + kIsCheckStateMixed = 1 << 25, }; const int kScrollableSemanticsFlags = diff --git a/engine/src/flutter/lib/web_ui/lib/semantics.dart b/engine/src/flutter/lib/web_ui/lib/semantics.dart index 10db1cfcc7..2c4909a498 100644 --- a/engine/src/flutter/lib/web_ui/lib/semantics.dart +++ b/engine/src/flutter/lib/web_ui/lib/semantics.dart @@ -163,6 +163,7 @@ class SemanticsFlag { static const int _kIsLinkIndex = 1 << 22; static const int _kIsSliderIndex = 1 << 23; static const int _kIsKeyboardKeyIndex = 1 << 24; + static const int _kIsCheckStateMixedIndex = 1 << 25; static const SemanticsFlag hasCheckedState = SemanticsFlag._(_kHasCheckedStateIndex); static const SemanticsFlag isChecked = SemanticsFlag._(_kIsCheckedIndex); @@ -189,6 +190,7 @@ class SemanticsFlag { static const SemanticsFlag hasToggledState = SemanticsFlag._(_kHasToggledStateIndex); static const SemanticsFlag isToggled = SemanticsFlag._(_kIsToggledIndex); static const SemanticsFlag hasImplicitScrolling = SemanticsFlag._(_kHasImplicitScrollingIndex); + static const SemanticsFlag isCheckStateMixed = SemanticsFlag._(_kIsCheckStateMixedIndex); static const Map values = { _kHasCheckedStateIndex: hasCheckedState, @@ -216,6 +218,7 @@ class SemanticsFlag { _kIsLinkIndex: isLink, _kIsSliderIndex: isSlider, _kIsKeyboardKeyIndex: isKeyboardKey, + _kIsCheckStateMixedIndex: isCheckStateMixed, }; @override @@ -271,6 +274,8 @@ class SemanticsFlag { return 'SemanticsFlag.isSlider'; case _kIsKeyboardKeyIndex: return 'SemanticsFlag.isKeyboardKey'; + case _kIsCheckStateMixedIndex: + return 'SemanticsFlag.isCheckStateMixed'; } assert(false, 'Unhandled index: $index (0x${index.toRadixString(8).padLeft(4, "0")})'); return ''; diff --git a/engine/src/flutter/lib/web_ui/test/engine/semantics/semantics_api_test.dart b/engine/src/flutter/lib/web_ui/test/engine/semantics/semantics_api_test.dart index c83fb52956..5a457eff1a 100644 --- a/engine/src/flutter/lib/web_ui/test/engine/semantics/semantics_api_test.dart +++ b/engine/src/flutter/lib/web_ui/test/engine/semantics/semantics_api_test.dart @@ -17,7 +17,7 @@ void main() { void testMain() { // This must match the number of flags in lib/ui/semantics.dart - const int numSemanticsFlags = 25; + const int numSemanticsFlags = 26; test('SemanticsFlag.values refers to all flags.', () async { expect(SemanticsFlag.values.length, equals(numSemanticsFlags)); for (int index = 0; index < numSemanticsFlags; ++index) { diff --git a/engine/src/flutter/shell/platform/android/io/flutter/view/AccessibilityBridge.java b/engine/src/flutter/shell/platform/android/io/flutter/view/AccessibilityBridge.java index 8b05faa160..8bc72471a2 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/view/AccessibilityBridge.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/view/AccessibilityBridge.java @@ -2131,7 +2131,8 @@ public class AccessibilityBridge extends AccessibilityNodeProvider { IS_FOCUSABLE(1 << 21), IS_LINK(1 << 22), IS_SLIDER(1 << 23), - IS_KEYBOARD_KEY(1 << 24); + IS_KEYBOARD_KEY(1 << 24), + IS_CHECK_STATE_MIXED(1 << 25); final int value; diff --git a/engine/src/flutter/shell/platform/common/accessibility_bridge.cc b/engine/src/flutter/shell/platform/common/accessibility_bridge.cc index 5890a248e2..0c83110402 100644 --- a/engine/src/flutter/shell/platform/common/accessibility_bridge.cc +++ b/engine/src/flutter/shell/platform/common/accessibility_bridge.cc @@ -380,7 +380,9 @@ void AccessibilityBridge::SetIntAttributesFromFlutterUpdate( node_data.AddIntAttribute( ax::mojom::IntAttribute::kCheckedState, static_cast( - flags & FlutterSemanticsFlag::kFlutterSemanticsFlagIsChecked + flags & FlutterSemanticsFlag::kFlutterSemanticsFlagIsCheckStateMixed + ? ax::mojom::CheckedState::kMixed + : flags & FlutterSemanticsFlag::kFlutterSemanticsFlagIsChecked ? ax::mojom::CheckedState::kTrue : ax::mojom::CheckedState::kFalse)); } diff --git a/engine/src/flutter/shell/platform/embedder/embedder.h b/engine/src/flutter/shell/platform/embedder/embedder.h index 93e92b7d4c..c8a90ff1cb 100644 --- a/engine/src/flutter/shell/platform/embedder/embedder.h +++ b/engine/src/flutter/shell/platform/embedder/embedder.h @@ -227,6 +227,8 @@ typedef enum { kFlutterSemanticsFlagIsSlider = 1 << 23, /// Whether the semantics node represents a keyboard key. kFlutterSemanticsFlagIsKeyboardKey = 1 << 24, + /// Whether the semantics node represents a tristate checkbox in mixed state. + kFlutterSemanticsFlagIsCheckStateMixed = 1 << 25, } FlutterSemanticsFlag; typedef enum { diff --git a/engine/src/flutter/shell/platform/windows/flutter_windows_view_unittests.cc b/engine/src/flutter/shell/platform/windows/flutter_windows_view_unittests.cc index d6830d6908..58b5cc7015 100644 --- a/engine/src/flutter/shell/platform/windows/flutter_windows_view_unittests.cc +++ b/engine/src/flutter/shell/platform/windows/flutter_windows_view_unittests.cc @@ -638,53 +638,90 @@ TEST(FlutterWindowsViewTest, CheckboxNativeState) { bridge->CommitUpdates(); - auto root_node = bridge - ->GetFlutterPlatformNodeDelegateFromID( - AccessibilityBridge::kRootNodeId) - .lock(); - EXPECT_EQ(root_node->GetData().role, ax::mojom::Role::kCheckBox); - EXPECT_EQ(root_node->GetData().GetCheckedState(), - ax::mojom::CheckedState::kTrue); + { + auto root_node = bridge + ->GetFlutterPlatformNodeDelegateFromID( + AccessibilityBridge::kRootNodeId) + .lock(); + EXPECT_EQ(root_node->GetData().role, ax::mojom::Role::kCheckBox); + 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); + // 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; + // Look up against the node itself (not one of its children). + VARIANT varchild = {}; + varchild.vt = VT_I4; - // Verify the checkbox is checked. - varchild.lVal = CHILDID_SELF; - VARIANT native_state = {}; - ASSERT_TRUE(SUCCEEDED(native_view->get_accState(varchild, &native_state))); - EXPECT_TRUE(native_state.lVal & STATE_SYSTEM_CHECKED); + // Verify the checkbox is checked. + varchild.lVal = CHILDID_SELF; + VARIANT native_state = {}; + ASSERT_TRUE(SUCCEEDED(native_view->get_accState(varchild, &native_state))); + EXPECT_TRUE(native_state.lVal & STATE_SYSTEM_CHECKED); + } - // Test unchecked too + // Test unchecked too. root.flags = static_cast( FlutterSemanticsFlag::kFlutterSemanticsFlagHasCheckedState); bridge->AddFlutterSemanticsNodeUpdate(&root); bridge->CommitUpdates(); - root_node = bridge - ->GetFlutterPlatformNodeDelegateFromID( - AccessibilityBridge::kRootNodeId) - .lock(); - EXPECT_EQ(root_node->GetData().role, ax::mojom::Role::kCheckBox); - EXPECT_EQ(root_node->GetData().GetCheckedState(), - ax::mojom::CheckedState::kFalse); - // Get the IAccessible for the root node. - native_view = root_node->GetNativeViewAccessible(); + { + auto root_node = bridge + ->GetFlutterPlatformNodeDelegateFromID( + AccessibilityBridge::kRootNodeId) + .lock(); + EXPECT_EQ(root_node->GetData().role, ax::mojom::Role::kCheckBox); + EXPECT_EQ(root_node->GetData().GetCheckedState(), + ax::mojom::CheckedState::kFalse); - // Look up against the node itself (not one of its children) - varchild = {}; - varchild.vt = VT_I4; + // Get the IAccessible for the root node. + IAccessible* native_view = root_node->GetNativeViewAccessible(); + ASSERT_TRUE(native_view != nullptr); - // Verify the checkbox is checked. - varchild.lVal = CHILDID_SELF; - native_state = {}; - ASSERT_TRUE(SUCCEEDED(native_view->get_accState(varchild, &native_state))); - EXPECT_FALSE(native_state.lVal & STATE_SYSTEM_CHECKED); + // Look up against the node itself (not one of its children). + VARIANT varchild = {}; + varchild.vt = VT_I4; + + // Verify the checkbox is checked. + varchild.lVal = CHILDID_SELF; + VARIANT native_state = {}; + ASSERT_TRUE(SUCCEEDED(native_view->get_accState(varchild, &native_state))); + EXPECT_FALSE(native_state.lVal & STATE_SYSTEM_CHECKED); + } + + // Now check mixed state. + root.flags = static_cast( + FlutterSemanticsFlag::kFlutterSemanticsFlagHasCheckedState | + FlutterSemanticsFlag::kFlutterSemanticsFlagIsCheckStateMixed); + bridge->AddFlutterSemanticsNodeUpdate(&root); + bridge->CommitUpdates(); + + { + auto root_node = bridge + ->GetFlutterPlatformNodeDelegateFromID( + AccessibilityBridge::kRootNodeId) + .lock(); + EXPECT_EQ(root_node->GetData().role, ax::mojom::Role::kCheckBox); + EXPECT_EQ(root_node->GetData().GetCheckedState(), + ax::mojom::CheckedState::kMixed); + + // 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 checkbox is checked. + 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); + } } } // namespace testing diff --git a/engine/src/flutter/testing/dart/semantics_test.dart b/engine/src/flutter/testing/dart/semantics_test.dart index e3ecb3dae7..15f1245dbe 100644 --- a/engine/src/flutter/testing/dart/semantics_test.dart +++ b/engine/src/flutter/testing/dart/semantics_test.dart @@ -11,7 +11,7 @@ import 'package:litetest/litetest.dart'; void main() { // This must match the number of flags in lib/ui/semantics.dart - const int numSemanticsFlags = 25; + const int numSemanticsFlags = 26; test('SemanticsFlag.values refers to all flags.', () async { expect(SemanticsFlag.values.length, equals(numSemanticsFlags)); for (int index = 0; index < numSemanticsFlags; ++index) {