Bug 1963996: Clear the selection if IAccessibleTextSelectionContainer::setSelections is called with nSelections set to 0. r=eeejay

I removed this behaviour in bug 1951573.
Unfortunately, it turns out that contrary to the spec (which says "1 or more selections"), NVDA depends on this behaviour.
Reinstate this by supporting kRemoveAllExistingSelectedRanges in HyperTextAccessibleBase::RemoveFromSelection and using that.

Differential Revision: https://phabricator.services.mozilla.com/D247875
This commit is contained in:
James Teh
2025-05-08 06:33:47 +00:00
committed by jteh@mozilla.com
parent cbb0e08325
commit 7932ffe32b
4 changed files with 20 additions and 2 deletions

View File

@@ -248,7 +248,8 @@ class HyperTextAccessibleBase {
}
/**
* Removes the specified selection.
* Removes the specified selection, or removes all selections if aSelectionNum
*is TextLeafRange::kRemoveAllExistingSelectedRanges.
* @return true if succeeded
*/
// TODO: annotate this with `MOZ_CAN_RUN_SCRIPT` instead.

View File

@@ -767,6 +767,11 @@ bool HyperTextAccessible::RemoveFromSelection(int32_t aSelectionNum) {
RefPtr<dom::Selection> domSel = DOMSelection();
if (!domSel) return false;
if (aSelectionNum == TextLeafRange::kRemoveAllExistingSelectedRanges) {
domSel->RemoveAllRanges(IgnoreErrors());
return true;
}
if (aSelectionNum < 0 ||
aSelectionNum >= static_cast<int32_t>(domSel->RangeCount())) {
return false;

View File

@@ -110,5 +110,13 @@ addAccessibleTask(
[p, 0, p, 1],
[link, 0, link, 1],
]);
info("Clearing selection");
selected = waitForEvent(EVENT_TEXT_SELECTION_CHANGED, docAcc);
await runPython(`
docSel.setSelections(0, byref(IA2TextSelection()))
`);
await selected;
checkSelection(docAcc, []);
}
);

View File

@@ -53,13 +53,17 @@ ia2AccessibleTextSelectionContainer::get_selections(
STDMETHODIMP
ia2AccessibleTextSelectionContainer::setSelections(
long nSelections, IA2TextSelection* selections) {
if (nSelections <= 0 || !selections) {
if (nSelections < 0 || !selections) {
return E_INVALIDARG;
}
HyperTextAccessibleBase* text = TextAcc();
if (!text) {
return CO_E_OBJNOTCONNECTED;
}
if (nSelections == 0) {
text->RemoveFromSelection(TextLeafRange::kRemoveAllExistingSelectedRanges);
return S_OK;
}
// Build and validate new selection ranges.
AutoTArray<TextLeafRange, 1> newRanges;
newRanges.SetCapacity(nSelections);