Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* vim: set ts=2 et sw=2 tw=80: */ |
michael@0 | 3 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | #ifndef mozilla_a11y_relation_h_ |
michael@0 | 8 | #define mozilla_a11y_relation_h_ |
michael@0 | 9 | |
michael@0 | 10 | #include "AccIterator.h" |
michael@0 | 11 | |
michael@0 | 12 | #include "mozilla/Move.h" |
michael@0 | 13 | |
michael@0 | 14 | namespace mozilla { |
michael@0 | 15 | namespace a11y { |
michael@0 | 16 | |
michael@0 | 17 | /** |
michael@0 | 18 | * A collection of relation targets of a certain type. Targets are computed |
michael@0 | 19 | * lazily while enumerating. |
michael@0 | 20 | */ |
michael@0 | 21 | class Relation |
michael@0 | 22 | { |
michael@0 | 23 | public: |
michael@0 | 24 | Relation() : mFirstIter(nullptr), mLastIter(nullptr) { } |
michael@0 | 25 | |
michael@0 | 26 | Relation(AccIterable* aIter) : |
michael@0 | 27 | mFirstIter(aIter), mLastIter(aIter) { } |
michael@0 | 28 | |
michael@0 | 29 | Relation(Accessible* aAcc) : |
michael@0 | 30 | mFirstIter(nullptr), mLastIter(nullptr) |
michael@0 | 31 | { AppendTarget(aAcc); } |
michael@0 | 32 | |
michael@0 | 33 | Relation(DocAccessible* aDocument, nsIContent* aContent) : |
michael@0 | 34 | mFirstIter(nullptr), mLastIter(nullptr) |
michael@0 | 35 | { AppendTarget(aDocument, aContent); } |
michael@0 | 36 | |
michael@0 | 37 | Relation(Relation&& aOther) : |
michael@0 | 38 | mFirstIter(Move(aOther.mFirstIter)), mLastIter(aOther.mLastIter) |
michael@0 | 39 | { |
michael@0 | 40 | aOther.mLastIter = nullptr; |
michael@0 | 41 | } |
michael@0 | 42 | |
michael@0 | 43 | Relation& operator = (Relation&& aRH) |
michael@0 | 44 | { |
michael@0 | 45 | mFirstIter = Move(aRH.mFirstIter); |
michael@0 | 46 | mLastIter = aRH.mLastIter; |
michael@0 | 47 | aRH.mLastIter = nullptr; |
michael@0 | 48 | return *this; |
michael@0 | 49 | } |
michael@0 | 50 | |
michael@0 | 51 | inline void AppendIter(AccIterable* aIter) |
michael@0 | 52 | { |
michael@0 | 53 | if (mLastIter) |
michael@0 | 54 | mLastIter->mNextIter = aIter; |
michael@0 | 55 | else |
michael@0 | 56 | mFirstIter = aIter; |
michael@0 | 57 | |
michael@0 | 58 | mLastIter = aIter; |
michael@0 | 59 | } |
michael@0 | 60 | |
michael@0 | 61 | /** |
michael@0 | 62 | * Append the given accessible to the set of related accessibles. |
michael@0 | 63 | */ |
michael@0 | 64 | inline void AppendTarget(Accessible* aAcc) |
michael@0 | 65 | { |
michael@0 | 66 | if (aAcc) |
michael@0 | 67 | AppendIter(new SingleAccIterator(aAcc)); |
michael@0 | 68 | } |
michael@0 | 69 | |
michael@0 | 70 | /** |
michael@0 | 71 | * Append the one accessible for this content node to the set of related |
michael@0 | 72 | * accessibles. |
michael@0 | 73 | */ |
michael@0 | 74 | void AppendTarget(DocAccessible* aDocument, nsIContent* aContent) |
michael@0 | 75 | { |
michael@0 | 76 | if (aContent) |
michael@0 | 77 | AppendTarget(aDocument->GetAccessible(aContent)); |
michael@0 | 78 | } |
michael@0 | 79 | |
michael@0 | 80 | /** |
michael@0 | 81 | * compute and return the next related accessible. |
michael@0 | 82 | */ |
michael@0 | 83 | inline Accessible* Next() |
michael@0 | 84 | { |
michael@0 | 85 | Accessible* target = nullptr; |
michael@0 | 86 | |
michael@0 | 87 | // a trick nsAutoPtr deletes what it used to point to when assigned to |
michael@0 | 88 | while (mFirstIter && !(target = mFirstIter->Next())) |
michael@0 | 89 | mFirstIter = mFirstIter->mNextIter; |
michael@0 | 90 | |
michael@0 | 91 | if (!mFirstIter) |
michael@0 | 92 | mLastIter = nullptr; |
michael@0 | 93 | |
michael@0 | 94 | return target; |
michael@0 | 95 | } |
michael@0 | 96 | |
michael@0 | 97 | private: |
michael@0 | 98 | Relation& operator = (const Relation&) MOZ_DELETE; |
michael@0 | 99 | Relation(const Relation&) MOZ_DELETE; |
michael@0 | 100 | |
michael@0 | 101 | nsAutoPtr<AccIterable> mFirstIter; |
michael@0 | 102 | AccIterable* mLastIter; |
michael@0 | 103 | }; |
michael@0 | 104 | |
michael@0 | 105 | } // namespace a11y |
michael@0 | 106 | } // namespace mozilla |
michael@0 | 107 | |
michael@0 | 108 | #endif |
michael@0 | 109 |