commit 3896f0220683b4242980fad903eeee35f2b963f5
parent 03d86a6181793bd3f7c9fb3147fab41086224619
Author: Eitan Isaacson <eitan@monotonous.org>
Date: Fri, 3 Oct 2025 14:55:34 +0000
Bug 1990631 - P2: Introduce Accessible::IsPopover and move GetMinimumRole. r=morgan
Putting GetMinimumRole in Accessible will allow us to do more role
calculations remotely.
For this to work we need a standard way to determine if an accessible is
a popover. IsPopover does that.
Differential Revision: https://phabricator.services.mozilla.com/D266496
Diffstat:
6 files changed, 34 insertions(+), 19 deletions(-)
diff --git a/accessible/basetypes/Accessible.cpp b/accessible/basetypes/Accessible.cpp
@@ -139,6 +139,19 @@ bool Accessible::HasStrongARIARole() const {
return roleMapEntry && roleMapEntry->roleRule == kUseMapRole;
}
+role Accessible::GetMinimumRole(role aRole) const {
+ if (aRole != roles::TEXT && aRole != roles::TEXT_CONTAINER &&
+ aRole != roles::SECTION) {
+ // This isn't a generic role, so aRole is specific enough.
+ return aRole;
+ }
+
+ if (IsPopover()) {
+ return roles::GROUPING;
+ }
+ return aRole;
+}
+
bool Accessible::HasGenericType(AccGenericType aType) const {
const nsRoleMapEntry* roleMapEntry = ARIARoleMap();
return (mGenericTypes & aType) ||
diff --git a/accessible/basetypes/Accessible.h b/accessible/basetypes/Accessible.h
@@ -651,6 +651,8 @@ class Accessible {
bool IsProgress() const { return mType == eProgressType; }
+ virtual bool IsPopover() const = 0;
+
bool IsRoot() const { return mType == eRootType; }
bool IsPassword() const { return mType == eHTMLTextPasswordFieldType; }
@@ -817,6 +819,12 @@ class Accessible {
*/
void ApplyImplicitState(uint64_t& aState) const;
+ /**
+ * Return the minimum role that should be used as a last resort if the element
+ * does not have a more specific role.
+ */
+ mozilla::a11y::role GetMinimumRole(mozilla::a11y::role aRole) const;
+
private:
static const uint8_t kTypeBits = 6;
static const uint8_t kGenericTypesBits = 18;
diff --git a/accessible/generic/LocalAccessible.cpp b/accessible/generic/LocalAccessible.cpp
@@ -2030,19 +2030,6 @@ role LocalAccessible::ARIATransformRole(role aRole) const {
return aRole;
}
-role LocalAccessible::GetMinimumRole(role aRole) const {
- if (aRole != roles::TEXT && aRole != roles::TEXT_CONTAINER &&
- aRole != roles::SECTION) {
- // This isn't a generic role, so aRole is specific enough.
- return aRole;
- }
- dom::Element* el = Elm();
- if (el && el->IsHTMLElement() && el->HasAttr(nsGkAtoms::popover)) {
- return roles::GROUPING;
- }
- return aRole;
-}
-
role LocalAccessible::NativeRole() const { return roles::NOTHING; }
uint8_t LocalAccessible::ActionCount() const {
@@ -2727,6 +2714,11 @@ bool LocalAccessible::IsScrollable() const {
return scrollRange.width > 0 || scrollRange.height > 0;
}
+bool LocalAccessible::IsPopover() const {
+ dom::Element* el = Elm();
+ return el && el->IsHTMLElement() && el->HasAttr(nsGkAtoms::popover);
+}
+
void LocalAccessible::AppendTextTo(nsAString& aText, uint32_t aStartOffset,
uint32_t aLength) {
// Return text representation of non-text accessible within hypertext
diff --git a/accessible/generic/LocalAccessible.h b/accessible/generic/LocalAccessible.h
@@ -432,6 +432,8 @@ class LocalAccessible : public nsISupports, public Accessible {
virtual bool IsScrollable() const override;
+ virtual bool IsPopover() const override;
+
/**
* Get a pointer to accessibility interface for this node, which is specific
* to the OS/accessibility toolkit we're running on.
@@ -865,12 +867,6 @@ class LocalAccessible : public nsISupports, public Accessible {
*/
mozilla::a11y::role ARIATransformRole(mozilla::a11y::role aRole) const;
- /**
- * Return the minimum role that should be used as a last resort if the element
- * does not have a more specific role.
- */
- mozilla::a11y::role GetMinimumRole(mozilla::a11y::role aRole) const;
-
//////////////////////////////////////////////////////////////////////////////
// Name helpers
diff --git a/accessible/ipc/RemoteAccessible.cpp b/accessible/ipc/RemoteAccessible.cpp
@@ -1557,6 +1557,10 @@ bool RemoteAccessible::IsScrollable() const {
return mCachedFields && mCachedFields->HasAttribute(CacheKey::ScrollPosition);
}
+bool RemoteAccessible::IsPopover() const {
+ return mCachedFields && mCachedFields->HasAttribute(CacheKey::PopupType);
+}
+
#if !defined(XP_WIN)
void RemoteAccessible::Announce(const nsString& aAnnouncement,
uint16_t aPriority) {
diff --git a/accessible/ipc/RemoteAccessible.h b/accessible/ipc/RemoteAccessible.h
@@ -381,6 +381,8 @@ class RemoteAccessible : public Accessible, public HyperTextAccessibleBase {
virtual bool IsScrollable() const override;
+ virtual bool IsPopover() const override;
+
#if !defined(XP_WIN)
void Announce(const nsString& aAnnouncement, uint16_t aPriority);
#endif // !defined(XP_WIN)