Skip to content

Conversation

twilco
Copy link
Contributor

@twilco twilco commented Mar 5, 2025

0420ca0

AX: Add a fast path for assistive technologies that search for all live regions and all non-root web areas on macOS
https://bugs.webkit.org/show_bug.cgi?id=289137
rdar://146185640

Reviewed by Chris Fleizach.

VoiceOver commonly sends remote search requests for all the live regions, and all the non-woot web areas on the page.
Prior to this commit, this always required a full tree traversal. With this commit, we eagerly maintain a pre-sorted
list of these objects, allowing us to answer these queries immediately. There are generally very few of these objects
on a page, so it's cheap to keep this list up-to-date.

To avoid confusion, the existing AXObjectCache::m_liveRegionObjects list is renamed to AXObjectCache::m_changedLiveRegions,
as that is what it actually holds (live regions that have changed and are waiting for notifications to be sent for them).

* LayoutTests/accessibility/mac/live-region-search-expected.txt: Added.
* LayoutTests/accessibility/mac/live-region-search.html: Added.
* Source/WebCore/accessibility/AXCoreObject.h:
* Source/WebCore/accessibility/AXObjectCache.cpp:
(WebCore::AXObjectCache::remove):
(WebCore::AXObjectCache::handleLiveRegionCreated):
(WebCore::AXObjectCache::postLiveRegionChangeNotification):
(WebCore::AXObjectCache::liveRegionChangedNotificationPostTimerFired):
(WebCore::AXObjectCache::handleRoleChanged):
(WebCore::AXObjectCache::handleAttributeChange):
(WebCore::AXObjectCache::performDeferredCacheUpdate):
* Source/WebCore/accessibility/AXObjectCache.h:
* Source/WebCore/accessibility/AXSearchManager.cpp:
(WebCore::AXSearchManager::findMatchingObjectsInternal):
(WebCore::AXSearchManager::findMatchingRange):
(WebCore::AXSearchManager::findNextStartingFrom):
(WebCore::AXSearchManager::findAllMatchingObjectsIgnoringCache):
* Source/WebCore/accessibility/AXSearchManager.h:
* Source/WebCore/accessibility/AccessibilityObject.cpp:
(WebCore::AccessibilityObject::updateRole):
* Source/WebCore/accessibility/AccessibilityObject.h:
* Source/WebCore/accessibility/AccessibilityRenderObject.cpp:
(WebCore::AccessibilityRenderObject::updateRoleAfterChildrenCreation):
* Source/WebCore/accessibility/cocoa/AXCoreObjectCocoa.mm:
(WebCore::AXCoreObject::sortedDescendants const):
* Source/WebCore/accessibility/isolatedtree/AXIsolatedObject.h:
* Source/WebCore/accessibility/isolatedtree/AXIsolatedTree.cpp:
(WebCore::AXIsolatedTree::sortedLiveRegions):
(WebCore::AXIsolatedTree::sortedNonRootWebAreas):
(WebCore::AXIsolatedTree::applyPendingChanges):
(WebCore::AXIsolatedTree::sortedLiveRegionsDidChange):
(WebCore::AXIsolatedTree::sortedNonRootWebAreasDidChange):
* Source/WebCore/accessibility/isolatedtree/AXIsolatedTree.h:
* Source/WebCore/accessibility/isolatedtree/mac/AXIsolatedObjectMac.mm:
(WebCore::AXIsolatedObject::allSortedLiveRegions const):
(WebCore::AXIsolatedObject::allSortedNonRootWebAreas const):
* Source/WebCore/accessibility/mac/AXObjectCacheMac.mm:
(WebCore::AXObjectCache::onDocumentRenderTreeCreation):
(WebCore::AXObjectCache::platformPerformDeferredCacheUpdate):
(WebCore::AXObjectCache::sortedLiveRegions const):
(WebCore::AXObjectCache::sortedNonRootWebAreas const):
(WebCore::AXObjectCache::addSortedObject):
(WebCore::AXObjectCache::removeLiveRegion):
(WebCore::AXObjectCache::initializeSortedIDLists):
* Source/WebCore/accessibility/mac/AccessibilityObjectMac.mm:
(WebCore::AccessibilityObject::allSortedLiveRegions const):
(WebCore::AccessibilityObject::allSortedNonRootWebAreas const):
* Source/WebCore/dom/Document.cpp:
(WebCore::Document::createRenderTree):

