Bug 1669359 - Fix GeckoTextMarker lesser-than operator. r=morgan

Differential Revision: https://phabricator.services.mozilla.com/D92511
This commit is contained in:
Eitan Isaacson 2020-10-06 17:24:19 +00:00
parent 3d963ac35e
commit 68fd6a3f35
2 changed files with 49 additions and 0 deletions

View File

@ -133,6 +133,33 @@ bool GeckoTextMarker::operator<(const GeckoTextMarker& aPoint) const {
}
}
if (pos1 != 0) {
// If parents1 is a superset of parents2 then mContainer is a
// descendant of aPoint.mContainer. The next element down in parents1
// is mContainer's ancestor that is the child of aPoint.mContainer.
// We compare its end offset in aPoint.mContainer with aPoint.mOffset.
AccessibleOrProxy child = parents1.ElementAt(pos1 - 1);
MOZ_ASSERT(child.Parent() == aPoint.mContainer);
bool unused;
uint32_t endOffset = child.IsProxy() ? child.AsProxy()->EndOffset(&unused)
: child.AsAccessible()->EndOffset();
return endOffset < static_cast<uint32_t>(aPoint.mOffset);
}
if (pos2 != 0) {
// If parents2 is a superset of parents1 then aPoint.mContainer is a
// descendant of mContainer. The next element down in parents2
// is aPoint.mContainer's ancestor that is the child of mContainer.
// We compare its start offset in mContainer with mOffset.
AccessibleOrProxy child = parents2.ElementAt(pos2 - 1);
MOZ_ASSERT(child.Parent() == mContainer);
bool unused;
uint32_t startOffset = child.IsProxy()
? child.AsProxy()->StartOffset(&unused)
: child.AsAccessible()->StartOffset();
return static_cast<uint32_t>(mOffset) < startOffset;
}
MOZ_ASSERT_UNREACHABLE("Broken tree?!");
return false;
}

View File

@ -216,3 +216,25 @@ addAccessibleTask("mac/doc_textmarker_test.html", async (browser, accDoc) => {
testMarkerIntegrity(accDoc, expectedMarkerValues);
});
// Test text marker lesser-than operator
addAccessibleTask(
`<p id="p">hello <a id="a" href="#">goodbye</a> world</p>`,
async (browser, accDoc) => {
let macDoc = accDoc.nativeInterface.QueryInterface(
Ci.nsIAccessibleMacInterface
);
let start = macDoc.getParameterizedAttributeValue(
"AXTextMarkerForIndex",
1
);
let end = macDoc.getParameterizedAttributeValue("AXTextMarkerForIndex", 10);
let range = macDoc.getParameterizedAttributeValue(
"AXTextMarkerRangeForUnorderedTextMarkers",
[end, start]
);
is(stringForRange(macDoc, range), "ello good");
}
);