2011-08-10 05:44:00 +04: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 15:12:37 +04: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 05:44:00 +04:00
|
|
|
|
2013-10-19 22:19:50 +04:00
|
|
|
#ifndef mozilla_a11y_relation_h_
|
|
|
|
#define mozilla_a11y_relation_h_
|
2011-08-10 05:44:00 +04:00
|
|
|
|
|
|
|
#include "AccIterator.h"
|
|
|
|
|
2014-02-28 02:24:31 +04:00
|
|
|
#include "mozilla/Move.h"
|
|
|
|
|
2012-06-11 02:18:31 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace a11y {
|
|
|
|
|
2011-08-10 05:44:00 +04:00
|
|
|
/**
|
|
|
|
* A collection of relation targets of a certain type. Targets are computed
|
|
|
|
* lazily while enumerating.
|
|
|
|
*/
|
|
|
|
class Relation
|
|
|
|
{
|
|
|
|
public:
|
2012-07-30 18:20:58 +04:00
|
|
|
Relation() : mFirstIter(nullptr), mLastIter(nullptr) { }
|
2011-08-10 05:44:00 +04:00
|
|
|
|
2014-09-02 20:19:58 +04:00
|
|
|
explicit Relation(AccIterable* aIter) :
|
2012-08-28 17:13:59 +04:00
|
|
|
mFirstIter(aIter), mLastIter(aIter) { }
|
2011-08-10 05:44:00 +04:00
|
|
|
|
2014-09-02 20:19:58 +04:00
|
|
|
explicit Relation(Accessible* aAcc) :
|
2012-07-30 18:20:58 +04:00
|
|
|
mFirstIter(nullptr), mLastIter(nullptr)
|
2011-08-10 05:44:00 +04:00
|
|
|
{ AppendTarget(aAcc); }
|
|
|
|
|
2012-05-27 13:01:40 +04:00
|
|
|
Relation(DocAccessible* aDocument, nsIContent* aContent) :
|
2012-07-30 18:20:58 +04:00
|
|
|
mFirstIter(nullptr), mLastIter(nullptr)
|
2012-05-08 04:00:29 +04:00
|
|
|
{ AppendTarget(aDocument, aContent); }
|
2011-08-10 05:44:00 +04:00
|
|
|
|
2014-02-28 02:24:31 +04:00
|
|
|
Relation(Relation&& aOther) :
|
|
|
|
mFirstIter(Move(aOther.mFirstIter)), mLastIter(aOther.mLastIter)
|
2011-08-10 05:44:00 +04:00
|
|
|
{
|
2014-02-28 02:24:31 +04:00
|
|
|
aOther.mLastIter = nullptr;
|
2011-08-10 05:44:00 +04:00
|
|
|
}
|
|
|
|
|
2014-02-28 02:24:31 +04:00
|
|
|
Relation& operator = (Relation&& aRH)
|
2011-08-10 05:44:00 +04:00
|
|
|
{
|
2014-02-28 02:24:31 +04:00
|
|
|
mFirstIter = Move(aRH.mFirstIter);
|
|
|
|
mLastIter = aRH.mLastIter;
|
|
|
|
aRH.mLastIter = nullptr;
|
|
|
|
return *this;
|
2011-08-10 05:44:00 +04:00
|
|
|
}
|
|
|
|
|
2013-02-26 11:17:10 +04:00
|
|
|
inline void AppendIter(AccIterable* aIter)
|
2011-08-10 05:44:00 +04:00
|
|
|
{
|
|
|
|
if (mLastIter)
|
|
|
|
mLastIter->mNextIter = aIter;
|
|
|
|
else
|
|
|
|
mFirstIter = aIter;
|
|
|
|
|
|
|
|
mLastIter = aIter;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Append the given accessible to the set of related accessibles.
|
|
|
|
*/
|
2012-05-29 05:18:45 +04:00
|
|
|
inline void AppendTarget(Accessible* aAcc)
|
2011-08-10 05:44:00 +04:00
|
|
|
{
|
|
|
|
if (aAcc)
|
2013-02-26 11:17:10 +04:00
|
|
|
AppendIter(new SingleAccIterator(aAcc));
|
2011-08-10 05:44:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Append the one accessible for this content node to the set of related
|
|
|
|
* accessibles.
|
|
|
|
*/
|
2012-05-27 13:01:40 +04:00
|
|
|
void AppendTarget(DocAccessible* aDocument, nsIContent* aContent)
|
2011-08-10 05:44:00 +04:00
|
|
|
{
|
|
|
|
if (aContent)
|
2012-05-08 04:00:29 +04:00
|
|
|
AppendTarget(aDocument->GetAccessible(aContent));
|
2011-08-10 05:44:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* compute and return the next related accessible.
|
|
|
|
*/
|
2012-05-29 05:18:45 +04:00
|
|
|
inline Accessible* Next()
|
2011-08-10 05:44:00 +04:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
Accessible* target = nullptr;
|
2011-08-10 05:44:00 +04:00
|
|
|
|
|
|
|
// a trick nsAutoPtr deletes what it used to point to when assigned to
|
|
|
|
while (mFirstIter && !(target = mFirstIter->Next()))
|
|
|
|
mFirstIter = mFirstIter->mNextIter;
|
|
|
|
|
|
|
|
if (!mFirstIter)
|
2012-07-30 18:20:58 +04:00
|
|
|
mLastIter = nullptr;
|
2011-08-10 05:44:00 +04:00
|
|
|
|
|
|
|
return target;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2015-01-07 02:35:02 +03:00
|
|
|
Relation& operator = (const Relation&) = delete;
|
|
|
|
Relation(const Relation&) = delete;
|
2011-08-10 05:44:00 +04:00
|
|
|
|
2013-02-26 11:17:10 +04:00
|
|
|
nsAutoPtr<AccIterable> mFirstIter;
|
|
|
|
AccIterable* mLastIter;
|
2011-08-10 05:44:00 +04:00
|
|
|
};
|
|
|
|
|
2012-06-11 02:18:31 +04:00
|
|
|
} // namespace a11y
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2011-08-10 05:44:00 +04:00
|
|
|
#endif
|
|
|
|
|