Bug 1839425: Use AVSampleBufferDisplayLayer for windowed video. r=mstange
[gecko.git] / accessible / base / Relation.h
blob24fceeab028f0bbe086b98096bae35d9489c4a82
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_a11y_relation_h_
8 #define mozilla_a11y_relation_h_
10 #include "AccIterator.h"
12 #include <memory>
14 namespace mozilla {
15 namespace a11y {
17 /**
18 * A collection of relation targets of a certain type. Targets are computed
19 * lazily while enumerating.
21 class Relation {
22 public:
23 Relation() : mFirstIter(nullptr), mLastIter(nullptr) {}
25 explicit Relation(AccIterable* aIter) : mFirstIter(aIter), mLastIter(aIter) {}
27 explicit Relation(Accessible* aAcc)
28 : mFirstIter(nullptr), mLastIter(nullptr) {
29 AppendTarget(aAcc);
32 Relation(DocAccessible* aDocument, nsIContent* aContent)
33 : mFirstIter(nullptr), mLastIter(nullptr) {
34 AppendTarget(aDocument, aContent);
37 Relation(Relation&& aOther)
38 : mFirstIter(std::move(aOther.mFirstIter)), mLastIter(aOther.mLastIter) {
39 aOther.mLastIter = nullptr;
42 Relation& operator=(Relation&& aRH) {
43 mFirstIter = std::move(aRH.mFirstIter);
44 mLastIter = aRH.mLastIter;
45 aRH.mLastIter = nullptr;
46 return *this;
49 inline void AppendIter(AccIterable* aIter) {
50 if (mLastIter) {
51 mLastIter->mNextIter.reset(aIter);
52 } else {
53 mFirstIter.reset(aIter);
56 mLastIter = aIter;
59 /**
60 * Append the given accessible to the set of related accessibles.
62 inline void AppendTarget(Accessible* aAcc) {
63 if (aAcc) AppendIter(new SingleAccIterator(aAcc));
66 /**
67 * Append the one accessible for this content node to the set of related
68 * accessibles.
70 void AppendTarget(DocAccessible* aDocument, nsIContent* aContent) {
71 if (aContent) AppendTarget(aDocument->GetAccessible(aContent));
74 /**
75 * compute and return the next related accessible.
77 inline Accessible* Next() {
78 Accessible* target = nullptr;
80 while (mFirstIter && !(target = mFirstIter->Next())) {
81 mFirstIter = std::move(mFirstIter->mNextIter);
84 if (!mFirstIter) mLastIter = nullptr;
86 return target;
89 inline LocalAccessible* LocalNext() {
90 Accessible* next = Next();
91 return next ? next->AsLocal() : nullptr;
94 private:
95 Relation& operator=(const Relation&) = delete;
96 Relation(const Relation&) = delete;
98 std::unique_ptr<AccIterable> mFirstIter;
99 AccIterable* mLastIter;
102 } // namespace a11y
103 } // namespace mozilla
105 #endif