Line data Source code
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/. */
6 :
7 : #ifndef mozilla_a11y_relation_h_
8 : #define mozilla_a11y_relation_h_
9 :
10 : #include "AccIterator.h"
11 :
12 : #include <memory>
13 :
14 : namespace mozilla {
15 : namespace a11y {
16 :
17 : /**
18 : * A collection of relation targets of a certain type. Targets are computed
19 : * lazily while enumerating.
20 : */
21 0 : class Relation
22 : {
23 : public:
24 0 : Relation() : mFirstIter(nullptr), mLastIter(nullptr) { }
25 :
26 0 : explicit Relation(AccIterable* aIter) :
27 0 : mFirstIter(aIter), mLastIter(aIter) { }
28 :
29 0 : explicit Relation(Accessible* aAcc) :
30 0 : mFirstIter(nullptr), mLastIter(nullptr)
31 0 : { AppendTarget(aAcc); }
32 :
33 0 : Relation(DocAccessible* aDocument, nsIContent* aContent) :
34 0 : mFirstIter(nullptr), mLastIter(nullptr)
35 0 : { AppendTarget(aDocument, aContent); }
36 :
37 0 : Relation(Relation&& aOther) :
38 0 : mFirstIter(Move(aOther.mFirstIter)), mLastIter(aOther.mLastIter)
39 : {
40 0 : aOther.mLastIter = nullptr;
41 0 : }
42 :
43 : Relation& operator = (Relation&& aRH)
44 : {
45 : mFirstIter = Move(aRH.mFirstIter);
46 : mLastIter = aRH.mLastIter;
47 : aRH.mLastIter = nullptr;
48 : return *this;
49 : }
50 :
51 0 : inline void AppendIter(AccIterable* aIter)
52 : {
53 0 : if (mLastIter)
54 0 : mLastIter->mNextIter.reset(aIter);
55 : else
56 0 : mFirstIter.reset(aIter);
57 :
58 0 : mLastIter = aIter;
59 0 : }
60 :
61 : /**
62 : * Append the given accessible to the set of related accessibles.
63 : */
64 0 : inline void AppendTarget(Accessible* aAcc)
65 : {
66 0 : if (aAcc)
67 0 : AppendIter(new SingleAccIterator(aAcc));
68 0 : }
69 :
70 : /**
71 : * Append the one accessible for this content node to the set of related
72 : * accessibles.
73 : */
74 0 : void AppendTarget(DocAccessible* aDocument, nsIContent* aContent)
75 : {
76 0 : if (aContent)
77 0 : AppendTarget(aDocument->GetAccessible(aContent));
78 0 : }
79 :
80 : /**
81 : * compute and return the next related accessible.
82 : */
83 0 : inline Accessible* Next()
84 : {
85 0 : Accessible* target = nullptr;
86 :
87 0 : while (mFirstIter && !(target = mFirstIter->Next()))
88 0 : mFirstIter = std::move(mFirstIter->mNextIter);
89 :
90 0 : if (!mFirstIter)
91 0 : mLastIter = nullptr;
92 :
93 0 : return target;
94 : }
95 :
96 : private:
97 : Relation& operator = (const Relation&) = delete;
98 : Relation(const Relation&) = delete;
99 :
100 : std::unique_ptr<AccIterable> mFirstIter;
101 : AccIterable* mLastIter;
102 : };
103 :
104 : } // namespace a11y
105 : } // namespace mozilla
106 :
107 : #endif
108 :
|