Bug 1877642 - Disable browser_fullscreen-tab-close-race.js on apple_silicon !debug...
[gecko.git] / accessible / atk / nsMaiInterfaceTable.cpp
blobcfba9e78d15cc0ab92ec54d5fcab72ddcb040238
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "InterfaceInitFuncs.h"
9 #include "AccessibleWrap.h"
10 #include "mozilla/a11y/TableAccessible.h"
11 #include "nsAccessibilityService.h"
12 #include "nsMai.h"
13 #include "RemoteAccessible.h"
14 #include "nsTArray.h"
16 #include "mozilla/Likely.h"
18 using namespace mozilla;
19 using namespace mozilla::a11y;
21 extern "C" {
22 static AtkObject* refAtCB(AtkTable* aTable, gint aRowIdx, gint aColIdx) {
23 if (aRowIdx < 0 || aColIdx < 0) {
24 return nullptr;
27 AtkObject* cellAtkObj = nullptr;
28 Accessible* acc = GetInternalObj(ATK_OBJECT(aTable));
29 if (!acc) {
30 return nullptr;
32 Accessible* cell = acc->AsTable()->CellAt(aRowIdx, aColIdx);
33 if (!cell) {
34 return nullptr;
37 cellAtkObj = GetWrapperFor(cell);
39 if (cellAtkObj) {
40 g_object_ref(cellAtkObj);
43 return cellAtkObj;
46 static gint getIndexAtCB(AtkTable* aTable, gint aRowIdx, gint aColIdx) {
47 if (aRowIdx < 0 || aColIdx < 0) {
48 return -1;
51 Accessible* acc = GetInternalObj(ATK_OBJECT(aTable));
52 if (!acc) {
53 return -1;
55 return static_cast<gint>(acc->AsTable()->CellIndexAt(aRowIdx, aColIdx));
58 static gint getColumnAtIndexCB(AtkTable* aTable, gint aIdx) {
59 if (aIdx < 0) {
60 return -1;
63 Accessible* acc = GetInternalObj(ATK_OBJECT(aTable));
64 if (!acc) {
65 return -1;
67 return static_cast<gint>(acc->AsTable()->ColIndexAt(aIdx));
70 static gint getRowAtIndexCB(AtkTable* aTable, gint aIdx) {
71 if (aIdx < 0) {
72 return -1;
75 Accessible* acc = GetInternalObj(ATK_OBJECT(aTable));
76 if (!acc) {
77 return -1;
79 return static_cast<gint>(acc->AsTable()->RowIndexAt(aIdx));
82 static gint getColumnCountCB(AtkTable* aTable) {
83 Accessible* acc = GetInternalObj(ATK_OBJECT(aTable));
84 if (!acc) {
85 return -1;
87 return static_cast<gint>(acc->AsTable()->ColCount());
90 static gint getRowCountCB(AtkTable* aTable) {
91 Accessible* acc = GetInternalObj(ATK_OBJECT(aTable));
92 if (!acc) {
93 return -1;
95 return static_cast<gint>(acc->AsTable()->RowCount());
98 static gint getColumnExtentAtCB(AtkTable* aTable, gint aRowIdx, gint aColIdx) {
99 if (aRowIdx < 0 || aColIdx < 0) {
100 return -1;
103 Accessible* acc = GetInternalObj(ATK_OBJECT(aTable));
104 if (!acc) {
105 return -1;
107 return static_cast<gint>(acc->AsTable()->ColExtentAt(aRowIdx, aColIdx));
110 static gint getRowExtentAtCB(AtkTable* aTable, gint aRowIdx, gint aColIdx) {
111 Accessible* acc = GetInternalObj(ATK_OBJECT(aTable));
112 if (!acc) {
113 return -1;
115 return static_cast<gint>(acc->AsTable()->RowExtentAt(aRowIdx, aColIdx));
118 static AtkObject* getCaptionCB(AtkTable* aTable) {
119 Accessible* acc = GetInternalObj(ATK_OBJECT(aTable));
120 if (!acc) {
121 return nullptr;
123 Accessible* caption = acc->AsTable()->Caption();
124 return caption ? GetWrapperFor(caption) : nullptr;
127 static const gchar* getColumnDescriptionCB(AtkTable* aTable, gint aColumn) {
128 Accessible* acc = GetInternalObj(ATK_OBJECT(aTable));
129 if (!acc) {
130 return nullptr;
132 nsAutoString autoStr;
133 acc->AsTable()->ColDescription(aColumn, autoStr);
134 return AccessibleWrap::ReturnString(autoStr);
137 static AtkObject* getColumnHeaderCB(AtkTable* aTable, gint aColIdx) {
138 Accessible* acc = GetInternalObj(ATK_OBJECT(aTable));
139 if (!acc) {
140 return nullptr;
142 Accessible* header = AccessibleWrap::GetColumnHeader(acc->AsTable(), aColIdx);
143 return header ? GetWrapperFor(header) : nullptr;
146 static const gchar* getRowDescriptionCB(AtkTable* aTable, gint aRow) {
147 Accessible* acc = GetInternalObj(ATK_OBJECT(aTable));
148 if (!acc) {
149 return nullptr;
151 nsAutoString autoStr;
152 acc->AsTable()->RowDescription(aRow, autoStr);
153 return AccessibleWrap::ReturnString(autoStr);
156 static AtkObject* getRowHeaderCB(AtkTable* aTable, gint aRowIdx) {
157 Accessible* acc = GetInternalObj(ATK_OBJECT(aTable));
158 if (!acc) {
159 return nullptr;
161 Accessible* header = AccessibleWrap::GetRowHeader(acc->AsTable(), aRowIdx);
162 return header ? GetWrapperFor(header) : nullptr;
165 static AtkObject* getSummaryCB(AtkTable* aTable) {
166 // Neither html:table nor xul:tree nor ARIA grid/tree have an ability to
167 // link an accessible object to specify a summary. There is closes method
168 // in TableAccessible::summary to get a summary as a string which is not
169 // mapped directly to ATK.
170 return nullptr;
173 static gint getSelectedColumnsCB(AtkTable* aTable, gint** aSelected) {
174 *aSelected = nullptr;
176 Accessible* acc = GetInternalObj(ATK_OBJECT(aTable));
177 if (!acc) {
178 return 0;
180 AutoTArray<uint32_t, 10> cols;
181 acc->AsTable()->SelectedColIndices(&cols);
183 if (cols.IsEmpty()) return 0;
185 gint* atkColumns = g_new(gint, cols.Length());
186 if (!atkColumns) {
187 NS_WARNING("OUT OF MEMORY");
188 return 0;
191 memcpy(atkColumns, cols.Elements(), cols.Length() * sizeof(uint32_t));
192 *aSelected = atkColumns;
193 return cols.Length();
196 static gint getSelectedRowsCB(AtkTable* aTable, gint** aSelected) {
197 Accessible* acc = GetInternalObj(ATK_OBJECT(aTable));
198 if (!acc) {
199 return 0;
201 AutoTArray<uint32_t, 10> rows;
202 acc->AsTable()->SelectedRowIndices(&rows);
204 gint* atkRows = g_new(gint, rows.Length());
205 if (!atkRows) {
206 NS_WARNING("OUT OF MEMORY");
207 return 0;
210 memcpy(atkRows, rows.Elements(), rows.Length() * sizeof(uint32_t));
211 *aSelected = atkRows;
212 return rows.Length();
215 static gboolean isColumnSelectedCB(AtkTable* aTable, gint aColIdx) {
216 Accessible* acc = GetInternalObj(ATK_OBJECT(aTable));
217 if (!acc) {
218 return FALSE;
220 return static_cast<gboolean>(acc->AsTable()->IsColSelected(aColIdx));
223 static gboolean isRowSelectedCB(AtkTable* aTable, gint aRowIdx) {
224 Accessible* acc = GetInternalObj(ATK_OBJECT(aTable));
225 if (!acc) {
226 return FALSE;
228 return static_cast<gboolean>(acc->AsTable()->IsRowSelected(aRowIdx));
231 static gboolean isCellSelectedCB(AtkTable* aTable, gint aRowIdx, gint aColIdx) {
232 Accessible* acc = GetInternalObj(ATK_OBJECT(aTable));
233 if (!acc) {
234 return FALSE;
236 return static_cast<gboolean>(
237 acc->AsTable()->IsCellSelected(aRowIdx, aColIdx));
241 void tableInterfaceInitCB(AtkTableIface* aIface) {
242 NS_ASSERTION(aIface, "no interface!");
243 if (MOZ_UNLIKELY(!aIface)) return;
245 aIface->ref_at = refAtCB;
246 aIface->get_index_at = getIndexAtCB;
247 aIface->get_column_at_index = getColumnAtIndexCB;
248 aIface->get_row_at_index = getRowAtIndexCB;
249 aIface->get_n_columns = getColumnCountCB;
250 aIface->get_n_rows = getRowCountCB;
251 aIface->get_column_extent_at = getColumnExtentAtCB;
252 aIface->get_row_extent_at = getRowExtentAtCB;
253 aIface->get_caption = getCaptionCB;
254 aIface->get_column_description = getColumnDescriptionCB;
255 aIface->get_column_header = getColumnHeaderCB;
256 aIface->get_row_description = getRowDescriptionCB;
257 aIface->get_row_header = getRowHeaderCB;
258 aIface->get_summary = getSummaryCB;
259 aIface->get_selected_columns = getSelectedColumnsCB;
260 aIface->get_selected_rows = getSelectedRowsCB;
261 aIface->is_column_selected = isColumnSelectedCB;
262 aIface->is_row_selected = isRowSelectedCB;
263 aIface->is_selected = isCellSelectedCB;