ia2AccessibleTableCell.cpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* vim:expandtab:shiftwidth=2:tabstop=2:
  3. */
  4. /* This Source Code Form is subject to the terms of the Mozilla Public
  5. * License, v. 2.0. If a copy of the MPL was not distributed with this
  6. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  7. #include "ia2AccessibleTableCell.h"
  8. #include "Accessible2.h"
  9. #include "AccessibleTable2_i.c"
  10. #include "AccessibleTableCell_i.c"
  11. #include "AccessibleWrap.h"
  12. #include "TableAccessible.h"
  13. #include "TableCellAccessible.h"
  14. #include "IUnknownImpl.h"
  15. #include "nsCOMPtr.h"
  16. #include "nsString.h"
  17. using namespace mozilla::a11y;
  18. // IUnknown
  19. STDMETHODIMP
  20. ia2AccessibleTableCell::QueryInterface(REFIID iid, void** ppv)
  21. {
  22. if (!ppv)
  23. return E_INVALIDARG;
  24. *ppv = nullptr;
  25. if (IID_IAccessibleTableCell == iid) {
  26. *ppv = static_cast<IAccessibleTableCell*>(this);
  27. (reinterpret_cast<IUnknown*>(*ppv))->AddRef();
  28. return S_OK;
  29. }
  30. return E_NOINTERFACE;
  31. }
  32. ////////////////////////////////////////////////////////////////////////////////
  33. // IAccessibleTableCell
  34. STDMETHODIMP
  35. ia2AccessibleTableCell::get_table(IUnknown** aTable)
  36. {
  37. if (!aTable)
  38. return E_INVALIDARG;
  39. *aTable = nullptr;
  40. if (!mTableCell)
  41. return CO_E_OBJNOTCONNECTED;
  42. TableAccessible* table = mTableCell->Table();
  43. if (!table)
  44. return E_FAIL;
  45. AccessibleWrap* wrap = static_cast<AccessibleWrap*>(table->AsAccessible());
  46. *aTable = static_cast<IAccessible*>(wrap);
  47. (*aTable)->AddRef();
  48. return S_OK;
  49. }
  50. STDMETHODIMP
  51. ia2AccessibleTableCell::get_columnExtent(long* aSpan)
  52. {
  53. if (!aSpan)
  54. return E_INVALIDARG;
  55. *aSpan = 0;
  56. if (!mTableCell)
  57. return CO_E_OBJNOTCONNECTED;
  58. *aSpan = mTableCell->ColExtent();
  59. return S_OK;
  60. }
  61. STDMETHODIMP
  62. ia2AccessibleTableCell::get_columnHeaderCells(IUnknown*** aCellAccessibles,
  63. long* aNColumnHeaderCells)
  64. {
  65. if (!aCellAccessibles || !aNColumnHeaderCells)
  66. return E_INVALIDARG;
  67. *aCellAccessibles = nullptr;
  68. *aNColumnHeaderCells = 0;
  69. if (!mTableCell)
  70. return CO_E_OBJNOTCONNECTED;
  71. AutoTArray<Accessible*, 10> cells;
  72. mTableCell->ColHeaderCells(&cells);
  73. *aNColumnHeaderCells = cells.Length();
  74. *aCellAccessibles =
  75. static_cast<IUnknown**>(::CoTaskMemAlloc(sizeof(IUnknown*) *
  76. cells.Length()));
  77. if (!*aCellAccessibles)
  78. return E_OUTOFMEMORY;
  79. for (uint32_t i = 0; i < cells.Length(); i++) {
  80. AccessibleWrap* cell = static_cast<AccessibleWrap*>(cells[i]);
  81. (*aCellAccessibles)[i] = static_cast<IAccessible*>(cell);
  82. (*aCellAccessibles)[i]->AddRef();
  83. }
  84. return S_OK;
  85. }
  86. STDMETHODIMP
  87. ia2AccessibleTableCell::get_columnIndex(long* aColIdx)
  88. {
  89. if (!aColIdx)
  90. return E_INVALIDARG;
  91. *aColIdx = -1;
  92. if (!mTableCell)
  93. return CO_E_OBJNOTCONNECTED;
  94. *aColIdx = mTableCell->ColIdx();
  95. return S_OK;
  96. }
  97. STDMETHODIMP
  98. ia2AccessibleTableCell::get_rowExtent(long* aSpan)
  99. {
  100. if (!aSpan)
  101. return E_INVALIDARG;
  102. *aSpan = 0;
  103. if (!mTableCell)
  104. return CO_E_OBJNOTCONNECTED;
  105. *aSpan = mTableCell->RowExtent();
  106. return S_OK;
  107. }
  108. STDMETHODIMP
  109. ia2AccessibleTableCell::get_rowHeaderCells(IUnknown*** aCellAccessibles,
  110. long* aNRowHeaderCells)
  111. {
  112. if (!aCellAccessibles || !aNRowHeaderCells)
  113. return E_INVALIDARG;
  114. *aCellAccessibles = nullptr;
  115. *aNRowHeaderCells = 0;
  116. if (!mTableCell)
  117. return CO_E_OBJNOTCONNECTED;
  118. AutoTArray<Accessible*, 10> cells;
  119. mTableCell->RowHeaderCells(&cells);
  120. *aNRowHeaderCells = cells.Length();
  121. *aCellAccessibles =
  122. static_cast<IUnknown**>(::CoTaskMemAlloc(sizeof(IUnknown*) *
  123. cells.Length()));
  124. if (!*aCellAccessibles)
  125. return E_OUTOFMEMORY;
  126. for (uint32_t i = 0; i < cells.Length(); i++) {
  127. AccessibleWrap* cell = static_cast<AccessibleWrap*>(cells[i]);
  128. (*aCellAccessibles)[i] = static_cast<IAccessible*>(cell);
  129. (*aCellAccessibles)[i]->AddRef();
  130. }
  131. return S_OK;
  132. }
  133. STDMETHODIMP
  134. ia2AccessibleTableCell::get_rowIndex(long* aRowIdx)
  135. {
  136. if (!aRowIdx)
  137. return E_INVALIDARG;
  138. *aRowIdx = -1;
  139. if (!mTableCell)
  140. return CO_E_OBJNOTCONNECTED;
  141. *aRowIdx = mTableCell->RowIdx();
  142. return S_OK;
  143. }
  144. STDMETHODIMP
  145. ia2AccessibleTableCell::get_rowColumnExtents(long* aRowIdx, long* aColIdx,
  146. long* aRowExtents,
  147. long* aColExtents,
  148. boolean* aIsSelected)
  149. {
  150. if (!aRowIdx || !aColIdx || !aRowExtents || !aColExtents || !aIsSelected)
  151. return E_INVALIDARG;
  152. *aRowIdx = *aColIdx = *aRowExtents = *aColExtents = 0;
  153. *aIsSelected = false;
  154. if (!mTableCell)
  155. return CO_E_OBJNOTCONNECTED;
  156. *aRowIdx = mTableCell->RowIdx();
  157. *aColIdx = mTableCell->ColIdx();
  158. *aRowExtents = mTableCell->RowExtent();
  159. *aColExtents = mTableCell->ColExtent();
  160. *aIsSelected = mTableCell->Selected();
  161. return S_OK;
  162. }
  163. STDMETHODIMP
  164. ia2AccessibleTableCell::get_isSelected(boolean* aIsSelected)
  165. {
  166. if (!aIsSelected)
  167. return E_INVALIDARG;
  168. *aIsSelected = false;
  169. if (!mTableCell)
  170. return CO_E_OBJNOTCONNECTED;
  171. *aIsSelected = mTableCell->Selected();
  172. return S_OK;
  173. }