LCOV - code coverage report
Current view: directory - accessible/src/xul - nsXULTreeAccessible.h (source / functions) Found Hit Coverage
Test: app.info Lines: 9 3 33.3 %
Date: 2012-06-02 Functions: 15 3 20.0 %

       1                 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       2                 : /* ***** BEGIN LICENSE BLOCK *****
       3                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
       4                 :  *
       5                 :  * The contents of this file are subject to the Mozilla Public License Version
       6                 :  * 1.1 (the "License"); you may not use this file except in compliance with
       7                 :  * the License. You may obtain a copy of the License at
       8                 :  * http://www.mozilla.org/MPL/
       9                 :  *
      10                 :  * Software distributed under the License is distributed on an "AS IS" basis,
      11                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      12                 :  * for the specific language governing rights and limitations under the
      13                 :  * License.
      14                 :  *
      15                 :  * The Original Code is mozilla.org code.
      16                 :  *
      17                 :  * The Initial Developer of the Original Code is
      18                 :  * Netscape Communications Corporation.
      19                 :  * Portions created by the Initial Developer are Copyright (C) 1998
      20                 :  * the Initial Developer. All Rights Reserved.
      21                 :  *
      22                 :  * Contributor(s):
      23                 :  *   Author: Kyle Yuan (kyle.yuan@sun.com)
      24                 :  *
      25                 :  * Alternatively, the contents of this file may be used under the terms of
      26                 :  * either of the GNU General Public License Version 2 or later (the "GPL"),
      27                 :  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      28                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      29                 :  * of those above. If you wish to allow use of your version of this file only
      30                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      31                 :  * use your version of this file under the terms of the MPL, indicate your
      32                 :  * decision by deleting the provisions above and replace them with the notice
      33                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      34                 :  * the provisions above, a recipient may use your version of this file under
      35                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      36                 :  *
      37                 :  * ***** END LICENSE BLOCK ***** */
      38                 : #ifndef __nsXULTreeAccessible_h__
      39                 : #define __nsXULTreeAccessible_h__
      40                 : 
      41                 : #include "nsITreeBoxObject.h"
      42                 : #include "nsITreeView.h"
      43                 : #include "nsITreeColumns.h"
      44                 : #include "nsXULListboxAccessible.h"
      45                 : 
      46                 : /*
      47                 :  * A class the represents the XUL Tree widget.
      48                 :  */
      49                 : const PRUint32 kMaxTreeColumns = 100;
      50                 : const PRUint32 kDefaultTreeCacheSize = 256;
      51                 : 
      52                 : /**
      53                 :  * Accessible class for XUL tree element.
      54                 :  */
      55                 : 
      56                 : #define NS_XULTREEACCESSIBLE_IMPL_CID                   \
      57                 : {  /* 2692e149-6176-42ee-b8e1-2c44b04185e3 */           \
      58                 :   0x2692e149,                                           \
      59                 :   0x6176,                                               \
      60                 :   0x42ee,                                               \
      61                 :   { 0xb8, 0xe1, 0x2c, 0x44, 0xb0, 0x41, 0x85, 0xe3 }    \
      62                 : }
      63                 : 
      64                 : class nsXULTreeAccessible : public nsAccessibleWrap
      65               0 : {
      66                 : public:
      67                 :   using nsAccessible::GetChildCount;
      68                 :   using nsAccessible::GetChildAt;
      69                 : 
      70                 :   nsXULTreeAccessible(nsIContent* aContent, nsDocAccessible* aDoc);
      71                 : 
      72                 :   // nsISupports and cycle collection
      73                 :   NS_DECL_ISUPPORTS_INHERITED
      74            1464 :   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsXULTreeAccessible,
      75                 :                                            nsAccessible)
      76                 : 
      77                 :   // nsIAccessible
      78                 :   NS_IMETHOD GetValue(nsAString& aValue);
      79                 : 
      80                 :   // nsAccessNode
      81                 :   virtual bool IsDefunct() const;
      82                 :   virtual void Shutdown();
      83                 : 
      84                 :   // nsAccessible
      85                 :   virtual mozilla::a11y::role NativeRole();
      86                 :   virtual PRUint64 NativeState();
      87                 :   virtual nsAccessible* ChildAtPoint(PRInt32 aX, PRInt32 aY,
      88                 :                                      EWhichChildAtPoint aWhichChild);
      89                 : 
      90                 :   virtual nsAccessible* GetChildAt(PRUint32 aIndex);
      91                 :   virtual PRInt32 GetChildCount();
      92                 : 
      93                 :   // SelectAccessible
      94                 :   virtual bool IsSelect();
      95                 :   virtual already_AddRefed<nsIArray> SelectedItems();
      96                 :   virtual PRUint32 SelectedItemCount();
      97                 :   virtual nsAccessible* GetSelectedItem(PRUint32 aIndex);
      98                 :   virtual bool IsItemSelected(PRUint32 aIndex);
      99                 :   virtual bool AddItemToSelection(PRUint32 aIndex);
     100                 :   virtual bool RemoveItemFromSelection(PRUint32 aIndex);
     101                 :   virtual bool SelectAll();
     102                 :   virtual bool UnselectAll();
     103                 : 
     104                 :   // Widgets
     105                 :   virtual bool IsWidget() const;
     106                 :   virtual bool IsActiveWidget() const;
     107                 :   virtual bool AreItemsOperable() const;
     108                 :   virtual nsAccessible* CurrentItem();
     109                 :   virtual void SetCurrentItem(nsAccessible* aItem);
     110                 : 
     111                 :   virtual nsAccessible* ContainerWidget() const;
     112                 : 
     113                 :   // nsXULTreeAccessible
     114                 : 
     115                 :   NS_DECLARE_STATIC_IID_ACCESSOR(NS_XULTREEACCESSIBLE_IMPL_CID)
     116                 : 
     117                 :   /**
     118                 :    * Return tree item accessible at the givem row. If accessible doesn't exist
     119                 :    * in the cache then create and cache it.
     120                 :    *
     121                 :    * @param aRow         [in] the given row index
     122                 :    */
     123                 :   nsAccessible* GetTreeItemAccessible(PRInt32 aRow);
     124                 : 
     125                 :   /**
     126                 :    * Invalidates the number of cached treeitem accessibles.
     127                 :    *
     128                 :    * @param aRow    [in] row index the invalidation starts from
     129                 :    * @param aCount  [in] the number of treeitem accessibles to invalidate,
     130                 :    *                 the number sign specifies whether rows have been
     131                 :    *                 inserted (plus) or removed (minus)
     132                 :    */
     133                 :   void InvalidateCache(PRInt32 aRow, PRInt32 aCount);
     134                 : 
     135                 :   /**
     136                 :    * Fires name change events for invalidated area of tree.
     137                 :    *
     138                 :    * @param aStartRow  [in] row index invalidation starts from
     139                 :    * @param aEndRow    [in] row index invalidation ends, -1 means last row index
     140                 :    * @param aStartCol  [in] column index invalidation starts from
     141                 :    * @param aEndCol    [in] column index invalidation ends, -1 mens last column
     142                 :    *                    index
     143                 :    */
     144                 :   void TreeViewInvalidated(PRInt32 aStartRow, PRInt32 aEndRow,
     145                 :                            PRInt32 aStartCol, PRInt32 aEndCol);
     146                 : 
     147                 :   /**
     148                 :    * Invalidates children created for previous tree view.
     149                 :    */
     150                 :   void TreeViewChanged();
     151                 : 
     152                 : protected:
     153                 :   /**
     154                 :    * Creates tree item accessible for the given row index.
     155                 :    */
     156                 :   virtual already_AddRefed<nsAccessible> CreateTreeItemAccessible(PRInt32 aRow);
     157                 : 
     158                 :   nsCOMPtr<nsITreeBoxObject> mTree;
     159                 :   nsCOMPtr<nsITreeView> mTreeView;
     160                 :   nsAccessibleHashtable mAccessibleCache;
     161                 : };
     162                 : 
     163                 : NS_DEFINE_STATIC_IID_ACCESSOR(nsXULTreeAccessible,
     164                 :                               NS_XULTREEACCESSIBLE_IMPL_CID)
     165                 : 
     166                 : /**
     167                 :  * Base class for tree item accessibles.
     168                 :  */
     169                 : 
     170                 : #define NS_XULTREEITEMBASEACCESSIBLE_IMPL_CID         \
     171                 : {  /* 1ab79ae7-766a-443c-940b-b1e6b0831dfc */         \
     172                 :   0x1ab79ae7,                                         \
     173                 :   0x766a,                                             \
     174                 :   0x443c,                                             \
     175                 :   { 0x94, 0x0b, 0xb1, 0xe6, 0xb0, 0x83, 0x1d, 0xfc }  \
     176                 : }
     177                 : 
     178                 : class nsXULTreeItemAccessibleBase : public nsAccessibleWrap
     179               0 : {
     180                 : public:
     181                 :   using nsAccessible::GetParent;
     182                 : 
     183                 :   nsXULTreeItemAccessibleBase(nsIContent* aContent, nsDocAccessible* aDoc,
     184                 :                               nsAccessible* aParent, nsITreeBoxObject* aTree,
     185                 :                               nsITreeView* aTreeView, PRInt32 aRow);
     186                 : 
     187                 :   // nsISupports and cycle collection
     188                 :   NS_DECL_ISUPPORTS_INHERITED
     189            4392 :   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsXULTreeItemAccessibleBase,
     190                 :                                            nsAccessibleWrap)
     191                 : 
     192                 :   // nsIAccessible
     193                 :   NS_IMETHOD GetBounds(PRInt32 *aX, PRInt32 *aY,
     194                 :                        PRInt32 *aWidth, PRInt32 *aHeight);
     195                 : 
     196                 :   NS_IMETHOD SetSelected(bool aSelect); 
     197                 :   NS_IMETHOD TakeFocus();
     198                 : 
     199                 :   NS_IMETHOD GroupPosition(PRInt32 *aGroupLevel,
     200                 :                            PRInt32 *aSimilarItemsInGroup,
     201                 :                            PRInt32 *aPositionInGroup);
     202                 : 
     203                 :   NS_IMETHOD GetActionName(PRUint8 aIndex, nsAString& aName);
     204                 :   NS_IMETHOD DoAction(PRUint8 aIndex);
     205                 : 
     206                 :   // nsAccessNode
     207                 :   virtual bool IsDefunct() const;
     208                 :   virtual void Shutdown();
     209                 :   virtual bool IsPrimaryForNode() const;
     210                 : 
     211                 :   // nsAccessible
     212                 :   virtual PRUint64 NativeState();
     213                 :   virtual PRInt32 IndexInParent() const;
     214                 :   virtual Relation RelationByType(PRUint32 aType);
     215                 :   virtual nsAccessible* FocusedChild();
     216                 : 
     217                 :   // ActionAccessible
     218                 :   virtual PRUint8 ActionCount();
     219                 : 
     220                 :   // Widgets
     221                 :   virtual nsAccessible* ContainerWidget() const;
     222                 : 
     223                 :   // nsXULTreeItemAccessibleBase
     224                 :   NS_DECLARE_STATIC_IID_ACCESSOR(NS_XULTREEITEMBASEACCESSIBLE_IMPL_CID)
     225                 : 
     226                 :   /**
     227                 :    * Return row index associated with the accessible.
     228                 :    */
     229                 :   PRInt32 GetRowIndex() const { return mRow; }
     230                 : 
     231                 :   /**
     232                 :    * Return cell accessible for the given column. If XUL tree accessible is not
     233                 :    * accessible table then return null.
     234                 :    */
     235               0 :   virtual nsAccessible* GetCellAccessible(nsITreeColumn *aColumn)
     236               0 :     { return nsnull; }
     237                 : 
     238                 :   /**
     239                 :    * Proccess row invalidation. Used to fires name change events.
     240                 :    */
     241                 :   virtual void RowInvalidated(PRInt32 aStartColIdx, PRInt32 aEndColIdx) = 0;
     242                 : 
     243                 : protected:
     244                 :   enum { eAction_Click = 0, eAction_Expand = 1 };
     245                 : 
     246                 :   // nsAccessible
     247                 :   virtual void DispatchClickEvent(nsIContent *aContent, PRUint32 aActionIndex);
     248                 :   virtual nsAccessible* GetSiblingAtOffset(PRInt32 aOffset,
     249                 :                                            nsresult *aError = nsnull) const;
     250                 : 
     251                 :   // nsXULTreeItemAccessibleBase
     252                 : 
     253                 :   /**
     254                 :    * Return true if the tree item accessible is expandable (contains subrows).
     255                 :    */
     256                 :   bool IsExpandable();
     257                 : 
     258                 :   /**
     259                 :    * Return name for cell at the given column.
     260                 :    */
     261                 :   void GetCellName(nsITreeColumn* aColumn, nsAString& aName);
     262                 : 
     263                 :   nsCOMPtr<nsITreeBoxObject> mTree;
     264                 :   nsCOMPtr<nsITreeView> mTreeView;
     265                 :   PRInt32 mRow;
     266                 : };
     267                 : 
     268                 : NS_DEFINE_STATIC_IID_ACCESSOR(nsXULTreeItemAccessibleBase,
     269                 :                               NS_XULTREEITEMBASEACCESSIBLE_IMPL_CID)
     270                 : 
     271                 : 
     272                 : /**
     273                 :  * Accessible class for items for XUL tree.
     274                 :  */
     275                 : class nsXULTreeItemAccessible : public nsXULTreeItemAccessibleBase
     276               0 : {
     277                 : public:
     278                 :   nsXULTreeItemAccessible(nsIContent* aContent, nsDocAccessible* aDoc,
     279                 :                           nsAccessible* aParent, nsITreeBoxObject* aTree,
     280                 :                           nsITreeView* aTreeView, PRInt32 aRow);
     281                 : 
     282                 :   // nsISupports and cycle collection
     283                 :   NS_DECL_ISUPPORTS_INHERITED
     284            1464 :   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsXULTreeItemAccessible,
     285                 :                                            nsXULTreeItemAccessibleBase)
     286                 : 
     287                 :   NS_IMETHOD GetName(nsAString& aName);
     288                 : 
     289                 :   // nsAccessNode
     290                 :   virtual bool IsDefunct() const;
     291                 :   virtual bool Init();
     292                 :   virtual void Shutdown();
     293                 : 
     294                 :   // nsAccessible
     295                 :   virtual mozilla::a11y::role NativeRole();
     296                 : 
     297                 :   // nsXULTreeItemAccessibleBase
     298                 :   virtual void RowInvalidated(PRInt32 aStartColIdx, PRInt32 aEndColIdx);
     299                 : 
     300                 : protected:
     301                 : 
     302                 :   // nsAccessible
     303                 :   virtual void CacheChildren();
     304                 : 
     305                 :   // nsXULTreeItemAccessible
     306                 :   nsCOMPtr<nsITreeColumn> mColumn;
     307                 :   nsString mCachedName;
     308                 : };
     309                 : 
     310                 : 
     311                 : /**
     312                 :  * Accessible class for columns element of XUL tree.
     313                 :  */
     314                 : class nsXULTreeColumnsAccessible : public nsXULColumnsAccessible
     315               0 : {
     316                 : public:
     317                 :   nsXULTreeColumnsAccessible(nsIContent* aContent, nsDocAccessible* aDoc);
     318                 : 
     319                 : protected:
     320                 : 
     321                 :   // nsAccessible
     322                 :   virtual nsAccessible* GetSiblingAtOffset(PRInt32 aOffset,
     323                 :                                            nsresult *aError = nsnull) const;
     324                 : };
     325                 : 
     326                 : #endif

Generated by: LCOV version 1.7