Bug 1780667: Don't fire a11y focus on the DOM element when its aria-activedescendant is cleared/invalidated if the element doesn't have DOM focus. r=eeejay

aria-activedescendant should only take effect when the element has DOM focus.
Previously, clearing aria-activedescendant or setting it to an invalid id on an element without DOM focus would incorrectly fire a11y focus on that element.
Also, this caused an assertion to be fired due to a defunct active item if this happened alongside a text selection change.

Differential Revision: https://phabricator.services.mozilla.com/D180630
This commit is contained in:
James Teh 2023-06-13 00:30:49 +00:00
Родитель 6b50a8161b
Коммит a984d0f58f
2 изменённых файлов: 18 добавлений и 6 удалений

Просмотреть файл

@ -928,14 +928,16 @@ void DocAccessible::ARIAActiveDescendantChanged(LocalAccessible* aAccessible) {
}
// aria-activedescendant was cleared or changed to a non-existent node.
// Move focus back to the element itself.
FocusMgr()->ActiveItemChanged(aAccessible, false);
// Move focus back to the element itself if it has DOM focus.
if (aAccessible->IsActiveWidget()) {
FocusMgr()->ActiveItemChanged(aAccessible, false);
#ifdef A11Y_LOG
if (logging::IsEnabled(logging::eFocus)) {
logging::ActiveItemChangeCausedBy("ARIA activedescedant cleared",
aAccessible);
}
if (logging::IsEnabled(logging::eFocus)) {
logging::ActiveItemChangeCausedBy("ARIA activedescedant cleared",
aAccessible);
}
#endif
}
}
}

Просмотреть файл

@ -241,6 +241,16 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=429547
listbox.setAttribute("aria-activedescendant", "item2");
await evtProm;
info("Setting aria-activedescendant to invalid id on non-focused node");
const combobox_entry = getNode("combobox_entry");
evtProm = PromEvents.waitForEvents({
expected: [[EVENT_FOCUS, combobox_entry]],
unexpected: [[EVENT_FOCUS, listbox]],
});
combobox_entry.focus();
listbox.setAttribute("aria-activedescendant", "invalid");
await evtProm;
SimpleTest.finish();
}