Canonical link: https://commits.webkit.org/291652@main

b192947

Misc iOS, visionOS, tvOS & watchOS macOS Linux Windows
✅ 🧪 style ✅ 🛠 ios ✅ 🛠 mac ✅ 🛠 wpe ✅ 🛠 win
✅ 🧪 bindings ✅ 🛠 ios-sim ✅ 🛠 mac-AS-debug ✅ 🧪 wpe-wk2 ✅ 🧪 win-tests
✅ 🧪 webkitperl ✅ 🧪 ios-wk2 ✅ 🧪 api-mac ✅ 🧪 api-wpe
✅ 🧪 ios-wk2-wpt ✅ 🧪 mac-wk1 ✅ 🛠 wpe-cairo
✅ 🧪 api-ios ✅ 🧪 mac-wk2 ✅ 🛠 gtk
✅ 🛠 vision ✅ 🧪 mac-AS-debug-wk2 ✅ 🧪 gtk-wk2
✅ 🛠 vision-sim ✅ 🧪 mac-wk2-stress ✅ 🧪 api-gtk
✅ 🛠 🧪 merge ✅ 🧪 vision-wk2 ✅ 🧪 mac-intel-wk2 ✅ 🛠 playstation
✅ 🛠 tv ✅ 🛠 mac-safer-cpp
✅ 🛠 tv-sim
✅ 🛠 watch
✅ 🛠 watch-sim

@twilco twilco requested review from cdumez and rniwa as code owners March 5, 2025 03:24
@twilco twilco self-assigned this Mar 5, 2025
@twilco twilco added the Accessibility For bugs related to accessibility. label Mar 5, 2025
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Mar 5, 2025
@twilco twilco force-pushed the eng/AX-Add-a-fast-path-for-assistive-technologies-that-search-for-all-live-regions-and-all-non-root-web-areas-on-macOS branch from ee7be21 to de7ae33 Compare March 5, 2025 03:49
@twilco twilco force-pushed the eng/AX-Add-a-fast-path-for-assistive-technologies-that-search-for-all-live-regions-and-all-non-root-web-areas-on-macOS branch from de7ae33 to a682fee Compare March 5, 2025 15:57
Copy link
Contributor

Choose a reason for hiding this comment

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

Out of curiosity, what is the motivation for moving children changed up here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We need to update the accessibility tree before any calls to addSortedObject, as otherwise we'll be trying to find the right place for a sorted object based on outdated accessibility tree state. This moves handling children-changed up above where we would potentially call addSortedObject.

Copy link
Contributor

Choose a reason for hiding this comment

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

This won't only apply to live regions, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops, right!

Copy link
Contributor

Choose a reason for hiding this comment

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

Same question as above, this isn't just for live regions, right?

@twilco twilco force-pushed the eng/AX-Add-a-fast-path-for-assistive-technologies-that-search-for-all-live-regions-and-all-non-root-web-areas-on-macOS branch from a682fee to b192947 Compare March 5, 2025 18:20
@twilco twilco added merge-queue Applied to send a pull request to merge-queue and removed merging-blocked Applied to prevent a change from being merged labels Mar 5, 2025
…ve regions and all non-root web areas on macOS

https://bugs.webkit.org/show_bug.cgi?id=289137
rdar://146185640

Reviewed by Chris Fleizach.

VoiceOver commonly sends remote search requests for all the live regions, and all the non-woot web areas on the page.
Prior to this commit, this always required a full tree traversal. With this commit, we eagerly maintain a pre-sorted
list of these objects, allowing us to answer these queries immediately. There are generally very few of these objects
on a page, so it's cheap to keep this list up-to-date.

To avoid confusion, the existing AXObjectCache::m_liveRegionObjects list is renamed to AXObjectCache::m_changedLiveRegions,
as that is what it actually holds (live regions that have changed and are waiting for notifications to be sent for them).

