Simplify win32 platform node delegate GetParent (flutter/engine#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: https://github.com/flutter/flutter/issues/77838
This commit is contained in:
Chris Bracken
2021-12-09 19:29:11 -08:00
committed by GitHub
parent 01b8db3de9
commit 616ed57c9b
3 changed files with 30 additions and 28 deletions

View File

@@ -163,6 +163,36 @@ void ExpectWinEventFromAXEvent(int32_t node_id,
} // namespace
TEST(AccessibilityBridgeDelegateWin32, GetParent) {
auto window_binding_handler =
std::make_unique<::testing::NiceMock<MockWindowBindingHandler>>();
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<MockWindowBindingHandler>>();
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<MockWindowBindingHandler>>();

View File

@@ -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<void**>(&iaccessible_parent)))) {
return iaccessible_parent;
}
return nullptr;
}
// |FlutterPlatformNodeDelegate|
gfx::Rect FlutterPlatformNodeDelegateWin32::GetBoundsRect(
const ui::AXCoordinateSystem coordinate_system,

View File

@@ -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,