|
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 file, |
|
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
6 |
|
7 #include "xpcAccessibleTable.h" |
|
8 |
|
9 #include "Accessible.h" |
|
10 #include "TableAccessible.h" |
|
11 |
|
12 #include "nsIMutableArray.h" |
|
13 #include "nsComponentManagerUtils.h" |
|
14 |
|
15 using namespace mozilla::a11y; |
|
16 |
|
17 static const uint32_t XPC_TABLE_DEFAULT_SIZE = 40; |
|
18 |
|
19 nsresult |
|
20 xpcAccessibleTable::GetCaption(nsIAccessible** aCaption) |
|
21 { |
|
22 NS_ENSURE_ARG_POINTER(aCaption); |
|
23 *aCaption = nullptr; |
|
24 if (!mTable) |
|
25 return NS_ERROR_FAILURE; |
|
26 |
|
27 NS_IF_ADDREF(*aCaption = mTable->Caption()); |
|
28 return NS_OK; |
|
29 } |
|
30 |
|
31 nsresult |
|
32 xpcAccessibleTable::GetColumnCount(int32_t* aColumnCount) |
|
33 { |
|
34 NS_ENSURE_ARG_POINTER(aColumnCount); |
|
35 *aColumnCount = 0; |
|
36 |
|
37 if (!mTable) |
|
38 return NS_ERROR_FAILURE; |
|
39 |
|
40 *aColumnCount = mTable->ColCount(); |
|
41 return NS_OK; |
|
42 } |
|
43 |
|
44 nsresult |
|
45 xpcAccessibleTable::GetRowCount(int32_t* aRowCount) |
|
46 { |
|
47 NS_ENSURE_ARG_POINTER(aRowCount); |
|
48 *aRowCount = 0; |
|
49 |
|
50 if (!mTable) |
|
51 return NS_ERROR_FAILURE; |
|
52 |
|
53 *aRowCount = mTable->RowCount(); |
|
54 return NS_OK; |
|
55 } |
|
56 |
|
57 nsresult |
|
58 xpcAccessibleTable::GetCellAt(int32_t aRowIdx, int32_t aColIdx, |
|
59 nsIAccessible** aCell) |
|
60 { |
|
61 NS_ENSURE_ARG_POINTER(aCell); |
|
62 *aCell = nullptr; |
|
63 |
|
64 if (!mTable) |
|
65 return NS_ERROR_FAILURE; |
|
66 |
|
67 if (aRowIdx < 0 || static_cast<uint32_t>(aRowIdx) >= mTable->RowCount() || |
|
68 aColIdx < 0 || static_cast<uint32_t>(aColIdx) >= mTable->ColCount()) |
|
69 return NS_ERROR_INVALID_ARG; |
|
70 |
|
71 NS_IF_ADDREF(*aCell = mTable->CellAt(aRowIdx, aColIdx)); |
|
72 return NS_OK; |
|
73 } |
|
74 |
|
75 nsresult |
|
76 xpcAccessibleTable::GetCellIndexAt(int32_t aRowIdx, int32_t aColIdx, |
|
77 int32_t* aCellIdx) |
|
78 { |
|
79 NS_ENSURE_ARG_POINTER(aCellIdx); |
|
80 *aCellIdx = -1; |
|
81 |
|
82 if (!mTable) |
|
83 return NS_ERROR_FAILURE; |
|
84 |
|
85 if (aRowIdx < 0 || static_cast<uint32_t>(aRowIdx) >= mTable->RowCount() || |
|
86 aColIdx < 0 || static_cast<uint32_t>(aColIdx) >= mTable->ColCount()) |
|
87 return NS_ERROR_INVALID_ARG; |
|
88 |
|
89 *aCellIdx = mTable->CellIndexAt(aRowIdx, aColIdx); |
|
90 return NS_OK; |
|
91 } |
|
92 |
|
93 nsresult |
|
94 xpcAccessibleTable::GetColumnExtentAt(int32_t aRowIdx, int32_t aColIdx, |
|
95 int32_t* aColumnExtent) |
|
96 { |
|
97 NS_ENSURE_ARG_POINTER(aColumnExtent); |
|
98 *aColumnExtent = -1; |
|
99 |
|
100 if (!mTable) |
|
101 return NS_ERROR_FAILURE; |
|
102 |
|
103 if (aRowIdx < 0 || static_cast<uint32_t>(aRowIdx) >= mTable->RowCount() || |
|
104 aColIdx < 0 || static_cast<uint32_t>(aColIdx) >= mTable->ColCount()) |
|
105 return NS_ERROR_INVALID_ARG; |
|
106 |
|
107 *aColumnExtent = mTable->ColExtentAt(aRowIdx, aColIdx); |
|
108 return NS_OK; |
|
109 } |
|
110 |
|
111 nsresult |
|
112 xpcAccessibleTable::GetRowExtentAt(int32_t aRowIdx, int32_t aColIdx, |
|
113 int32_t* aRowExtent) |
|
114 { |
|
115 NS_ENSURE_ARG_POINTER(aRowExtent); |
|
116 *aRowExtent = -1; |
|
117 |
|
118 if (!mTable) |
|
119 return NS_ERROR_FAILURE; |
|
120 |
|
121 if (aRowIdx < 0 || static_cast<uint32_t>(aRowIdx) >= mTable->RowCount() || |
|
122 aColIdx < 0 || static_cast<uint32_t>(aColIdx) >= mTable->ColCount()) |
|
123 return NS_ERROR_INVALID_ARG; |
|
124 |
|
125 *aRowExtent = mTable->RowExtentAt(aRowIdx, aColIdx); |
|
126 return NS_OK; |
|
127 } |
|
128 |
|
129 nsresult |
|
130 xpcAccessibleTable::GetColumnDescription(int32_t aColIdx, |
|
131 nsAString& aDescription) |
|
132 { |
|
133 if (!mTable) |
|
134 return NS_ERROR_FAILURE; |
|
135 |
|
136 if (aColIdx < 0 || static_cast<uint32_t>(aColIdx) >= mTable->ColCount()) |
|
137 return NS_ERROR_INVALID_ARG; |
|
138 |
|
139 nsAutoString description; |
|
140 mTable->ColDescription(aColIdx, description); |
|
141 aDescription.Assign(description); |
|
142 |
|
143 return NS_OK; |
|
144 } |
|
145 |
|
146 nsresult |
|
147 xpcAccessibleTable::GetRowDescription(int32_t aRowIdx, nsAString& aDescription) |
|
148 { |
|
149 if (!mTable) |
|
150 return NS_ERROR_FAILURE; |
|
151 |
|
152 if (aRowIdx < 0 || static_cast<uint32_t>(aRowIdx) >= mTable->ColCount()) |
|
153 return NS_ERROR_INVALID_ARG; |
|
154 |
|
155 nsAutoString description; |
|
156 mTable->RowDescription(aRowIdx, description); |
|
157 aDescription.Assign(description); |
|
158 |
|
159 return NS_OK; |
|
160 } |
|
161 |
|
162 nsresult |
|
163 xpcAccessibleTable::IsColumnSelected(int32_t aColIdx, bool* aIsSelected) |
|
164 { |
|
165 NS_ENSURE_ARG_POINTER(aIsSelected); |
|
166 *aIsSelected = false; |
|
167 |
|
168 if (!mTable) |
|
169 return NS_ERROR_FAILURE; |
|
170 |
|
171 if (aColIdx < 0 || static_cast<uint32_t>(aColIdx) >= mTable->ColCount()) |
|
172 return NS_ERROR_INVALID_ARG; |
|
173 |
|
174 *aIsSelected = mTable->IsColSelected(aColIdx); |
|
175 return NS_OK; |
|
176 } |
|
177 |
|
178 nsresult |
|
179 xpcAccessibleTable::IsRowSelected(int32_t aRowIdx, bool* aIsSelected) |
|
180 { |
|
181 NS_ENSURE_ARG_POINTER(aIsSelected); |
|
182 *aIsSelected = false; |
|
183 |
|
184 if (!mTable) |
|
185 return NS_ERROR_FAILURE; |
|
186 |
|
187 if (aRowIdx < 0 || static_cast<uint32_t>(aRowIdx) >= mTable->RowCount()) |
|
188 return NS_ERROR_INVALID_ARG; |
|
189 |
|
190 *aIsSelected = mTable->IsRowSelected(aRowIdx); |
|
191 return NS_OK; |
|
192 } |
|
193 |
|
194 nsresult |
|
195 xpcAccessibleTable::IsCellSelected(int32_t aRowIdx, int32_t aColIdx, |
|
196 bool* aIsSelected) |
|
197 { |
|
198 NS_ENSURE_ARG_POINTER(aIsSelected); |
|
199 *aIsSelected = false; |
|
200 |
|
201 if (!mTable) |
|
202 return NS_ERROR_FAILURE; |
|
203 |
|
204 if (aRowIdx < 0 || static_cast<uint32_t>(aRowIdx) >= mTable->RowCount() || |
|
205 aColIdx < 0 || static_cast<uint32_t>(aColIdx) >= mTable->ColCount()) |
|
206 return NS_ERROR_INVALID_ARG; |
|
207 |
|
208 *aIsSelected = mTable->IsCellSelected(aRowIdx, aColIdx); |
|
209 return NS_OK; |
|
210 } |
|
211 |
|
212 nsresult |
|
213 xpcAccessibleTable::GetSelectedCellCount(uint32_t* aSelectedCellCount) |
|
214 { |
|
215 NS_ENSURE_ARG_POINTER(aSelectedCellCount); |
|
216 *aSelectedCellCount = 0; |
|
217 |
|
218 if (!mTable) |
|
219 return NS_ERROR_FAILURE; |
|
220 |
|
221 *aSelectedCellCount = mTable->SelectedCellCount(); |
|
222 return NS_OK; |
|
223 } |
|
224 |
|
225 nsresult |
|
226 xpcAccessibleTable::GetSelectedColumnCount(uint32_t* aSelectedColumnCount) |
|
227 { |
|
228 NS_ENSURE_ARG_POINTER(aSelectedColumnCount); |
|
229 *aSelectedColumnCount = 0; |
|
230 |
|
231 if (!mTable) |
|
232 return NS_ERROR_FAILURE; |
|
233 |
|
234 *aSelectedColumnCount = mTable->SelectedColCount(); |
|
235 return NS_OK; |
|
236 } |
|
237 |
|
238 nsresult |
|
239 xpcAccessibleTable::GetSelectedRowCount(uint32_t* aSelectedRowCount) |
|
240 { |
|
241 NS_ENSURE_ARG_POINTER(aSelectedRowCount); |
|
242 *aSelectedRowCount = 0; |
|
243 |
|
244 if (!mTable) |
|
245 return NS_ERROR_FAILURE; |
|
246 |
|
247 *aSelectedRowCount = mTable->SelectedRowCount(); |
|
248 return NS_OK; |
|
249 } |
|
250 |
|
251 nsresult |
|
252 xpcAccessibleTable::GetSelectedCells(nsIArray** aSelectedCells) |
|
253 { |
|
254 NS_ENSURE_ARG_POINTER(aSelectedCells); |
|
255 *aSelectedCells = nullptr; |
|
256 |
|
257 if (!mTable) |
|
258 return NS_ERROR_FAILURE; |
|
259 |
|
260 nsresult rv = NS_OK; |
|
261 nsCOMPtr<nsIMutableArray> selCells = |
|
262 do_CreateInstance(NS_ARRAY_CONTRACTID, &rv); |
|
263 NS_ENSURE_SUCCESS(rv, rv); |
|
264 |
|
265 nsAutoTArray<Accessible*, XPC_TABLE_DEFAULT_SIZE> cellsArray; |
|
266 mTable->SelectedCells(&cellsArray); |
|
267 |
|
268 uint32_t totalCount = cellsArray.Length(); |
|
269 for (uint32_t idx = 0; idx < totalCount; idx++) { |
|
270 Accessible* cell = cellsArray.ElementAt(idx); |
|
271 selCells -> AppendElement(static_cast<nsIAccessible*>(cell), false); |
|
272 } |
|
273 |
|
274 NS_ADDREF(*aSelectedCells = selCells); |
|
275 return NS_OK; |
|
276 } |
|
277 |
|
278 nsresult |
|
279 xpcAccessibleTable::GetSelectedCellIndices(uint32_t* aCellsArraySize, |
|
280 int32_t** aCellsArray) |
|
281 { |
|
282 NS_ENSURE_ARG_POINTER(aCellsArraySize); |
|
283 *aCellsArraySize = 0; |
|
284 |
|
285 NS_ENSURE_ARG_POINTER(aCellsArray); |
|
286 *aCellsArray = 0; |
|
287 |
|
288 if (!mTable) |
|
289 return NS_ERROR_FAILURE; |
|
290 |
|
291 nsAutoTArray<uint32_t, XPC_TABLE_DEFAULT_SIZE> cellsArray; |
|
292 mTable->SelectedCellIndices(&cellsArray); |
|
293 |
|
294 *aCellsArraySize = cellsArray.Length(); |
|
295 *aCellsArray = static_cast<int32_t*> |
|
296 (moz_xmalloc(*aCellsArraySize * sizeof(int32_t))); |
|
297 memcpy(*aCellsArray, cellsArray.Elements(), |
|
298 *aCellsArraySize * sizeof(int32_t)); |
|
299 |
|
300 return NS_OK; |
|
301 } |
|
302 |
|
303 nsresult |
|
304 xpcAccessibleTable::GetSelectedColumnIndices(uint32_t* aColsArraySize, |
|
305 int32_t** aColsArray) |
|
306 { |
|
307 NS_ENSURE_ARG_POINTER(aColsArraySize); |
|
308 *aColsArraySize = 0; |
|
309 |
|
310 NS_ENSURE_ARG_POINTER(aColsArray); |
|
311 *aColsArray = 0; |
|
312 |
|
313 if (!mTable) |
|
314 return NS_ERROR_FAILURE; |
|
315 |
|
316 nsAutoTArray<uint32_t, XPC_TABLE_DEFAULT_SIZE> colsArray; |
|
317 mTable->SelectedColIndices(&colsArray); |
|
318 |
|
319 *aColsArraySize = colsArray.Length(); |
|
320 *aColsArray = static_cast<int32_t*> |
|
321 (moz_xmalloc(*aColsArraySize * sizeof(int32_t))); |
|
322 memcpy(*aColsArray, colsArray.Elements(), |
|
323 *aColsArraySize * sizeof(int32_t)); |
|
324 |
|
325 return NS_OK; |
|
326 } |
|
327 |
|
328 nsresult |
|
329 xpcAccessibleTable::GetSelectedRowIndices(uint32_t* aRowsArraySize, |
|
330 int32_t** aRowsArray) |
|
331 { |
|
332 NS_ENSURE_ARG_POINTER(aRowsArraySize); |
|
333 *aRowsArraySize = 0; |
|
334 |
|
335 NS_ENSURE_ARG_POINTER(aRowsArray); |
|
336 *aRowsArray = 0; |
|
337 |
|
338 if (!mTable) |
|
339 return NS_ERROR_FAILURE; |
|
340 |
|
341 nsAutoTArray<uint32_t, XPC_TABLE_DEFAULT_SIZE> rowsArray; |
|
342 mTable->SelectedRowIndices(&rowsArray); |
|
343 |
|
344 *aRowsArraySize = rowsArray.Length(); |
|
345 *aRowsArray = static_cast<int32_t*> |
|
346 (moz_xmalloc(*aRowsArraySize * sizeof(int32_t))); |
|
347 memcpy(*aRowsArray, rowsArray.Elements(), |
|
348 *aRowsArraySize * sizeof(int32_t)); |
|
349 |
|
350 return NS_OK; |
|
351 } |
|
352 |
|
353 nsresult |
|
354 xpcAccessibleTable::GetColumnIndexAt(int32_t aCellIdx, int32_t* aColIdx) |
|
355 { |
|
356 NS_ENSURE_ARG_POINTER(aColIdx); |
|
357 *aColIdx = -1; |
|
358 |
|
359 if (!mTable) |
|
360 return NS_ERROR_FAILURE; |
|
361 |
|
362 if (aCellIdx < 0 |
|
363 || static_cast<uint32_t>(aCellIdx) |
|
364 >= mTable->RowCount() * mTable->ColCount()) |
|
365 return NS_ERROR_INVALID_ARG; |
|
366 |
|
367 *aColIdx = mTable->ColIndexAt(aCellIdx); |
|
368 return NS_OK; |
|
369 } |
|
370 |
|
371 nsresult |
|
372 xpcAccessibleTable::GetRowIndexAt(int32_t aCellIdx, int32_t* aRowIdx) |
|
373 { |
|
374 NS_ENSURE_ARG_POINTER(aRowIdx); |
|
375 *aRowIdx = -1; |
|
376 |
|
377 if (!mTable) |
|
378 return NS_ERROR_FAILURE; |
|
379 |
|
380 if (aCellIdx < 0 |
|
381 || static_cast<uint32_t>(aCellIdx) |
|
382 >= mTable->RowCount() * mTable->ColCount()) |
|
383 return NS_ERROR_INVALID_ARG; |
|
384 |
|
385 *aRowIdx = mTable->RowIndexAt(aCellIdx); |
|
386 return NS_OK; |
|
387 } |
|
388 |
|
389 nsresult |
|
390 xpcAccessibleTable::GetRowAndColumnIndicesAt(int32_t aCellIdx, int32_t* aRowIdx, |
|
391 int32_t* aColIdx) |
|
392 { |
|
393 NS_ENSURE_ARG_POINTER(aRowIdx); |
|
394 *aRowIdx = -1; |
|
395 NS_ENSURE_ARG_POINTER(aColIdx); |
|
396 *aColIdx = -1; |
|
397 |
|
398 if (!mTable) |
|
399 return NS_ERROR_FAILURE; |
|
400 |
|
401 if (aCellIdx < 0 |
|
402 || static_cast<uint32_t>(aCellIdx) |
|
403 >= mTable->RowCount() * mTable->ColCount()) |
|
404 return NS_ERROR_INVALID_ARG; |
|
405 |
|
406 mTable->RowAndColIndicesAt(aCellIdx, aRowIdx, aColIdx); |
|
407 return NS_OK; |
|
408 } |
|
409 |
|
410 nsresult |
|
411 xpcAccessibleTable::GetSummary(nsAString& aSummary) |
|
412 { |
|
413 if (!mTable) |
|
414 return NS_ERROR_FAILURE; |
|
415 |
|
416 nsAutoString summary; |
|
417 mTable->Summary(summary); |
|
418 aSummary.Assign(summary); |
|
419 |
|
420 return NS_OK; |
|
421 } |
|
422 |
|
423 nsresult |
|
424 xpcAccessibleTable::IsProbablyForLayout(bool* aResult) |
|
425 { |
|
426 NS_ENSURE_ARG_POINTER(aResult); |
|
427 *aResult = false; |
|
428 if (!mTable) |
|
429 return NS_ERROR_FAILURE; |
|
430 |
|
431 *aResult = mTable->IsProbablyLayoutTable(); |
|
432 return NS_OK; |
|
433 } |
|
434 |
|
435 nsresult |
|
436 xpcAccessibleTable::SelectColumn(int32_t aColIdx) |
|
437 { |
|
438 if (!mTable) |
|
439 return NS_ERROR_FAILURE; |
|
440 |
|
441 if (aColIdx < 0 || static_cast<uint32_t>(aColIdx) >= mTable->ColCount()) |
|
442 return NS_ERROR_INVALID_ARG; |
|
443 |
|
444 mTable->SelectCol(aColIdx); |
|
445 return NS_OK; |
|
446 } |
|
447 |
|
448 nsresult |
|
449 xpcAccessibleTable::SelectRow(int32_t aRowIdx) |
|
450 { |
|
451 if (!mTable) |
|
452 return NS_ERROR_FAILURE; |
|
453 |
|
454 if (aRowIdx < 0 || static_cast<uint32_t>(aRowIdx) >= mTable->RowCount()) |
|
455 return NS_ERROR_INVALID_ARG; |
|
456 |
|
457 mTable->SelectRow(aRowIdx); |
|
458 return NS_OK; |
|
459 } |
|
460 |
|
461 nsresult |
|
462 xpcAccessibleTable::UnselectColumn(int32_t aColIdx) |
|
463 { |
|
464 if (!mTable) |
|
465 return NS_ERROR_FAILURE; |
|
466 |
|
467 if (aColIdx < 0 || static_cast<uint32_t>(aColIdx) >= mTable->ColCount()) |
|
468 return NS_ERROR_INVALID_ARG; |
|
469 |
|
470 mTable->UnselectCol(aColIdx); |
|
471 return NS_OK; |
|
472 } |
|
473 |
|
474 nsresult |
|
475 xpcAccessibleTable::UnselectRow(int32_t aRowIdx) |
|
476 { |
|
477 if (!mTable) |
|
478 return NS_ERROR_FAILURE; |
|
479 |
|
480 if (aRowIdx < 0 || static_cast<uint32_t>(aRowIdx) >= mTable->RowCount()) |
|
481 return NS_ERROR_INVALID_ARG; |
|
482 |
|
483 mTable->UnselectRow(aRowIdx); |
|
484 return NS_OK; |
|
485 } |
|
486 |
|
487 |