Bug 1869971: When calculating a DOM point for the end of a non-text node, use the child index for the node after that node. r=eeejay

A TextLeafPoint is always a leaf Accessible and an offset within that Accessible.
When a TextLeafPoint is created for the end of a container and the last Accessible in the container isn't text (e.g. it is an image), TextLeafPoint represents this as offset 1 within the image.
When calculating a DOM point for such a TextLeafPoint, we need to use the child index for the next DOM node.
This indicates to DOM that the point should be positioned after the node.

Differential Revision: https://phabricator.services.mozilla.com/D247874
This commit is contained in:
James Teh
2025-05-07 04:26:04 +00:00
committed by jteh@mozilla.com
parent b7064a9f1d
commit c1029be8ea
2 changed files with 21 additions and 2 deletions

View File

@@ -580,12 +580,15 @@ std::pair<nsIContent*, uint32_t> TextLeafPoint::ToDOMPoint(
if (!mAcc->IsHyperText()) {
// For non-text nodes (e.g. images), DOM points use the child index within
// the parent.
// the parent. mOffset could be 0 (for the start of the node) or 1 (for the
// end of the node). mOffset could be 1 if this is the last Accessible in a
// container and the point is at the end of the container.
MOZ_ASSERT(mOffset == 0 || mOffset == 1);
nsIContent* parent = content->GetParent();
MOZ_ASSERT(parent);
auto childIndex = parent->ComputeIndexOf(content);
MOZ_ASSERT(childIndex);
return {parent, *childIndex};
return {parent, mOffset == 0 ? *childIndex : *childIndex + 1};
}
// This could be an empty editable container, whitespace or an empty doc. In

View File

@@ -81,6 +81,22 @@ addAccessibleTask(
is(sel.focusOffset, 3, "DOM selection focus offset correct");
});
info("Selecting fg");
selected = waitForEvent(EVENT_TEXT_SELECTION_CHANGED, p);
await runPython(`
docSel.setSelections(1, byref(IA2TextSelection(p, 4, p, 6, False)))
`);
await selected;
checkSelection(docAcc, [[p, 4, p, 6]]);
info("Selecting g");
selected = waitForEvent(EVENT_TEXT_SELECTION_CHANGED, p);
await runPython(`
docSel.setSelections(1, byref(IA2TextSelection(p, 5, p, 6, False)))
`);
await selected;
checkSelection(docAcc, [[p, 5, p, 6]]);
info("Selecting a, c");
selected = waitForEvent(EVENT_TEXT_SELECTION_CHANGED, link);
await runPython(`