* LayoutTests/accessibility/mac/live-region-search-expected.txt: Added.
* LayoutTests/accessibility/mac/live-region-search.html: Added.
* Source/WebCore/accessibility/AXCoreObject.h:
* Source/WebCore/accessibility/AXObjectCache.cpp:
(WebCore::AXObjectCache::remove):
(WebCore::AXObjectCache::handleLiveRegionCreated):
(WebCore::AXObjectCache::postLiveRegionChangeNotification):
(WebCore::AXObjectCache::liveRegionChangedNotificationPostTimerFired):
(WebCore::AXObjectCache::handleRoleChanged):
(WebCore::AXObjectCache::handleAttributeChange):
(WebCore::AXObjectCache::performDeferredCacheUpdate):
* Source/WebCore/accessibility/AXObjectCache.h:
* Source/WebCore/accessibility/AXSearchManager.cpp:
(WebCore::AXSearchManager::findMatchingObjectsInternal):
(WebCore::AXSearchManager::findMatchingRange):
(WebCore::AXSearchManager::findNextStartingFrom):
(WebCore::AXSearchManager::findAllMatchingObjectsIgnoringCache):
* Source/WebCore/accessibility/AXSearchManager.h:
* Source/WebCore/accessibility/AccessibilityObject.cpp:
(WebCore::AccessibilityObject::updateRole):
* Source/WebCore/accessibility/AccessibilityObject.h:
* Source/WebCore/accessibility/AccessibilityRenderObject.cpp:
(WebCore::AccessibilityRenderObject::updateRoleAfterChildrenCreation):
* Source/WebCore/accessibility/cocoa/AXCoreObjectCocoa.mm:
(WebCore::AXCoreObject::sortedDescendants const):
* Source/WebCore/accessibility/isolatedtree/AXIsolatedObject.h:
* Source/WebCore/accessibility/isolatedtree/AXIsolatedTree.cpp:
(WebCore::AXIsolatedTree::sortedLiveRegions):
(WebCore::AXIsolatedTree::sortedNonRootWebAreas):
(WebCore::AXIsolatedTree::applyPendingChanges):
(WebCore::AXIsolatedTree::sortedLiveRegionsDidChange):
(WebCore::AXIsolatedTree::sortedNonRootWebAreasDidChange):
* Source/WebCore/accessibility/isolatedtree/AXIsolatedTree.h:
* Source/WebCore/accessibility/isolatedtree/mac/AXIsolatedObjectMac.mm:
(WebCore::AXIsolatedObject::allSortedLiveRegions const):
(WebCore::AXIsolatedObject::allSortedNonRootWebAreas const):
* Source/WebCore/accessibility/mac/AXObjectCacheMac.mm:
(WebCore::AXObjectCache::onDocumentRenderTreeCreation):
(WebCore::AXObjectCache::platformPerformDeferredCacheUpdate):
(WebCore::AXObjectCache::sortedLiveRegions const):
(WebCore::AXObjectCache::sortedNonRootWebAreas const):
(WebCore::AXObjectCache::addSortedObject):
(WebCore::AXObjectCache::removeLiveRegion):
(WebCore::AXObjectCache::initializeSortedIDLists):
* Source/WebCore/accessibility/mac/AccessibilityObjectMac.mm:
(WebCore::AccessibilityObject::allSortedLiveRegions const):
(WebCore::AccessibilityObject::allSortedNonRootWebAreas const):
* Source/WebCore/dom/Document.cpp:
(WebCore::Document::createRenderTree):

Canonical link: https://commits.webkit.org/291652@main
@webkit-commit-queue webkit-commit-queue force-pushed the eng/AX-Add-a-fast-path-for-assistive-technologies-that-search-for-all-live-regions-and-all-non-root-web-areas-on-macOS branch from b192947 to 0420ca0 Compare March 5, 2025 22:28
@webkit-commit-queue
Copy link
Collaborator

Committed 291652@main (0420ca0): https://commits.webkit.org/291652@main

Reviewed commits have been landed. Closing PR #41898 and removing active labels.

@webkit-commit-queue webkit-commit-queue merged commit 0420ca0 into WebKit:main Mar 5, 2025
@webkit-commit-queue webkit-commit-queue removed the merge-queue Applied to send a pull request to merge-queue label Mar 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Accessibility For bugs related to accessibility.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants