From e1d1c2d669f5f19dbd174c3282edae114031a82a Mon Sep 17 00:00:00 2001 From: "Stephen (Alex) Wallen" Date: Thu, 18 Aug 2022 09:04:07 -0700 Subject: [PATCH] [macOS] A11y Zoom Crash (flutter/engine#35453) --- .../ax/platform/ax_platform_node_mac.mm | 4 +++- .../platform/ax_platform_node_mac_unittest.mm | 21 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/engine/src/flutter/third_party/accessibility/ax/platform/ax_platform_node_mac.mm b/engine/src/flutter/third_party/accessibility/ax/platform/ax_platform_node_mac.mm index 78c318bba2..572b2ca741 100644 --- a/engine/src/flutter/third_party/accessibility/ax/platform/ax_platform_node_mac.mm +++ b/engine/src/flutter/third_party/accessibility/ax/platform/ax_platform_node_mac.mm @@ -1016,7 +1016,9 @@ bool AlsoUseShowMenuActionForDefaultAction(const ui::AXNodeData& data) { } - (NSRange)accessibilityRangeForPosition:(NSPoint)point { - BASE_UNREACHABLE(); + // TODO(a-wallen): Framework needs to send Text Metrics + // to the AXTree in order for a NSPoint (x, y) to be + // translated to the appropriate range of UTF-16 chars. return NSMakeRange(0, 0); } diff --git a/engine/src/flutter/third_party/accessibility/ax/platform/ax_platform_node_mac_unittest.mm b/engine/src/flutter/third_party/accessibility/ax/platform/ax_platform_node_mac_unittest.mm index 7597942518..2b7629a8c0 100644 --- a/engine/src/flutter/third_party/accessibility/ax/platform/ax_platform_node_mac_unittest.mm +++ b/engine/src/flutter/third_party/accessibility/ax/platform/ax_platform_node_mac_unittest.mm @@ -46,4 +46,25 @@ TEST_F(AXPlatformNodeMacTest, CanGetCocoaPlatformNodeFromTree) { EXPECT_TRUE(native_root != nullptr); } +// Test that [AXPlatformNodeCocoa accessbilityRangeForPosition:] doesn't crash. +// https://github.com/flutter/flutter/issues/102416 +TEST_F(AXPlatformNodeMacTest, AccessibilityRangeForPositionDoesntCrash) { + AXNodeData root; + root.id = 1; + root.relative_bounds.bounds = gfx::RectF(0, 0, 40, 40); + + Init(root); + AXNode* root_node = GetRootAsAXNode(); + ASSERT_TRUE(root_node != nullptr); + + AXPlatformNode* platform_node = AXPlatformNodeFromNode(root_node); + ASSERT_TRUE(platform_node != nullptr); + + NSPoint point = NSMakePoint(0, 0); + AXPlatformNodeCocoa* native_root = platform_node->GetNativeViewAccessible(); + ASSERT_TRUE(native_root != nullptr); + + [native_root accessibilityRangeForPosition:(NSPoint)point]; +} + } // namespace ui