diff --git a/engine/src/flutter/shell/platform/common/accessibility_bridge.cc b/engine/src/flutter/shell/platform/common/accessibility_bridge.cc index d0f19089dd..0482abe70d 100644 --- a/engine/src/flutter/shell/platform/common/accessibility_bridge.cc +++ b/engine/src/flutter/shell/platform/common/accessibility_bridge.cc @@ -283,6 +283,7 @@ void AccessibilityBridge::ConvertFlutterUpdate(const SemanticsNode& node, SetStringListAttributesFromFlutterUpdate(node_data, node); SetNameFromFlutterUpdate(node_data, node); SetValueFromFlutterUpdate(node_data, node); + SetTooltipFromFlutterUpdate(node_data, node); node_data.relative_bounds.bounds.SetRect(node.rect.left, node.rect.top, node.rect.right - node.rect.left, node.rect.bottom - node.rect.top); @@ -516,6 +517,12 @@ void AccessibilityBridge::SetValueFromFlutterUpdate(ui::AXNodeData& node_data, node_data.SetValue(node.value); } +void AccessibilityBridge::SetTooltipFromFlutterUpdate( + ui::AXNodeData& node_data, + const SemanticsNode& node) { + node_data.SetTooltip(node.tooltip); +} + void AccessibilityBridge::SetTreeData(const SemanticsNode& node, ui::AXTreeUpdate& tree_update) { FlutterSemanticsFlag flags = node.flags; @@ -582,6 +589,9 @@ AccessibilityBridge::FromFlutterSemanticsNode( if (flutter_node->decreased_value) { result.decreased_value = std::string(flutter_node->decreased_value); } + if (flutter_node->tooltip) { + result.tooltip = std::string(flutter_node->tooltip); + } result.text_direction = flutter_node->text_direction; result.rect = flutter_node->rect; result.transform = flutter_node->transform; diff --git a/engine/src/flutter/shell/platform/common/accessibility_bridge.h b/engine/src/flutter/shell/platform/common/accessibility_bridge.h index 70fcd20c3d..2eec7f7d93 100644 --- a/engine/src/flutter/shell/platform/common/accessibility_bridge.h +++ b/engine/src/flutter/shell/platform/common/accessibility_bridge.h @@ -195,6 +195,7 @@ class AccessibilityBridge std::string value; std::string increased_value; std::string decreased_value; + std::string tooltip; FlutterTextDirection text_direction; FlutterRect rect; FlutterTransformation transform; @@ -249,6 +250,8 @@ class AccessibilityBridge const SemanticsNode& node); void SetValueFromFlutterUpdate(ui::AXNodeData& node_data, const SemanticsNode& node); + void SetTooltipFromFlutterUpdate(ui::AXNodeData& node_data, + const SemanticsNode& node); void SetTreeData(const SemanticsNode& node, ui::AXTreeUpdate& tree_update); SemanticsNode FromFlutterSemanticsNode( const FlutterSemanticsNode* flutter_node); diff --git a/engine/src/flutter/shell/platform/common/accessibility_bridge_unittests.cc b/engine/src/flutter/shell/platform/common/accessibility_bridge_unittests.cc index c320b12b33..6b6c2129f5 100644 --- a/engine/src/flutter/shell/platform/common/accessibility_bridge_unittests.cc +++ b/engine/src/flutter/shell/platform/common/accessibility_bridge_unittests.cc @@ -32,6 +32,7 @@ FlutterSemanticsNode CreateSemanticsNode( .child_count = children ? children->size() : 0, .children_in_traversal_order = children ? children->data() : nullptr, .custom_accessibility_actions_count = 0, + .tooltip = "", }; } diff --git a/engine/src/flutter/shell/platform/common/flutter_platform_node_delegate_unittests.cc b/engine/src/flutter/shell/platform/common/flutter_platform_node_delegate_unittests.cc index 62a1b22487..aa25e24571 100644 --- a/engine/src/flutter/shell/platform/common/flutter_platform_node_delegate_unittests.cc +++ b/engine/src/flutter/shell/platform/common/flutter_platform_node_delegate_unittests.cc @@ -57,6 +57,7 @@ TEST(FlutterPlatformNodeDelegateTest, canPerfomActions) { root.value = ""; root.increased_value = ""; root.decreased_value = ""; + root.tooltip = ""; root.child_count = 0; root.custom_accessibility_actions_count = 0; bridge->AddFlutterSemanticsNodeUpdate(&root); @@ -102,6 +103,7 @@ TEST(FlutterPlatformNodeDelegateTest, canGetAXNode) { root.value = ""; root.increased_value = ""; root.decreased_value = ""; + root.tooltip = ""; root.child_count = 0; root.custom_accessibility_actions_count = 0; bridge->AddFlutterSemanticsNodeUpdate(&root); @@ -123,6 +125,7 @@ TEST(FlutterPlatformNodeDelegateTest, canCalculateBoundsCorrectly) { root.value = ""; root.increased_value = ""; root.decreased_value = ""; + root.tooltip = ""; root.child_count = 1; int32_t children[] = {1}; root.children_in_traversal_order = children; @@ -138,6 +141,7 @@ TEST(FlutterPlatformNodeDelegateTest, canCalculateBoundsCorrectly) { child1.value = ""; child1.increased_value = ""; child1.decreased_value = ""; + child1.tooltip = ""; child1.child_count = 0; child1.custom_accessibility_actions_count = 0; child1.rect = {0, 0, 50, 50}; // LTRB @@ -168,6 +172,7 @@ TEST(FlutterPlatformNodeDelegateTest, canCalculateOffScreenBoundsCorrectly) { root.value = ""; root.increased_value = ""; root.decreased_value = ""; + root.tooltip = ""; root.child_count = 1; int32_t children[] = {1}; root.children_in_traversal_order = children; @@ -183,6 +188,7 @@ TEST(FlutterPlatformNodeDelegateTest, canCalculateOffScreenBoundsCorrectly) { child1.value = ""; child1.increased_value = ""; child1.decreased_value = ""; + child1.tooltip = ""; child1.child_count = 0; child1.custom_accessibility_actions_count = 0; child1.rect = {90, 90, 100, 100}; // LTRB @@ -213,6 +219,7 @@ TEST(FlutterPlatformNodeDelegateTest, canUseOwnerBridge) { root.value = ""; root.increased_value = ""; root.decreased_value = ""; + root.tooltip = ""; root.child_count = 1; int32_t children[] = {1}; root.children_in_traversal_order = children; @@ -228,6 +235,7 @@ TEST(FlutterPlatformNodeDelegateTest, canUseOwnerBridge) { child1.value = ""; child1.increased_value = ""; child1.decreased_value = ""; + child1.tooltip = ""; child1.child_count = 0; child1.custom_accessibility_actions_count = 0; child1.rect = {0, 0, 50, 50}; // LTRB diff --git a/engine/src/flutter/shell/platform/darwin/macos/framework/Source/AccessibilityBridgeMacDelegateTest.mm b/engine/src/flutter/shell/platform/darwin/macos/framework/Source/AccessibilityBridgeMacDelegateTest.mm index 5f4a6d6a8d..625272b192 100644 --- a/engine/src/flutter/shell/platform/darwin/macos/framework/Source/AccessibilityBridgeMacDelegateTest.mm +++ b/engine/src/flutter/shell/platform/darwin/macos/framework/Source/AccessibilityBridgeMacDelegateTest.mm @@ -67,6 +67,7 @@ TEST(AccessibilityBridgeMacDelegateTest, root.value = ""; root.increased_value = ""; root.decreased_value = ""; + root.tooltip = ""; root.child_count = 0; root.custom_accessibility_actions_count = 0; bridge->AddFlutterSemanticsNodeUpdate(&root); @@ -119,6 +120,7 @@ TEST(AccessibilityBridgeMacDelegateTest, doesNotSendAccessibilityCreateNotificat root.value = ""; root.increased_value = ""; root.decreased_value = ""; + root.tooltip = ""; root.child_count = 0; root.custom_accessibility_actions_count = 0; bridge->AddFlutterSemanticsNodeUpdate(&root); @@ -172,6 +174,7 @@ TEST(AccessibilityBridgeMacDelegateTest, doesNotSendAccessibilityCreateNotificat root.value = ""; root.increased_value = ""; root.decreased_value = ""; + root.tooltip = ""; root.child_count = 0; root.custom_accessibility_actions_count = 0; bridge->AddFlutterSemanticsNodeUpdate(&root); diff --git a/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterEngineTest.mm b/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterEngineTest.mm index 1f9e825176..439519575e 100644 --- a/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterEngineTest.mm +++ b/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterEngineTest.mm @@ -145,6 +145,7 @@ TEST_F(FlutterEngineTest, CanToggleAccessibility) { root.value = ""; root.increased_value = ""; root.decreased_value = ""; + root.tooltip = ""; root.child_count = 1; int32_t children[] = {1}; root.children_in_traversal_order = children; @@ -162,6 +163,7 @@ TEST_F(FlutterEngineTest, CanToggleAccessibility) { child1.value = ""; child1.increased_value = ""; child1.decreased_value = ""; + child1.tooltip = ""; child1.child_count = 0; child1.custom_accessibility_actions_count = 0; update_node_callback(&child1, (void*)CFBridgingRetain(engine)); @@ -238,6 +240,7 @@ TEST_F(FlutterEngineTest, CanToggleAccessibilityWhenHeadless) { root.value = ""; root.increased_value = ""; root.decreased_value = ""; + root.tooltip = ""; root.child_count = 1; int32_t children[] = {1}; root.children_in_traversal_order = children; @@ -255,6 +258,7 @@ TEST_F(FlutterEngineTest, CanToggleAccessibilityWhenHeadless) { child1.value = ""; child1.increased_value = ""; child1.decreased_value = ""; + child1.tooltip = ""; child1.child_count = 0; child1.custom_accessibility_actions_count = 0; update_node_callback(&child1, (void*)CFBridgingRetain(engine)); @@ -327,6 +331,7 @@ TEST_F(FlutterEngineTest, ResetsAccessibilityBridgeWhenSetsNewViewController) { root.value = ""; root.increased_value = ""; root.decreased_value = ""; + root.tooltip = ""; root.child_count = 1; int32_t children[] = {1}; root.children_in_traversal_order = children; @@ -344,6 +349,7 @@ TEST_F(FlutterEngineTest, ResetsAccessibilityBridgeWhenSetsNewViewController) { child1.value = ""; child1.increased_value = ""; child1.decreased_value = ""; + child1.tooltip = ""; child1.child_count = 0; child1.custom_accessibility_actions_count = 0; update_node_callback(&child1, (void*)CFBridgingRetain(engine)); diff --git a/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterPlatformNodeDelegateMacTest.mm b/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterPlatformNodeDelegateMacTest.mm index 18b2f21386..a7fa46c57b 100644 --- a/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterPlatformNodeDelegateMacTest.mm +++ b/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterPlatformNodeDelegateMacTest.mm @@ -46,6 +46,7 @@ TEST(FlutterPlatformNodeDelegateMac, Basics) { root.value = ""; root.increased_value = ""; root.decreased_value = ""; + root.tooltip = ""; root.child_count = 0; root.custom_accessibility_actions_count = 0; bridge->AddFlutterSemanticsNodeUpdate(&root); @@ -82,6 +83,7 @@ TEST(FlutterPlatformNodeDelegateMac, SelectableTextHasCorrectSemantics) { root.value = "selectable text"; root.increased_value = ""; root.decreased_value = ""; + root.tooltip = ""; root.child_count = 0; root.custom_accessibility_actions_count = 0; bridge->AddFlutterSemanticsNodeUpdate(&root); @@ -122,6 +124,7 @@ TEST(FlutterPlatformNodeDelegateMac, SelectableTextWithoutSelectionReturnZeroRan root.value = "selectable text"; root.increased_value = ""; root.decreased_value = ""; + root.tooltip = ""; root.child_count = 0; root.custom_accessibility_actions_count = 0; bridge->AddFlutterSemanticsNodeUpdate(&root); @@ -168,6 +171,7 @@ TEST(FlutterPlatformNodeDelegateMac, CanPerformAction) { root.value = ""; root.increased_value = ""; root.decreased_value = ""; + root.tooltip = ""; root.child_count = 1; int32_t children[] = {1}; root.children_in_traversal_order = children; @@ -181,6 +185,7 @@ TEST(FlutterPlatformNodeDelegateMac, CanPerformAction) { child1.value = ""; child1.increased_value = ""; child1.decreased_value = ""; + child1.tooltip = ""; child1.child_count = 0; child1.custom_accessibility_actions_count = 0; bridge->AddFlutterSemanticsNodeUpdate(&child1); @@ -248,6 +253,7 @@ TEST(FlutterPlatformNodeDelegateMac, TextFieldUsesFlutterTextField) { root.value = ""; root.increased_value = ""; root.decreased_value = ""; + root.tooltip = ""; root.child_count = 1; int32_t children[] = {1}; root.children_in_traversal_order = children; @@ -268,6 +274,7 @@ TEST(FlutterPlatformNodeDelegateMac, TextFieldUsesFlutterTextField) { child1.value = "textfield"; child1.increased_value = ""; child1.decreased_value = ""; + child1.tooltip = ""; child1.text_selection_base = -1; child1.text_selection_extent = -1; child1.child_count = 0; diff --git a/engine/src/flutter/shell/platform/embedder/embedder.cc b/engine/src/flutter/shell/platform/embedder/embedder.cc index dcb19c0202..41f8f8227f 100644 --- a/engine/src/flutter/shell/platform/embedder/embedder.cc +++ b/engine/src/flutter/shell/platform/embedder/embedder.cc @@ -1462,6 +1462,7 @@ FlutterEngineResult FlutterEngineInitialize(size_t version, node.customAccessibilityActions.size(), node.customAccessibilityActions.data(), node.platformViewId, + node.tooltip.c_str(), }; update_semantics_node_callback(&embedder_node, user_data); } diff --git a/engine/src/flutter/shell/platform/embedder/embedder.h b/engine/src/flutter/shell/platform/embedder/embedder.h index 5a1d91d433..c9e7bc27bb 100644 --- a/engine/src/flutter/shell/platform/embedder/embedder.h +++ b/engine/src/flutter/shell/platform/embedder/embedder.h @@ -1082,8 +1082,8 @@ typedef struct { /// A value that `value` will have after a kFlutterSemanticsActionDecrease` /// action has been performed. const char* decreased_value; - /// The reading direction for `label`, `value`, `hint`, `increasedValue`, and - /// `decreasedValue`. + /// The reading direction for `label`, `value`, `hint`, `increasedValue`, + /// `decreasedValue`, and `tooltip`. FlutterTextDirection text_direction; /// The bounding box for this node in its coordinate system. FlutterRect rect; @@ -1104,6 +1104,8 @@ typedef struct { /// Identifier of the platform view associated with this semantics node, or /// -1 if none. FlutterPlatformViewIdentifier platform_view_id; + /// A textual tooltip attached to the node. + const char* tooltip; } FlutterSemanticsNode; /// `FlutterSemanticsCustomAction` ID used as a sentinel to signal the end of a 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 766d36af89..f2699206f0 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 @@ -821,5 +821,48 @@ TEST(FlutterWindowsViewTest, SwitchNativeState) { } } +TEST(FlutterWindowsViewTest, TooltipNodeData) { + 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.tooltip = "tooltip"; + root.child_count = 0; + root.custom_accessibility_actions_count = 0; + root.flags = static_cast( + FlutterSemanticsFlag::kFlutterSemanticsFlagIsTextField); + bridge->AddFlutterSemanticsNodeUpdate(&root); + + bridge->CommitUpdates(); + auto root_node = bridge + ->GetFlutterPlatformNodeDelegateFromID( + AccessibilityBridge::kRootNodeId) + .lock(); + std::string tooltip = root_node->GetData().GetStringAttribute( + ax::mojom::StringAttribute::kTooltip); + EXPECT_EQ(tooltip, "tooltip"); +} + } // namespace testing } // namespace flutter diff --git a/engine/src/flutter/third_party/accessibility/ax/ax_node_data.cc b/engine/src/flutter/third_party/accessibility/ax/ax_node_data.cc index 09fb9e7b3d..f13be3d2e6 100644 --- a/engine/src/flutter/third_party/accessibility/ax/ax_node_data.cc +++ b/engine/src/flutter/third_party/accessibility/ax/ax_node_data.cc @@ -633,6 +633,14 @@ void AXNodeData::SetValue(const std::u16string& value) { SetValue(base::UTF16ToUTF8(value)); } +void AXNodeData::SetTooltip(const std::string& value) { + AddStringAttribute(ax::mojom::StringAttribute::kTooltip, value); +} + +void AXNodeData::SetTooltip(const std::u16string& value) { + SetTooltip(base::UTF16ToUTF8(value)); +} + bool AXNodeData::HasState(ax::mojom::State state_enum) const { return IsFlagSet(state, static_cast(state_enum)); } diff --git a/engine/src/flutter/third_party/accessibility/ax/ax_node_data.h b/engine/src/flutter/third_party/accessibility/ax/ax_node_data.h index 8a54b37c05..7af60a2db0 100644 --- a/engine/src/flutter/third_party/accessibility/ax/ax_node_data.h +++ b/engine/src/flutter/third_party/accessibility/ax/ax_node_data.h @@ -148,6 +148,10 @@ struct AX_BASE_EXPORT AXNodeData { void SetValue(const std::string& value); void SetValue(const std::u16string& value); + // Adds the tooltip attribute or replaces it if already present. + void SetTooltip(const std::string& value); + void SetTooltip(const std::u16string& value); + // Returns true if the given enum bit is 1. bool HasState(ax::mojom::State state) const; bool HasAction(ax::mojom::Action action) const; diff --git a/engine/src/flutter/third_party/accessibility/ax/platform/ax_platform_node_win.cc b/engine/src/flutter/third_party/accessibility/ax/platform/ax_platform_node_win.cc index 1e649877a8..dad8d27398 100644 --- a/engine/src/flutter/third_party/accessibility/ax/platform/ax_platform_node_win.cc +++ b/engine/src/flutter/third_party/accessibility/ax/platform/ax_platform_node_win.cc @@ -1017,6 +1017,14 @@ IFACEMETHODIMP AXPlatformNodeWin::get_accName(VARIANT var_id, BSTR* name_bstr) { bool has_name = target->HasStringAttribute(ax::mojom::StringAttribute::kName); std::u16string name = target->GetNameAsString16(); + + // Simply appends the tooltip, if any, to the end of the MSAA name. + const std::u16string tooltip = + target->GetString16Attribute(ax::mojom::StringAttribute::kTooltip); + if (!tooltip.empty()) { + AppendTextToString(tooltip, &name); + } + auto status = GetData().GetImageAnnotationStatus(); switch (status) { case ax::mojom::ImageAnnotationStatus::kNone: