From d0c44f89db1af6c8b4eac372ad8297c797a04baf Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Thu, 9 Dec 2021 16:15:17 -0800 Subject: [PATCH] Simplify win32 platform node delegate GetParent In the Win32 accessibility tree, each AXTree node has an associated IAccessible object. In WindowWin32, our WM_GETOBJECT handler returns the IAccessible associated with the root node of the tree (node 0). On other platforms, we often add our root accessibility object as a subnode of some existing accessibility object associated with the view. On Windows, the root IAccessible _is_ the accessibility object associated with the view (on Windows, and HWND). In the previous implementation, AccessibleObjectFromWindow actually just returns the root IAccessible object, which is equivalent to just returning GetNativeViewAccessible. Instead, we just return null once we hit the root of the tree. Issue: https://github.com/flutter/flutter/issues/77838 --- ...ibility_bridge_delegate_win32_unittests.cc | 30 +++++++++++++++++++ .../flutter_platform_node_delegate_win32.cc | 25 ---------------- .../flutter_platform_node_delegate_win32.h | 3 -- 3 files changed, 30 insertions(+), 28 deletions(-) diff --git a/shell/platform/windows/accessibility_bridge_delegate_win32_unittests.cc b/shell/platform/windows/accessibility_bridge_delegate_win32_unittests.cc index 67baa9a74a059..8afc6351de42d 100644 --- a/shell/platform/windows/accessibility_bridge_delegate_win32_unittests.cc +++ b/shell/platform/windows/accessibility_bridge_delegate_win32_unittests.cc @@ -163,6 +163,36 @@ void ExpectWinEventFromAXEvent(int32_t node_id, } // namespace +TEST(AccessibilityBridgeDelegateWin32, GetParent) { + auto window_binding_handler = + std::make_unique<::testing::NiceMock>(); + FlutterWindowsView view(std::move(window_binding_handler)); + view.SetEngine(GetTestEngine()); + view.OnUpdateSemanticsEnabled(true); + + auto bridge = view.GetEngine()->accessibility_bridge().lock(); + PopulateAXTree(bridge); + + auto node0_delegate = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock(); + auto node1_delegate = bridge->GetFlutterPlatformNodeDelegateFromID(1).lock(); + EXPECT_EQ(node0_delegate->GetNativeViewAccessible(), + node1_delegate->GetParent()); +} + +TEST(AccessibilityBridgeDelegateWin32, GetParentOnRootRetunsNullptr) { + auto window_binding_handler = + std::make_unique<::testing::NiceMock>(); + FlutterWindowsView view(std::move(window_binding_handler)); + view.SetEngine(GetTestEngine()); + view.OnUpdateSemanticsEnabled(true); + + auto bridge = view.GetEngine()->accessibility_bridge().lock(); + PopulateAXTree(bridge); + + auto node0_delegate = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock(); + ASSERT_TRUE(node0_delegate->GetParent() == nullptr); +} + TEST(AccessibilityBridgeDelegateWin32, NodeDelegateHasUniqueId) { auto window_binding_handler = std::make_unique<::testing::NiceMock>(); diff --git a/shell/platform/windows/flutter_platform_node_delegate_win32.cc b/shell/platform/windows/flutter_platform_node_delegate_win32.cc index 75d904fb0ae62..eb0d4769e7f9d 100644 --- a/shell/platform/windows/flutter_platform_node_delegate_win32.cc +++ b/shell/platform/windows/flutter_platform_node_delegate_win32.cc @@ -37,31 +37,6 @@ FlutterPlatformNodeDelegateWin32::GetNativeViewAccessible() { return ax_platform_node_->GetNativeViewAccessible(); } -// |FlutterPlatformNodeDelegate| -gfx::NativeViewAccessible FlutterPlatformNodeDelegateWin32::GetParent() { - gfx::NativeViewAccessible parent = FlutterPlatformNodeDelegate::GetParent(); - if (parent) { - return parent; - } - assert(engine_); - FlutterWindowsView* view = engine_->view(); - if (!view) { - return nullptr; - } - HWND hwnd = view->GetPlatformWindow(); - if (!hwnd) { - return nullptr; - } - - IAccessible* iaccessible_parent; - if (SUCCEEDED(::AccessibleObjectFromWindow( - hwnd, OBJID_WINDOW, IID_IAccessible, - reinterpret_cast(&iaccessible_parent)))) { - return iaccessible_parent; - } - return nullptr; -} - // |FlutterPlatformNodeDelegate| gfx::Rect FlutterPlatformNodeDelegateWin32::GetBoundsRect( const ui::AXCoordinateSystem coordinate_system, diff --git a/shell/platform/windows/flutter_platform_node_delegate_win32.h b/shell/platform/windows/flutter_platform_node_delegate_win32.h index f42c2baa4c87d..2b36f7aff460d 100644 --- a/shell/platform/windows/flutter_platform_node_delegate_win32.h +++ b/shell/platform/windows/flutter_platform_node_delegate_win32.h @@ -29,9 +29,6 @@ class FlutterPlatformNodeDelegateWin32 : public FlutterPlatformNodeDelegate { // |ui::AXPlatformNodeDelegate| gfx::NativeViewAccessible GetNativeViewAccessible() override; - // |FlutterPlatformNodeDelegate| - gfx::NativeViewAccessible GetParent() override; - // |FlutterPlatformNodeDelegate| gfx::Rect GetBoundsRect( const ui::AXCoordinateSystem coordinate_system,