michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim: set ts=2 et sw=2 tw=80: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef mozilla_a11y_AccIterator_h__ michael@0: #define mozilla_a11y_AccIterator_h__ michael@0: michael@0: #include "DocAccessible.h" michael@0: #include "Filters.h" michael@0: michael@0: class nsITreeView; michael@0: michael@0: namespace mozilla { michael@0: namespace a11y { michael@0: michael@0: /** michael@0: * AccIterable is a basic interface for iterators over accessibles. michael@0: */ michael@0: class AccIterable michael@0: { michael@0: public: michael@0: virtual ~AccIterable() { } michael@0: virtual Accessible* Next() = 0; michael@0: michael@0: private: michael@0: friend class Relation; michael@0: nsAutoPtr mNextIter; michael@0: }; michael@0: michael@0: /** michael@0: * Allows to iterate through accessible children or subtree complying with michael@0: * filter function. michael@0: */ michael@0: class AccIterator : public AccIterable michael@0: { michael@0: public: michael@0: AccIterator(Accessible* aRoot, filters::FilterFuncPtr aFilterFunc); michael@0: virtual ~AccIterator(); michael@0: michael@0: /** michael@0: * Return next accessible complying with filter function. Return the first michael@0: * accessible for the first time. michael@0: */ michael@0: virtual Accessible* Next(); michael@0: michael@0: private: michael@0: AccIterator(); michael@0: AccIterator(const AccIterator&); michael@0: AccIterator& operator =(const AccIterator&); michael@0: michael@0: struct IteratorState michael@0: { michael@0: IteratorState(Accessible* aParent, IteratorState* mParentState = nullptr); michael@0: michael@0: Accessible* mParent; michael@0: int32_t mIndex; michael@0: IteratorState* mParentState; michael@0: }; michael@0: michael@0: filters::FilterFuncPtr mFilterFunc; michael@0: IteratorState* mState; michael@0: }; michael@0: michael@0: michael@0: /** michael@0: * Allows to traverse through related accessibles that are pointing to the given michael@0: * dependent accessible by relation attribute. michael@0: */ michael@0: class RelatedAccIterator : public AccIterable michael@0: { michael@0: public: michael@0: /** michael@0: * Constructor. michael@0: * michael@0: * @param aDocument [in] the document accessible the related michael@0: * & accessibles belong to. michael@0: * @param aDependentContent [in] the content of dependent accessible that michael@0: * relations were requested for michael@0: * @param aRelAttr [in] relation attribute that relations are michael@0: * pointed by michael@0: */ michael@0: RelatedAccIterator(DocAccessible* aDocument, nsIContent* aDependentContent, michael@0: nsIAtom* aRelAttr); michael@0: michael@0: virtual ~RelatedAccIterator() { } michael@0: michael@0: /** michael@0: * Return next related accessible for the given dependent accessible. michael@0: */ michael@0: virtual Accessible* Next(); michael@0: michael@0: private: michael@0: RelatedAccIterator(); michael@0: RelatedAccIterator(const RelatedAccIterator&); michael@0: RelatedAccIterator& operator = (const RelatedAccIterator&); michael@0: michael@0: DocAccessible* mDocument; michael@0: nsIAtom* mRelAttr; michael@0: DocAccessible::AttrRelProviderArray* mProviders; michael@0: nsIContent* mBindingParent; michael@0: uint32_t mIndex; michael@0: }; michael@0: michael@0: michael@0: /** michael@0: * Used to iterate through HTML labels associated with the given accessible. michael@0: */ michael@0: class HTMLLabelIterator : public AccIterable michael@0: { michael@0: public: michael@0: enum LabelFilter { michael@0: eAllLabels, michael@0: eSkipAncestorLabel michael@0: }; michael@0: michael@0: HTMLLabelIterator(DocAccessible* aDocument, const Accessible* aAccessible, michael@0: LabelFilter aFilter = eAllLabels); michael@0: michael@0: virtual ~HTMLLabelIterator() { } michael@0: michael@0: /** michael@0: * Return next label accessible associated with the given element. michael@0: */ michael@0: virtual Accessible* Next(); michael@0: michael@0: private: michael@0: HTMLLabelIterator(); michael@0: HTMLLabelIterator(const HTMLLabelIterator&); michael@0: HTMLLabelIterator& operator = (const HTMLLabelIterator&); michael@0: michael@0: RelatedAccIterator mRelIter; michael@0: // XXX: replace it on weak reference (bug 678429), it's safe to use raw michael@0: // pointer now because iterators life cycle is short. michael@0: const Accessible* mAcc; michael@0: LabelFilter mLabelFilter; michael@0: }; michael@0: michael@0: michael@0: /** michael@0: * Used to iterate through HTML outputs associated with the given element. michael@0: */ michael@0: class HTMLOutputIterator : public AccIterable michael@0: { michael@0: public: michael@0: HTMLOutputIterator(DocAccessible* aDocument, nsIContent* aElement); michael@0: virtual ~HTMLOutputIterator() { } michael@0: michael@0: /** michael@0: * Return next output accessible associated with the given element. michael@0: */ michael@0: virtual Accessible* Next(); michael@0: michael@0: private: michael@0: HTMLOutputIterator(); michael@0: HTMLOutputIterator(const HTMLOutputIterator&); michael@0: HTMLOutputIterator& operator = (const HTMLOutputIterator&); michael@0: michael@0: RelatedAccIterator mRelIter; michael@0: }; michael@0: michael@0: michael@0: /** michael@0: * Used to iterate through XUL labels associated with the given element. michael@0: */ michael@0: class XULLabelIterator : public AccIterable michael@0: { michael@0: public: michael@0: XULLabelIterator(DocAccessible* aDocument, nsIContent* aElement); michael@0: virtual ~XULLabelIterator() { } michael@0: michael@0: /** michael@0: * Return next label accessible associated with the given element. michael@0: */ michael@0: virtual Accessible* Next(); michael@0: michael@0: private: michael@0: XULLabelIterator(); michael@0: XULLabelIterator(const XULLabelIterator&); michael@0: XULLabelIterator& operator = (const XULLabelIterator&); michael@0: michael@0: RelatedAccIterator mRelIter; michael@0: }; michael@0: michael@0: michael@0: /** michael@0: * Used to iterate through XUL descriptions associated with the given element. michael@0: */ michael@0: class XULDescriptionIterator : public AccIterable michael@0: { michael@0: public: michael@0: XULDescriptionIterator(DocAccessible* aDocument, nsIContent* aElement); michael@0: virtual ~XULDescriptionIterator() { } michael@0: michael@0: /** michael@0: * Return next description accessible associated with the given element. michael@0: */ michael@0: virtual Accessible* Next(); michael@0: michael@0: private: michael@0: XULDescriptionIterator(); michael@0: XULDescriptionIterator(const XULDescriptionIterator&); michael@0: XULDescriptionIterator& operator = (const XULDescriptionIterator&); michael@0: michael@0: RelatedAccIterator mRelIter; michael@0: }; michael@0: michael@0: /** michael@0: * Used to iterate through IDs, elements or accessibles pointed by IDRefs michael@0: * attribute. Note, any method used to iterate through IDs, elements, or michael@0: * accessibles moves iterator to next position. michael@0: */ michael@0: class IDRefsIterator : public AccIterable michael@0: { michael@0: public: michael@0: IDRefsIterator(DocAccessible* aDoc, nsIContent* aContent, michael@0: nsIAtom* aIDRefsAttr); michael@0: virtual ~IDRefsIterator() { } michael@0: michael@0: /** michael@0: * Return next ID. michael@0: */ michael@0: const nsDependentSubstring NextID(); michael@0: michael@0: /** michael@0: * Return next element. michael@0: */ michael@0: nsIContent* NextElem(); michael@0: michael@0: /** michael@0: * Return the element with the given ID. michael@0: */ michael@0: nsIContent* GetElem(const nsDependentSubstring& aID); michael@0: michael@0: // AccIterable michael@0: virtual Accessible* Next(); michael@0: michael@0: private: michael@0: IDRefsIterator(); michael@0: IDRefsIterator(const IDRefsIterator&); michael@0: IDRefsIterator operator = (const IDRefsIterator&); michael@0: michael@0: nsString mIDs; michael@0: nsIContent* mContent; michael@0: DocAccessible* mDoc; michael@0: nsAString::index_type mCurrIdx; michael@0: }; michael@0: michael@0: /** michael@0: * Iterator that points to a single accessible returning it on the first call michael@0: * to Next(). michael@0: */ michael@0: class SingleAccIterator : public AccIterable michael@0: { michael@0: public: michael@0: SingleAccIterator(Accessible* aTarget): mAcc(aTarget) { } michael@0: virtual ~SingleAccIterator() { } michael@0: michael@0: virtual Accessible* Next(); michael@0: michael@0: private: michael@0: SingleAccIterator(); michael@0: SingleAccIterator(const SingleAccIterator&); michael@0: SingleAccIterator& operator = (const SingleAccIterator&); michael@0: michael@0: nsRefPtr mAcc; michael@0: }; michael@0: michael@0: michael@0: /** michael@0: * Used to iterate items of the given item container. michael@0: */ michael@0: class ItemIterator : public AccIterable michael@0: { michael@0: public: michael@0: ItemIterator(Accessible* aItemContainer) : michael@0: mContainer(aItemContainer), mAnchor(nullptr) { } michael@0: virtual ~ItemIterator() { } michael@0: michael@0: virtual Accessible* Next(); michael@0: michael@0: private: michael@0: ItemIterator() MOZ_DELETE; michael@0: ItemIterator(const ItemIterator&) MOZ_DELETE; michael@0: ItemIterator& operator = (const ItemIterator&) MOZ_DELETE; michael@0: michael@0: Accessible* mContainer; michael@0: Accessible* mAnchor; michael@0: }; michael@0: michael@0: michael@0: /** michael@0: * Used to iterate through XUL tree items of the same level. michael@0: */ michael@0: class XULTreeItemIterator : public AccIterable michael@0: { michael@0: public: michael@0: XULTreeItemIterator(XULTreeAccessible* aXULTree, nsITreeView* aTreeView, michael@0: int32_t aRowIdx); michael@0: virtual ~XULTreeItemIterator() { } michael@0: michael@0: virtual Accessible* Next(); michael@0: michael@0: private: michael@0: XULTreeItemIterator() MOZ_DELETE; michael@0: XULTreeItemIterator(const XULTreeItemIterator&) MOZ_DELETE; michael@0: XULTreeItemIterator& operator = (const XULTreeItemIterator&) MOZ_DELETE; michael@0: michael@0: XULTreeAccessible* mXULTree; michael@0: nsITreeView* mTreeView; michael@0: int32_t mRowCount; michael@0: int32_t mContainerLevel; michael@0: int32_t mCurrRowIdx; michael@0: }; michael@0: michael@0: } // namespace a11y michael@0: } // namespace mozilla michael@0: michael@0: #endif