XULTreeGridAccessible.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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_XULTreeGridAccessible_h__
  6. #define mozilla_a11y_XULTreeGridAccessible_h__
  7. #include "XULTreeAccessible.h"
  8. #include "TableAccessible.h"
  9. #include "TableCellAccessible.h"
  10. #include "xpcAccessibleTable.h"
  11. #include "xpcAccessibleTableCell.h"
  12. namespace mozilla {
  13. namespace a11y {
  14. class XULTreeGridCellAccessible;
  15. /**
  16. * Represents accessible for XUL tree in the case when it has multiple columns.
  17. */
  18. class XULTreeGridAccessible : public XULTreeAccessible,
  19. public TableAccessible
  20. {
  21. public:
  22. XULTreeGridAccessible(nsIContent* aContent, DocAccessible* aDoc,
  23. nsTreeBodyFrame* aTreeFrame) :
  24. XULTreeAccessible(aContent, aDoc, aTreeFrame)
  25. { mGenericTypes |= eTable; }
  26. // TableAccessible
  27. virtual uint32_t ColCount() override;
  28. virtual uint32_t RowCount() override;
  29. virtual Accessible* CellAt(uint32_t aRowIndex, uint32_t aColumnIndex) override;
  30. virtual void ColDescription(uint32_t aColIdx, nsString& aDescription) override;
  31. virtual bool IsColSelected(uint32_t aColIdx) override;
  32. virtual bool IsRowSelected(uint32_t aRowIdx) override;
  33. virtual bool IsCellSelected(uint32_t aRowIdx, uint32_t aColIdx) override;
  34. virtual uint32_t SelectedCellCount() override;
  35. virtual uint32_t SelectedColCount() override;
  36. virtual uint32_t SelectedRowCount() override;
  37. virtual void SelectedCells(nsTArray<Accessible*>* aCells) override;
  38. virtual void SelectedCellIndices(nsTArray<uint32_t>* aCells) override;
  39. virtual void SelectedColIndices(nsTArray<uint32_t>* aCols) override;
  40. virtual void SelectedRowIndices(nsTArray<uint32_t>* aRows) override;
  41. virtual void SelectRow(uint32_t aRowIdx) override;
  42. virtual void UnselectRow(uint32_t aRowIdx) override;
  43. virtual Accessible* AsAccessible() override { return this; }
  44. // Accessible
  45. virtual TableAccessible* AsTable() override { return this; }
  46. virtual a11y::role NativeRole() override;
  47. protected:
  48. virtual ~XULTreeGridAccessible();
  49. // XULTreeAccessible
  50. virtual already_AddRefed<Accessible>
  51. CreateTreeItemAccessible(int32_t aRow) const override;
  52. };
  53. /**
  54. * Represents accessible for XUL tree item in the case when XUL tree has
  55. * multiple columns.
  56. */
  57. class XULTreeGridRowAccessible final : public XULTreeItemAccessibleBase
  58. {
  59. public:
  60. using Accessible::GetChildAt;
  61. XULTreeGridRowAccessible(nsIContent* aContent, DocAccessible* aDoc,
  62. Accessible* aParent, nsITreeBoxObject* aTree,
  63. nsITreeView* aTreeView, int32_t aRow);
  64. // nsISupports and cycle collection
  65. NS_DECL_ISUPPORTS_INHERITED
  66. NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(XULTreeGridRowAccessible,
  67. XULTreeItemAccessibleBase)
  68. // Accessible
  69. virtual void Shutdown() override;
  70. virtual a11y::role NativeRole() override;
  71. virtual ENameValueFlag Name(nsString& aName) override;
  72. virtual Accessible* ChildAtPoint(int32_t aX, int32_t aY,
  73. EWhichChildAtPoint aWhichChild) override;
  74. virtual Accessible* GetChildAt(uint32_t aIndex) const override;
  75. virtual uint32_t ChildCount() const override;
  76. // XULTreeItemAccessibleBase
  77. virtual XULTreeGridCellAccessible* GetCellAccessible(nsITreeColumn* aColumn)
  78. const override final;
  79. virtual void RowInvalidated(int32_t aStartColIdx, int32_t aEndColIdx) override;
  80. protected:
  81. virtual ~XULTreeGridRowAccessible();
  82. // XULTreeItemAccessibleBase
  83. mutable nsRefPtrHashtable<nsPtrHashKey<const void>, XULTreeGridCellAccessible>
  84. mAccessibleCache;
  85. };
  86. /**
  87. * Represents an accessible for XUL tree cell in the case when XUL tree has
  88. * multiple columns.
  89. */
  90. class XULTreeGridCellAccessible : public LeafAccessible,
  91. public TableCellAccessible
  92. {
  93. public:
  94. XULTreeGridCellAccessible(nsIContent* aContent, DocAccessible* aDoc,
  95. XULTreeGridRowAccessible* aRowAcc,
  96. nsITreeBoxObject* aTree, nsITreeView* aTreeView,
  97. int32_t aRow, nsITreeColumn* aColumn);
  98. // nsISupports
  99. NS_DECL_ISUPPORTS_INHERITED
  100. NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(XULTreeGridCellAccessible,
  101. LeafAccessible)
  102. // Accessible
  103. virtual TableCellAccessible* AsTableCell() override { return this; }
  104. virtual nsIntRect Bounds() const override;
  105. virtual ENameValueFlag Name(nsString& aName) override;
  106. virtual Accessible* FocusedChild() override;
  107. virtual already_AddRefed<nsIPersistentProperties> NativeAttributes() override;
  108. virtual int32_t IndexInParent() const override;
  109. virtual Relation RelationByType(RelationType aType) override;
  110. virtual a11y::role NativeRole() override;
  111. virtual uint64_t NativeState() override;
  112. virtual uint64_t NativeInteractiveState() const override;
  113. // ActionAccessible
  114. virtual uint8_t ActionCount() override;
  115. virtual void ActionNameAt(uint8_t aIndex, nsAString& aName) override;
  116. virtual bool DoAction(uint8_t aIndex) override;
  117. // TableCellAccessible
  118. virtual TableAccessible* Table() const override;
  119. virtual uint32_t ColIdx() const override;
  120. virtual uint32_t RowIdx() const override;
  121. virtual void ColHeaderCells(nsTArray<Accessible*>* aHeaderCells) override;
  122. virtual void RowHeaderCells(nsTArray<Accessible*>* aCells) override { }
  123. virtual bool Selected() override;
  124. /**
  125. * Fire name or state change event if the accessible text or value has been
  126. * changed.
  127. * @return true if name has changed
  128. */
  129. bool CellInvalidated();
  130. protected:
  131. virtual ~XULTreeGridCellAccessible();
  132. // Accessible
  133. virtual Accessible* GetSiblingAtOffset(int32_t aOffset,
  134. nsresult* aError = nullptr) const override;
  135. virtual void DispatchClickEvent(nsIContent* aContent, uint32_t aActionIndex) override;
  136. // XULTreeGridCellAccessible
  137. /**
  138. * Return true if value of cell can be modified.
  139. */
  140. bool IsEditable() const;
  141. enum { eAction_Click = 0 };
  142. nsCOMPtr<nsITreeBoxObject> mTree;
  143. nsITreeView* mTreeView;
  144. int32_t mRow;
  145. nsCOMPtr<nsITreeColumn> mColumn;
  146. nsString mCachedTextEquiv;
  147. };
  148. } // namespace a11y
  149. } // namespace mozilla
  150. #endif