Bug 493683 part 5: When aria-labell/describedby is set, set HasName/DescriptionDependent on the target subtree. r=eeejay

Differential Revision: https://phabricator.services.mozilla.com/D102680
This commit is contained in:
James Teh 2021-01-25 17:31:19 +00:00
Родитель 49597d49e1
Коммит 38a46d893a
3 изменённых файлов: 69 добавлений и 1 удалений

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

@ -16,6 +16,7 @@
#include "nsEventShell.h"
#include "nsLayoutUtils.h"
#include "nsTextEquivUtils.h"
#include "Pivot.h"
#include "Role.h"
#include "RootAccessible.h"
#include "TreeWalker.h"
@ -851,15 +852,50 @@ void DocAccessible::AttributeChangedImpl(Accessible* aAccessible,
return;
}
dom::Element* elm = aAccessible->GetContent()->AsElement();
if (aAttribute == nsGkAtoms::aria_describedby) {
FireDelayedEvent(nsIAccessibleEvent::EVENT_DESCRIPTION_CHANGE, aAccessible);
if (aModType == dom::MutationEvent_Binding::MODIFICATION ||
aModType == dom::MutationEvent_Binding::ADDITION) {
// The subtrees of the new aria-describedby targets might be used to
// compute the description for aAccessible. Therefore, we need to set
// the eHasDescriptionDependent flag on all Accessibles in these subtrees.
IDRefsIterator iter(this, aAccessible->Elm(),
nsGkAtoms::aria_describedby);
while (Accessible* target = iter.Next()) {
Pivot pivot(target);
LocalAccInSameDocRule rule;
for (AccessibleOrProxy anchor(target); !anchor.IsNull();
anchor = pivot.Next(anchor, rule)) {
Accessible* acc = anchor.AsAccessible();
MOZ_ASSERT(acc);
acc->mContextFlags |= eHasDescriptionDependent;
}
}
}
return;
}
dom::Element* elm = aAccessible->GetContent()->AsElement();
if (aAttribute == nsGkAtoms::aria_labelledby &&
!elm->HasAttr(kNameSpaceID_None, nsGkAtoms::aria_label)) {
FireDelayedEvent(nsIAccessibleEvent::EVENT_NAME_CHANGE, aAccessible);
if (aModType == dom::MutationEvent_Binding::MODIFICATION ||
aModType == dom::MutationEvent_Binding::ADDITION) {
// The subtrees of the new aria-labelledby targets might be used to
// compute the name for aAccessible. Therefore, we need to set
// the eHasNameDependent flag on all Accessibles in these subtrees.
IDRefsIterator iter(this, aAccessible->Elm(), nsGkAtoms::aria_labelledby);
while (Accessible* target = iter.Next()) {
Pivot pivot(target);
LocalAccInSameDocRule rule;
for (AccessibleOrProxy anchor(target); !anchor.IsNull();
anchor = pivot.Next(anchor, rule)) {
Accessible* acc = anchor.AsAccessible();
MOZ_ASSERT(acc);
acc->mContextFlags |= eHasNameDependent;
}
}
}
return;
}

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

@ -90,6 +90,22 @@
getNode("descriptionChild").textContent = "d4";
await descChanged;
const lateDescribedBy = getNode("lateDescribedBy");
descChanged = PromEvents.waitForEvent(
EVENT_DESCRIPTION_CHANGE,
lateDescribedBy
);
info("Setting aria-describedby");
lateDescribedBy.setAttribute("aria-describedby", "lateDescription");
await descChanged;
descChanged = PromEvents.waitForEvent(
EVENT_DESCRIPTION_CHANGE,
lateDescribedBy
);
info("Changing text of late aria-describedby target's child");
getNode("lateDescriptionChild").textContent = "d2";
await descChanged;
SimpleTest.finish();
}
@ -117,6 +133,9 @@
<div id="describedBy" aria-describedby="description"></div>
<div id="description">d1</div>
<div id="lateDescribedBy"></div>
<div id="lateDescription"><p id="lateDescriptionChild">d1</p></div>
<div id="eventdump"></div>
</body>
</html>

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

@ -119,6 +119,16 @@
getNode("labelChild").textContent = "l4";
await nameChanged;
const lateLabelledBy = getNode("lateLabelledBy");
nameChanged = PromEvents.waitForEvent(EVENT_NAME_CHANGE, lateLabelledBy);
info("Setting aria-labelledby");
lateLabelledBy.setAttribute("aria-labelledby", "lateLabel");
await nameChanged;
nameChanged = PromEvents.waitForEvent(EVENT_NAME_CHANGE, lateLabelledBy);
info("Changing text of late aria-labelledby target's child");
getNode("lateLabelChild").textContent = "l2";
await nameChanged;
SimpleTest.finish();
}
@ -148,6 +158,9 @@
<div id="labelledBy" aria-labelledby="label"></div>
<div id="label">l1</div>
<div id="lateLabelledBy"></div>
<div id="lateLabel"><p id="lateLabelChild">l1</p></div>
<div id="eventdump"></div>
</body>
</html>