gecko-dev/accessible/base/AccIterator.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

304 строки
7.8 KiB
C
Исходник Обычный вид История

/* -*- 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/. */
#ifndef mozilla_a11y_AccIterator_h__
#define mozilla_a11y_AccIterator_h__
#include "DocAccessible.h"
#include "Filters.h"
#include <memory>
class nsITreeView;
namespace mozilla {
namespace a11y {
/**
* AccIterable is a basic interface for iterators over accessibles.
*/
class AccIterable {
public:
virtual ~AccIterable() {}
virtual Accessible* Next() = 0;
private:
friend class Relation;
std::unique_ptr<AccIterable> mNextIter;
};
/**
* Allows to iterate through accessible children or subtree complying with
* filter function.
*/
class AccIterator : public AccIterable {
public:
AccIterator(const Accessible* aRoot, filters::FilterFuncPtr aFilterFunc);
virtual ~AccIterator();
/**
* Return next accessible complying with filter function. Return the first
* accessible for the first time.
*/
virtual Accessible* Next() override;
private:
AccIterator();
AccIterator(const AccIterator&);
AccIterator& operator=(const AccIterator&);
struct IteratorState {
explicit IteratorState(const Accessible* aParent,
IteratorState* mParentState = nullptr);
const Accessible* mParent;
int32_t mIndex;
IteratorState* mParentState;
};
filters::FilterFuncPtr mFilterFunc;
IteratorState* mState;
};
/**
* Allows to traverse through related accessibles that are pointing to the given
* dependent accessible by relation attribute.
*/
class RelatedAccIterator : public AccIterable {
public:
/**
* Constructor.
*
* @param aDocument [in] the document accessible the related
* & accessibles belong to.
* @param aDependentContent [in] the content of dependent accessible that
* relations were requested for
* @param aRelAttr [in] relation attribute that relations are
* pointed by
*/
RelatedAccIterator(DocAccessible* aDocument, nsIContent* aDependentContent,
nsAtom* aRelAttr);
virtual ~RelatedAccIterator() {}
/**
* Return next related accessible for the given dependent accessible.
*/
virtual Accessible* Next() override;
private:
RelatedAccIterator();
RelatedAccIterator(const RelatedAccIterator&);
RelatedAccIterator& operator=(const RelatedAccIterator&);
DocAccessible* mDocument;
nsAtom* mRelAttr;
DocAccessible::AttrRelProviders* mProviders;
uint32_t mIndex;
};
/**
* Used to iterate through HTML labels associated with the given accessible.
*/
class HTMLLabelIterator : public AccIterable {
public:
enum LabelFilter { eAllLabels, eSkipAncestorLabel };
HTMLLabelIterator(DocAccessible* aDocument, const Accessible* aAccessible,
LabelFilter aFilter = eAllLabels);
virtual ~HTMLLabelIterator() {}
/**
* Return next label accessible associated with the given element.
*/
virtual Accessible* Next() override;
private:
HTMLLabelIterator();
HTMLLabelIterator(const HTMLLabelIterator&);
HTMLLabelIterator& operator=(const HTMLLabelIterator&);
bool IsLabel(Accessible* aLabel);
RelatedAccIterator mRelIter;
// XXX: replace it on weak reference (bug 678429), it's safe to use raw
// pointer now because iterators life cycle is short.
const Accessible* mAcc;
LabelFilter mLabelFilter;
};
/**
* Used to iterate through HTML outputs associated with the given element.
*/
class HTMLOutputIterator : public AccIterable {
public:
HTMLOutputIterator(DocAccessible* aDocument, nsIContent* aElement);
virtual ~HTMLOutputIterator() {}
/**
* Return next output accessible associated with the given element.
*/
virtual Accessible* Next() override;
private:
HTMLOutputIterator();
HTMLOutputIterator(const HTMLOutputIterator&);
HTMLOutputIterator& operator=(const HTMLOutputIterator&);
RelatedAccIterator mRelIter;
};
/**
* Used to iterate through XUL labels associated with the given element.
*/
class XULLabelIterator : public AccIterable {
public:
XULLabelIterator(DocAccessible* aDocument, nsIContent* aElement);
virtual ~XULLabelIterator() {}
/**
* Return next label accessible associated with the given element.
*/
virtual Accessible* Next() override;
private:
XULLabelIterator();
XULLabelIterator(const XULLabelIterator&);
XULLabelIterator& operator=(const XULLabelIterator&);
RelatedAccIterator mRelIter;
};
/**
* Used to iterate through XUL descriptions associated with the given element.
*/
class XULDescriptionIterator : public AccIterable {
public:
XULDescriptionIterator(DocAccessible* aDocument, nsIContent* aElement);
virtual ~XULDescriptionIterator() {}
/**
* Return next description accessible associated with the given element.
*/
virtual Accessible* Next() override;
private:
XULDescriptionIterator();
XULDescriptionIterator(const XULDescriptionIterator&);
XULDescriptionIterator& operator=(const XULDescriptionIterator&);
RelatedAccIterator mRelIter;
};
/**
* Used to iterate through IDs, elements or accessibles pointed by IDRefs
* attribute. Note, any method used to iterate through IDs, elements, or
* accessibles moves iterator to next position.
*/
class IDRefsIterator : public AccIterable {
public:
IDRefsIterator(DocAccessible* aDoc, nsIContent* aContent,
nsAtom* aIDRefsAttr);
virtual ~IDRefsIterator() {}
/**
* Return next ID.
*/
const nsDependentSubstring NextID();
/**
* Return next element.
*/
nsIContent* NextElem();
/**
* Return the element with the given ID.
*/
static dom::Element* GetElem(nsIContent* aContent, const nsAString& aID);
dom::Element* GetElem(const nsDependentSubstring& aID);
// AccIterable
virtual Accessible* Next() override;
private:
IDRefsIterator();
IDRefsIterator(const IDRefsIterator&);
IDRefsIterator operator=(const IDRefsIterator&);
nsString mIDs;
nsIContent* mContent;
DocAccessible* mDoc;
nsAString::index_type mCurrIdx;
};
/**
* Iterator that points to a single accessible returning it on the first call
* to Next().
*/
class SingleAccIterator : public AccIterable {
public:
explicit SingleAccIterator(Accessible* aTarget) : mAcc(aTarget) {}
virtual ~SingleAccIterator() {}
virtual Accessible* Next() override;
private:
SingleAccIterator();
SingleAccIterator(const SingleAccIterator&);
SingleAccIterator& operator=(const SingleAccIterator&);
Bug 1207245 - part 6 - rename nsRefPtr<T> to RefPtr<T>; r=ehsan; a=Tomcat The bulk of this commit was generated with a script, executed at the top level of a typical source code checkout. The only non-machine-generated part was modifying MFBT's moz.build to reflect the new naming. CLOSED TREE makes big refactorings like this a piece of cake. # The main substitution. find . -name '*.cpp' -o -name '*.cc' -o -name '*.h' -o -name '*.mm' -o -name '*.idl'| \ xargs perl -p -i -e ' s/nsRefPtr\.h/RefPtr\.h/g; # handle includes s/nsRefPtr ?</RefPtr</g; # handle declarations and variables ' # Handle a special friend declaration in gfx/layers/AtomicRefCountedWithFinalize.h. perl -p -i -e 's/::nsRefPtr;/::RefPtr;/' gfx/layers/AtomicRefCountedWithFinalize.h # Handle nsRefPtr.h itself, a couple places that define constructors # from nsRefPtr, and code generators specially. We do this here, rather # than indiscriminantly s/nsRefPtr/RefPtr/, because that would rename # things like nsRefPtrHashtable. perl -p -i -e 's/nsRefPtr/RefPtr/g' \ mfbt/nsRefPtr.h \ xpcom/glue/nsCOMPtr.h \ xpcom/base/OwningNonNull.h \ ipc/ipdl/ipdl/lower.py \ ipc/ipdl/ipdl/builtin.py \ dom/bindings/Codegen.py \ python/lldbutils/lldbutils/utils.py # In our indiscriminate substitution above, we renamed # nsRefPtrGetterAddRefs, the class behind getter_AddRefs. Fix that up. find . -name '*.cpp' -o -name '*.h' -o -name '*.idl' | \ xargs perl -p -i -e 's/nsRefPtrGetterAddRefs/RefPtrGetterAddRefs/g' if [ -d .git ]; then git mv mfbt/nsRefPtr.h mfbt/RefPtr.h else hg mv mfbt/nsRefPtr.h mfbt/RefPtr.h fi --HG-- rename : mfbt/nsRefPtr.h => mfbt/RefPtr.h
2015-10-18 08:24:48 +03:00
RefPtr<Accessible> mAcc;
};
/**
* Used to iterate items of the given item container.
*/
class ItemIterator : public AccIterable {
public:
explicit ItemIterator(const Accessible* aItemContainer)
: mContainer(aItemContainer), mAnchor(nullptr) {}
virtual ~ItemIterator() {}
virtual Accessible* Next() override;
private:
ItemIterator() = delete;
ItemIterator(const ItemIterator&) = delete;
ItemIterator& operator=(const ItemIterator&) = delete;
const Accessible* mContainer;
Accessible* mAnchor;
};
/**
* Used to iterate through XUL tree items of the same level.
*/
class XULTreeItemIterator : public AccIterable {
public:
XULTreeItemIterator(const XULTreeAccessible* aXULTree, nsITreeView* aTreeView,
int32_t aRowIdx);
virtual ~XULTreeItemIterator() {}
virtual Accessible* Next() override;
private:
XULTreeItemIterator() = delete;
XULTreeItemIterator(const XULTreeItemIterator&) = delete;
XULTreeItemIterator& operator=(const XULTreeItemIterator&) = delete;
const XULTreeAccessible* mXULTree;
nsITreeView* mTreeView;
int32_t mRowCount;
int32_t mContainerLevel;
int32_t mCurrRowIdx;
};
} // namespace a11y
} // namespace mozilla
#endif