Bug 1305428: Don't set ARIA DOM attributes due to accessibility API calls. r=eeejay

Per the spec, with respect to ARIA, "accessibility APIs operate in one direction only. User agents publish WAI-ARIA information (roles, states, and properties) via an accessibility API, and an AT can acquire that information using the same API. However, the other direction is not supported."
Although Firefox has not complied with this part of the spec for many years, this can cause problems for some ARIA widgets which aren't expecting ARIA attributes to be changed by the browser (nor should they, per the spec).
This might change one day, but for now, we should align with the spec.

Differential Revision: https://phabricator.services.mozilla.com/D204559
This commit is contained in:
James Teh 2024-03-19 04:53:47 +00:00
parent c5e7ba7cee
commit c0b30241a5
3 changed files with 4 additions and 57 deletions

View File

@ -744,22 +744,8 @@ LayoutDeviceIntRect LocalAccessible::Bounds() const {
void LocalAccessible::SetSelected(bool aSelect) {
if (!HasOwnContent()) return;
LocalAccessible* select = nsAccUtils::GetSelectableContainer(this, State());
if (select) {
if (select->State() & states::MULTISELECTABLE) {
if (mContent->IsElement() && ARIARoleMap()) {
if (aSelect) {
mContent->AsElement()->SetAttr(
kNameSpaceID_None, nsGkAtoms::aria_selected, u"true"_ns, true);
} else {
mContent->AsElement()->UnsetAttr(kNameSpaceID_None,
nsGkAtoms::aria_selected, true);
}
}
return;
}
if (aSelect) TakeFocus();
if (nsAccUtils::GetSelectableContainer(this, State()) && aSelect) {
TakeFocus();
}
}
@ -1819,27 +1805,7 @@ double LocalAccessible::CurValue() const {
return checkValue;
}
bool LocalAccessible::SetCurValue(double aValue) {
const nsRoleMapEntry* roleMapEntry = ARIARoleMap();
if (!roleMapEntry || roleMapEntry->valueRule == eNoValue) return false;
const uint32_t kValueCannotChange = states::READONLY | states::UNAVAILABLE;
if (State() & kValueCannotChange) return false;
double checkValue = MinValue();
if (!std::isnan(checkValue) && aValue < checkValue) return false;
checkValue = MaxValue();
if (!std::isnan(checkValue) && aValue > checkValue) return false;
nsAutoString strValue;
strValue.AppendFloat(aValue);
if (!mContent->IsElement()) return true;
return NS_SUCCEEDED(mContent->AsElement()->SetAttr(
kNameSpaceID_None, nsGkAtoms::aria_valuenow, strValue, true));
}
bool LocalAccessible::SetCurValue(double aValue) { return false; }
role LocalAccessible::FindNextValidARIARole(
std::initializer_list<nsStaticAtom*> aRolesToSkip) const {
@ -3069,15 +3035,7 @@ LocalAccessible* LocalAccessible::CurrentItem() const {
return nullptr;
}
void LocalAccessible::SetCurrentItem(const LocalAccessible* aItem) {
nsAtom* id = aItem->GetContent()->GetID();
if (id) {
nsAutoString idStr;
id->ToString(idStr);
mContent->AsElement()->SetAttr(
kNameSpaceID_None, nsGkAtoms::aria_activedescendant, idStr, true);
}
}
void LocalAccessible::SetCurrentItem(const LocalAccessible* aItem) {}
LocalAccessible* LocalAccessible::ContainerWidget() const {
if (HasARIARole() && mContent->HasID()) {

View File

@ -45,16 +45,6 @@ const valueTests = [
id: "slider",
expected: ["5", 5, 0, 7, 0],
},
{
desc: "Value should change when currentValue is called",
id: "slider",
async action(browser, acc) {
acc.QueryInterface(nsIAccessibleValue);
acc.currentValue = 4;
},
waitFor: EVENT_VALUE_CHANGE,
expected: ["4", 4, 0, 7, 0],
},
{
desc: "Value should change when @aria-valuenow is updated",
id: "slider",

View File

@ -48,7 +48,6 @@
gQueue.push(new takeFocusInvoker("aria-link"));
gQueue.push(new takeFocusInvoker("aria-link2"));
gQueue.push(new takeFocusInvoker("link"));
gQueue.push(new takeFocusInvoker("item2"));
gQueue.push(new takeFocusInvoker(document));
gQueue.push(new takeFocusInvoker("lb_item2"));
gQueue.push(new takeFocusInvoker(document));