Skip to content

AX: Exclude aria-hidden text from stitched accessibility text#59904

Merged
webkit-commit-queue merged 1 commit intoWebKit:mainfrom
twilco:eng/AX-Exclude-aria-hidden-text-from-stitched-accessibility-text
Mar 11, 2026
Merged

AX: Exclude aria-hidden text from stitched accessibility text#59904
webkit-commit-queue merged 1 commit intoWebKit:mainfrom
twilco:eng/AX-Exclude-aria-hidden-text-from-stitched-accessibility-text

Conversation

@twilco
Copy link
Contributor

@twilco twilco commented Mar 4, 2026

361a2d0

AX: Exclude aria-hidden text from stitched accessibility text
https://bugs.webkit.org/show_bug.cgi?id=309167
rdar://171726246

Reviewed by Joshua Hoffman.

When text stitching is enabled, text within aria-hidden="true" elements was
incorrectly included in the stitched text output. For example, given
<span>$45.79<span aria-hidden="true">/mo.</span> per month</span>, the
stitched text included "/mo." when it should only expose "$45.79 per month".

The root cause was that stringValue() computed stitched text using a contiguous
range from first to last stitch group member, capturing all DOM text in between,
including text from aria-hidden nodes.

Fix this by:
- Main thread: building text from consecutive runs of non-hidden members,
flushing each run as a DOM range to preserve inter-element whitespace while
skipping hidden content.
- Isolated tree: iterating members individually and skipping hidden ones.
- Filtering hidden members from bounding box computation, simpleRange()
endpoints, and textMarkerRange() endpoints.

To support isAXHidden() on both live and isolated trees, store IsARIAHidden
(a local per-node property) in the isolated tree, then compute isAXHidden()
on-the-fly via ancestor traversal in AXCoreObject. This avoids the need to
dirty stitch groups when aria-hidden changes dynamically.

Also fix duplicate stitch group members caused by multiple layout boxes sharing
the same RenderText renderer (e.g. text split across lines). This was exposed by
test hit-test-on-stitched-text.html due to the new AXIsolatedObject::stringValue
implementation which explicitly visits each stitch-group member.

Test: accessibility/aria-hidden-text-stitching.html

* LayoutTests/accessibility/aria-hidden-text-stitching-expected.txt: Added.
* LayoutTests/accessibility/aria-hidden-text-stitching.html: Added.
* Source/WebCore/accessibility/AXCoreObject.cpp:
(WebCore::AXCoreObject::isAXHidden const):
* Source/WebCore/accessibility/AXCoreObject.h:
(WebCore::AXCoreObject::isARIAHidden const):
* Source/WebCore/accessibility/AXLogger.cpp:
(WebCore::operator<<):
* Source/WebCore/accessibility/AXObjectCache.cpp:
(WebCore::AXObjectCache::handleAttributeChange):
* Source/WebCore/accessibility/AXUtilities.cpp:
(WebCore::lastNonAriaHiddenNode):
(WebCore::lastNode): Deleted.
* Source/WebCore/accessibility/AXUtilities.h:
* Source/WebCore/accessibility/AccessibilityNodeObject.cpp:
(WebCore::AccessibilityNodeObject::stitchGroups const):
(WebCore::AccessibilityNodeObject::stringValue const):
* Source/WebCore/accessibility/AccessibilityObject.cpp:
(WebCore::AccessibilityObject::simpleRange const):
(WebCore::AccessibilityObject::cachedIsIgnored const):
(WebCore::AccessibilityObject::isAXHidden const): Deleted.
* Source/WebCore/accessibility/AccessibilityObject.h:
* Source/WebCore/accessibility/AccessibilityRenderObject.cpp:
(WebCore::AccessibilityRenderObject::boundingBoxRect const):
* Source/WebCore/accessibility/AccessibilityScrollView.cpp:
(WebCore::AccessibilityScrollView::isAXHidden const): Deleted.
* Source/WebCore/accessibility/AccessibilityScrollView.h:
* Source/WebCore/accessibility/isolatedtree/AXIsolatedObject.cpp:
(WebCore::AXIsolatedObject::relativeFrame const):
(WebCore::AXIsolatedObject::stringValue const):
* Source/WebCore/accessibility/isolatedtree/AXIsolatedObject.h:
* Source/WebCore/accessibility/isolatedtree/AXIsolatedTree.cpp:
(WebCore::AXIsolatedTree::updateNodeProperties):
(WebCore::convertToPropertyFlag):
(WebCore::createIsolatedObjectData):
* Source/WebCore/accessibility/isolatedtree/AXIsolatedTree.h:
* Source/WebCore/accessibility/isolatedtree/mac/AXIsolatedObjectMac.mm:
(WebCore::AXIsolatedObject::textMarkerRange const):

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

083f2c4

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

