Skip to content

Truly independent web browser

UI/Qt: Don’t post AXLayoutChanged for an accessibility tree update

sideshowbarker9eb8e2c47abd
diff --git a/Documentation/ScreenReaderSupport.md b/Documentation/ScreenReaderSupport.md
index 297c22f8223..129754923d4 100644
--- a/Documentation/ScreenReaderSupport.md
+++ b/Documentation/ScreenReaderSupport.md
@@ -275,7 +275,7 @@ Until that first request, WebContent reports nothing: `Page::accessibility_inter
- Load finish (a navigation listener) → `request_accessibility_tree()`, but only while an assistive technology is present, which Qt reports as `QAccessible::isActive()`: on macOS, `-[QNSView activateQtAccessibility]` turns that on at the first accessibility query into any Qt window. Without one, the view never requests the tree — so WebContent never sends it tree updates or focus changes (see _Live DOM-mutation updates_ above).
- An assistive technology that turns up later → `accessibilityActiveChanged()` (the view is a `QAccessible::ActivationObserver`) → `request_accessibility_tree()`, if the view hasn’t requested the tree yet. That tree doesn’t take the first responder.
-- `on_accessibility_tree_received` → update manager; then `update_accessibility_tree()` drops the cached elements of the nodes that left the tree (invalidating them first) and keeps the rest, so an assistive technology’s handles survive a DOM mutation; posts `NSAccessibilityLayoutChangedNotification` and `@"AXLoadComplete"` (matching what Chromium and Firefox do), and calls `NSAccessibilityHandleFocusChanged()` — so AppKit refreshes its cached focused-UI-element. For the first tree after each load only, it first makes the widget’s NSView the window’s first responder, so AppKit resolves `accessibilityFocusedUIElement` through it (and thus into the `AXWebArea`).
+- `on_accessibility_tree_received` → update manager; then `update_accessibility_tree()` drops the cached elements of the nodes that left the tree (invalidating them first) and keeps the rest, so an assistive technology’s handles survive a DOM mutation. For the first tree after each load only, it makes the widget’s NSView the window’s first responder, so AppKit resolves `accessibilityFocusedUIElement` through it (and thus into the `AXWebArea`); posts `@"AXLoadComplete"` (matching what Chromium and Firefox do); and calls `NSAccessibilityHandleFocusChanged()` — so AppKit refreshes its cached focused-UI-element. Any other tree posts no notification at all, and no tree posts `NSAccessibilityLayoutChangedNotification`: VoiceOver answers that one by moving its cursor back to the `AXWebArea`, announcing “frame” — and by setting `AXFocused` there, which takes the focus from whatever element in the page had it.
- `on_accessibility_focus_changed` → update manager, post `NSAccessibilityFocusedUIElementChangedNotification` on the node’s element (`post_accessibility_focus_changed()`)
- `on_live_region_changed` → post `NSAccessibilityAnnouncementRequestedNotification` (`post_accessibility_announcement()`)
diff --git a/Tests/LibWeb/AccessibilityBridgeMac/tests/test_regressions.py b/Tests/LibWeb/AccessibilityBridgeMac/tests/test_regressions.py
index d38583a55e3..dd9ea716c90 100644
--- a/Tests/LibWeb/AccessibilityBridgeMac/tests/test_regressions.py
+++ b/Tests/LibWeb/AccessibilityBridgeMac/tests/test_regressions.py
@@ -497,7 +497,10 @@ class TreeUpdateDoesNotRefocusDocumentTests(AccessibilityBridgeMacTestCase):
the AXWebArea, posted AXLoadComplete, and refreshed AppKit's focus cache.
Fix: gate that block on a per-page flag that the load-finish path resets, so only the first tree for a page takes
- focus and announces the load; later pushes post only AXLayoutChanged."""
+ focus and announces the load; later pushes post nothing.
+
+ And no push posts AXLayoutChanged either: VoiceOver answered each one by moving its cursor back to the AXWebArea,
+ announcing a "frame", and setting AXFocused there — a tree push of its own, so it never stopped."""
FIXTURE = "mutations.html"
@@ -524,8 +527,12 @@ class TreeUpdateDoesNotRefocusDocumentTests(AccessibilityBridgeMacTestCase):
collector.close()
names = collector.names()
- # Control: the pushes are observable at all. Every tree update posts AXLayoutChanged, gated or not.
- self.assertIn("AXLayoutChanged", names, f"no AXLayoutChanged seen; notifications received: {names}")
+ self.assertNotIn(
+ "AXLayoutChanged",
+ names,
+ "a DOM-mutation tree update posted AXLayoutChanged, which pulls VoiceOver's cursor back to the AXWebArea. "
+ f"Notifications received: {names}",
+ )
self.assertNotIn(
"AXLoadComplete",
names,
diff --git a/UI/Qt/WebContentViewAccessibility.mm b/UI/Qt/WebContentViewAccessibility.mm
index d2c4586faac..5d6039142d0 100644
--- a/UI/Qt/WebContentViewAccessibility.mm
+++ b/UI/Qt/WebContentViewAccessibility.mm
@@ -456,9 +456,9 @@ void update_accessibility_tree(WebContentView* view, bool take_initial_focus, bo
[overlay.elements[key] invalidate];
[overlay.elements removeObjectForKey:key];
}
- // On the overlay, not on Qt's NSView: that one is ignored for accessibility, and a notification posted on an ignored
- // element reaches no observer.
- NSAccessibilityPostNotification(overlay, NSAccessibilityLayoutChangedNotification);
+ // No notification for the update itself: VoiceOver answers an AXLayoutChanged on the overlay by moving its cursor
+ // back to the AXWebArea inside it, announcing a "frame" — and by setting AXFocused there, which takes the focus
+ // from whatever element in the page had it.
// Only a page's first tree takes the window's first responder and announces the load — the gate WebContentView
// puts on its setFocus(), for the same reason: WebContent rebuilds the tree on DOM mutations too, and doing this on