accessible/src/xul/XULTreeAccessible.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 #ifndef mozilla_a11y_XULTreeAccessible_h__
     7 #define mozilla_a11y_XULTreeAccessible_h__
     9 #include "nsITreeBoxObject.h"
    10 #include "nsITreeView.h"
    11 #include "nsITreeColumns.h"
    12 #include "XULListboxAccessible.h"
    14 class nsTreeBodyFrame;
    16 namespace mozilla {
    17 namespace a11y {
    19 /*
    20  * A class the represents the XUL Tree widget.
    21  */
    22 const uint32_t kMaxTreeColumns = 100;
    23 const uint32_t kDefaultTreeCacheSize = 256;
    25 /**
    26  * Accessible class for XUL tree element.
    27  */
    29 class XULTreeAccessible : public AccessibleWrap
    30 {
    31 public:
    32   using Accessible::GetChildAt;
    34   XULTreeAccessible(nsIContent* aContent, DocAccessible* aDoc,
    35                     nsTreeBodyFrame* aTreeframe);
    37   // nsISupports and cycle collection
    38   NS_DECL_ISUPPORTS_INHERITED
    39   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(XULTreeAccessible, Accessible)
    41   // Accessible
    42   virtual void Shutdown();
    43   virtual void Value(nsString& aValue);
    44   virtual a11y::role NativeRole();
    45   virtual uint64_t NativeState();
    46   virtual Accessible* ChildAtPoint(int32_t aX, int32_t aY,
    47                                    EWhichChildAtPoint aWhichChild);
    49   virtual Accessible* GetChildAt(uint32_t aIndex) const MOZ_OVERRIDE;
    50   virtual uint32_t ChildCount() const MOZ_OVERRIDE;
    51   virtual Relation RelationByType(RelationType aType) MOZ_OVERRIDE;
    53   // SelectAccessible
    54   virtual already_AddRefed<nsIArray> SelectedItems();
    55   virtual uint32_t SelectedItemCount();
    56   virtual Accessible* GetSelectedItem(uint32_t aIndex);
    57   virtual bool IsItemSelected(uint32_t aIndex);
    58   virtual bool AddItemToSelection(uint32_t aIndex);
    59   virtual bool RemoveItemFromSelection(uint32_t aIndex);
    60   virtual bool SelectAll();
    61   virtual bool UnselectAll();
    63   // Widgets
    64   virtual bool IsWidget() const;
    65   virtual bool IsActiveWidget() const;
    66   virtual bool AreItemsOperable() const;
    67   virtual Accessible* CurrentItem();
    68   virtual void SetCurrentItem(Accessible* aItem);
    70   virtual Accessible* ContainerWidget() const;
    72   // XULTreeAccessible
    74   /**
    75    * Return tree item accessible at the givem row. If accessible doesn't exist
    76    * in the cache then create and cache it.
    77    *
    78    * @param aRow         [in] the given row index
    79    */
    80   Accessible* GetTreeItemAccessible(int32_t aRow) const;
    82   /**
    83    * Invalidates the number of cached treeitem accessibles.
    84    *
    85    * @param aRow    [in] row index the invalidation starts from
    86    * @param aCount  [in] the number of treeitem accessibles to invalidate,
    87    *                 the number sign specifies whether rows have been
    88    *                 inserted (plus) or removed (minus)
    89    */
    90   void InvalidateCache(int32_t aRow, int32_t aCount);
    92   /**
    93    * Fires name change events for invalidated area of tree.
    94    *
    95    * @param aStartRow  [in] row index invalidation starts from
    96    * @param aEndRow    [in] row index invalidation ends, -1 means last row index
    97    * @param aStartCol  [in] column index invalidation starts from
    98    * @param aEndCol    [in] column index invalidation ends, -1 mens last column
    99    *                    index
   100    */
   101   void TreeViewInvalidated(int32_t aStartRow, int32_t aEndRow,
   102                            int32_t aStartCol, int32_t aEndCol);
   104   /**
   105    * Invalidates children created for previous tree view.
   106    */
   107   void TreeViewChanged(nsITreeView* aView);
   109 protected:
   110   /**
   111    * Creates tree item accessible for the given row index.
   112    */
   113   virtual already_AddRefed<Accessible>
   114     CreateTreeItemAccessible(int32_t aRow) const;
   116   nsCOMPtr<nsITreeBoxObject> mTree;
   117   nsITreeView* mTreeView;
   118   mutable AccessibleHashtable mAccessibleCache;
   119 };
   121 /**
   122  * Base class for tree item accessibles.
   123  */
   125 #define XULTREEITEMBASEACCESSIBLE_IMPL_CID            \
   126 {  /* 1ab79ae7-766a-443c-940b-b1e6b0831dfc */         \
   127   0x1ab79ae7,                                         \
   128   0x766a,                                             \
   129   0x443c,                                             \
   130   { 0x94, 0x0b, 0xb1, 0xe6, 0xb0, 0x83, 0x1d, 0xfc }  \
   131 }
   133 class XULTreeItemAccessibleBase : public AccessibleWrap
   134 {
   135 public:
   136   using Accessible::GetParent;
   138   XULTreeItemAccessibleBase(nsIContent* aContent, DocAccessible* aDoc,
   139                             Accessible* aParent, nsITreeBoxObject* aTree,
   140                             nsITreeView* aTreeView, int32_t aRow);
   142   // nsISupports and cycle collection
   143   NS_DECL_ISUPPORTS_INHERITED
   144   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(XULTreeItemAccessibleBase,
   145                                            AccessibleWrap)
   147   // nsIAccessible
   148   NS_IMETHOD GetBounds(int32_t *aX, int32_t *aY,
   149                        int32_t *aWidth, int32_t *aHeight);
   151   NS_IMETHOD SetSelected(bool aSelect);
   152   NS_IMETHOD TakeFocus();
   154   NS_IMETHOD GetActionName(uint8_t aIndex, nsAString& aName);
   155   NS_IMETHOD DoAction(uint8_t aIndex);
   157   // Accessible
   158   virtual void Shutdown();
   159   virtual GroupPos GroupPosition();
   160   virtual uint64_t NativeState();
   161   virtual uint64_t NativeInteractiveState() const;
   162   virtual int32_t IndexInParent() const;
   163   virtual Relation RelationByType(RelationType aType) MOZ_OVERRIDE;
   164   virtual Accessible* FocusedChild();
   166   // ActionAccessible
   167   virtual uint8_t ActionCount();
   169   // Widgets
   170   virtual Accessible* ContainerWidget() const;
   172   // XULTreeItemAccessibleBase
   173   NS_DECLARE_STATIC_IID_ACCESSOR(XULTREEITEMBASEACCESSIBLE_IMPL_CID)
   175   /**
   176    * Return row index associated with the accessible.
   177    */
   178   int32_t GetRowIndex() const { return mRow; }
   180   /**
   181    * Return cell accessible for the given column. If XUL tree accessible is not
   182    * accessible table then return null.
   183    */
   184   virtual Accessible* GetCellAccessible(nsITreeColumn* aColumn) const
   185     { return nullptr; }
   187   /**
   188    * Proccess row invalidation. Used to fires name change events.
   189    */
   190   virtual void RowInvalidated(int32_t aStartColIdx, int32_t aEndColIdx) = 0;
   192 protected:
   193   enum { eAction_Click = 0, eAction_Expand = 1 };
   195   // Accessible
   196   virtual void DispatchClickEvent(nsIContent *aContent, uint32_t aActionIndex);
   197   virtual Accessible* GetSiblingAtOffset(int32_t aOffset,
   198                                          nsresult *aError = nullptr) const;
   200   // XULTreeItemAccessibleBase
   202   /**
   203    * Return true if the tree item accessible is expandable (contains subrows).
   204    */
   205   bool IsExpandable();
   207   /**
   208    * Return name for cell at the given column.
   209    */
   210   void GetCellName(nsITreeColumn* aColumn, nsAString& aName);
   212   nsCOMPtr<nsITreeBoxObject> mTree;
   213   nsITreeView* mTreeView;
   214   int32_t mRow;
   215 };
   217 NS_DEFINE_STATIC_IID_ACCESSOR(XULTreeItemAccessibleBase,
   218                               XULTREEITEMBASEACCESSIBLE_IMPL_CID)
   221 /**
   222  * Accessible class for items for XUL tree.
   223  */
   224 class XULTreeItemAccessible : public XULTreeItemAccessibleBase
   225 {
   226 public:
   227   XULTreeItemAccessible(nsIContent* aContent, DocAccessible* aDoc,
   228                         Accessible* aParent, nsITreeBoxObject* aTree,
   229                         nsITreeView* aTreeView, int32_t aRow);
   231   // nsISupports and cycle collection
   232   NS_DECL_ISUPPORTS_INHERITED
   233   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(XULTreeItemAccessible,
   234                                            XULTreeItemAccessibleBase)
   236   // Accessible
   237   virtual void Shutdown();
   238   virtual ENameValueFlag Name(nsString& aName);
   239   virtual a11y::role NativeRole();
   241   // XULTreeItemAccessibleBase
   242   virtual void RowInvalidated(int32_t aStartColIdx, int32_t aEndColIdx);
   244 protected:
   246   // Accessible
   247   virtual void CacheChildren();
   249   // XULTreeItemAccessible
   250   nsCOMPtr<nsITreeColumn> mColumn;
   251   nsString mCachedName;
   252 };
   255 /**
   256  * Accessible class for columns element of XUL tree.
   257  */
   258 class XULTreeColumAccessible : public XULColumAccessible
   259 {
   260 public:
   261   XULTreeColumAccessible(nsIContent* aContent, DocAccessible* aDoc);
   263 protected:
   265   // Accessible
   266   virtual Accessible* GetSiblingAtOffset(int32_t aOffset,
   267                                          nsresult *aError = nullptr) const;
   268 };
   271 ////////////////////////////////////////////////////////////////////////////////
   272 // Accessible downcasting method
   274 inline XULTreeAccessible*
   275 Accessible::AsXULTree()
   276 {
   277   return IsXULTree() ? static_cast<XULTreeAccessible*>(this) : nullptr;
   278 }
   280 } // namespace a11y
   281 } // namespace mozilla
   283 #endif

mercurial