From 0d41ebed6a3c9c9eb0686583447c6d51578c3a6f Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Wed, 8 Dec 2021 09:41:46 -0800 Subject: [PATCH] Implement GetUniqueId on Windows node delegates (flutter/engine#30204) `AXPlatformNodeDelegate` provides a default implementation of `GetUniqueId()` which returns the same value (1) for all nodes. `AXPlatformNodeWin` relies on a unique ID being returned from this method in its `GetTargetFromChildID` method. In the world MSAA accessibility, each `HWND` may have a root `IAccessible` object associated with it. Events are fired by calling the `NotifyWinEvent` Win32 call and specifying: 1. The `HWND` (in our case, the one associated with our `WindowWin32`) 2. The target object (`OBJID_CLIENT` for the root `IAccessible` associated with that `HWND`) 3. A child identifier that uniquely identifies the target node in the tree This child identifier can be one of: * `CHILDID_SELF` for events targeting the root `IAccessible`. * A positive integer that specifies the index of a direct child of the root. * A negative integer which, when negated, specifies the unique ID of a child within the tree. On receipt of an accessibility event, `AXPlatformWin` (our `IAccessible` implementation) looks up the target `IAccessible` from the child ID specified on the event using its `GetTargetFromChildID` method and delegates the appropriate method call to that object. So, why is this implemented on our `AXPlatformNodeDelegate` subclass and not on `AXPlatformNodeWin` itself? Because the implementation of `AXPlatformNode::GetUniqueId()` delegates this lookup to the node delegate. As background, `AXUniqueId` automatically assigns itself a globally-unique value in its constructor; it tracks all used values in an internal static pool. Issue: https://github.com/flutter/flutter/issues/77838 --- ...cessibility_bridge_delegate_win32_unittests.cc | 15 +++++++++++++++ .../flutter_platform_node_delegate_win32.h | 4 ++++ 2 files changed, 19 insertions(+) diff --git a/engine/src/flutter/shell/platform/windows/accessibility_bridge_delegate_win32_unittests.cc b/engine/src/flutter/shell/platform/windows/accessibility_bridge_delegate_win32_unittests.cc index 296ce154b7..25546894b1 100644 --- a/engine/src/flutter/shell/platform/windows/accessibility_bridge_delegate_win32_unittests.cc +++ b/engine/src/flutter/shell/platform/windows/accessibility_bridge_delegate_win32_unittests.cc @@ -98,6 +98,21 @@ void PopulateAXTree(std::shared_ptr bridge) { } // namespace +TEST(AccessibilityBridgeDelegateWin32, NodeDelegateHasUniqueId) { + 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_TRUE(node0_delegate->GetUniqueId() != node1_delegate->GetUniqueId()); +} + TEST(AccessibilityBridgeDelegateWin32, DispatchAccessibilityAction) { auto window_binding_handler = std::make_unique<::testing::NiceMock>(); diff --git a/engine/src/flutter/shell/platform/windows/flutter_platform_node_delegate_win32.h b/engine/src/flutter/shell/platform/windows/flutter_platform_node_delegate_win32.h index 964dcdf2cf..8e04483567 100644 --- a/engine/src/flutter/shell/platform/windows/flutter_platform_node_delegate_win32.h +++ b/engine/src/flutter/shell/platform/windows/flutter_platform_node_delegate_win32.h @@ -8,6 +8,7 @@ #include "flutter/shell/platform/common/flutter_platform_node_delegate.h" #include "flutter/shell/platform/windows/flutter_windows_engine.h" #include "flutter/third_party/accessibility/ax/platform/ax_platform_node.h" +#include "flutter/third_party/accessibility/ax/platform/ax_unique_id.h" namespace flutter { @@ -37,9 +38,12 @@ class FlutterPlatformNodeDelegateWin32 : public FlutterPlatformNodeDelegate { const ui::AXClippingBehavior clipping_behavior, ui::AXOffscreenResult* offscreen_result) const override; + const ui::AXUniqueId& GetUniqueId() const override { return unique_id_; } + private: ui::AXPlatformNode* ax_platform_node_; FlutterWindowsEngine* engine_; + ui::AXUniqueId unique_id_; }; } // namespace flutter