From 895cab5bd7e5b7b4343faeda63946e55b9c1413d Mon Sep 17 00:00:00 2001 From: LouiseHsu Date: Wed, 12 Mar 2025 13:40:07 -0700 Subject: [PATCH] [a11y] fixes overlayPortals not showing VoiceControl labels (#164754) Fixes https://github.com/flutter/flutter/issues/157753 Even when a `uiaccessibilityelement` is marked as `accessibilityRespondsToUserInteraction`, if it's spatially far away enough from its parent's `accessibilityFrame`, a VoiceControl label will not be created for it. In this PR, I set the parent `SemanticObjectContainer`'s `accessibilityFrame` so it is the minimum rect that will cover all it's children. ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. --- .../ios/framework/Source/SemanticsObject.mm | 7 +++- .../framework/Source/SemanticsObjectTest.mm | 35 +++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) 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 2b6dfd9dde..e864cc463a 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 @@ -941,7 +941,12 @@ CGRect ConvertRectToGlobal(SemanticsObject* reference, CGRect local_rect) { } - (CGRect)accessibilityFrame { - return self.semanticsObject.accessibilityFrame; + // For OverlayPortals, the child element is sometimes outside the bounds of the parent + // Even if it's marked accessible, VoiceControl labels will not appear if it's too + // spatially distant. Set the frame to be the max screen size so all children are guaraenteed + // to be contained. + + return UIScreen.mainScreen.bounds; } - (id)accessibilityContainer { 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 02fb11f983..b91d83cfef 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 @@ -614,6 +614,41 @@ const float kFloatCompareEpsilon = 0.001; XCTAssertTrue([object.accessibilityLabel isEqualToString:@"label\ntooltip"]); } +- (void)testSemanticsObjectContainerAccessibilityFrameCoversEntireScreen { + flutter::testing::MockAccessibilityBridge* mock = new flutter::testing::MockAccessibilityBridge(); + mock->isVoiceOverRunningValue = true; + fml::WeakPtrFactory factory(mock); + fml::WeakPtr bridge = factory.GetWeakPtr(); + + flutter::SemanticsNode parent; + parent.id = 0; + parent.actions = static_cast(flutter::SemanticsAction::kTap); + + flutter::SemanticsNode child; + child.id = 1; + child.actions = static_cast(flutter::SemanticsAction::kTap); + child.rect = SkRect::MakeXYWH(0, 0, 100, 100); + parent.childrenInTraversalOrder.push_back(1); + + FlutterSemanticsObject* parentObject = [[FlutterSemanticsObject alloc] initWithBridge:bridge + uid:0]; + [parentObject setSemanticsNode:&parent]; + + FlutterSemanticsObject* childObject = [[FlutterSemanticsObject alloc] initWithBridge:bridge + uid:1]; + [childObject setSemanticsNode:&child]; + + parentObject.children = @[ childObject ]; + [parentObject accessibilityBridgeDidFinishUpdate]; + [childObject accessibilityBridgeDidFinishUpdate]; + + SemanticsObjectContainer* container = + static_cast(parentObject.accessibilityContainer); + + XCTAssertTrue(childObject.accessibilityRespondsToUserInteraction); + XCTAssertTrue(CGRectEqualToRect(container.accessibilityFrame, UIScreen.mainScreen.bounds)); +} + - (void)testFlutterSemanticsObjectAttributedStringsDoNotCrashWhenEmpty { flutter::testing::MockAccessibilityBridge* mock = new flutter::testing::MockAccessibilityBridge(); mock->isVoiceOverRunningValue = true;