Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

[macOS] Remove a single accessibility root assumption #40316

Merged
merged 2 commits into from
Mar 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions shell/platform/common/accessibility_bridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,6 @@ class AccessibilityBridge
AccessibilityBridge();
virtual ~AccessibilityBridge();

//-----------------------------------------------------------------------------
/// @brief The ID of the root node in the accessibility tree. In Flutter,
/// this is always 0.
// TODO(loicsharma): Remove this as it is incorrect in a multi-view world.
// See: https://github.com/flutter/flutter/issues/119391
static constexpr int32_t kRootNodeId = 0;

//------------------------------------------------------------------------------
/// @brief Adds a semantics node update to the pending semantics update.
/// Calling this method alone will NOT update the semantics tree.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,7 @@
if (ax_node.data().HasState(ax::mojom::State::kEditable)) {
Copy link
Member Author

@loic-sharma loic-sharma Mar 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chunhtai Do you know a widget that exercises this scenario? This scenario can only be reached by nodes with the kEditable state that don't have the kTextField role.

The logic to create AXNodes only gives the kEditable state to semantic nodes with the kFlutterSemanticsFlagIsTextField flag but not the kFlutterSemanticsFlagIsReadOnly flag. However, such a semantics node would have the kTextField role. In other words, it seems this code is unreachable. Please let me know if I misunderstood something.

Copy link
Member

@cbracken cbracken Mar 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there documentation in the ax::mojo::State enum for this role?

The ax::mojo::State enum is defined as strictly powers of two? i.e. there's no state kFoo that happens to be kBar | kEditable I assume? Agreed that at first glance, it certainly looks like this is probably dead code.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like these are defined as enum class so the answer appears to be that at least today, this is unused code.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh just to make sure it's clear: semantic nodes have both state bit flags and a role enum. These are separate :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is copied code from chromium, I don't think flutter have such widget that would run this code. We may in the future though, and we would need to update the common a11y_bridge to support that, but I am ok if we delete this code path.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha. I'll leave it in for now given we may have such a widget in the future.

events.push_back({
.name = NSAccessibilityValueChangedNotification,
.target = GetFlutterPlatformNodeDelegateFromID(AccessibilityBridge::kRootNodeId)
.lock()
->GetNativeViewAccessible(),
.target = RootDelegate()->GetNativeViewAccessible(),
.user_info = nil,
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ @implementation AccessibilityBridgeTestViewController
}
} // namespace

TEST(AccessibilityBridgeMacTest, sendsAccessibilityCreateNotificationToWindowOfFlutterView) {
TEST(AccessibilityBridgeMacTest, SendsAccessibilityCreateNotificationToWindowOfFlutterView) {
FlutterViewController* viewController = CreateTestViewController();
FlutterEngine* engine = viewController.engine;
[viewController loadView];
Expand Down Expand Up @@ -112,7 +112,84 @@ @implementation AccessibilityBridgeTestViewController
[engine shutDownEngine];
}

TEST(AccessibilityBridgeMacTest, doesNotSendAccessibilityCreateNotificationWhenHeadless) {
// Flutter used to assume that the accessibility root had ID 0.
// In a multi-view world, each view has its own accessibility root
// with a globally unique node ID.
//
// node1
// |
// node2
TEST(AccessibilityBridgeMacTest, NonZeroRootNodeId) {
FlutterViewController* viewController = CreateTestViewController();
FlutterEngine* engine = viewController.engine;
[viewController loadView];

NSWindow* expectedTarget = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 800, 600)
styleMask:NSBorderlessWindowMask
backing:NSBackingStoreBuffered
defer:NO];
expectedTarget.contentView = viewController.view;
// Setting up bridge so that the AccessibilityBridgeMacDelegateSpy
// can query semantics information from.
engine.semanticsEnabled = YES;
auto bridge = std::static_pointer_cast<AccessibilityBridgeMacSpy>(
viewController.accessibilityBridge.lock());
Copy link
Member

@cbracken cbracken Mar 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#40334 ... you saw nothing 🤫


FlutterSemanticsNode node1;
std::vector<int32_t> node1_children{2};
node1.id = 1;
node1.flags = static_cast<FlutterSemanticsFlag>(0);
node1.actions = static_cast<FlutterSemanticsAction>(0);
node1.text_selection_base = -1;
node1.text_selection_extent = -1;
node1.label = "node1";
node1.hint = "";
node1.value = "";
node1.increased_value = "";
node1.decreased_value = "";
node1.tooltip = "";
node1.child_count = node1_children.size();
node1.children_in_traversal_order = node1_children.data();
node1.children_in_hit_test_order = node1_children.data();
node1.custom_accessibility_actions_count = 0;

FlutterSemanticsNode node2;
node2.id = 2;
node2.flags = static_cast<FlutterSemanticsFlag>(0);
node2.actions = static_cast<FlutterSemanticsAction>(0);
node2.text_selection_base = -1;
node2.text_selection_extent = -1;
node2.label = "node2";
node2.hint = "";
node2.value = "";
node2.increased_value = "";
node2.decreased_value = "";
node2.tooltip = "";
node2.child_count = 0;
node2.custom_accessibility_actions_count = 0;

bridge->AddFlutterSemanticsNodeUpdate(node1);
bridge->AddFlutterSemanticsNodeUpdate(node2);
bridge->CommitUpdates();

// Look up the root node delegate.
auto root_delegate = bridge->GetFlutterPlatformNodeDelegateFromID(1).lock();
ASSERT_TRUE(root_delegate);
ASSERT_EQ(root_delegate->GetChildCount(), 1);

// Look up the child node delegate.
auto child_delegate = bridge->GetFlutterPlatformNodeDelegateFromID(2).lock();
ASSERT_TRUE(child_delegate);
ASSERT_EQ(child_delegate->GetChildCount(), 0);

// Ensure a node with ID 0 does not exist.
auto invalid_delegate = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
ASSERT_FALSE(invalid_delegate);

[engine shutDownEngine];
}

TEST(AccessibilityBridgeMacTest, DoesNotSendAccessibilityCreateNotificationWhenHeadless) {
FlutterViewController* viewController = CreateTestViewController();
FlutterEngine* engine = viewController.engine;
[viewController loadView];
Expand Down Expand Up @@ -158,7 +235,7 @@ @implementation AccessibilityBridgeTestViewController
[engine shutDownEngine];
}

TEST(AccessibilityBridgeMacTest, doesNotSendAccessibilityCreateNotificationWhenNoWindow) {
TEST(AccessibilityBridgeMacTest, DoesNotSendAccessibilityCreateNotificationWhenNoWindow) {
FlutterViewController* viewController = CreateTestViewController();
FlutterEngine* engine = viewController.engine;
[viewController loadView];
Expand Down