Skip to content

Commit 6aa8d5c

Browse files
authored
Simplify win32 platform node delegate GetParent (#30258)
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: #77838
1 parent df21689 commit 6aa8d5c

File tree

3 files changed

+30
-28
lines changed

3 files changed

+30
-28
lines changed

shell/platform/windows/accessibility_bridge_delegate_win32_unittests.cc

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,36 @@ void ExpectWinEventFromAXEvent(int32_t node_id,
163163

164164
} // namespace
165165

166+
TEST(AccessibilityBridgeDelegateWin32, GetParent) {
167+
auto window_binding_handler =
168+
std::make_unique<::testing::NiceMock<MockWindowBindingHandler>>();
169+
FlutterWindowsView view(std::move(window_binding_handler));
170+
view.SetEngine(GetTestEngine());
171+
view.OnUpdateSemanticsEnabled(true);
172+
173+
auto bridge = view.GetEngine()->accessibility_bridge().lock();
174+
PopulateAXTree(bridge);
175+
176+
auto node0_delegate = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
177+
auto node1_delegate = bridge->GetFlutterPlatformNodeDelegateFromID(1).lock();
178+
EXPECT_EQ(node0_delegate->GetNativeViewAccessible(),
179+
node1_delegate->GetParent());
180+
}
181+
182+
TEST(AccessibilityBridgeDelegateWin32, GetParentOnRootRetunsNullptr) {
183+
auto window_binding_handler =
184+
std::make_unique<::testing::NiceMock<MockWindowBindingHandler>>();
185+
FlutterWindowsView view(std::move(window_binding_handler));
186+
view.SetEngine(GetTestEngine());
187+
view.OnUpdateSemanticsEnabled(true);
188+
189+
auto bridge = view.GetEngine()->accessibility_bridge().lock();
190+
PopulateAXTree(bridge);
191+
192+
auto node0_delegate = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
193+
ASSERT_TRUE(node0_delegate->GetParent() == nullptr);
194+
}
195+
166196
TEST(AccessibilityBridgeDelegateWin32, NodeDelegateHasUniqueId) {
167197
auto window_binding_handler =
168198
std::make_unique<::testing::NiceMock<MockWindowBindingHandler>>();

shell/platform/windows/flutter_platform_node_delegate_win32.cc

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -37,31 +37,6 @@ FlutterPlatformNodeDelegateWin32::GetNativeViewAccessible() {
3737
return ax_platform_node_->GetNativeViewAccessible();
3838
}
3939

40-
// |FlutterPlatformNodeDelegate|
41-
gfx::NativeViewAccessible FlutterPlatformNodeDelegateWin32::GetParent() {
42-
gfx::NativeViewAccessible parent = FlutterPlatformNodeDelegate::GetParent();
43-
if (parent) {
44-
return parent;
45-
}
46-
assert(engine_);
47-
FlutterWindowsView* view = engine_->view();
48-
if (!view) {
49-
return nullptr;
50-
}
51-
HWND hwnd = view->GetPlatformWindow();
52-
if (!hwnd) {
53-
return nullptr;
54-
}
55-
56-
IAccessible* iaccessible_parent;
57-
if (SUCCEEDED(::AccessibleObjectFromWindow(
58-
hwnd, OBJID_WINDOW, IID_IAccessible,
59-
reinterpret_cast<void**>(&iaccessible_parent)))) {
60-
return iaccessible_parent;
61-
}
62-
return nullptr;
63-
}
64-
6540
// |FlutterPlatformNodeDelegate|
6641
gfx::Rect FlutterPlatformNodeDelegateWin32::GetBoundsRect(
6742
const ui::AXCoordinateSystem coordinate_system,

shell/platform/windows/flutter_platform_node_delegate_win32.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ class FlutterPlatformNodeDelegateWin32 : public FlutterPlatformNodeDelegate {
2929
// |ui::AXPlatformNodeDelegate|
3030
gfx::NativeViewAccessible GetNativeViewAccessible() override;
3131

32-
// |FlutterPlatformNodeDelegate|
33-
gfx::NativeViewAccessible GetParent() override;
34-
3532
// |FlutterPlatformNodeDelegate|
3633
gfx::Rect GetBoundsRect(
3734
const ui::AXCoordinateSystem coordinate_system,

0 commit comments

Comments
 (0)