Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit b8332e3

Browse files
author
Chris Yang
authored
[CP][iOS][A11Y] fix hittest with non-SemanticsObject (#44342)
Cherry-pick #44014 Fixes flutter/flutter#131885 [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
1 parent 7568412 commit b8332e3

File tree

2 files changed

+54
-3
lines changed

2 files changed

+54
-3
lines changed

shell/platform/darwin/ios/framework/Source/SemanticsObject.mm

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -547,17 +547,16 @@ - (bool)containsPoint:(CGPoint)point {
547547
}
548548

549549
// Finds the first eligiable semantics object in hit test order.
550-
- (SemanticsObject*)search:(CGPoint)point {
550+
- (id)search:(CGPoint)point {
551551
// Search children in hit test order.
552552
for (SemanticsObject* child in [self childrenInHitTestOrder]) {
553553
if ([child containsPoint:point]) {
554-
SemanticsObject* childSearchResult = [child search:point];
554+
id childSearchResult = [child search:point];
555555
if (childSearchResult != nil) {
556556
return childSearchResult;
557557
}
558558
}
559559
}
560-
561560
// Check if the current semantic object should be returned.
562561
if ([self containsPoint:point] && [self isFocusable]) {
563562
return self.nativeAccessibility;
@@ -879,6 +878,10 @@ - (void)dealloc {
879878
[super dealloc];
880879
}
881880

881+
- (id)nativeAccessibility {
882+
return _platformView;
883+
}
884+
882885
#pragma mark - UIAccessibilityContainer overrides
883886

884887
- (NSArray*)accessibilityElements {

shell/platform/darwin/ios/framework/Source/SemanticsObjectTest.mm

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,54 @@ - (void)testAccessibilityHitTestNoFocusableItem {
203203
XCTAssertNil(hitTestResult);
204204
}
205205

206+
- (void)testAccessibilityHitTestSearchCanReturnPlatformView {
207+
fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(
208+
new flutter::MockAccessibilityBridge());
209+
fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr();
210+
SemanticsObject* object0 = [[SemanticsObject alloc] initWithBridge:bridge uid:0];
211+
SemanticsObject* object1 = [[SemanticsObject alloc] initWithBridge:bridge uid:1];
212+
SemanticsObject* object3 = [[SemanticsObject alloc] initWithBridge:bridge uid:3];
213+
UIView* platformView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
214+
FlutterPlatformViewSemanticsContainer* platformViewSemanticsContainer =
215+
[[FlutterPlatformViewSemanticsContainer alloc] initWithBridge:bridge
216+
uid:1
217+
platformView:platformView];
218+
219+
object0.children = @[ object1 ];
220+
object0.childrenInHitTestOrder = @[ object1 ];
221+
object1.children = @[ platformViewSemanticsContainer, object3 ];
222+
object1.childrenInHitTestOrder = @[ platformViewSemanticsContainer, object3 ];
223+
224+
flutter::SemanticsNode node0;
225+
node0.id = 0;
226+
node0.rect = SkRect::MakeXYWH(0, 0, 200, 200);
227+
node0.label = "0";
228+
[object0 setSemanticsNode:&node0];
229+
230+
flutter::SemanticsNode node1;
231+
node1.id = 1;
232+
node1.rect = SkRect::MakeXYWH(0, 0, 200, 200);
233+
node1.label = "1";
234+
[object1 setSemanticsNode:&node1];
235+
236+
flutter::SemanticsNode node2;
237+
node2.id = 2;
238+
node2.rect = SkRect::MakeXYWH(0, 0, 100, 100);
239+
node2.label = "2";
240+
[platformViewSemanticsContainer setSemanticsNode:&node2];
241+
242+
flutter::SemanticsNode node3;
243+
node3.id = 3;
244+
node3.rect = SkRect::MakeXYWH(0, 0, 200, 200);
245+
node3.label = "3";
246+
[object3 setSemanticsNode:&node3];
247+
248+
CGPoint point = CGPointMake(10, 10);
249+
id hitTestResult = [object0 _accessibilityHitTest:point withEvent:nil];
250+
251+
XCTAssertEqual(hitTestResult, platformView);
252+
}
253+
206254
- (void)testAccessibilityScrollToVisible {
207255
fml::WeakPtrFactory<flutter::MockAccessibilityBridge> factory(
208256
new flutter::MockAccessibilityBridge());

0 commit comments

Comments
 (0)