accessible/src/base/AccIterator.h

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

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_AccIterator_h__
michael@0 8 #define mozilla_a11y_AccIterator_h__
michael@0 9
michael@0 10 #include "DocAccessible.h"
michael@0 11 #include "Filters.h"
michael@0 12
michael@0 13 class nsITreeView;
michael@0 14
michael@0 15 namespace mozilla {
michael@0 16 namespace a11y {
michael@0 17
michael@0 18 /**
michael@0 19 * AccIterable is a basic interface for iterators over accessibles.
michael@0 20 */
michael@0 21 class AccIterable
michael@0 22 {
michael@0 23 public:
michael@0 24 virtual ~AccIterable() { }
michael@0 25 virtual Accessible* Next() = 0;
michael@0 26
michael@0 27 private:
michael@0 28 friend class Relation;
michael@0 29 nsAutoPtr<AccIterable> mNextIter;
michael@0 30 };
michael@0 31
michael@0 32 /**
michael@0 33 * Allows to iterate through accessible children or subtree complying with
michael@0 34 * filter function.
michael@0 35 */
michael@0 36 class AccIterator : public AccIterable
michael@0 37 {
michael@0 38 public:
michael@0 39 AccIterator(Accessible* aRoot, filters::FilterFuncPtr aFilterFunc);
michael@0 40 virtual ~AccIterator();
michael@0 41
michael@0 42 /**
michael@0 43 * Return next accessible complying with filter function. Return the first
michael@0 44 * accessible for the first time.
michael@0 45 */
michael@0 46 virtual Accessible* Next();
michael@0 47
michael@0 48 private:
michael@0 49 AccIterator();
michael@0 50 AccIterator(const AccIterator&);
michael@0 51 AccIterator& operator =(const AccIterator&);
michael@0 52
michael@0 53 struct IteratorState
michael@0 54 {
michael@0 55 IteratorState(Accessible* aParent, IteratorState* mParentState = nullptr);
michael@0 56
michael@0 57 Accessible* mParent;
michael@0 58 int32_t mIndex;
michael@0 59 IteratorState* mParentState;
michael@0 60 };
michael@0 61
michael@0 62 filters::FilterFuncPtr mFilterFunc;
michael@0 63 IteratorState* mState;
michael@0 64 };
michael@0 65
michael@0 66
michael@0 67 /**
michael@0 68 * Allows to traverse through related accessibles that are pointing to the given
michael@0 69 * dependent accessible by relation attribute.
michael@0 70 */
michael@0 71 class RelatedAccIterator : public AccIterable
michael@0 72 {
michael@0 73 public:
michael@0 74 /**
michael@0 75 * Constructor.
michael@0 76 *
michael@0 77 * @param aDocument [in] the document accessible the related
michael@0 78 * & accessibles belong to.
michael@0 79 * @param aDependentContent [in] the content of dependent accessible that
michael@0 80 * relations were requested for
michael@0 81 * @param aRelAttr [in] relation attribute that relations are
michael@0 82 * pointed by
michael@0 83 */
michael@0 84 RelatedAccIterator(DocAccessible* aDocument, nsIContent* aDependentContent,
michael@0 85 nsIAtom* aRelAttr);
michael@0 86
michael@0 87 virtual ~RelatedAccIterator() { }
michael@0 88
michael@0 89 /**
michael@0 90 * Return next related accessible for the given dependent accessible.
michael@0 91 */
michael@0 92 virtual Accessible* Next();
michael@0 93
michael@0 94 private:
michael@0 95 RelatedAccIterator();
michael@0 96 RelatedAccIterator(const RelatedAccIterator&);
michael@0 97 RelatedAccIterator& operator = (const RelatedAccIterator&);
michael@0 98
michael@0 99 DocAccessible* mDocument;
michael@0 100 nsIAtom* mRelAttr;
michael@0 101 DocAccessible::AttrRelProviderArray* mProviders;
michael@0 102 nsIContent* mBindingParent;
michael@0 103 uint32_t mIndex;
michael@0 104 };
michael@0 105
michael@0 106
michael@0 107 /**
michael@0 108 * Used to iterate through HTML labels associated with the given accessible.
michael@0 109 */
michael@0 110 class HTMLLabelIterator : public AccIterable
michael@0 111 {
michael@0 112 public:
michael@0 113 enum LabelFilter {
michael@0 114 eAllLabels,
michael@0 115 eSkipAncestorLabel
michael@0 116 };
michael@0 117
michael@0 118 HTMLLabelIterator(DocAccessible* aDocument, const Accessible* aAccessible,
michael@0 119 LabelFilter aFilter = eAllLabels);
michael@0 120
michael@0 121 virtual ~HTMLLabelIterator() { }
michael@0 122
michael@0 123 /**
michael@0 124 * Return next label accessible associated with the given element.
michael@0 125 */
michael@0 126 virtual Accessible* Next();
michael@0 127
michael@0 128 private:
michael@0 129 HTMLLabelIterator();
michael@0 130 HTMLLabelIterator(const HTMLLabelIterator&);
michael@0 131 HTMLLabelIterator& operator = (const HTMLLabelIterator&);
michael@0 132
michael@0 133 RelatedAccIterator mRelIter;
michael@0 134 // XXX: replace it on weak reference (bug 678429), it's safe to use raw
michael@0 135 // pointer now because iterators life cycle is short.
michael@0 136 const Accessible* mAcc;
michael@0 137 LabelFilter mLabelFilter;
michael@0 138 };
michael@0 139
michael@0 140
michael@0 141 /**
michael@0 142 * Used to iterate through HTML outputs associated with the given element.
michael@0 143 */
michael@0 144 class HTMLOutputIterator : public AccIterable
michael@0 145 {
michael@0 146 public:
michael@0 147 HTMLOutputIterator(DocAccessible* aDocument, nsIContent* aElement);
michael@0 148 virtual ~HTMLOutputIterator() { }
michael@0 149
michael@0 150 /**
michael@0 151 * Return next output accessible associated with the given element.
michael@0 152 */
michael@0 153 virtual Accessible* Next();
michael@0 154
michael@0 155 private:
michael@0 156 HTMLOutputIterator();
michael@0 157 HTMLOutputIterator(const HTMLOutputIterator&);
michael@0 158 HTMLOutputIterator& operator = (const HTMLOutputIterator&);
michael@0 159
michael@0 160 RelatedAccIterator mRelIter;
michael@0 161 };
michael@0 162
michael@0 163
michael@0 164 /**
michael@0 165 * Used to iterate through XUL labels associated with the given element.
michael@0 166 */
michael@0 167 class XULLabelIterator : public AccIterable
michael@0 168 {
michael@0 169 public:
michael@0 170 XULLabelIterator(DocAccessible* aDocument, nsIContent* aElement);
michael@0 171 virtual ~XULLabelIterator() { }
michael@0 172
michael@0 173 /**
michael@0 174 * Return next label accessible associated with the given element.
michael@0 175 */
michael@0 176 virtual Accessible* Next();
michael@0 177
michael@0 178 private:
michael@0 179 XULLabelIterator();
michael@0 180 XULLabelIterator(const XULLabelIterator&);
michael@0 181 XULLabelIterator& operator = (const XULLabelIterator&);
michael@0 182
michael@0 183 RelatedAccIterator mRelIter;
michael@0 184 };
michael@0 185
michael@0 186
michael@0 187 /**
michael@0 188 * Used to iterate through XUL descriptions associated with the given element.
michael@0 189 */
michael@0 190 class XULDescriptionIterator : public AccIterable
michael@0 191 {
michael@0 192 public:
michael@0 193 XULDescriptionIterator(DocAccessible* aDocument, nsIContent* aElement);
michael@0 194 virtual ~XULDescriptionIterator() { }
michael@0 195
michael@0 196 /**
michael@0 197 * Return next description accessible associated with the given element.
michael@0 198 */
michael@0 199 virtual Accessible* Next();
michael@0 200
michael@0 201 private:
michael@0 202 XULDescriptionIterator();
michael@0 203 XULDescriptionIterator(const XULDescriptionIterator&);
michael@0 204 XULDescriptionIterator& operator = (const XULDescriptionIterator&);
michael@0 205
michael@0 206 RelatedAccIterator mRelIter;
michael@0 207 };
michael@0 208
michael@0 209 /**
michael@0 210 * Used to iterate through IDs, elements or accessibles pointed by IDRefs
michael@0 211 * attribute. Note, any method used to iterate through IDs, elements, or
michael@0 212 * accessibles moves iterator to next position.
michael@0 213 */
michael@0 214 class IDRefsIterator : public AccIterable
michael@0 215 {
michael@0 216 public:
michael@0 217 IDRefsIterator(DocAccessible* aDoc, nsIContent* aContent,
michael@0 218 nsIAtom* aIDRefsAttr);
michael@0 219 virtual ~IDRefsIterator() { }
michael@0 220
michael@0 221 /**
michael@0 222 * Return next ID.
michael@0 223 */
michael@0 224 const nsDependentSubstring NextID();
michael@0 225
michael@0 226 /**
michael@0 227 * Return next element.
michael@0 228 */
michael@0 229 nsIContent* NextElem();
michael@0 230
michael@0 231 /**
michael@0 232 * Return the element with the given ID.
michael@0 233 */
michael@0 234 nsIContent* GetElem(const nsDependentSubstring& aID);
michael@0 235
michael@0 236 // AccIterable
michael@0 237 virtual Accessible* Next();
michael@0 238
michael@0 239 private:
michael@0 240 IDRefsIterator();
michael@0 241 IDRefsIterator(const IDRefsIterator&);
michael@0 242 IDRefsIterator operator = (const IDRefsIterator&);
michael@0 243
michael@0 244 nsString mIDs;
michael@0 245 nsIContent* mContent;
michael@0 246 DocAccessible* mDoc;
michael@0 247 nsAString::index_type mCurrIdx;
michael@0 248 };
michael@0 249
michael@0 250 /**
michael@0 251 * Iterator that points to a single accessible returning it on the first call
michael@0 252 * to Next().
michael@0 253 */
michael@0 254 class SingleAccIterator : public AccIterable
michael@0 255 {
michael@0 256 public:
michael@0 257 SingleAccIterator(Accessible* aTarget): mAcc(aTarget) { }
michael@0 258 virtual ~SingleAccIterator() { }
michael@0 259
michael@0 260 virtual Accessible* Next();
michael@0 261
michael@0 262 private:
michael@0 263 SingleAccIterator();
michael@0 264 SingleAccIterator(const SingleAccIterator&);
michael@0 265 SingleAccIterator& operator = (const SingleAccIterator&);
michael@0 266
michael@0 267 nsRefPtr<Accessible> mAcc;
michael@0 268 };
michael@0 269
michael@0 270
michael@0 271 /**
michael@0 272 * Used to iterate items of the given item container.
michael@0 273 */
michael@0 274 class ItemIterator : public AccIterable
michael@0 275 {
michael@0 276 public:
michael@0 277 ItemIterator(Accessible* aItemContainer) :
michael@0 278 mContainer(aItemContainer), mAnchor(nullptr) { }
michael@0 279 virtual ~ItemIterator() { }
michael@0 280
michael@0 281 virtual Accessible* Next();
michael@0 282
michael@0 283 private:
michael@0 284 ItemIterator() MOZ_DELETE;
michael@0 285 ItemIterator(const ItemIterator&) MOZ_DELETE;
michael@0 286 ItemIterator& operator = (const ItemIterator&) MOZ_DELETE;
michael@0 287
michael@0 288 Accessible* mContainer;
michael@0 289 Accessible* mAnchor;
michael@0 290 };
michael@0 291
michael@0 292
michael@0 293 /**
michael@0 294 * Used to iterate through XUL tree items of the same level.
michael@0 295 */
michael@0 296 class XULTreeItemIterator : public AccIterable
michael@0 297 {
michael@0 298 public:
michael@0 299 XULTreeItemIterator(XULTreeAccessible* aXULTree, nsITreeView* aTreeView,
michael@0 300 int32_t aRowIdx);
michael@0 301 virtual ~XULTreeItemIterator() { }
michael@0 302
michael@0 303 virtual Accessible* Next();
michael@0 304
michael@0 305 private:
michael@0 306 XULTreeItemIterator() MOZ_DELETE;
michael@0 307 XULTreeItemIterator(const XULTreeItemIterator&) MOZ_DELETE;
michael@0 308 XULTreeItemIterator& operator = (const XULTreeItemIterator&) MOZ_DELETE;
michael@0 309
michael@0 310 XULTreeAccessible* mXULTree;
michael@0 311 nsITreeView* mTreeView;
michael@0 312 int32_t mRowCount;
michael@0 313 int32_t mContainerLevel;
michael@0 314 int32_t mCurrRowIdx;
michael@0 315 };
michael@0 316
michael@0 317 } // namespace a11y
michael@0 318 } // namespace mozilla
michael@0 319
michael@0 320 #endif

mercurial