Bug 1774043: [Part 3] Make remote ::Relations and ::RelationByType functions to use cache r=Jamie

Differential Revision: https://phabricator.services.mozilla.com/D152102
This commit is contained in:
Morgan Rae Reschenberg 2022-08-03 05:09:54 +00:00
parent 2cd46a7d14
commit 8180b70ae7
6 changed files with 62 additions and 7 deletions

View File

@ -626,6 +626,50 @@ LayoutDeviceIntRect RemoteAccessibleBase<Derived>::Bounds() const {
return BoundsWithOffset(Nothing());
}
template <class Derived>
nsTArray<RemoteAccessible*> RemoteAccessibleBase<Derived>::RelationByType(
RelationType aType) const {
nsTArray<RemoteAccessible*> accs;
if (!mCachedFields) {
return accs;
}
for (auto data : kRelationTypeAtoms) {
if (data.mType != aType ||
(data.mValidTag && TagName() != data.mValidTag)) {
continue;
}
if (auto maybeIds =
mCachedFields->GetAttribute<nsTArray<uint64_t>>(data.mAtom)) {
for (uint64_t id : *maybeIds) {
if (RemoteAccessible* acc = mDoc->GetAccessible(id)) {
accs.AppendElement(acc);
}
}
}
// Each relation type has only one relevant cached attribute,
// so break after we've handled the attr for this type,
// even if we didn't find any targets.
break;
}
if (auto accRelMapEntry = mDoc->mReverseRelations.Lookup(ID())) {
if (auto reverseIdsEntry =
accRelMapEntry.Data().Lookup(static_cast<uint64_t>(aType))) {
nsTArray<uint64_t>& reverseIds = reverseIdsEntry.Data();
for (uint64_t id : reverseIds) {
if (RemoteAccessible* acc = mDoc->GetAccessible(id)) {
accs.AppendElement(acc);
}
}
}
}
return accs;
}
template <class Derived>
void RemoteAccessibleBase<Derived>::AppendTextTo(nsAString& aText,
uint32_t aStartOffset,

View File

@ -183,6 +183,8 @@ class RemoteAccessibleBase : public Accessible, public HyperTextAccessibleBase {
virtual nsRect BoundsInAppUnits() const override;
virtual nsTArray<RemoteAccessible*> RelationByType(RelationType aType) const;
virtual uint64_t State() override;
virtual already_AddRefed<AccAttributes> Attributes() override;

View File

@ -51,13 +51,8 @@ virtual already_AddRefed<AccAttributes> Attributes() override;
/**
* Return set of targets of given relation type.
*/
nsTArray<RemoteAccessible*> RelationByType(RelationType aType) const;
/**
* Get all relations for this accessible.
*/
void Relations(nsTArray<RelationType>* aTypes,
nsTArray<nsTArray<RemoteAccessible*>>* aTargetSets) const;
virtual nsTArray<RemoteAccessible*> RelationByType(
RelationType aType) const override;
bool IsSearchbox() const;

View File

@ -78,6 +78,10 @@ already_AddRefed<AccAttributes> RemoteAccessible::Attributes() {
nsTArray<RemoteAccessible*> RemoteAccessible::RelationByType(
RelationType aType) const {
if (StaticPrefs::accessibility_cache_enabled_AtStartup()) {
return RemoteAccessibleBase<RemoteAccessible>::RelationByType(aType);
}
nsTArray<uint64_t> targetIDs;
Unused << mDoc->SendRelationByType(mID, static_cast<uint32_t>(aType),
&targetIDs);

View File

@ -77,6 +77,12 @@ class RemoteAccessible : public RemoteAccessibleBase<RemoteAccessible> {
virtual bool TableIsProbablyForLayout() override;
/**
* Get all relations for this accessible.
*/
void Relations(nsTArray<RelationType>* aTypes,
nsTArray<nsTArray<RemoteAccessible*>>* aTargetSets) const;
protected:
explicit RemoteAccessible(DocAccessibleParent* aThisAsDoc)
: RemoteAccessibleBase(aThisAsDoc) {

View File

@ -392,6 +392,10 @@ already_AddRefed<AccAttributes> RemoteAccessible::Attributes() {
nsTArray<RemoteAccessible*> RemoteAccessible::RelationByType(
RelationType aType) const {
if (StaticPrefs::accessibility_cache_enabled_AtStartup()) {
return RemoteAccessibleBase<RemoteAccessible>::RelationByType(aType);
}
RefPtr<IAccessible2_2> acc = QueryInterface<IAccessible2_2>(this);
if (!acc) {
return nsTArray<RemoteAccessible*>();