Bug 1762116: When a global ARIA attribute is added to an element, create an Accessible if there isn't one already. r=morgan

We don't create Accessibles for all elements.
If an element has a global ARIA attribute when it is shown, we do create an Accessible for it.
However, previously, if we didn't initially create an Accessible for an element (e.g. no global ARIA attributes) and it subsequently gained a global ARIA attribute, we didn't create an Accessible at that point.
We now explicitly handle this case when such an attribute is added.

Differential Revision: https://phabricator.services.mozilla.com/D151348
This commit is contained in:
James Teh 2022-07-14 00:48:47 +00:00
Родитель e29e5e6308
Коммит c838f807ed
2 изменённых файлов: 24 добавлений и 8 удалений

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

@ -758,16 +758,24 @@ void DocAccessible::AttributeChanged(dom::Element* aElement,
return;
}
// Ignore attribute change if the element doesn't have an accessible (at all
// or still) if the element is not a root content of this document accessible
// (which is treated as attribute change on this document accessible).
// Note: we don't bail if all the content hasn't finished loading because
// these attributes are changing for a loaded part of the content.
LocalAccessible* accessible = GetAccessible(aElement);
if (!accessible) {
if (mContent != aElement) return;
accessible = this;
if (mContent == aElement) {
// The attribute change occurred on the root content of this
// DocAccessible, so handle it as an attribute change on this.
accessible = this;
} else {
if (aModType == dom::MutationEvent_Binding::ADDITION &&
aria::AttrCharacteristicsFor(aAttribute) & ATTR_GLOBAL) {
// The element doesn't have an Accessible, but a global ARIA attribute
// was just added, which means we should probably create an Accessible.
ContentInserted(aElement, aElement->GetNextSibling());
return;
}
// The element doesn't have an Accessible, so ignore the attribute
// change.
return;
}
}
MOZ_ASSERT(accessible->IsBoundToParent() || accessible->IsDoc(),

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

@ -51,6 +51,13 @@
document.getElementById("text").setAttribute("type", "password");
await events;
msg = "Add aria-label to a span";
ok(!isAccessible("span2"), "span2 has no accessible");
events = waitForOrderedEvents(
[[EVENT_SHOW, "span2"], [EVENT_REORDER, "container"]], msg);
document.getElementById("span2").setAttribute("aria-label", "label");
await events;
SimpleTest.finish();
}
@ -78,6 +85,7 @@
<div id="div3" role="listbox">list</div>
<input type="password" id="password"/>
<input type="text" id="text"/>
<span id="span2"></span>
</div>
<div id="eventdump"></div>