@twilco twilco self-assigned this Mar 4, 2026
@twilco twilco added the Accessibility For bugs related to accessibility. label Mar 4, 2026
@twilco twilco force-pushed the eng/AX-Exclude-aria-hidden-text-from-stitched-accessibility-text branch from 4049a0d to 0ae3161 Compare March 4, 2026 19:03
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Mar 4, 2026
@twilco twilco force-pushed the eng/AX-Exclude-aria-hidden-text-from-stitched-accessibility-text branch from 0ae3161 to 0cddb59 Compare March 5, 2026 04:14
@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, 2026
@twilco twilco force-pushed the eng/AX-Exclude-aria-hidden-text-from-stitched-accessibility-text branch from 0cddb59 to 99eae9e Compare March 11, 2026 15:42
@webkit-ews-buildbot webkit-ews-buildbot added merging-blocked Applied to prevent a change from being merged and removed merge-queue Applied to send a pull request to merge-queue labels Mar 11, 2026
@twilco twilco force-pushed the eng/AX-Exclude-aria-hidden-text-from-stitched-accessibility-text branch from 99eae9e to 083f2c4 Compare March 11, 2026 16:07
@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 11, 2026
https://bugs.webkit.org/show_bug.cgi?id=309167
rdar://171726246

Reviewed by Joshua Hoffman.

When text stitching is enabled, text within aria-hidden="true" elements was
incorrectly included in the stitched text output. For example, given
<span>$45.79<span aria-hidden="true">/mo.</span> per month</span>, the
stitched text included "/mo." when it should only expose "$45.79 per month".

The root cause was that stringValue() computed stitched text using a contiguous
range from first to last stitch group member, capturing all DOM text in between,
including text from aria-hidden nodes.

Fix this by:
- Main thread: building text from consecutive runs of non-hidden members,
flushing each run as a DOM range to preserve inter-element whitespace while
skipping hidden content.
- Isolated tree: iterating members individually and skipping hidden ones.
- Filtering hidden members from bounding box computation, simpleRange()
endpoints, and textMarkerRange() endpoints.

To support isAXHidden() on both live and isolated trees, store IsARIAHidden
(a local per-node property) in the isolated tree, then compute isAXHidden()
on-the-fly via ancestor traversal in AXCoreObject. This avoids the need to
dirty stitch groups when aria-hidden changes dynamically.

Also fix duplicate stitch group members caused by multiple layout boxes sharing
the same RenderText renderer (e.g. text split across lines). This was exposed by
test hit-test-on-stitched-text.html due to the new AXIsolatedObject::stringValue
implementation which explicitly visits each stitch-group member.

Test: accessibility/aria-hidden-text-stitching.html

* LayoutTests/accessibility/aria-hidden-text-stitching-expected.txt: Added.
* LayoutTests/accessibility/aria-hidden-text-stitching.html: Added.
* Source/WebCore/accessibility/AXCoreObject.cpp:
(WebCore::AXCoreObject::isAXHidden const):
* Source/WebCore/accessibility/AXCoreObject.h:
(WebCore::AXCoreObject::isARIAHidden const):
* Source/WebCore/accessibility/AXLogger.cpp:
(WebCore::operator<<):
* Source/WebCore/accessibility/AXObjectCache.cpp:
(WebCore::AXObjectCache::handleAttributeChange):
* Source/WebCore/accessibility/AXUtilities.cpp:
(WebCore::lastNonAriaHiddenNode):
(WebCore::lastNode): Deleted.
* Source/WebCore/accessibility/AXUtilities.h:
* Source/WebCore/accessibility/AccessibilityNodeObject.cpp:
(WebCore::AccessibilityNodeObject::stitchGroups const):
(WebCore::AccessibilityNodeObject::stringValue const):
* Source/WebCore/accessibility/AccessibilityObject.cpp:
(WebCore::AccessibilityObject::simpleRange const):
(WebCore::AccessibilityObject::cachedIsIgnored const):
(WebCore::AccessibilityObject::isAXHidden const): Deleted.
* Source/WebCore/accessibility/AccessibilityObject.h:
* Source/WebCore/accessibility/AccessibilityRenderObject.cpp:
(WebCore::AccessibilityRenderObject::boundingBoxRect const):
* Source/WebCore/accessibility/AccessibilityScrollView.cpp:
(WebCore::AccessibilityScrollView::isAXHidden const): Deleted.
* Source/WebCore/accessibility/AccessibilityScrollView.h:
* Source/WebCore/accessibility/isolatedtree/AXIsolatedObject.cpp:
(WebCore::AXIsolatedObject::relativeFrame const):
(WebCore::AXIsolatedObject::stringValue const):
* Source/WebCore/accessibility/isolatedtree/AXIsolatedObject.h:
* Source/WebCore/accessibility/isolatedtree/AXIsolatedTree.cpp:
(WebCore::AXIsolatedTree::updateNodeProperties):
(WebCore::convertToPropertyFlag):
(WebCore::createIsolatedObjectData):
* Source/WebCore/accessibility/isolatedtree/AXIsolatedTree.h:
* Source/WebCore/accessibility/isolatedtree/mac/AXIsolatedObjectMac.mm:
(WebCore::AXIsolatedObject::textMarkerRange const):

Canonical link: https://commits.webkit.org/309096@main
@webkit-commit-queue webkit-commit-queue force-pushed the eng/AX-Exclude-aria-hidden-text-from-stitched-accessibility-text branch from 083f2c4 to 361a2d0 Compare March 11, 2026 22:04
@webkit-commit-queue
Copy link
Collaborator

Committed 309096@main (361a2d0): https://commits.webkit.org/309096@main

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

@webkit-commit-queue webkit-commit-queue merged commit 361a2d0 into WebKit:main Mar 11, 2026
@webkit-commit-queue webkit-commit-queue removed the merge-queue Applied to send a pull request to merge-queue label Mar 11, 2026
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.

5 participants