diff --git a/engine/src/flutter/lib/ui/semantics.dart b/engine/src/flutter/lib/ui/semantics.dart index b702109bc4..08c539c4a2 100644 --- a/engine/src/flutter/lib/ui/semantics.dart +++ b/engine/src/flutter/lib/ui/semantics.dart @@ -800,6 +800,9 @@ class SemanticsUpdateBuilder extends NativeFieldWrapperClass1 { /// and `decreasedValue` respectively. Their contents must not be changed during /// the semantics update. /// + /// The `tooltip` is a string that describe additional information when user + /// hover or long press on the backing widget of this semantics node. + /// /// The fields `textSelectionBase` and `textSelectionExtent` describe the /// currently selected text within `value`. A value of -1 indicates no /// current text selection base or extent. @@ -857,15 +860,16 @@ class SemanticsUpdateBuilder extends NativeFieldWrapperClass1 { required double thickness, required Rect rect, required String label, - List? labelAttributes, + required List labelAttributes, required String value, - List? valueAttributes, + required List valueAttributes, required String increasedValue, - List? increasedValueAttributes, + required List increasedValueAttributes, required String decreasedValue, - List? decreasedValueAttributes, + required List decreasedValueAttributes, required String hint, - List? hintAttributes, + required List hintAttributes, + String? tooltip, TextDirection? textDirection, required Float64List transform, required Int32List childrenInTraversalOrder, @@ -907,6 +911,7 @@ class SemanticsUpdateBuilder extends NativeFieldWrapperClass1 { decreasedValueAttributes, hint, hintAttributes, + tooltip, textDirection != null ? textDirection.index + 1 : 0, transform, childrenInTraversalOrder, @@ -935,15 +940,16 @@ class SemanticsUpdateBuilder extends NativeFieldWrapperClass1 { double elevation, double thickness, String label, - List? labelAttributes, + List labelAttributes, String value, - List? valueAttributes, + List valueAttributes, String increasedValue, - List? increasedValueAttributes, + List increasedValueAttributes, String decreasedValue, - List? decreasedValueAttributes, + List decreasedValueAttributes, String hint, - List? hintAttributes, + List hintAttributes, + String? tooltip, int textDirection, Float64List transform, Int32List childrenInTraversalOrder, diff --git a/engine/src/flutter/lib/ui/semantics/semantics_node.h b/engine/src/flutter/lib/ui/semantics/semantics_node.h index b75d94eb5a..6fc4d733d6 100644 --- a/engine/src/flutter/lib/ui/semantics/semantics_node.h +++ b/engine/src/flutter/lib/ui/semantics/semantics_node.h @@ -131,6 +131,7 @@ struct SemanticsNode { StringAttributes increasedValueAttributes; std::string decreasedValue; StringAttributes decreasedValueAttributes; + std::string tooltip; int32_t textDirection = 0; // 0=unknown, 1=rtl, 2=ltr SkRect rect = SkRect::MakeEmpty(); // Local space, relative to parent. diff --git a/engine/src/flutter/lib/ui/semantics/semantics_update_builder.cc b/engine/src/flutter/lib/ui/semantics/semantics_update_builder.cc index beae3a3b1e..e1b1a6adad 100644 --- a/engine/src/flutter/lib/ui/semantics/semantics_update_builder.cc +++ b/engine/src/flutter/lib/ui/semantics/semantics_update_builder.cc @@ -76,6 +76,7 @@ void SemanticsUpdateBuilder::updateNode( std::vector decreasedValueAttributes, std::string hint, std::vector hintAttributes, + std::string tooltip, int textDirection, const tonic::Float64List& transform, const tonic::Int32List& childrenInTraversalOrder, @@ -114,6 +115,7 @@ void SemanticsUpdateBuilder::updateNode( pushStringAttributes(node.decreasedValueAttributes, decreasedValueAttributes); node.hint = hint; pushStringAttributes(node.hintAttributes, hintAttributes); + node.tooltip = tooltip; node.textDirection = textDirection; SkScalar scalarTransform[16]; for (int i = 0; i < 16; ++i) { diff --git a/engine/src/flutter/lib/ui/semantics/semantics_update_builder.h b/engine/src/flutter/lib/ui/semantics/semantics_update_builder.h index 96c29a1bce..6f83e471d2 100644 --- a/engine/src/flutter/lib/ui/semantics/semantics_update_builder.h +++ b/engine/src/flutter/lib/ui/semantics/semantics_update_builder.h @@ -55,6 +55,7 @@ class SemanticsUpdateBuilder std::vector decreasedValueAttributes, std::string hint, std::vector hintAttributes, + std::string tooltip, int textDirection, const tonic::Float64List& transform, const tonic::Int32List& childrenInTraversalOrder, diff --git a/engine/src/flutter/lib/web_ui/lib/src/engine/semantics/semantics.dart b/engine/src/flutter/lib/web_ui/lib/src/engine/semantics/semantics.dart index 4e544c5fe1..fbd06b16fd 100644 --- a/engine/src/flutter/lib/web_ui/lib/src/engine/semantics/semantics.dart +++ b/engine/src/flutter/lib/web_ui/lib/src/engine/semantics/semantics.dart @@ -78,15 +78,16 @@ class SemanticsNodeUpdate { required this.scrollExtentMin, required this.rect, required this.label, - this.labelAttributes, + required this.labelAttributes, required this.hint, - this.hintAttributes, + required this.hintAttributes, required this.value, - this.valueAttributes, + required this.valueAttributes, required this.increasedValue, - this.increasedValueAttributes, + required this.increasedValueAttributes, required this.decreasedValue, - this.decreasedValueAttributes, + required this.decreasedValueAttributes, + this.tooltip, this.textDirection, required this.transform, required this.elevation, @@ -142,31 +143,34 @@ class SemanticsNodeUpdate { final String label; /// See [ui.SemanticsUpdateBuilder.updateNode]. - final List? labelAttributes; + final List labelAttributes; /// See [ui.SemanticsUpdateBuilder.updateNode]. final String hint; /// See [ui.SemanticsUpdateBuilder.updateNode]. - final List? hintAttributes; + final List hintAttributes; /// See [ui.SemanticsUpdateBuilder.updateNode]. final String value; /// See [ui.SemanticsUpdateBuilder.updateNode]. - final List? valueAttributes; + final List valueAttributes; /// See [ui.SemanticsUpdateBuilder.updateNode]. final String increasedValue; /// See [ui.SemanticsUpdateBuilder.updateNode]. - final List? increasedValueAttributes; + final List increasedValueAttributes; /// See [ui.SemanticsUpdateBuilder.updateNode]. final String decreasedValue; /// See [ui.SemanticsUpdateBuilder.updateNode]. - final List? decreasedValueAttributes; + final List decreasedValueAttributes; + + /// See [ui.SemanticsUpdateBuilder.updateNode]. + final String? tooltip; /// See [ui.SemanticsUpdateBuilder.updateNode]. final ui.TextDirection? textDirection; diff --git a/engine/src/flutter/lib/web_ui/lib/src/ui/semantics.dart b/engine/src/flutter/lib/web_ui/lib/src/ui/semantics.dart index f3a6ca21a7..59adfda24e 100644 --- a/engine/src/flutter/lib/web_ui/lib/src/ui/semantics.dart +++ b/engine/src/flutter/lib/web_ui/lib/src/ui/semantics.dart @@ -349,15 +349,16 @@ class SemanticsUpdateBuilder { required double thickness, required Rect rect, required String label, - List? labelAttributes, + required List labelAttributes, required String value, - List? valueAttributes, + required List valueAttributes, required String increasedValue, - List? increasedValueAttributes, + required List increasedValueAttributes, required String decreasedValue, - List? decreasedValueAttributes, + required List decreasedValueAttributes, required String hint, - List? hintAttributes, + required List hintAttributes, + String? tooltip, TextDirection? textDirection, required Float64List transform, required Int32List childrenInTraversalOrder, @@ -390,6 +391,7 @@ class SemanticsUpdateBuilder { decreasedValueAttributes: decreasedValueAttributes, hint: hint, hintAttributes: hintAttributes, + tooltip: tooltip, textDirection: textDirection, transform: engine.toMatrix32(transform), elevation: elevation, diff --git a/engine/src/flutter/lib/web_ui/test/engine/semantics/semantics_test.dart b/engine/src/flutter/lib/web_ui/test/engine/semantics/semantics_test.dart index 3af88c138d..d3ba3c33c6 100644 --- a/engine/src/flutter/lib/web_ui/test/engine/semantics/semantics_test.dart +++ b/engine/src/flutter/lib/web_ui/test/engine/semantics/semantics_test.dart @@ -1488,10 +1488,16 @@ void updateNode( double thickness = 0.0, ui.Rect rect = ui.Rect.zero, String label = '', + List labelAttributes = const [], String hint = '', + List hintAttributes = const [], String value = '', + List valueAttributes = const [], String increasedValue = '', + List increasedValueAttributes = const [], String decreasedValue = '', + List decreasedValueAttributes = const [], + String tooltip = '', ui.TextDirection textDirection = ui.TextDirection.ltr, Float64List? transform, Int32List? childrenInTraversalOrder, @@ -1520,10 +1526,16 @@ void updateNode( thickness: thickness, rect: rect, label: label, + labelAttributes: labelAttributes, hint: hint, + hintAttributes: hintAttributes, value: value, + valueAttributes: valueAttributes, increasedValue: increasedValue, + increasedValueAttributes: increasedValueAttributes, decreasedValue: decreasedValue, + decreasedValueAttributes: decreasedValueAttributes, + tooltip: tooltip, textDirection: textDirection, transform: transform, childrenInTraversalOrder: childrenInTraversalOrder, diff --git a/engine/src/flutter/lib/web_ui/test/engine/semantics/semantics_tester.dart b/engine/src/flutter/lib/web_ui/test/engine/semantics/semantics_tester.dart index b812c8de98..8771201643 100644 --- a/engine/src/flutter/lib/web_ui/test/engine/semantics/semantics_tester.dart +++ b/engine/src/flutter/lib/web_ui/test/engine/semantics/semantics_tester.dart @@ -115,10 +115,16 @@ class SemanticsTester { double? thickness, ui.Rect? rect, String? label, + List? labelAttributes, String? hint, + List? hintAttributes, String? value, + List? valueAttributes, String? increasedValue, + List? increasedValueAttributes, String? decreasedValue, + List? decreasedValueAttributes, + String? tooltip, ui.TextDirection? textDirection, Float64List? transform, Int32List? additionalActions, @@ -306,10 +312,16 @@ class SemanticsTester { scrollExtentMin: scrollExtentMin ?? 0, rect: effectiveRect, label: label ?? '', + labelAttributes: labelAttributes ?? const [], hint: hint ?? '', + hintAttributes: hintAttributes ?? const [], value: value ?? '', + valueAttributes: valueAttributes ?? const [], increasedValue: increasedValue ?? '', + increasedValueAttributes: increasedValueAttributes ?? const [], decreasedValue: decreasedValue ?? '', + decreasedValueAttributes: decreasedValueAttributes ?? const [], + tooltip: tooltip ?? '', transform: transform != null ? toMatrix32(transform) : Matrix4.identity().storage, elevation: elevation ?? 0, thickness: thickness ?? 0, 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 b88301dabd..3894721d90 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 @@ -266,6 +266,15 @@ public class AccessibilityBridge extends AccessibilityNodeProvider { /** The user has opened a tooltip. */ @Override public void onTooltip(@NonNull String message) { + // Native Android tooltip is no longer announced when it pops up after API 28 and is + // handled by + // AccessibilityNodeInfo.setTooltipText instead. + // + // To reproduce native behavior, see + // https://developer.android.com/guide/topics/ui/tooltips. + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { + return; + } AccessibilityEvent e = obtainAccessibilityEvent(ROOT_NODE_ID, AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED); e.getText().add(message); @@ -820,15 +829,31 @@ public class AccessibilityBridge extends AccessibilityNodeProvider { result.setLiveRegion(View.ACCESSIBILITY_LIVE_REGION_POLITE); } + // Scopes routes are not focusable, only need to set the content + // for non-scopes-routes semantics nodes. if (semanticsNode.hasFlag(Flag.IS_TEXT_FIELD)) { result.setText(semanticsNode.getValueLabelHint()); } else if (!semanticsNode.hasFlag(Flag.SCOPES_ROUTE)) { CharSequence content = semanticsNode.getValueLabelHint(); + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) { + if (semanticsNode.tooltip != null) { + // For backward compatibility with Flutter SDK before Android API + // level 28, the tooltip is appended at the end of content description. + content = content != null ? content : ""; + content = content + "\n" + semanticsNode.tooltip; + } + } if (content != null) { result.setContentDescription(content); } } + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { + if (semanticsNode.tooltip != null) { + result.setTooltipText(semanticsNode.tooltip); + } + } + boolean hasCheckedState = semanticsNode.hasFlag(Flag.HAS_CHECKED_STATE); boolean hasToggledState = semanticsNode.hasFlag(Flag.HAS_TOGGLED_STATE); if (BuildConfig.DEBUG && (hasCheckedState && hasToggledState)) { @@ -2188,6 +2213,12 @@ public class AccessibilityBridge extends AccessibilityNodeProvider { private String hint; private List hintAttributes; + // The textual description of the backing widget's tooltip. + // + // The tooltip is attached through AccessibilityNodInfo.setTooltipText if + // API level >= 28; otherwise, this is attached to the end of content description. + @Nullable private String tooltip; + // The id of the sibling node that is before this node in traversal // order. // @@ -2390,6 +2421,9 @@ public class AccessibilityBridge extends AccessibilityNodeProvider { hintAttributes = getStringAttributesFromBuffer(buffer, stringAttributeArgs); + stringIndex = buffer.getInt(); + tooltip = stringIndex == -1 ? null : strings[stringIndex]; + textDirection = TextDirection.fromInt(buffer.getInt()); left = buffer.getFloat(); diff --git a/engine/src/flutter/shell/platform/android/platform_view_android_delegate/platform_view_android_delegate.cc b/engine/src/flutter/shell/platform/android/platform_view_android_delegate/platform_view_android_delegate.cc index 1f6522f86a..8cfa5bed47 100644 --- a/engine/src/flutter/shell/platform/android/platform_view_android_delegate/platform_view_android_delegate.cc +++ b/engine/src/flutter/shell/platform/android/platform_view_android_delegate/platform_view_android_delegate.cc @@ -42,7 +42,7 @@ PlatformViewAndroidDelegate::PlatformViewAndroidDelegate( void PlatformViewAndroidDelegate::UpdateSemantics( flutter::SemanticsNodeUpdates update, flutter::CustomAccessibilityActionUpdates actions) { - constexpr size_t kBytesPerNode = 46 * sizeof(int32_t); + constexpr size_t kBytesPerNode = 47 * sizeof(int32_t); constexpr size_t kBytesPerChild = sizeof(int32_t); constexpr size_t kBytesPerCustomAction = sizeof(int32_t); constexpr size_t kBytesPerAction = 4 * sizeof(int32_t); @@ -148,6 +148,13 @@ void PlatformViewAndroidDelegate::UpdateSemantics( putStringAttributesIntoBuffer(node.hintAttributes, buffer_int32, position, string_attribute_args); + if (node.tooltip.empty()) { + buffer_int32[position++] = -1; + } else { + buffer_int32[position++] = strings.size(); + strings.push_back(node.tooltip); + } + buffer_int32[position++] = node.textDirection; buffer_float32[position++] = node.rect.left(); buffer_float32[position++] = node.rect.top(); diff --git a/engine/src/flutter/shell/platform/android/platform_view_android_delegate/platform_view_android_delegate_unittests.cc b/engine/src/flutter/shell/platform/android/platform_view_android_delegate/platform_view_android_delegate_unittests.cc index 674544b176..6c370e4ae2 100644 --- a/engine/src/flutter/shell/platform/android/platform_view_android_delegate/platform_view_android_delegate_unittests.cc +++ b/engine/src/flutter/shell/platform/android/platform_view_android_delegate/platform_view_android_delegate_unittests.cc @@ -19,9 +19,10 @@ TEST(PlatformViewShell, UpdateSemanticsDoesFlutterViewUpdateSemantics) { flutter::SemanticsNode node0; node0.id = 0; node0.label = "label"; + node0.tooltip = "tooltip"; update.insert(std::make_pair(0, std::move(node0))); - std::vector expected_buffer(184); + std::vector expected_buffer(188); std::vector> expected_string_attribute_args(0); size_t position = 0; int32_t* buffer_int32 = reinterpret_cast(&expected_buffer[0]); @@ -51,6 +52,8 @@ TEST(PlatformViewShell, UpdateSemanticsDoesFlutterViewUpdateSemantics) { buffer_int32[position++] = -1; // node0.decreasedValueAttributes buffer_int32[position++] = -1; // node0.hint buffer_int32[position++] = -1; // node0.hintAttributes + buffer_int32[position++] = expected_strings.size(); // node0.tooltip + expected_strings.push_back(node0.tooltip); buffer_int32[position++] = node0.textDirection; buffer_float32[position++] = node0.rect.left(); buffer_float32[position++] = node0.rect.top(); @@ -93,7 +96,7 @@ TEST(PlatformViewShell, node0.hintAttributes.push_back(locale_attribute); update.insert(std::make_pair(0, std::move(node0))); - std::vector expected_buffer(216); + std::vector expected_buffer(220); std::vector> expected_string_attribute_args; size_t position = 0; int32_t* buffer_int32 = reinterpret_cast(&expected_buffer[0]); @@ -132,9 +135,10 @@ TEST(PlatformViewShell, buffer_int32[position++] = 3; // node0.hintAttributes[0].end buffer_int32[position++] = 1; // node0.hintAttributes[0].type buffer_int32[position++] = - expected_string_attribute_args.size(); // node0.labelAttributes[0].args + expected_string_attribute_args.size(); // node0.hintAttributes[0].args expected_string_attribute_args.push_back( {locale_attribute->locale.begin(), locale_attribute->locale.end()}); + buffer_int32[position++] = -1; // node0.tooltip buffer_int32[position++] = node0.textDirection; buffer_float32[position++] = node0.rect.left(); buffer_float32[position++] = node0.rect.top(); diff --git a/engine/src/flutter/shell/platform/android/test/io/flutter/view/AccessibilityBridgeTest.java b/engine/src/flutter/shell/platform/android/test/io/flutter/view/AccessibilityBridgeTest.java index 49df2d82ea..c2ea02f6ae 100644 --- a/engine/src/flutter/shell/platform/android/test/io/flutter/view/AccessibilityBridgeTest.java +++ b/engine/src/flutter/shell/platform/android/test/io/flutter/view/AccessibilityBridgeTest.java @@ -719,6 +719,43 @@ public class AccessibilityBridgeTest { assertEquals(actual.getSpanEnd(spellOutSpan), 9); } + @TargetApi(28) + @Test + public void itSetsTooltipCorrectly() { + AccessibilityChannel mockChannel = mock(AccessibilityChannel.class); + AccessibilityViewEmbedder mockViewEmbedder = mock(AccessibilityViewEmbedder.class); + AccessibilityManager mockManager = mock(AccessibilityManager.class); + View mockRootView = mock(View.class); + Context context = mock(Context.class); + when(mockRootView.getContext()).thenReturn(context); + when(context.getPackageName()).thenReturn("test"); + AccessibilityBridge accessibilityBridge = + setUpBridge( + /*rootAccessibilityView=*/ mockRootView, + /*accessibilityChannel=*/ mockChannel, + /*accessibilityManager=*/ mockManager, + /*contentResolver=*/ null, + /*accessibilityViewEmbedder=*/ mockViewEmbedder, + /*platformViewsAccessibilityDelegate=*/ null); + + ViewParent mockParent = mock(ViewParent.class); + when(mockRootView.getParent()).thenReturn(mockParent); + when(mockManager.isEnabled()).thenReturn(true); + // Create a node with tooltip. + TestSemanticsNode root = new TestSemanticsNode(); + root.id = 0; + root.tooltip = "tooltip"; + + TestSemanticsUpdate testSemanticsUpdate = root.toUpdate(); + testSemanticsUpdate.sendUpdateToBridge(accessibilityBridge); + + // Test the generated AccessibilityNodeInfo for the node we created + // and verify it has correct tooltip text. + AccessibilityNodeInfo nodeInfo = accessibilityBridge.createAccessibilityNodeInfo(0); + CharSequence actual = nodeInfo.getTooltipText(); + assertEquals(actual.toString(), root.tooltip); + } + @TargetApi(21) @Test public void itCanCreateAccessibilityNodeInfoWithSetText() { @@ -1552,6 +1589,7 @@ public class AccessibilityBridgeTest { List decreasedValueAttributes; String hint = null; List hintAttributes; + String tooltip = null; int textDirection = 0; float left = 0.0f; float top = 0.0f; @@ -1603,6 +1641,12 @@ public class AccessibilityBridgeTest { updateString(increasedValue, increasedValueAttributes, bytes, strings, stringAttributeArgs); updateString(decreasedValue, decreasedValueAttributes, bytes, strings, stringAttributeArgs); updateString(hint, hintAttributes, bytes, strings, stringAttributeArgs); + if (tooltip == null) { + bytes.putInt(-1); + } else { + strings.add(tooltip); + bytes.putInt(strings.size() - 1); + } bytes.putInt(textDirection); bytes.putFloat(left); bytes.putFloat(top); diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/SemanticsObject.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/SemanticsObject.mm index a2ff91ff5c..cddce14dca 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/SemanticsObject.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/SemanticsObject.mm @@ -606,10 +606,16 @@ CGRect ConvertRectToGlobal(SemanticsObject* reference, CGRect local_rect) { - (NSString*)accessibilityLabel { if (![self isAccessibilityBridgeAlive]) return nil; - - if ([self node].label.empty()) - return nil; - return @([self node].label.data()); + NSString* label; + if (![self node].label.empty()) { + label = @([self node].label.data()); + } + if (![self node].tooltip.empty()) { + label = [NSString stringWithFormat:@"%@%@", + label ? [NSString stringWithFormat:@"%@\n", label] : @"", + @([self node].tooltip.data())]; + } + return label; } - (NSAttributedString*)accessibilityAttributedLabel { diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/SemanticsObjectTest.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/SemanticsObjectTest.mm index f6475beff2..a1d164dff8 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/SemanticsObjectTest.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/SemanticsObjectTest.mm @@ -398,6 +398,22 @@ class MockAccessibilityBridge : public AccessibilityBridgeIos { XCTAssertTrue([scrollable_object.accessibilityHint isEqualToString:@"hint"]); } +- (void)testFlutterSemanticsObjectMergeTooltipToLabel { + flutter::MockAccessibilityBridge* mock = new flutter::MockAccessibilityBridge(); + mock->isVoiceOverRunningValue = true; + fml::WeakPtrFactory factory(mock); + fml::WeakPtr bridge = factory.GetWeakPtr(); + + flutter::SemanticsNode node; + node.rect = SkRect::MakeXYWH(0, 0, 100, 200); + node.label = "label"; + node.tooltip = "tooltip"; + FlutterSemanticsObject* object = [[FlutterSemanticsObject alloc] initWithBridge:bridge uid:0]; + [object setSemanticsNode:&node]; + XCTAssertTrue(object.isAccessibilityElement); + XCTAssertTrue([object.accessibilityLabel isEqualToString:@"label\ntooltip"]); +} + - (void)testFlutterScrollableSemanticsObjectReturnsParentContainerIfNoChildren { flutter::MockAccessibilityBridge* mock = new flutter::MockAccessibilityBridge(); mock->isVoiceOverRunningValue = true; diff --git a/engine/src/flutter/shell/platform/embedder/fixtures/main.dart b/engine/src/flutter/shell/platform/embedder/fixtures/main.dart index bd2232b656..5866aa0a09 100644 --- a/engine/src/flutter/shell/platform/embedder/fixtures/main.dart +++ b/engine/src/flutter/shell/platform/embedder/fixtures/main.dart @@ -120,6 +120,7 @@ void a11y_main() async { ..updateNode( id: 42, label: 'A: root', + labelAttributes: [], rect: Rect.fromLTRB(0.0, 0.0, 10.0, 10.0), transform: kTestTransform, childrenInTraversalOrder: Int32List.fromList([84, 96]), @@ -138,15 +139,21 @@ void a11y_main() async { scrollExtentMin: 0.0, elevation: 0.0, thickness: 0.0, - hint: "", - value: "", - increasedValue: "", - decreasedValue: "", + hint: '', + hintAttributes: [], + value: '', + valueAttributes: [], + increasedValue: '', + increasedValueAttributes: [], + decreasedValue: '', + decreasedValueAttributes: [], + tooltip: '', additionalActions: Int32List(0), ) ..updateNode( id: 84, label: 'B: leaf', + labelAttributes: [], rect: Rect.fromLTRB(40.0, 40.0, 80.0, 80.0), transform: kTestTransform, actions: 0, @@ -163,10 +170,15 @@ void a11y_main() async { scrollExtentMin: 0.0, elevation: 0.0, thickness: 0.0, - hint: "", - value: "", - increasedValue: "", - decreasedValue: "", + hint: '', + hintAttributes: [], + value: '', + valueAttributes: [], + increasedValue: '', + increasedValueAttributes: [], + decreasedValue: '', + decreasedValueAttributes: [], + tooltip: '', additionalActions: Int32List(0), childrenInHitTestOrder: Int32List(0), childrenInTraversalOrder: Int32List(0), @@ -174,6 +186,7 @@ void a11y_main() async { ..updateNode( id: 96, label: 'C: branch', + labelAttributes: [], rect: Rect.fromLTRB(40.0, 40.0, 80.0, 80.0), transform: kTestTransform, childrenInTraversalOrder: Int32List.fromList([128]), @@ -192,15 +205,21 @@ void a11y_main() async { scrollExtentMin: 0.0, elevation: 0.0, thickness: 0.0, - hint: "", - value: "", - increasedValue: "", - decreasedValue: "", + hint: '', + hintAttributes: [], + value: '', + valueAttributes: [], + increasedValue: '', + increasedValueAttributes: [], + decreasedValue: '', + decreasedValueAttributes: [], + tooltip: '', additionalActions: Int32List(0), ) ..updateNode( id: 128, label: 'D: leaf', + labelAttributes: [], rect: Rect.fromLTRB(40.0, 40.0, 80.0, 80.0), transform: kTestTransform, additionalActions: Int32List.fromList([21]), @@ -218,10 +237,15 @@ void a11y_main() async { scrollExtentMin: 0.0, elevation: 0.0, thickness: 0.0, - hint: "", - value: "", - increasedValue: "", - decreasedValue: "", + hint: '', + hintAttributes: [], + value: '', + valueAttributes: [], + increasedValue: '', + increasedValueAttributes: [], + decreasedValue: '', + decreasedValueAttributes: [], + tooltip: '', childrenInHitTestOrder: Int32List(0), childrenInTraversalOrder: Int32List(0), ) diff --git a/engine/src/flutter/shell/platform/fuchsia/flutter/accessibility_bridge.cc b/engine/src/flutter/shell/platform/fuchsia/flutter/accessibility_bridge.cc index 1493d11f75..76a1da4a53 100644 --- a/engine/src/flutter/shell/platform/fuchsia/flutter/accessibility_bridge.cc +++ b/engine/src/flutter/shell/platform/fuchsia/flutter/accessibility_bridge.cc @@ -331,6 +331,15 @@ AccessibilityBridge::GetNodeAttributes(const flutter::SemanticsNode& node, *added_size += node.label.size(); } + if (node.tooltip.size() > fuchsia::accessibility::semantics::MAX_LABEL_SIZE) { + attributes.set_secondary_label(node.tooltip.substr( + 0, fuchsia::accessibility::semantics::MAX_LABEL_SIZE)); + *added_size += fuchsia::accessibility::semantics::MAX_LABEL_SIZE; + } else { + attributes.set_secondary_label(node.tooltip); + *added_size += node.tooltip.size(); + } + if (node.HasFlag(flutter::SemanticsFlags::kIsKeyboardKey)) { attributes.set_is_keyboard_key(true); } diff --git a/engine/src/flutter/shell/platform/fuchsia/flutter/accessibility_bridge_unittest.cc b/engine/src/flutter/shell/platform/fuchsia/flutter/accessibility_bridge_unittest.cc index 6f06e79236..61ba6d4cfc 100644 --- a/engine/src/flutter/shell/platform/fuchsia/flutter/accessibility_bridge_unittest.cc +++ b/engine/src/flutter/shell/platform/fuchsia/flutter/accessibility_bridge_unittest.cc @@ -585,6 +585,52 @@ TEST_F(AccessibilityBridgeTest, TruncatesLargeLabel) { EXPECT_FALSE(semantics_manager_.UpdateOverflowed()); } +TEST_F(AccessibilityBridgeTest, TruncatesLargeToolTip) { + // Test that tooltips which are too long are truncated. + flutter::SemanticsNode node0; + node0.id = 0; + + flutter::SemanticsNode node1; + node1.id = 1; + + flutter::SemanticsNode bad_node; + bad_node.id = 2; + bad_node.tooltip = + std::string(fuchsia::accessibility::semantics::MAX_LABEL_SIZE + 1, '2'); + + node0.childrenInTraversalOrder = {1, 2}; + node0.childrenInHitTestOrder = {1, 2}; + + accessibility_bridge_->AddSemanticsNodeUpdate( + { + {0, node0}, + {1, node1}, + {2, bad_node}, + }, + 1.f); + RunLoopUntilIdle(); + + // Nothing to delete, but we should have broken + EXPECT_EQ(0, semantics_manager_.DeleteCount()); + EXPECT_EQ(1, semantics_manager_.UpdateCount()); + EXPECT_EQ(1, semantics_manager_.CommitCount()); + EXPECT_EQ(3U, semantics_manager_.LastUpdatedNodes().size()); + auto trimmed_node = + std::find_if(semantics_manager_.LastUpdatedNodes().begin(), + semantics_manager_.LastUpdatedNodes().end(), + [id = static_cast(bad_node.id)]( + fuchsia::accessibility::semantics::Node const& node) { + return node.node_id() == id; + }); + ASSERT_NE(trimmed_node, semantics_manager_.LastUpdatedNodes().end()); + ASSERT_TRUE(trimmed_node->has_attributes()); + EXPECT_EQ( + trimmed_node->attributes().secondary_label(), + std::string(fuchsia::accessibility::semantics::MAX_LABEL_SIZE, '2')); + EXPECT_FALSE(semantics_manager_.DeleteOverflowed()); + EXPECT_FALSE(semantics_manager_.UpdateOverflowed()); +} + TEST_F(AccessibilityBridgeTest, TruncatesLargeValue) { // Test that values which are too long are truncated. flutter::SemanticsNode node0; diff --git a/engine/src/flutter/testing/scenario_app/lib/src/locale_initialization.dart b/engine/src/flutter/testing/scenario_app/lib/src/locale_initialization.dart index 1a9d73fd43..d6a9afcdae 100644 --- a/engine/src/flutter/testing/scenario_app/lib/src/locale_initialization.dart +++ b/engine/src/flutter/testing/scenario_app/lib/src/locale_initialization.dart @@ -52,6 +52,7 @@ class LocaleInitialization extends Scenario { actions: 1, rect: const Rect.fromLTRB(0.0, 0.0, 414.0, 48.0), label: window.locales.toString(), + labelAttributes: [], textDirection: TextDirection.ltr, textSelectionBase: -1, textSelectionExtent: -1, @@ -67,9 +68,14 @@ class LocaleInitialization extends Scenario { elevation: 0.0, thickness: 0.0, hint: '', + hintAttributes: [], value: '', + valueAttributes: [], increasedValue: '', + increasedValueAttributes: [], decreasedValue: '', + decreasedValueAttributes: [], + tooltip: '', childrenInTraversalOrder: Int32List(0), childrenInHitTestOrder: Int32List(0), additionalActions: Int32List(0), @@ -101,6 +107,7 @@ class LocaleInitialization extends Scenario { actions: 1, rect: const Rect.fromLTRB(0.0, 0.0, 414.0, 48.0), label: label, + labelAttributes: [], textDirection: TextDirection.ltr, textSelectionBase: 0, textSelectionExtent: 0, @@ -116,9 +123,14 @@ class LocaleInitialization extends Scenario { elevation: 0.0, thickness: 0.0, hint: '', + hintAttributes: [], value: '', + valueAttributes: [], increasedValue: '', + increasedValueAttributes: [], decreasedValue: '', + decreasedValueAttributes: [], + tooltip: '', childrenInTraversalOrder: Int32List(0), childrenInHitTestOrder: Int32List(0), additionalActions: Int32List(0), diff --git a/engine/src/flutter/testing/scenario_app/lib/src/send_text_focus_semantics.dart b/engine/src/flutter/testing/scenario_app/lib/src/send_text_focus_semantics.dart index 94997cf070..7ecc04b7d0 100644 --- a/engine/src/flutter/testing/scenario_app/lib/src/send_text_focus_semantics.dart +++ b/engine/src/flutter/testing/scenario_app/lib/src/send_text_focus_semantics.dart @@ -47,6 +47,7 @@ class SendTextFocusSemantics extends Scenario { actions: 1, rect: const Rect.fromLTRB(0.0, 0.0, 414.0, 48.0), label: 'flutter textfield', + labelAttributes: [], textDirection: TextDirection.ltr, textSelectionBase: -1, textSelectionExtent: -1, @@ -62,9 +63,14 @@ class SendTextFocusSemantics extends Scenario { elevation: 0.0, thickness: 0.0, hint: '', + hintAttributes: [], value: '', + valueAttributes: [], increasedValue: '', + increasedValueAttributes: [], decreasedValue: '', + decreasedValueAttributes: [], + tooltip: '', childrenInTraversalOrder: Int32List(0), childrenInHitTestOrder: Int32List(0), additionalActions: Int32List(0), @@ -104,6 +110,7 @@ class SendTextFocusSemantics extends Scenario { actions: 18433, rect: const Rect.fromLTRB(0.0, 0.0, 414.0, 48.0), label: 'focused flutter textfield', + labelAttributes: [], textDirection: TextDirection.ltr, textSelectionBase: 0, textSelectionExtent: 0, @@ -119,9 +126,14 @@ class SendTextFocusSemantics extends Scenario { elevation: 0.0, thickness: 0.0, hint: '', + hintAttributes: [], value: '', + valueAttributes: [], increasedValue: '', + increasedValueAttributes: [], decreasedValue: '', + decreasedValueAttributes: [], + tooltip: '', childrenInTraversalOrder: Int32List(0), childrenInHitTestOrder: Int32List(0), additionalActions: Int32List(0),