commit c3b7d1644108660a1186b89fb7c4b60d30088854
parent 3896f0220683b4242980fad903eeee35f2b963f5
Author: Eitan Isaacson <eitan@monotonous.org>
Date: Fri, 3 Oct 2025 14:55:34 +0000
Bug 1990631 - P3: Introduce ARIA attr is and has checkers. r=morgan
This also puts the aria role as an "aria" attribute in the remote
accessible.
Differential Revision: https://phabricator.services.mozilla.com/D266499
Diffstat:
5 files changed, 92 insertions(+), 0 deletions(-)
diff --git a/accessible/basetypes/Accessible.h b/accessible/basetypes/Accessible.h
@@ -435,6 +435,10 @@ class Accessible {
virtual bool GetStringARIAAttr(nsAtom* aAttrName,
nsAString& aAttrValue) const = 0;
+ virtual bool ARIAAttrValueIs(nsAtom* aAttrName, nsAtom* aAttrValue) const = 0;
+
+ virtual bool HasARIAAttr(nsAtom* aAttrName) const = 0;
+
/**
* Get the relation of the given type.
*/
diff --git a/accessible/generic/LocalAccessible.cpp b/accessible/generic/LocalAccessible.cpp
@@ -4655,3 +4655,17 @@ bool LocalAccessible::GetStringARIAAttr(nsAtom* aAttrName,
}
return false;
}
+
+bool LocalAccessible::ARIAAttrValueIs(nsAtom* aAttrName,
+ nsAtom* aAttrValue) const {
+ if (dom::Element* elm = Elm()) {
+ return nsAccUtils::ARIAAttrValueIs(elm, aAttrName, aAttrValue,
+ eCaseMatters);
+ }
+ return false;
+}
+
+bool LocalAccessible::HasARIAAttr(nsAtom* aAttrName) const {
+ return mContent ? nsAccUtils::HasDefinedARIAToken(mContent, aAttrName)
+ : false;
+}
diff --git a/accessible/generic/LocalAccessible.h b/accessible/generic/LocalAccessible.h
@@ -445,6 +445,11 @@ class LocalAccessible : public nsISupports, public Accessible {
virtual bool GetStringARIAAttr(nsAtom* aAttrName,
nsAString& aAttrValue) const override;
+ virtual bool ARIAAttrValueIs(nsAtom* aAttrName,
+ nsAtom* aAttrValue) const override;
+
+ virtual bool HasARIAAttr(nsAtom* aAttrName) const override;
+
//////////////////////////////////////////////////////////////////////////////
// Downcasting and types
diff --git a/accessible/ipc/RemoteAccessible.cpp b/accessible/ipc/RemoteAccessible.cpp
@@ -2431,6 +2431,22 @@ bool RemoteAccessible::GetStringARIAAttr(nsAtom* aAttrName,
if (RequestDomainsIfInactive(CacheDomain::ARIA)) {
return false;
}
+
+ if (aAttrName == nsGkAtoms::role) {
+ if (mCachedFields->GetAttribute(CacheKey::ARIARole, aAttrValue)) {
+ // Unknown, or multiple roles.
+ return true;
+ }
+
+ if (const nsRoleMapEntry* roleMap = ARIARoleMap()) {
+ if (roleMap->roleAtom != nsGkAtoms::_empty) {
+ // Non-empty rolemap, stringify it and return true.
+ roleMap->roleAtom->ToString(aAttrValue);
+ return true;
+ }
+ }
+ }
+
if (auto attrs = GetCachedARIAAttributes()) {
return attrs->GetAttribute(aAttrName, aAttrValue);
}
@@ -2438,6 +2454,54 @@ bool RemoteAccessible::GetStringARIAAttr(nsAtom* aAttrName,
return false;
}
+bool RemoteAccessible::ARIAAttrValueIs(nsAtom* aAttrName,
+ nsAtom* aAttrValue) const {
+ if (RequestDomainsIfInactive(CacheDomain::ARIA)) {
+ return false;
+ }
+
+ if (aAttrName == nsGkAtoms::role) {
+ nsAutoString roleStr;
+ if (mCachedFields->GetAttribute(CacheKey::ARIARole, roleStr)) {
+ return aAttrValue->Equals(roleStr);
+ }
+
+ if (const nsRoleMapEntry* roleMap = ARIARoleMap()) {
+ return roleMap->roleAtom == aAttrValue;
+ }
+ }
+
+ if (auto attrs = GetCachedARIAAttributes()) {
+ if (auto val = attrs->GetAttribute<RefPtr<nsAtom>>(aAttrName)) {
+ return *val == aAttrValue;
+ }
+ }
+
+ return false;
+}
+
+bool RemoteAccessible::HasARIAAttr(nsAtom* aAttrName) const {
+ if (RequestDomainsIfInactive(CacheDomain::ARIA)) {
+ return false;
+ }
+
+ if (aAttrName == nsGkAtoms::role) {
+ if (const nsRoleMapEntry* roleMap = ARIARoleMap()) {
+ if (roleMap->roleAtom != nsGkAtoms::_empty) {
+ return true;
+ }
+ }
+
+ return mCachedFields->HasAttribute(CacheKey::ARIARole);
+ }
+
+ if (auto attrs = GetCachedARIAAttributes()) {
+ return attrs->HasAttribute(aAttrName);
+ }
+
+ return false;
+}
+
void RemoteAccessible::Language(nsAString& aLocale) {
if (RequestDomainsIfInactive(CacheDomain::Text)) {
return;
diff --git a/accessible/ipc/RemoteAccessible.h b/accessible/ipc/RemoteAccessible.h
@@ -236,6 +236,11 @@ class RemoteAccessible : public Accessible, public HyperTextAccessibleBase {
virtual bool GetStringARIAAttr(nsAtom* aAttrName,
nsAString& aAttrValue) const override;
+ virtual bool ARIAAttrValueIs(nsAtom* aAttrName,
+ nsAtom* aAttrValue) const override;
+
+ virtual bool HasARIAAttr(nsAtom* aAttrName) const override;
+
virtual void Language(nsAString& aLocale) override;
//////////////////////////////////////////////////////////////////////////////