Bug 1837105: Add methods for determining generic Accessibles and getting the nearest non-generic ancestor. r=nlapre

Differential Revision: https://phabricator.services.mozilla.com/D179800
This commit is contained in:
James Teh 2023-06-07 22:34:49 +00:00
parent 783d448fa2
commit a89668b961
2 changed files with 26 additions and 23 deletions

View File

@ -14,8 +14,6 @@
using namespace mozilla::a11y;
static bool IsGenericContainer(role aRole);
static Accessible* GetRelevantParent(const Accessible* aAcc);
static role BaseRole(role aRole);
// This rule finds candidate siblings for compound widget children.
@ -37,7 +35,7 @@ class CompoundWidgetSiblingRule : public PivotRule {
// Ignore generic accessibles, but keep searching through the subtree for
// siblings.
if (IsGenericContainer(accRole)) {
if (aAcc->IsGeneric()) {
return nsIAccessibleTraversalRule::FILTER_IGNORE;
}
@ -57,7 +55,7 @@ AccGroupInfo::AccGroupInfo(const Accessible* aItem, role aRole)
void AccGroupInfo::Update() {
mParent = nullptr;
Accessible* parent = GetRelevantParent(mItem);
Accessible* parent = mItem->GetNonGenericParent();
if (!parent) {
return;
}
@ -173,7 +171,7 @@ void AccGroupInfo::Update() {
if (mRole == roles::OUTLINEITEM) {
// Find the relevant grandparent of the item. Use that parent as the root
// and find the previous outline item sibling within that root.
Accessible* grandParent = GetRelevantParent(parent);
Accessible* grandParent = parent->GetNonGenericParent();
MOZ_ASSERT(grandParent);
Pivot pivot{grandParent};
CompoundWidgetSiblingRule parentSiblingRule{mRole};
@ -188,7 +186,7 @@ void AccGroupInfo::Update() {
// the parent of the item will be a group and containing item of the group is
// a conceptual parent of the item.
if (mRole == roles::LISTITEM || mRole == roles::OUTLINEITEM) {
Accessible* grandParent = GetRelevantParent(parent);
Accessible* grandParent = parent->GetNonGenericParent();
if (grandParent && grandParent->Role() == mRole) {
mParent = grandParent;
}
@ -373,23 +371,6 @@ int32_t AccGroupInfo::GetARIAOrDefaultLevel(const Accessible* aAccessible) {
return aAccessible->GetLevel(true);
}
static bool IsGenericContainer(role aRole) {
return aRole == roles::TEXT || aRole == roles::TEXT_CONTAINER ||
aRole == roles::SECTION;
}
static Accessible* GetRelevantParent(const Accessible* aAcc) {
MOZ_ASSERT(aAcc);
// Search through ancestors until we find a relevant parent, skipping generic
// accessibles.
Accessible* parent = aAcc->Parent();
while (parent && IsGenericContainer(parent->Role())) {
parent = parent->Parent();
}
return parent;
}
static role BaseRole(role aRole) {
if (aRole == roles::CHECK_MENU_ITEM || aRole == roles::PARENT_MENUITEM ||
aRole == roles::RADIO_MENU_ITEM) {

View File

@ -578,6 +578,28 @@ class Accessible {
virtual bool HasNumericValue() const = 0;
/**
* Returns true if this is a generic container element that has no meaning on
* its own.
*/
bool IsGeneric() const {
role accRole = Role();
return accRole == roles::TEXT || accRole == roles::TEXT_CONTAINER ||
accRole == roles::SECTION;
}
/**
* Returns the nearest ancestor which is not a generic element.
*/
Accessible* GetNonGenericParent() const {
for (Accessible* parent = Parent(); parent; parent = parent->Parent()) {
if (!parent->IsGeneric()) {
return parent;
}
}
return nullptr;
}
/**
* Return true if the link is valid (e. g. points to a valid URL).
*/