Bug 1787101: HyperTextAccessibleBase::OffsetAtPoint: Transform the offset before returning it. r=morgan

Otherwise, the returned offset is incorrect if the point is in a child other than the first.

Differential Revision: https://phabricator.services.mozilla.com/D155571
This commit is contained in:
James Teh 2022-08-26 07:25:12 +00:00
parent fff8d45634
commit 08d6b123a8
2 changed files with 19 additions and 1 deletions

View File

@ -281,7 +281,15 @@ int32_t HyperTextAccessibleBase::OffsetAtPoint(int32_t aX, int32_t aY,
/* aIncludeOrigin */ false)) {
}
}
return point.ContainsPoint(coords.x, coords.y) ? point.mOffset : -1;
if (!point.ContainsPoint(coords.x, coords.y)) {
return -1;
}
DebugOnly<bool> ok = false;
int32_t htOffset;
std::tie(ok, htOffset) =
TransformOffset(point.mAcc, point.mOffset, /* aIsEndOffset */ false);
MOZ_ASSERT(ok, "point should be a descendant of this");
return htOffset;
}
TextLeafPoint HyperTextAccessibleBase::ToTextLeafPoint(int32_t aOffset,

View File

@ -8,6 +8,7 @@ addAccessibleTask(
`
a
<div id="noChars" style="width: 5px; height: 5px;"><p></p></div>
<p id="twoText"><span>a</span><span>b</span></p>
`,
async function(browser, docAcc) {
const dpr = await getContentDPR(browser);
@ -18,6 +19,15 @@ a
]);
let [x, y] = Layout.getBounds(noChars, dpr);
await testOffsetAtPoint(noChars, x, y, COORDTYPE_SCREEN_RELATIVE, -1);
// Test that the correct offset is returned for a point in a second text
// leaf.
const twoText = findAccessibleChildByID(docAcc, "twoText", [
Ci.nsIAccessibleText,
]);
const text2 = twoText.getChildAt(1);
[x, y] = Layout.getBounds(text2, dpr);
await testOffsetAtPoint(twoText, x, y, COORDTYPE_SCREEN_RELATIVE, 1);
},
{
topLevel: true,