Bug 1520611 - Consolidate ProxyAccessible::MustPruneChildren into nsAccUtils. r=Jamie

Differential Revision: https://phabricator.services.mozilla.com/D16997

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Eitan Isaacson 2019-01-24 00:23:30 +00:00
Родитель e17294b6e9
Коммит e18c6010be
6 изменённых файлов: 36 добавлений и 41 удалений

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

@ -726,7 +726,7 @@ gint getChildCountCB(AtkObject* aAtkObj) {
}
ProxyAccessible* proxy = GetProxy(aAtkObj);
if (proxy && !proxy->MustPruneChildren()) {
if (proxy && !nsAccUtils::MustPrune(proxy)) {
return proxy->EmbeddedChildCount();
}
@ -757,7 +757,9 @@ AtkObject* refChildCB(AtkObject* aAtkObj, gint aChildIndex) {
}
}
} else if (ProxyAccessible* proxy = GetProxy(aAtkObj)) {
if (proxy->MustPruneChildren()) return nullptr;
if (nsAccUtils::MustPrune(proxy)) {
return nullptr;
}
ProxyAccessible* child = proxy->EmbeddedChildAt(aChildIndex);
if (child) childAtkObj = GetWrapperFor(child);

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

@ -389,23 +389,34 @@ uint32_t nsAccUtils::TextLength(Accessible* aAccessible) {
return text.Length();
}
bool nsAccUtils::MustPrune(Accessible* aAccessible) {
roles::Role role = aAccessible->Role();
bool nsAccUtils::MustPrune(AccessibleOrProxy aAccessible) {
MOZ_ASSERT(!aAccessible.IsNull());
roles::Role role = aAccessible.Role();
return
// Always prune the tree for sliders, as it doesn't make sense for a
// slider to have descendants and this confuses NVDA.
role == roles::SLIDER ||
// Don't prune the tree for certain roles if the tree is more complex than
// a single text leaf.
((role == roles::MENUITEM || role == roles::COMBOBOX_OPTION ||
role == roles::OPTION || role == roles::ENTRY ||
role == roles::FLAT_EQUATION || role == roles::PASSWORD_TEXT ||
role == roles::PUSHBUTTON || role == roles::TOGGLE_BUTTON ||
role == roles::GRAPHIC || role == roles::PROGRESSBAR ||
role == roles::SEPARATOR) &&
aAccessible->ContentChildCount() == 1 &&
aAccessible->ContentChildAt(0)->IsTextLeaf());
if (role == roles::SLIDER) {
// Always prune the tree for sliders, as it doesn't make sense for a
// slider to have descendants and this confuses NVDA.
return true;
}
if (role != roles::MENUITEM && role != roles::COMBOBOX_OPTION &&
role != roles::OPTION && role != roles::ENTRY &&
role != roles::FLAT_EQUATION && role != roles::PASSWORD_TEXT &&
role != roles::PUSHBUTTON && role != roles::TOGGLE_BUTTON &&
role != roles::GRAPHIC && role != roles::PROGRESSBAR &&
role != roles::SEPARATOR) {
// If it doesn't match any of these roles, don't prune its children.
return false;
}
if (aAccessible.ChildCount() != 1) {
// If the accessible has more than one child, don't prune it.
return false;
}
roles::Role childRole = aAccessible.FirstChild().Role();
// If the accessible's child is a text leaf, prune the accessible.
return childRole == roles::TEXT_LEAF || childRole == roles::STATICTEXT;
}
bool nsAccUtils::PersistentPropertiesToArray(nsIPersistentProperties* aProps,

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

@ -9,6 +9,7 @@
#include "mozilla/a11y/Accessible.h"
#include "mozilla/a11y/DocManager.h"
#include "AccessibleOrProxy.h"
#include "nsAccessibilityService.h"
#include "nsCoreUtils.h"
@ -251,7 +252,7 @@ class nsAccUtils {
* Return true if the given accessible can't have children. Used when exposing
* to platform accessibility APIs, should the children be pruned off?
*/
static bool MustPrune(Accessible* aAccessible);
static bool MustPrune(AccessibleOrProxy aAccessible);
static bool PersistentPropertiesToArray(nsIPersistentProperties* aProps,
nsTArray<Attribute>* aAttributes);

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

@ -67,24 +67,6 @@ void ProxyAccessibleBase<Derived>::ClearChildDoc(
mChildren.RemoveElement(aChildDoc);
}
template <class Derived>
bool ProxyAccessibleBase<Derived>::MustPruneChildren() const {
// this is the equivalent to nsAccUtils::MustPrune for proxies and should be
// kept in sync with that.
if (mRole != roles::MENUITEM && mRole != roles::COMBOBOX_OPTION &&
mRole != roles::OPTION && mRole != roles::ENTRY &&
mRole != roles::FLAT_EQUATION && mRole != roles::PASSWORD_TEXT &&
mRole != roles::PUSHBUTTON && mRole != roles::TOGGLE_BUTTON &&
mRole != roles::GRAPHIC && mRole != roles::SLIDER &&
mRole != roles::PROGRESSBAR && mRole != roles::SEPARATOR)
return false;
if (mChildren.Length() != 1) return false;
return mChildren[0]->Role() == roles::TEXT_LEAF ||
mChildren[0]->Role() == roles::STATICTEXT;
}
template <class Derived>
uint32_t ProxyAccessibleBase<Derived>::EmbeddedChildCount() const {
size_t count = 0, kids = mChildren.Length();

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

@ -71,7 +71,6 @@ class ProxyAccessibleBase {
uint32_t EmbeddedChildCount() const;
int32_t IndexOfEmbeddedChild(const Derived* aChild);
Derived* EmbeddedChildAt(size_t aChildIdx);
bool MustPruneChildren() const;
void Shutdown();

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

@ -903,7 +903,7 @@ AccessibleWrap::accNavigate(
switch (navDir) {
case NAVDIR_FIRSTCHILD:
if (IsProxy()) {
if (!Proxy()->MustPruneChildren()) {
if (!nsAccUtils::MustPrune(Proxy())) {
navAccessible = WrapperFor(Proxy()->FirstChild());
}
} else {
@ -912,7 +912,7 @@ AccessibleWrap::accNavigate(
break;
case NAVDIR_LASTCHILD:
if (IsProxy()) {
if (!Proxy()->MustPruneChildren()) {
if (!nsAccUtils::MustPrune(Proxy())) {
navAccessible = WrapperFor(Proxy()->LastChild());
}
} else {
@ -1387,7 +1387,7 @@ already_AddRefed<IAccessible> AccessibleWrap::GetIAccessibleFor(
}
if (varChild.ulVal != GetExistingID() &&
(IsProxy() ? Proxy()->MustPruneChildren()
(IsProxy() ? nsAccUtils::MustPrune(Proxy())
: nsAccUtils::MustPrune(this))) {
// This accessible should have no subtree in platform, return null for its
// children.