Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 6371c7a9813368cba21d606cb2a3209d064144c1
      
https://github.com/WebKit/WebKit/commit/6371c7a9813368cba21d606cb2a3209d064144c1
  Author: Dominic Mazzoni <[email protected]>
  Date:   2026-07-20 (Mon, 20 Jul 2026)

  Changed paths:
    M 
LayoutTests/accessibility/mac/index-for-zero-offset-text-marker-expected.txt
    M LayoutTests/accessibility/mac/index-for-zero-offset-text-marker.html
    A LayoutTests/accessibility/mac/text-marker-index-round-trip-expected.txt
    A 
LayoutTests/accessibility/mac/text-marker-index-round-trip-list-expected.txt
    A LayoutTests/accessibility/mac/text-marker-index-round-trip-list.html
    A 
LayoutTests/accessibility/mac/text-marker-index-round-trip-nested-blocks-expected.txt
    A 
LayoutTests/accessibility/mac/text-marker-index-round-trip-nested-blocks.html
    A 
LayoutTests/accessibility/mac/text-marker-index-round-trip-table-expected.txt
    A LayoutTests/accessibility/mac/text-marker-index-round-trip-table.html
    A LayoutTests/accessibility/mac/text-marker-index-round-trip.html
    A LayoutTests/resources/ax-text-marker-helper.js
    M Source/WebCore/accessibility/AXTextMarker.cpp

  Log Message:
  -----------
  AX: AXTextMarkerForIndex and AXIndexForTextMarker don't round-trip in the 
isolated tree
https://bugs.webkit.org/show_bug.cgi?id=319672
rdar://182515917

Reviewed by Tyler Wilcock and Andres Gonzalez.

AXIndexForTextMarker and AXTextMarkerForIndex are documented inverses
-- VoiceOver converts a text marker to a document-relative index and
back -- but in the isolated-tree text path the two directions were
implemented by separate traversals that counted positions differently:

- AXTextMarkerRange::toString (the string) walks findObjectWithRuns and emits a 
newline
  "don't repeat a newline" rule).
- offsetFromRoot (AXIndexForTextMarker) walked nextInPreOrder and counted 
newlines with
  an emitsNewline() bool that added at most 1, never accounting for 
DoubleNewline.
- nextMarkerFromOffset (AXTextMarkerForIndex) walked findMarker and counted 
every step.

Because these three disagree, converting a marker to an index and back
drifted, and the drift accumulated with each list, table, nested block
wrapper, <br>, and paragraph break, so selecting content further down
a page (e.g. Wikipedia) was increasingly wrong.

Make offsetFromRoot and nextMarkerFromOffset inverses by construction
by driving both from a single shared forward walk
(forEachRunObjectForward) that mirrors AXTextMarkerRange:: toString's
iteration and newline emission. The index of a marker is defined as
the number of characters before it in that walk; nextMarkerFromOffset
walks the same way until it has consumed that many characters. Image
alt text is intentionally excluded, so the index space is independent
of it. The round-trip is now exact for every real (run-position)
marker -- which is what VoiceOver round-trips -- while positions
inside an emitted newline gap, which have no marker of their own, snap
to an adjacent boundary (bounded and non-accumulating).

Tests: accessibility/mac/text-marker-index-round-trip-list.html
       accessibility/mac/text-marker-index-round-trip-nested-blocks.html
       accessibility/mac/text-marker-index-round-trip-table.html
       accessibility/mac/text-marker-index-round-trip.html

* LayoutTests/accessibility/mac/index-for-zero-offset-text-marker-expected.txt:
* LayoutTests/accessibility/mac/index-for-zero-offset-text-marker.html:
* LayoutTests/accessibility/mac/text-marker-index-round-trip-expected.txt: 
Added.
* LayoutTests/accessibility/mac/text-marker-index-round-trip-list-expected.txt: 
Added.
* LayoutTests/accessibility/mac/text-marker-index-round-trip-list.html: Added.
* 
LayoutTests/accessibility/mac/text-marker-index-round-trip-nested-blocks-expected.txt:
 Added.
* 
LayoutTests/accessibility/mac/text-marker-index-round-trip-nested-blocks.html: 
Added.
* 
LayoutTests/accessibility/mac/text-marker-index-round-trip-table-expected.txt: 
Added.
* LayoutTests/accessibility/mac/text-marker-index-round-trip-table.html: Added.
* LayoutTests/accessibility/mac/text-marker-index-round-trip.html: Added.
* LayoutTests/resources/ax-text-marker-helper.js: Added.
(checkRoundTripAllTextMarkerIndicesWithinContainer):
* Source/WebCore/accessibility/AXTextMarker.cpp:
(WebCore::runEndsWithNewline):
(WebCore::emittedNewlineLength):
(WebCore::forEachRunObjectForward):
(WebCore::AXTextMarker::offsetFromRoot const):
(WebCore::AXTextMarker::nextMarkerFromOffset const):

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



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

Reply via email to