2011-08-10 01:44:00 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=2 et sw=2 tw=80: */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* 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/. */
|
2011-08-10 01:44:00 +00:00
|
|
|
|
2013-10-19 18:19:50 +00:00
|
|
|
#ifndef mozilla_a11y_relation_h_
|
|
|
|
#define mozilla_a11y_relation_h_
|
2011-08-10 01:44:00 +00:00
|
|
|
|
|
|
|
#include "AccIterator.h"
|
|
|
|
|
2016-06-06 22:02:38 +00:00
|
|
|
#include <memory>
|
2014-02-27 22:24:31 +00:00
|
|
|
|
2012-06-10 22:18:31 +00:00
|
|
|
namespace mozilla {
|
|
|
|
namespace a11y {
|
|
|
|
|
2011-08-10 01:44:00 +00:00
|
|
|
/**
|
|
|
|
* A collection of relation targets of a certain type. Targets are computed
|
|
|
|
* lazily while enumerating.
|
|
|
|
*/
|
|
|
|
class Relation
|
|
|
|
{
|
|
|
|
public:
|
2012-07-30 14:20:58 +00:00
|
|
|
Relation() : mFirstIter(nullptr), mLastIter(nullptr) { }
|
2011-08-10 01:44:00 +00:00
|
|
|
|
2014-09-02 16:19:58 +00:00
|
|
|
explicit Relation(AccIterable* aIter) :
|
2012-08-28 13:13:59 +00:00
|
|
|
mFirstIter(aIter), mLastIter(aIter) { }
|
2011-08-10 01:44:00 +00:00
|
|
|
|
2014-09-02 16:19:58 +00:00
|
|
|
explicit Relation(Accessible* aAcc) :
|
2012-07-30 14:20:58 +00:00
|
|
|
mFirstIter(nullptr), mLastIter(nullptr)
|
2011-08-10 01:44:00 +00:00
|
|
|
{ AppendTarget(aAcc); }
|
|
|
|
|
2012-05-27 09:01:40 +00:00
|
|
|
Relation(DocAccessible* aDocument, nsIContent* aContent) :
|
2012-07-30 14:20:58 +00:00
|
|
|
mFirstIter(nullptr), mLastIter(nullptr)
|
2012-05-08 00:00:29 +00:00
|
|
|
{ AppendTarget(aDocument, aContent); }
|
2011-08-10 01:44:00 +00:00
|
|
|
|
2014-02-27 22:24:31 +00:00
|
|
|
Relation(Relation&& aOther) :
|
|
|
|
mFirstIter(Move(aOther.mFirstIter)), mLastIter(aOther.mLastIter)
|
2011-08-10 01:44:00 +00:00
|
|
|
{
|
2014-02-27 22:24:31 +00:00
|
|
|
aOther.mLastIter = nullptr;
|
2011-08-10 01:44:00 +00:00
|
|
|
}
|
|
|
|
|
2014-02-27 22:24:31 +00:00
|
|
|
Relation& operator = (Relation&& aRH)
|
2011-08-10 01:44:00 +00:00
|
|
|
{
|
2014-02-27 22:24:31 +00:00
|
|
|
mFirstIter = Move(aRH.mFirstIter);
|
|
|
|
mLastIter = aRH.mLastIter;
|
|
|
|
aRH.mLastIter = nullptr;
|
|
|
|
return *this;
|
2011-08-10 01:44:00 +00:00
|
|
|
}
|
|
|
|
|
2013-02-26 07:17:10 +00:00
|
|
|
inline void AppendIter(AccIterable* aIter)
|
2011-08-10 01:44:00 +00:00
|
|
|
{
|
|
|
|
if (mLastIter)
|
2016-06-06 22:02:38 +00:00
|
|
|
mLastIter->mNextIter.reset(aIter);
|
2011-08-10 01:44:00 +00:00
|
|
|
else
|
2016-06-06 22:02:38 +00:00
|
|
|
mFirstIter.reset(aIter);
|
2011-08-10 01:44:00 +00:00
|
|
|
|
|
|
|
mLastIter = aIter;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Append the given accessible to the set of related accessibles.
|
|
|
|
*/
|
2012-05-29 01:18:45 +00:00
|
|
|
inline void AppendTarget(Accessible* aAcc)
|
2011-08-10 01:44:00 +00:00
|
|
|
{
|
|
|
|
if (aAcc)
|
2013-02-26 07:17:10 +00:00
|
|
|
AppendIter(new SingleAccIterator(aAcc));
|
2011-08-10 01:44:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Append the one accessible for this content node to the set of related
|
|
|
|
* accessibles.
|
|
|
|
*/
|
2012-05-27 09:01:40 +00:00
|
|
|
void AppendTarget(DocAccessible* aDocument, nsIContent* aContent)
|
2011-08-10 01:44:00 +00:00
|
|
|
{
|
|
|
|
if (aContent)
|
2012-05-08 00:00:29 +00:00
|
|
|
AppendTarget(aDocument->GetAccessible(aContent));
|
2011-08-10 01:44:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* compute and return the next related accessible.
|
|
|
|
*/
|
2012-05-29 01:18:45 +00:00
|
|
|
inline Accessible* Next()
|
2011-08-10 01:44:00 +00:00
|
|
|
{
|
2012-07-30 14:20:58 +00:00
|
|
|
Accessible* target = nullptr;
|
2011-08-10 01:44:00 +00:00
|
|
|
|
|
|
|
while (mFirstIter && !(target = mFirstIter->Next()))
|
2016-06-06 22:02:38 +00:00
|
|
|
mFirstIter = std::move(mFirstIter->mNextIter);
|
2011-08-10 01:44:00 +00:00
|
|
|
|
|
|
|
if (!mFirstIter)
|
2012-07-30 14:20:58 +00:00
|
|
|
mLastIter = nullptr;
|
2011-08-10 01:44:00 +00:00
|
|
|
|
|
|
|
return target;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2015-01-06 23:35:02 +00:00
|
|
|
Relation& operator = (const Relation&) = delete;
|
|
|
|
Relation(const Relation&) = delete;
|
2011-08-10 01:44:00 +00:00
|
|
|
|
2016-06-06 22:02:38 +00:00
|
|
|
std::unique_ptr<AccIterable> mFirstIter;
|
2013-02-26 07:17:10 +00:00
|
|
|
AccIterable* mLastIter;
|
2011-08-10 01:44:00 +00:00
|
|
|
};
|
|
|
|
|
2012-06-10 22:18:31 +00:00
|
|
|
} // namespace a11y
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2011-08-10 01:44:00 +00:00
|
|
|
#endif
|
|
|
|
|