/src/mozilla-central/accessible/base/Relation.h
Line | Count | Source (jump to first uncovered line) |
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 | | class Relation |
22 | | { |
23 | | public: |
24 | 0 | Relation() : mFirstIter(nullptr), mLastIter(nullptr) { } |
25 | | |
26 | | explicit Relation(AccIterable* aIter) : |
27 | 0 | mFirstIter(aIter), mLastIter(aIter) { } |
28 | | |
29 | | explicit Relation(Accessible* aAcc) : |
30 | | mFirstIter(nullptr), mLastIter(nullptr) |
31 | 0 | { AppendTarget(aAcc); } |
32 | | |
33 | | Relation(DocAccessible* aDocument, nsIContent* aContent) : |
34 | | mFirstIter(nullptr), mLastIter(nullptr) |
35 | 0 | { AppendTarget(aDocument, aContent); } |
36 | | |
37 | | Relation(Relation&& aOther) : |
38 | | mFirstIter(std::move(aOther.mFirstIter)), mLastIter(aOther.mLastIter) |
39 | 0 | { |
40 | 0 | aOther.mLastIter = nullptr; |
41 | 0 | } |
42 | | |
43 | | Relation& operator = (Relation&& aRH) |
44 | 0 | { |
45 | 0 | mFirstIter = std::move(aRH.mFirstIter); |
46 | 0 | mLastIter = aRH.mLastIter; |
47 | 0 | aRH.mLastIter = nullptr; |
48 | 0 | return *this; |
49 | 0 | } |
50 | | |
51 | | inline void AppendIter(AccIterable* aIter) |
52 | 0 | { |
53 | 0 | if (mLastIter) |
54 | 0 | mLastIter->mNextIter.reset(aIter); |
55 | 0 | else |
56 | 0 | mFirstIter.reset(aIter); |
57 | 0 |
|
58 | 0 | mLastIter = aIter; |
59 | 0 | } |
60 | | |
61 | | /** |
62 | | * Append the given accessible to the set of related accessibles. |
63 | | */ |
64 | | inline void AppendTarget(Accessible* aAcc) |
65 | 0 | { |
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 | | void AppendTarget(DocAccessible* aDocument, nsIContent* aContent) |
75 | 0 | { |
76 | 0 | if (aContent) |
77 | 0 | AppendTarget(aDocument->GetAccessible(aContent)); |
78 | 0 | } |
79 | | |
80 | | /** |
81 | | * compute and return the next related accessible. |
82 | | */ |
83 | | inline Accessible* Next() |
84 | 0 | { |
85 | 0 | Accessible* target = nullptr; |
86 | 0 |
|
87 | 0 | while (mFirstIter && !(target = mFirstIter->Next())) |
88 | 0 | mFirstIter = std::move(mFirstIter->mNextIter); |
89 | 0 |
|
90 | 0 | if (!mFirstIter) |
91 | 0 | mLastIter = nullptr; |
92 | 0 |
|
93 | 0 | return target; |
94 | 0 | } |
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 | | |