accessible/src/xpcom/xpcAccessibleTable.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial