commit 5d3dbed3906de44ebbdfb3a9754730f99b965914
parent 68053ff36fe3bdc18525f8b70815fd1b455c080f
Author: Eitan Isaacson <eitan@monotonous.org>
Date: Thu, 20 Nov 2025 03:53:15 +0000
Bug 1998255 - P1: Intro and use ArrayAccIterator. r=morgan
This cleans things up a bit and allows us to use the iterator after ID
lookup.
Depends on D271313
Differential Revision: https://phabricator.services.mozilla.com/D272725
Diffstat:
4 files changed, 33 insertions(+), 7 deletions(-)
diff --git a/accessible/base/AccIterator.cpp b/accessible/base/AccIterator.cpp
@@ -411,3 +411,14 @@ Accessible* RemoteAccIterator::Next() {
}
return nullptr;
}
+
+////////////////////////////////////////////////////////////////////////////////
+// ArrayAccIterator
+////////////////////////////////////////////////////////////////////////////////
+
+Accessible* ArrayAccIterator::Next() {
+ if (mIndex < mAccs.Length()) {
+ return mAccs[mIndex++];
+ }
+ return nullptr;
+}
diff --git a/accessible/base/AccIterator.h b/accessible/base/AccIterator.h
@@ -333,6 +333,23 @@ class RemoteAccIterator : public AccIterable {
uint32_t mIndex;
};
+/**
+ * Used to iterate through an array of accessibles
+ */
+class ArrayAccIterator : public AccIterable {
+ public:
+ explicit ArrayAccIterator(nsTArray<Accessible*>&& aAccs)
+ : mAccs(std::move(aAccs)), mIndex(0) {}
+
+ virtual ~ArrayAccIterator() = default;
+
+ virtual Accessible* Next() override;
+
+ private:
+ nsTArray<Accessible*> mAccs;
+ uint32_t mIndex;
+};
+
} // namespace a11y
} // namespace mozilla
diff --git a/accessible/ipc/RemoteAccessible.cpp b/accessible/ipc/RemoteAccessible.cpp
@@ -1297,9 +1297,7 @@ Relation RemoteAccessible::RelationByType(RelationType aType) const {
// both aria-labelledby and a <figcaption> must return two LABELLED_BY
// targets: the aria-labelledby and then the <figcaption>.
if (aType == RelationType::LABELLED_BY) {
- for (RemoteAccessible* label : LegendsOrCaptions()) {
- rel.AppendTarget(label);
- }
+ rel.AppendIter(new ArrayAccIterator(LegendsOrCaptions()));
} else if (aType == RelationType::LABEL_FOR) {
if (RemoteAccessible* labelTarget = LegendOrCaptionFor()) {
rel.AppendTarget(labelTarget);
@@ -1309,12 +1307,12 @@ Relation RemoteAccessible::RelationByType(RelationType aType) const {
return rel;
}
-nsTArray<RemoteAccessible*> RemoteAccessible::LegendsOrCaptions() const {
- nsTArray<RemoteAccessible*> children;
+nsTArray<Accessible*> RemoteAccessible::LegendsOrCaptions() const {
+ nsTArray<Accessible*> children;
auto AddChildWithTag = [this, &children](nsAtom* aTarget) {
uint32_t count = ChildCount();
for (uint32_t c = 0; c < count; ++c) {
- RemoteAccessible* child = RemoteChildAt(c);
+ Accessible* child = ChildAt(c);
MOZ_ASSERT(child);
if (child->TagName() == aTarget) {
children.AppendElement(child);
diff --git a/accessible/ipc/RemoteAccessible.h b/accessible/ipc/RemoteAccessible.h
@@ -500,7 +500,7 @@ class RemoteAccessible : public Accessible, public HyperTextAccessibleBase {
virtual nsTArray<int32_t>& GetCachedHyperTextOffsets() override;
- nsTArray<RemoteAccessible*> LegendsOrCaptions() const;
+ nsTArray<Accessible*> LegendsOrCaptions() const;
RemoteAccessible* LegendOrCaptionFor() const;