Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 98a71680bf36199e257bd8e195b4205c3fcd5fe9
      
https://github.com/WebKit/WebKit/commit/98a71680bf36199e257bd8e195b4205c3fcd5fe9
  Author: Andres Gonzalez <[email protected]>
  Date:   2026-05-27 (Wed, 27 May 2026)

  Changed paths:
    M LayoutTests/accessibility/mac/bounds-for-range-expected.txt
    M LayoutTests/accessibility/mac/menu-parameterized-attributes-expected.txt
    A LayoutTests/accessibility/mac/relative-index-for-text-marker-expected.txt
    A LayoutTests/accessibility/mac/relative-index-for-text-marker.html
    M Source/WebCore/accessibility/AXCoreObject.h
    M Source/WebCore/accessibility/cocoa/AXCoreObjectCocoa.mm
    M Source/WebCore/accessibility/cocoa/CocoaAccessibilityConstants.h
    M Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapperMac.mm
    M Tools/WebKitTestRunner/InjectedBundle/AccessibilityUIElement.cpp
    M Tools/WebKitTestRunner/InjectedBundle/AccessibilityUIElement.h
    M Tools/WebKitTestRunner/InjectedBundle/Bindings/AccessibilityUIElement.idl
    M Tools/WebKitTestRunner/InjectedBundle/mac/AccessibilityUIElementMac.h
    M Tools/WebKitTestRunner/InjectedBundle/mac/AccessibilityUIElementMac.mm

  Log Message:
  -----------
  AX: Add AXRelativeIndexForTextMarker parameterized attribute.
https://bugs.webkit.org/show_bug.cgi?id=315589
<rdar://problem/177973707>

Reviewed by Tyler Wilcock.

AXIndexForTextMarker returns the position of a text marker as an offset
from the AX tree root. That contract is well defined and intentionally
preserved (an AT navigating across element boundaries needs document
positions, e.g. rdar://144892240 for runless objects), but it forces
clients that want a *receiver*-relative offset — the position of the
marker within a specific element's text content, in its own 0..N
character space — to reconstruct one by querying AXIndexForTextMarker
on the receiver's range bounds and on the marker, then subtracting.
Each of those queries walks from the AX tree root and is therefore
O(document length), and the subtraction has to be repeated at every
client call site that needs receiver-relative positions.

This patch adds AXRelativeIndexForTextMarker, a parameterized
attribute that takes a text marker and returns its character offset
within the receiver's textMarkerRange (0..numberOfCharacters), or
NSNotFound when the marker does not lie within the receiver's range.
It is the receiver-relative counterpart to AXIndexForTextMarker.

The implementation lives on AXCoreObject so it works in both
isolated-tree and non-isolated-tree configurations via virtual
dispatch on textMarkerRange(). It composes:

- A fast path for the common case: when the supplied marker is
  anchored to the receiver and the receiver carries text runs, the
  marker's own characterOffset is already receiver-local, so the
  attribute returns it directly without any walk. O(1).

- A fallback path that subtracts the receiver's range start offset
  from the supplied marker's offset, both computed against the AX
  tree root. This is correct on both threads, returns std::nullopt
  when the marker falls outside the receiver, and is no slower than
  the existing client-side alternative (the client would have made
  the same root-walks itself, only multiplied across IPC). A FIXME
  notes that a forward walk bounded by the receiver's range end
  would make this O(receiver length) instead of O(document length).

The attribute is registered on both the editable-text and static-text
parameterized-attribute lists alongside AXIndexForTextMarker. There
is no SDK feature flag — this is a new attribute, not a contract
change, so older WebKit builds simply do not register it and clients
querying it on those builds get the AX server's standard
"unknown attribute" response.

Added relativeIndexForTextMarker binding to WebKitTestRunner mirroring
indexForTextMarker. The new layout test covers in-range markers 
(start/end/middle),
out-of-range markers (in a preceding sibling, in a following sibling), and 
confirms
the result is receiver-relative by querying the same marker on its own anchoring
element and getting 0.

* LayoutTests/accessibility/mac/bounds-for-range-expected.txt:
* LayoutTests/accessibility/mac/menu-parameterized-attributes-expected.txt:
* LayoutTests/accessibility/mac/relative-index-for-text-marker-expected.txt: 
Added.
* LayoutTests/accessibility/mac/relative-index-for-text-marker.html: Added.
* Source/WebCore/accessibility/AXCoreObject.h:
* Source/WebCore/accessibility/cocoa/AXCoreObjectCocoa.mm:
(WebCore::offsetFromRootForMarker):
(WebCore::AXCoreObject::relativeIndexForTextMarker):
* Source/WebCore/accessibility/cocoa/CocoaAccessibilityConstants.h:
* Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapperMac.mm:
(-[WebAccessibilityObjectWrapper accessibilityParameterizedAttributeNames]):
(handleRelativeIndexForTextMarkerAttribute):
(createParameterizedAttributeHandlerMap):
* Tools/WebKitTestRunner/InjectedBundle/AccessibilityUIElement.cpp:
(WTR::AccessibilityUIElement::relativeIndexForTextMarker):
* Tools/WebKitTestRunner/InjectedBundle/AccessibilityUIElement.h:
* Tools/WebKitTestRunner/InjectedBundle/Bindings/AccessibilityUIElement.idl:
* Tools/WebKitTestRunner/InjectedBundle/mac/AccessibilityUIElementMac.h:
* Tools/WebKitTestRunner/InjectedBundle/mac/AccessibilityUIElementMac.mm:
(WTR::AccessibilityUIElementMac::relativeIndexForTextMarker):

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



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications

Reply via email to