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"
13 #include "RemoteAccessible.h"
16 #include "mozilla/Likely.h"
18 using namespace mozilla
;
19 using namespace mozilla::a11y
;
22 static AtkObject
* refAtCB(AtkTable
* aTable
, gint aRowIdx
, gint aColIdx
) {
23 if (aRowIdx
< 0 || aColIdx
< 0) {
27 AtkObject
* cellAtkObj
= nullptr;
28 Accessible
* acc
= GetInternalObj(ATK_OBJECT(aTable
));
32 Accessible
* cell
= acc
->AsTable()->CellAt(aRowIdx
, aColIdx
);
37 cellAtkObj
= GetWrapperFor(cell
);
40 g_object_ref(cellAtkObj
);
46 static gint
getIndexAtCB(AtkTable
* aTable
, gint aRowIdx
, gint aColIdx
) {
47 if (aRowIdx
< 0 || aColIdx
< 0) {
51 Accessible
* acc
= GetInternalObj(ATK_OBJECT(aTable
));
55 return static_cast<gint
>(acc
->AsTable()->CellIndexAt(aRowIdx
, aColIdx
));
58 static gint
getColumnAtIndexCB(AtkTable
* aTable
, gint aIdx
) {
63 Accessible
* acc
= GetInternalObj(ATK_OBJECT(aTable
));
67 return static_cast<gint
>(acc
->AsTable()->ColIndexAt(aIdx
));
70 static gint
getRowAtIndexCB(AtkTable
* aTable
, gint aIdx
) {
75 Accessible
* acc
= GetInternalObj(ATK_OBJECT(aTable
));
79 return static_cast<gint
>(acc
->AsTable()->RowIndexAt(aIdx
));
82 static gint
getColumnCountCB(AtkTable
* aTable
) {
83 Accessible
* acc
= GetInternalObj(ATK_OBJECT(aTable
));
87 return static_cast<gint
>(acc
->AsTable()->ColCount());
90 static gint
getRowCountCB(AtkTable
* aTable
) {
91 Accessible
* acc
= GetInternalObj(ATK_OBJECT(aTable
));
95 return static_cast<gint
>(acc
->AsTable()->RowCount());
98 static gint
getColumnExtentAtCB(AtkTable
* aTable
, gint aRowIdx
, gint aColIdx
) {
99 if (aRowIdx
< 0 || aColIdx
< 0) {
103 Accessible
* acc
= GetInternalObj(ATK_OBJECT(aTable
));
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
));
115 return static_cast<gint
>(acc
->AsTable()->RowExtentAt(aRowIdx
, aColIdx
));
118 static AtkObject
* getCaptionCB(AtkTable
* aTable
) {
119 Accessible
* acc
= GetInternalObj(ATK_OBJECT(aTable
));
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
));
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
));
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
));
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
));
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.
173 static gint
getSelectedColumnsCB(AtkTable
* aTable
, gint
** aSelected
) {
174 *aSelected
= nullptr;
176 Accessible
* acc
= GetInternalObj(ATK_OBJECT(aTable
));
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());
187 NS_WARNING("OUT OF MEMORY");
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
));
201 AutoTArray
<uint32_t, 10> rows
;
202 acc
->AsTable()->SelectedRowIndices(&rows
);
204 gint
* atkRows
= g_new(gint
, rows
.Length());
206 NS_WARNING("OUT OF MEMORY");
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
));
220 return static_cast<gboolean
>(acc
->AsTable()->IsColSelected(aColIdx
));
223 static gboolean
isRowSelectedCB(AtkTable
* aTable
, gint aRowIdx
) {
224 Accessible
* acc
= GetInternalObj(ATK_OBJECT(aTable
));
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
));
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
;