tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 6448a82fffee3d405e33034eb99bc0d6766ebbd0
parent 47214fc350b0881fbecdae044f32f54072776be7
Author: Eitan Isaacson <eitan@monotonous.org>
Date:   Fri, 21 Nov 2025 18:48:41 +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:
Maccessible/base/AccIterator.cpp | 11+++++++++++
Maccessible/base/AccIterator.h | 17+++++++++++++++++
Maccessible/ipc/RemoteAccessible.cpp | 10++++------
Maccessible/ipc/RemoteAccessible.h | 2+-
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;