Override FlutterPlatformNodeDelegate::GetUniqueId (flutter/engine#30261)

The default implementation of GetUniqueId on ui::AXPlatformNodeDelegate
always returns ID 1. We had previously implemented this on the windows
platform node delegate, but for consistency's sake, and because the
default implementation is surprising, we're promoting this to the
FlutterPlatformNodeDelegate base class.

Issue: https://github.com/flutter/flutter/issues/77838
This commit is contained in:
Chris Bracken
2021-12-10 10:05:00 -08:00
committed by GitHub
parent 95eab38132
commit 2474482021
4 changed files with 32 additions and 18 deletions

View File

@@ -98,6 +98,9 @@ class FlutterPlatformNodeDelegate : public ui::AXPlatformNodeDelegateBase {
// |ui::AXPlatformNodeDelegateBase|
virtual ~FlutterPlatformNodeDelegate() override;
// |ui::AXPlatformNodeDelegateBase|
const ui::AXUniqueId& GetUniqueId() const override { return unique_id_; }
// |ui::AXPlatformNodeDelegateBase|
const ui::AXNodeData& GetData() const override;
@@ -144,6 +147,7 @@ class FlutterPlatformNodeDelegate : public ui::AXPlatformNodeDelegateBase {
private:
ui::AXNode* ax_node_;
std::weak_ptr<OwnerBridge> bridge_;
ui::AXUniqueId unique_id_;
};
} // namespace flutter

View File

@@ -12,6 +12,34 @@
namespace flutter {
namespace testing {
TEST(FlutterPlatformNodeDelegateTest, NodeDelegateHasUniqueId) {
TestAccessibilityBridgeDelegate* delegate =
new TestAccessibilityBridgeDelegate();
std::unique_ptr<TestAccessibilityBridgeDelegate> ptr(delegate);
std::shared_ptr<AccessibilityBridge> bridge =
std::make_shared<AccessibilityBridge>(std::move(ptr));
// Add node 0: root.
FlutterSemanticsNode node0{sizeof(FlutterSemanticsNode), 0};
std::vector<int32_t> node0_children{1};
node0.child_count = node0_children.size();
node0.children_in_traversal_order = node0_children.data();
node0.children_in_hit_test_order = node0_children.data();
// Add node 1: text child of node 0.
FlutterSemanticsNode node1{sizeof(FlutterSemanticsNode), 1};
node1.label = "prefecture";
node1.value = "Kyoto";
bridge->AddFlutterSemanticsNodeUpdate(&node0);
bridge->AddFlutterSemanticsNodeUpdate(&node1);
bridge->CommitUpdates();
auto node0_delegate = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
auto node1_delegate = bridge->GetFlutterPlatformNodeDelegateFromID(1).lock();
EXPECT_TRUE(node0_delegate->GetUniqueId() != node1_delegate->GetUniqueId());
}
TEST(FlutterPlatformNodeDelegateTest, canPerfomActions) {
TestAccessibilityBridgeDelegate* delegate =
new TestAccessibilityBridgeDelegate();

View File

@@ -193,21 +193,6 @@ TEST(AccessibilityBridgeDelegateWin32, GetParentOnRootRetunsNullptr) {
ASSERT_TRUE(node0_delegate->GetParent() == nullptr);
}
TEST(AccessibilityBridgeDelegateWin32, NodeDelegateHasUniqueId) {
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_TRUE(node0_delegate->GetUniqueId() != node1_delegate->GetUniqueId());
}
TEST(AccessibilityBridgeDelegateWin32, DispatchAccessibilityAction) {
auto window_binding_handler =
std::make_unique<::testing::NiceMock<MockWindowBindingHandler>>();

View File

@@ -35,8 +35,6 @@ class FlutterPlatformNodeDelegateWin32 : public FlutterPlatformNodeDelegate {
const ui::AXClippingBehavior clipping_behavior,
ui::AXOffscreenResult* offscreen_result) const override;
const ui::AXUniqueId& GetUniqueId() const override { return unique_id_; }
// Dispatches a Windows accessibility event of the specified type, generated
// by the accessibility node associated with this object. This is a
// convenience wrapper around |NotifyWinEvent|.
@@ -49,7 +47,6 @@ class FlutterPlatformNodeDelegateWin32 : public FlutterPlatformNodeDelegate {
private:
ui::AXPlatformNode* ax_platform_node_;
FlutterWindowsEngine* engine_;
ui::AXUniqueId unique_id_;
};
} // namespace flutter