ARIAGridAccessible.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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_ARIAGridAccessible_h_
  6. #define MOZILLA_A11Y_ARIAGridAccessible_h_
  7. #include "HyperTextAccessibleWrap.h"
  8. #include "TableAccessible.h"
  9. #include "TableCellAccessible.h"
  10. namespace mozilla {
  11. namespace a11y {
  12. /**
  13. * Accessible for ARIA grid and treegrid.
  14. */
  15. class ARIAGridAccessible : public AccessibleWrap,
  16. public TableAccessible
  17. {
  18. public:
  19. ARIAGridAccessible(nsIContent* aContent, DocAccessible* aDoc);
  20. NS_DECL_ISUPPORTS_INHERITED
  21. // Accessible
  22. virtual TableAccessible* AsTable() override { return this; }
  23. // TableAccessible
  24. virtual uint32_t ColCount() override;
  25. virtual uint32_t RowCount() override;
  26. virtual Accessible* CellAt(uint32_t aRowIndex, uint32_t aColumnIndex) override;
  27. virtual bool IsColSelected(uint32_t aColIdx) override;
  28. virtual bool IsRowSelected(uint32_t aRowIdx) override;
  29. virtual bool IsCellSelected(uint32_t aRowIdx, uint32_t aColIdx) override;
  30. virtual uint32_t SelectedCellCount() override;
  31. virtual uint32_t SelectedColCount() override;
  32. virtual uint32_t SelectedRowCount() override;
  33. virtual void SelectedCells(nsTArray<Accessible*>* aCells) override;
  34. virtual void SelectedCellIndices(nsTArray<uint32_t>* aCells) override;
  35. virtual void SelectedColIndices(nsTArray<uint32_t>* aCols) override;
  36. virtual void SelectedRowIndices(nsTArray<uint32_t>* aRows) override;
  37. virtual void SelectCol(uint32_t aColIdx) override;
  38. virtual void SelectRow(uint32_t aRowIdx) override;
  39. virtual void UnselectCol(uint32_t aColIdx) override;
  40. virtual void UnselectRow(uint32_t aRowIdx) override;
  41. virtual Accessible* AsAccessible() override { return this; }
  42. protected:
  43. virtual ~ARIAGridAccessible() {}
  44. /**
  45. * Return row accessible at the given row index.
  46. */
  47. Accessible* GetRowAt(int32_t aRow);
  48. /**
  49. * Return cell accessible at the given column index in the row.
  50. */
  51. Accessible* GetCellInRowAt(Accessible* aRow, int32_t aColumn);
  52. /**
  53. * Set aria-selected attribute value on DOM node of the given accessible.
  54. *
  55. * @param aAccessible [in] accessible
  56. * @param aIsSelected [in] new value of aria-selected attribute
  57. * @param aNotify [in, optional] specifies if DOM should be notified
  58. * about attribute change (used internally).
  59. */
  60. nsresult SetARIASelected(Accessible* aAccessible, bool aIsSelected,
  61. bool aNotify = true);
  62. };
  63. /**
  64. * Accessible for ARIA row.
  65. */
  66. class ARIARowAccessible : public AccessibleWrap
  67. {
  68. public:
  69. ARIARowAccessible(nsIContent* aContent, DocAccessible* aDoc);
  70. NS_DECL_ISUPPORTS_INHERITED
  71. // Accessible
  72. virtual mozilla::a11y::GroupPos GroupPosition() override;
  73. protected:
  74. virtual ~ARIARowAccessible() {}
  75. };
  76. /**
  77. * Accessible for ARIA gridcell and rowheader/columnheader.
  78. */
  79. class ARIAGridCellAccessible : public HyperTextAccessibleWrap,
  80. public TableCellAccessible
  81. {
  82. public:
  83. ARIAGridCellAccessible(nsIContent* aContent, DocAccessible* aDoc);
  84. NS_DECL_ISUPPORTS_INHERITED
  85. // Accessible
  86. virtual TableCellAccessible* AsTableCell() override { return this; }
  87. virtual void ApplyARIAState(uint64_t* aState) const override;
  88. virtual already_AddRefed<nsIPersistentProperties> NativeAttributes() override;
  89. virtual mozilla::a11y::GroupPos GroupPosition() override;
  90. protected:
  91. virtual ~ARIAGridCellAccessible() {}
  92. /**
  93. * Return a containing row.
  94. */
  95. Accessible* Row() const
  96. {
  97. Accessible* row = Parent();
  98. return row && row->IsTableRow() ? row : nullptr;
  99. }
  100. /**
  101. * Return index of the given row.
  102. */
  103. int32_t RowIndexFor(Accessible* aRow) const;
  104. // TableCellAccessible
  105. virtual TableAccessible* Table() const override;
  106. virtual uint32_t ColIdx() const override;
  107. virtual uint32_t RowIdx() const override;
  108. virtual bool Selected() override;
  109. };
  110. } // namespace a11y
  111. } // namespace mozilla
  112. #endif