LCOV - code coverage report
Current view: directory - accessible/src/base - AccIterator.h (source / functions) Found Hit Coverage
Test: app.info Lines: 10 0 0.0 %
Date: 2012-06-02 Functions: 18 0 0.0 %

       1                 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       2                 : /* vim: set ts=2 et sw=2 tw=80: */
       3                 : /* ***** BEGIN LICENSE BLOCK *****
       4                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
       5                 :  *
       6                 :  * The contents of this file are subject to the Mozilla Public License Version
       7                 :  * 1.1 (the "License"); you may not use this file except in compliance with
       8                 :  * the License. You may obtain a copy of the License at
       9                 :  * http://www.mozilla.org/MPL/
      10                 :  *
      11                 :  * Software distributed under the License is distributed on an "AS IS" basis,
      12                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      13                 :  * for the specific language governing rights and limitations under the
      14                 :  * License.
      15                 :  *
      16                 :  * The Original Code is mozilla.org code.
      17                 :  *
      18                 :  * The Initial Developer of the Original Code is
      19                 :  * Mozilla Foundation.
      20                 :  * Portions created by the Initial Developer are Copyright (C) 2010
      21                 :  * the Initial Developer. All Rights Reserved.
      22                 :  *
      23                 :  * Contributor(s):
      24                 :  *  Alexander Surkov <surkov.alexander@gmail.com> (original author)
      25                 :  *
      26                 :  * Alternatively, the contents of this file may be used under the terms of
      27                 :  * either the GNU General Public License Version 2 or later (the "GPL"), or
      28                 :  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      29                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      30                 :  * of those above. If you wish to allow use of your version of this file only
      31                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      32                 :  * use your version of this file under the terms of the MPL, indicate your
      33                 :  * decision by deleting the provisions above and replace them with the notice
      34                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      35                 :  * the provisions above, a recipient may use your version of this file under
      36                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      37                 :  *
      38                 :  * ***** END LICENSE BLOCK ***** */
      39                 : 
      40                 : #ifndef nsAccIterator_h_
      41                 : #define nsAccIterator_h_
      42                 : 
      43                 : #include "nsAccessibilityService.h"
      44                 : #include "filters.h"
      45                 : #include "nscore.h"
      46                 : #include "nsDocAccessible.h"
      47                 : 
      48                 : #include "nsIDOMDocumentXBL.h"
      49                 : 
      50                 : /**
      51                 :  * AccIterable is a basic interface for iterators over accessibles.
      52                 :  */
      53                 : class AccIterable
      54               0 : {
      55                 : public:
      56               0 :   virtual ~AccIterable() { }
      57                 :   virtual nsAccessible* Next() = 0;
      58                 : 
      59                 : private:
      60                 :   friend class Relation;
      61                 :   nsAutoPtr<AccIterable> mNextIter;
      62                 : };
      63                 : 
      64                 : /**
      65                 :  * Allows to iterate through accessible children or subtree complying with
      66                 :  * filter function.
      67                 :  */
      68                 : class AccIterator : public AccIterable
      69                 : {
      70                 : public:
      71                 :   /**
      72                 :    * Used to define iteration type.
      73                 :    */
      74                 :   enum IterationType {
      75                 :     /**
      76                 :      * Navigation happens through direct children.
      77                 :      */
      78                 :     eFlatNav,
      79                 : 
      80                 :     /**
      81                 :      * Navigation through subtree excluding iterator root; if the accessible
      82                 :      * complies with filter, iterator ignores its children.
      83                 :      */
      84                 :     eTreeNav
      85                 :   };
      86                 : 
      87                 :   AccIterator(nsAccessible* aRoot, filters::FilterFuncPtr aFilterFunc,
      88                 :               IterationType aIterationType = eFlatNav);
      89                 :   virtual ~AccIterator();
      90                 : 
      91                 :   /**
      92                 :    * Return next accessible complying with filter function. Return the first
      93                 :    * accessible for the first time.
      94                 :    */
      95                 :   virtual nsAccessible *Next();
      96                 : 
      97                 : private:
      98                 :   AccIterator();
      99                 :   AccIterator(const AccIterator&);
     100                 :   AccIterator& operator =(const AccIterator&);
     101                 : 
     102                 :   struct IteratorState
     103                 :   {
     104                 :     IteratorState(nsAccessible *aParent, IteratorState *mParentState = nsnull);
     105                 : 
     106                 :     nsAccessible *mParent;
     107                 :     PRInt32 mIndex;
     108                 :     IteratorState *mParentState;
     109                 :   };
     110                 : 
     111                 :   filters::FilterFuncPtr mFilterFunc;
     112                 :   bool mIsDeep;
     113                 :   IteratorState *mState;
     114                 : };
     115                 : 
     116                 : 
     117                 : /**
     118                 :  * Allows to traverse through related accessibles that are pointing to the given
     119                 :  * dependent accessible by relation attribute.
     120                 :  */
     121                 : class RelatedAccIterator : public AccIterable
     122                 : {
     123                 : public:
     124                 :   /**
     125                 :    * Constructor.
     126                 :    *
     127                 :    * @param aDocument         [in] the document accessible the related
     128                 :    * &                         accessibles belong to.
     129                 :    * @param aDependentContent [in] the content of dependent accessible that
     130                 :    *                           relations were requested for
     131                 :    * @param aRelAttr          [in] relation attribute that relations are
     132                 :    *                           pointed by
     133                 :    */
     134                 :   RelatedAccIterator(nsDocAccessible* aDocument, nsIContent* aDependentContent,
     135                 :                      nsIAtom* aRelAttr);
     136                 : 
     137               0 :   virtual ~RelatedAccIterator() { }
     138                 : 
     139                 :   /**
     140                 :    * Return next related accessible for the given dependent accessible.
     141                 :    */
     142                 :   virtual nsAccessible* Next();
     143                 : 
     144                 : private:
     145                 :   RelatedAccIterator();
     146                 :   RelatedAccIterator(const RelatedAccIterator&);
     147                 :   RelatedAccIterator& operator = (const RelatedAccIterator&);
     148                 : 
     149                 :   nsDocAccessible* mDocument;
     150                 :   nsIAtom* mRelAttr;
     151                 :   nsDocAccessible::AttrRelProviderArray* mProviders;
     152                 :   nsIContent* mBindingParent;
     153                 :   PRUint32 mIndex;
     154                 : };
     155                 : 
     156                 : 
     157                 : /**
     158                 :  * Used to iterate through HTML labels associated with the given accessible.
     159                 :  */
     160                 : class HTMLLabelIterator : public AccIterable
     161                 : {
     162                 : public:
     163                 :   enum LabelFilter {
     164                 :     eAllLabels,
     165                 :     eSkipAncestorLabel
     166                 :   };
     167                 : 
     168                 :   HTMLLabelIterator(nsDocAccessible* aDocument, const nsAccessible* aAccessible,
     169                 :                     LabelFilter aFilter = eAllLabels);
     170                 : 
     171               0 :   virtual ~HTMLLabelIterator() { }
     172                 : 
     173                 :   /**
     174                 :    * Return next label accessible associated with the given element.
     175                 :    */
     176                 :   virtual nsAccessible* Next();
     177                 : 
     178                 : private:
     179                 :   HTMLLabelIterator();
     180                 :   HTMLLabelIterator(const HTMLLabelIterator&);
     181                 :   HTMLLabelIterator& operator = (const HTMLLabelIterator&);
     182                 : 
     183                 :   RelatedAccIterator mRelIter;
     184                 :   // XXX: replace it on weak reference (bug 678429), it's safe to use raw
     185                 :   // pointer now because iterators life cycle is short.
     186                 :   const nsAccessible* mAcc;
     187                 :   LabelFilter mLabelFilter;
     188                 : };
     189                 : 
     190                 : 
     191                 : /**
     192                 :  * Used to iterate through HTML outputs associated with the given element.
     193                 :  */
     194                 : class HTMLOutputIterator : public AccIterable
     195                 : {
     196                 : public:
     197                 :   HTMLOutputIterator(nsDocAccessible* aDocument, nsIContent* aElement);
     198               0 :   virtual ~HTMLOutputIterator() { }
     199                 : 
     200                 :   /**
     201                 :    * Return next output accessible associated with the given element.
     202                 :    */
     203                 :   virtual nsAccessible* Next();
     204                 : 
     205                 : private:
     206                 :   HTMLOutputIterator();
     207                 :   HTMLOutputIterator(const HTMLOutputIterator&);
     208                 :   HTMLOutputIterator& operator = (const HTMLOutputIterator&);
     209                 : 
     210                 :   RelatedAccIterator mRelIter;
     211                 : };
     212                 : 
     213                 : 
     214                 : /**
     215                 :  * Used to iterate through XUL labels associated with the given element.
     216                 :  */
     217                 : class XULLabelIterator : public AccIterable
     218                 : {
     219                 : public:
     220                 :   XULLabelIterator(nsDocAccessible* aDocument, nsIContent* aElement);
     221               0 :   virtual ~XULLabelIterator() { }
     222                 : 
     223                 :   /**
     224                 :    * Return next label accessible associated with the given element.
     225                 :    */
     226                 :   virtual nsAccessible* Next();
     227                 : 
     228                 : private:
     229                 :   XULLabelIterator();
     230                 :   XULLabelIterator(const XULLabelIterator&);
     231                 :   XULLabelIterator& operator = (const XULLabelIterator&);
     232                 : 
     233                 :   RelatedAccIterator mRelIter;
     234                 : };
     235                 : 
     236                 : 
     237                 : /**
     238                 :  * Used to iterate through XUL descriptions associated with the given element.
     239                 :  */
     240                 : class XULDescriptionIterator : public AccIterable
     241                 : {
     242                 : public:
     243                 :   XULDescriptionIterator(nsDocAccessible* aDocument, nsIContent* aElement);
     244               0 :   virtual ~XULDescriptionIterator() { }
     245                 : 
     246                 :   /**
     247                 :    * Return next description accessible associated with the given element.
     248                 :    */
     249                 :   virtual nsAccessible* Next();
     250                 : 
     251                 : private:
     252                 :   XULDescriptionIterator();
     253                 :   XULDescriptionIterator(const XULDescriptionIterator&);
     254                 :   XULDescriptionIterator& operator = (const XULDescriptionIterator&);
     255                 : 
     256                 :   RelatedAccIterator mRelIter;
     257                 : };
     258                 : 
     259                 : /**
     260                 :  * Used to iterate through IDs, elements or accessibles pointed by IDRefs
     261                 :  * attribute. Note, any method used to iterate through IDs, elements, or
     262                 :  * accessibles moves iterator to next position.
     263                 :  */
     264                 : class IDRefsIterator : public AccIterable
     265                 : {
     266                 : public:
     267                 :   IDRefsIterator(nsIContent* aContent, nsIAtom* aIDRefsAttr);
     268               0 :   virtual ~IDRefsIterator() { }
     269                 : 
     270                 :   /**
     271                 :    * Return next ID.
     272                 :    */
     273                 :   const nsDependentSubstring NextID();
     274                 : 
     275                 :   /**
     276                 :    * Return next element.
     277                 :    */
     278                 :   nsIContent* NextElem();
     279                 : 
     280                 :   /**
     281                 :    * Return the element with the given ID.
     282                 :    */
     283                 :   nsIContent* GetElem(const nsDependentSubstring& aID);
     284                 : 
     285                 :   // AccIterable
     286                 :   virtual nsAccessible* Next();
     287                 : 
     288                 : private:
     289                 :   IDRefsIterator();
     290                 :   IDRefsIterator(const IDRefsIterator&);
     291                 :   IDRefsIterator operator = (const IDRefsIterator&);
     292                 : 
     293                 :   nsString mIDs;
     294                 :   nsAString::index_type mCurrIdx;
     295                 : 
     296                 :   nsIDocument* mDocument;
     297                 :   nsCOMPtr<nsIDOMDocumentXBL> mXBLDocument;
     298                 :   nsCOMPtr<nsIDOMElement> mBindingParent;
     299                 : };
     300                 : 
     301                 : /**
     302                 :  * Iterator that points to a single accessible returning it on the first call
     303                 :  * to Next().
     304                 :  */
     305                 : class SingleAccIterator : public AccIterable
     306                 : {
     307                 : public:
     308               0 :   SingleAccIterator(nsAccessible* aTarget): mAcc(aTarget) { }
     309               0 :   virtual ~SingleAccIterator() { }
     310                 : 
     311                 :   virtual nsAccessible* Next();
     312                 : 
     313                 : private:
     314                 :   SingleAccIterator();
     315                 :   SingleAccIterator(const SingleAccIterator&);
     316                 :   SingleAccIterator& operator = (const SingleAccIterator&);
     317                 : 
     318                 :   nsRefPtr<nsAccessible> mAcc;
     319                 : };
     320                 : 
     321                 : #endif

Generated by: LCOV version 1.7