summaryrefslogtreecommitdiffstats
path: root/accessible/base/Relation.h
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /accessible/base/Relation.h
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'accessible/base/Relation.h')
-rw-r--r--accessible/base/Relation.h108
1 files changed, 108 insertions, 0 deletions
diff --git a/accessible/base/Relation.h b/accessible/base/Relation.h
new file mode 100644
index 000000000..49a2c692e
--- /dev/null
+++ b/accessible/base/Relation.h
@@ -0,0 +1,108 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef mozilla_a11y_relation_h_
+#define mozilla_a11y_relation_h_
+
+#include "AccIterator.h"
+
+#include <memory>
+
+namespace mozilla {
+namespace a11y {
+
+/**
+ * A collection of relation targets of a certain type. Targets are computed
+ * lazily while enumerating.
+ */
+class Relation
+{
+public:
+ Relation() : mFirstIter(nullptr), mLastIter(nullptr) { }
+
+ explicit Relation(AccIterable* aIter) :
+ mFirstIter(aIter), mLastIter(aIter) { }
+
+ explicit Relation(Accessible* aAcc) :
+ mFirstIter(nullptr), mLastIter(nullptr)
+ { AppendTarget(aAcc); }
+
+ Relation(DocAccessible* aDocument, nsIContent* aContent) :
+ mFirstIter(nullptr), mLastIter(nullptr)
+ { AppendTarget(aDocument, aContent); }
+
+ Relation(Relation&& aOther) :
+ mFirstIter(Move(aOther.mFirstIter)), mLastIter(aOther.mLastIter)
+ {
+ aOther.mLastIter = nullptr;
+ }
+
+ Relation& operator = (Relation&& aRH)
+ {
+ mFirstIter = Move(aRH.mFirstIter);
+ mLastIter = aRH.mLastIter;
+ aRH.mLastIter = nullptr;
+ return *this;
+ }
+
+ inline void AppendIter(AccIterable* aIter)
+ {
+ if (mLastIter)
+ mLastIter->mNextIter.reset(aIter);
+ else
+ mFirstIter.reset(aIter);
+
+ mLastIter = aIter;
+ }
+
+ /**
+ * Append the given accessible to the set of related accessibles.
+ */
+ inline void AppendTarget(Accessible* aAcc)
+ {
+ if (aAcc)
+ AppendIter(new SingleAccIterator(aAcc));
+ }
+
+ /**
+ * Append the one accessible for this content node to the set of related
+ * accessibles.
+ */
+ void AppendTarget(DocAccessible* aDocument, nsIContent* aContent)
+ {
+ if (aContent)
+ AppendTarget(aDocument->GetAccessible(aContent));
+ }
+
+ /**
+ * compute and return the next related accessible.
+ */
+ inline Accessible* Next()
+ {
+ Accessible* target = nullptr;
+
+ while (mFirstIter && !(target = mFirstIter->Next()))
+ mFirstIter = std::move(mFirstIter->mNextIter);
+
+ if (!mFirstIter)
+ mLastIter = nullptr;
+
+ return target;
+ }
+
+private:
+ Relation& operator = (const Relation&) = delete;
+ Relation(const Relation&) = delete;
+
+ std::unique_ptr<AccIterable> mFirstIter;
+ AccIterable* mLastIter;
+};
+
+} // namespace a11y
+} // namespace mozilla
+
+#endif
+