XULTreeAccessible.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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/. */
  5. #ifndef mozilla_a11y_XULTreeAccessible_h__
  6. #define mozilla_a11y_XULTreeAccessible_h__
  7. #include "nsITreeBoxObject.h"
  8. #include "nsITreeView.h"
  9. #include "nsITreeColumns.h"
  10. #include "XULListboxAccessible.h"
  11. class nsTreeBodyFrame;
  12. namespace mozilla {
  13. namespace a11y {
  14. class XULTreeGridCellAccessible;
  15. /*
  16. * A class the represents the XUL Tree widget.
  17. */
  18. const uint32_t kMaxTreeColumns = 100;
  19. const uint32_t kDefaultTreeCacheLength = 128;
  20. /**
  21. * Accessible class for XUL tree element.
  22. */
  23. class XULTreeAccessible : public AccessibleWrap
  24. {
  25. public:
  26. XULTreeAccessible(nsIContent* aContent, DocAccessible* aDoc,
  27. nsTreeBodyFrame* aTreeframe);
  28. // nsISupports and cycle collection
  29. NS_DECL_ISUPPORTS_INHERITED
  30. NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(XULTreeAccessible, Accessible)
  31. // Accessible
  32. virtual void Shutdown() override;
  33. virtual void Value(nsString& aValue) override;
  34. virtual a11y::role NativeRole() override;
  35. virtual uint64_t NativeState() override;
  36. virtual Accessible* ChildAtPoint(int32_t aX, int32_t aY,
  37. EWhichChildAtPoint aWhichChild) override;
  38. virtual Accessible* GetChildAt(uint32_t aIndex) const override;
  39. virtual uint32_t ChildCount() const override;
  40. virtual Relation RelationByType(RelationType aType) override;
  41. // SelectAccessible
  42. virtual void SelectedItems(nsTArray<Accessible*>* aItems) override;
  43. virtual uint32_t SelectedItemCount() override;
  44. virtual Accessible* GetSelectedItem(uint32_t aIndex) override;
  45. virtual bool IsItemSelected(uint32_t aIndex) override;
  46. virtual bool AddItemToSelection(uint32_t aIndex) override;
  47. virtual bool RemoveItemFromSelection(uint32_t aIndex) override;
  48. virtual bool SelectAll() override;
  49. virtual bool UnselectAll() override;
  50. // Widgets
  51. virtual bool IsWidget() const override;
  52. virtual bool IsActiveWidget() const override;
  53. virtual bool AreItemsOperable() const override;
  54. virtual Accessible* CurrentItem() override;
  55. virtual void SetCurrentItem(Accessible* aItem) override;
  56. virtual Accessible* ContainerWidget() const override;
  57. // XULTreeAccessible
  58. /**
  59. * Return tree item accessible at the givem row. If accessible doesn't exist
  60. * in the cache then create and cache it.
  61. *
  62. * @param aRow [in] the given row index
  63. */
  64. Accessible* GetTreeItemAccessible(int32_t aRow) const;
  65. /**
  66. * Invalidates the number of cached treeitem accessibles.
  67. *
  68. * @param aRow [in] row index the invalidation starts from
  69. * @param aCount [in] the number of treeitem accessibles to invalidate,
  70. * the number sign specifies whether rows have been
  71. * inserted (plus) or removed (minus)
  72. */
  73. void InvalidateCache(int32_t aRow, int32_t aCount);
  74. /**
  75. * Fires name change events for invalidated area of tree.
  76. *
  77. * @param aStartRow [in] row index invalidation starts from
  78. * @param aEndRow [in] row index invalidation ends, -1 means last row index
  79. * @param aStartCol [in] column index invalidation starts from
  80. * @param aEndCol [in] column index invalidation ends, -1 mens last column
  81. * index
  82. */
  83. void TreeViewInvalidated(int32_t aStartRow, int32_t aEndRow,
  84. int32_t aStartCol, int32_t aEndCol);
  85. /**
  86. * Invalidates children created for previous tree view.
  87. */
  88. void TreeViewChanged(nsITreeView* aView);
  89. protected:
  90. virtual ~XULTreeAccessible();
  91. /**
  92. * Creates tree item accessible for the given row index.
  93. */
  94. virtual already_AddRefed<Accessible>
  95. CreateTreeItemAccessible(int32_t aRow) const;
  96. nsCOMPtr<nsITreeBoxObject> mTree;
  97. nsITreeView* mTreeView;
  98. mutable AccessibleHashtable mAccessibleCache;
  99. };
  100. /**
  101. * Base class for tree item accessibles.
  102. */
  103. #define XULTREEITEMBASEACCESSIBLE_IMPL_CID \
  104. { /* 1ab79ae7-766a-443c-940b-b1e6b0831dfc */ \
  105. 0x1ab79ae7, \
  106. 0x766a, \
  107. 0x443c, \
  108. { 0x94, 0x0b, 0xb1, 0xe6, 0xb0, 0x83, 0x1d, 0xfc } \
  109. }
  110. class XULTreeItemAccessibleBase : public AccessibleWrap
  111. {
  112. public:
  113. XULTreeItemAccessibleBase(nsIContent* aContent, DocAccessible* aDoc,
  114. Accessible* aParent, nsITreeBoxObject* aTree,
  115. nsITreeView* aTreeView, int32_t aRow);
  116. // nsISupports and cycle collection
  117. NS_DECL_ISUPPORTS_INHERITED
  118. NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(XULTreeItemAccessibleBase,
  119. AccessibleWrap)
  120. // Accessible
  121. virtual void Shutdown() override;
  122. virtual nsIntRect Bounds() const override;
  123. virtual GroupPos GroupPosition() override;
  124. virtual uint64_t NativeState() override;
  125. virtual uint64_t NativeInteractiveState() const override;
  126. virtual int32_t IndexInParent() const override;
  127. virtual Relation RelationByType(RelationType aType) override;
  128. virtual Accessible* FocusedChild() override;
  129. virtual void SetSelected(bool aSelect) override;
  130. virtual void TakeFocus() override;
  131. // ActionAccessible
  132. virtual uint8_t ActionCount() override;
  133. virtual void ActionNameAt(uint8_t aIndex, nsAString& aName) override;
  134. virtual bool DoAction(uint8_t aIndex) override;
  135. // Widgets
  136. virtual Accessible* ContainerWidget() const override;
  137. // XULTreeItemAccessibleBase
  138. NS_DECLARE_STATIC_IID_ACCESSOR(XULTREEITEMBASEACCESSIBLE_IMPL_CID)
  139. /**
  140. * Return row index associated with the accessible.
  141. */
  142. int32_t GetRowIndex() const { return mRow; }
  143. /**
  144. * Return cell accessible for the given column. If XUL tree accessible is not
  145. * accessible table then return null.
  146. */
  147. virtual XULTreeGridCellAccessible* GetCellAccessible(nsITreeColumn* aColumn) const
  148. { return nullptr; }
  149. /**
  150. * Proccess row invalidation. Used to fires name change events.
  151. */
  152. virtual void RowInvalidated(int32_t aStartColIdx, int32_t aEndColIdx) = 0;
  153. protected:
  154. virtual ~XULTreeItemAccessibleBase();
  155. enum { eAction_Click = 0, eAction_Expand = 1 };
  156. // Accessible
  157. virtual void DispatchClickEvent(nsIContent *aContent, uint32_t aActionIndex) override;
  158. virtual Accessible* GetSiblingAtOffset(int32_t aOffset,
  159. nsresult *aError = nullptr) const override;
  160. // XULTreeItemAccessibleBase
  161. /**
  162. * Return true if the tree item accessible is expandable (contains subrows).
  163. */
  164. bool IsExpandable();
  165. /**
  166. * Return name for cell at the given column.
  167. */
  168. void GetCellName(nsITreeColumn* aColumn, nsAString& aName);
  169. nsCOMPtr<nsITreeBoxObject> mTree;
  170. nsITreeView* mTreeView;
  171. int32_t mRow;
  172. };
  173. NS_DEFINE_STATIC_IID_ACCESSOR(XULTreeItemAccessibleBase,
  174. XULTREEITEMBASEACCESSIBLE_IMPL_CID)
  175. /**
  176. * Accessible class for items for XUL tree.
  177. */
  178. class XULTreeItemAccessible : public XULTreeItemAccessibleBase
  179. {
  180. public:
  181. XULTreeItemAccessible(nsIContent* aContent, DocAccessible* aDoc,
  182. Accessible* aParent, nsITreeBoxObject* aTree,
  183. nsITreeView* aTreeView, int32_t aRow);
  184. // nsISupports and cycle collection
  185. NS_DECL_ISUPPORTS_INHERITED
  186. NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(XULTreeItemAccessible,
  187. XULTreeItemAccessibleBase)
  188. // Accessible
  189. virtual void Shutdown() override;
  190. virtual ENameValueFlag Name(nsString& aName) override;
  191. virtual a11y::role NativeRole() override;
  192. // XULTreeItemAccessibleBase
  193. virtual void RowInvalidated(int32_t aStartColIdx, int32_t aEndColIdx) override;
  194. protected:
  195. virtual ~XULTreeItemAccessible();
  196. // XULTreeItemAccessible
  197. nsCOMPtr<nsITreeColumn> mColumn;
  198. nsString mCachedName;
  199. };
  200. /**
  201. * Accessible class for columns element of XUL tree.
  202. */
  203. class XULTreeColumAccessible : public XULColumAccessible
  204. {
  205. public:
  206. XULTreeColumAccessible(nsIContent* aContent, DocAccessible* aDoc);
  207. protected:
  208. // Accessible
  209. virtual Accessible* GetSiblingAtOffset(int32_t aOffset,
  210. nsresult* aError = nullptr) const
  211. override;
  212. };
  213. ////////////////////////////////////////////////////////////////////////////////
  214. // Accessible downcasting method
  215. inline XULTreeAccessible*
  216. Accessible::AsXULTree()
  217. {
  218. return IsXULTree() ? static_cast<XULTreeAccessible*>(this) : nullptr;
  219. }
  220. } // namespace a11y
  221. } // namespace mozilla
  222. #endif