1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/accessible/src/base/AccCollector.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,95 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +#ifndef mozilla_a11y_AccCollector_h__ 1.9 +#define mozilla_a11y_AccCollector_h__ 1.10 + 1.11 +#include "Filters.h" 1.12 + 1.13 +#include "nsTArray.h" 1.14 + 1.15 +namespace mozilla { 1.16 +namespace a11y { 1.17 + 1.18 +class Accessible; 1.19 + 1.20 +/** 1.21 + * Collect accessible children complying with filter function. Provides quick 1.22 + * access to accessible by index. 1.23 + */ 1.24 +class AccCollector 1.25 +{ 1.26 +public: 1.27 + AccCollector(Accessible* aRoot, filters::FilterFuncPtr aFilterFunc); 1.28 + virtual ~AccCollector(); 1.29 + 1.30 + /** 1.31 + * Return accessible count within the collection. 1.32 + */ 1.33 + uint32_t Count(); 1.34 + 1.35 + /** 1.36 + * Return an accessible from the collection at the given index. 1.37 + */ 1.38 + Accessible* GetAccessibleAt(uint32_t aIndex); 1.39 + 1.40 + /** 1.41 + * Return index of the given accessible within the collection. 1.42 + */ 1.43 + virtual int32_t GetIndexAt(Accessible* aAccessible); 1.44 + 1.45 +protected: 1.46 + /** 1.47 + * Ensure accessible at the given index is stored and return it. 1.48 + */ 1.49 + Accessible* EnsureNGetObject(uint32_t aIndex); 1.50 + 1.51 + /** 1.52 + * Ensure index for the given accessible is stored and return it. 1.53 + */ 1.54 + int32_t EnsureNGetIndex(Accessible* aAccessible); 1.55 + 1.56 + /** 1.57 + * Append the object to collection. 1.58 + */ 1.59 + virtual void AppendObject(Accessible* aAccessible); 1.60 + 1.61 + filters::FilterFuncPtr mFilterFunc; 1.62 + Accessible* mRoot; 1.63 + uint32_t mRootChildIdx; 1.64 + 1.65 + nsTArray<Accessible*> mObjects; 1.66 + 1.67 +private: 1.68 + AccCollector(); 1.69 + AccCollector(const AccCollector&); 1.70 + AccCollector& operator =(const AccCollector&); 1.71 +}; 1.72 + 1.73 +/** 1.74 + * Collect embedded objects. Provide quick access to accessible by index and 1.75 + * vice versa. 1.76 + */ 1.77 +class EmbeddedObjCollector : public AccCollector 1.78 +{ 1.79 +public: 1.80 + virtual ~EmbeddedObjCollector() { } 1.81 + 1.82 +public: 1.83 + virtual int32_t GetIndexAt(Accessible* aAccessible); 1.84 + 1.85 +protected: 1.86 + // Make sure it's used by Accessible class only. 1.87 + EmbeddedObjCollector(Accessible* aRoot) : 1.88 + AccCollector(aRoot, filters::GetEmbeddedObject) { } 1.89 + 1.90 + virtual void AppendObject(Accessible* aAccessible); 1.91 + 1.92 + friend class Accessible; 1.93 +}; 1.94 + 1.95 +} // namespace a11y 1.96 +} // namespace mozilla 1.97 + 1.98 +#endif