accessible/src/xpcom/xpcAccessibleTable.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/accessible/src/xpcom/xpcAccessibleTable.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,487 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* vim: set ts=2 et sw=2 tw=80: */
     1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this file,
     1.8 + * You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +#include "xpcAccessibleTable.h"
    1.11 +
    1.12 +#include "Accessible.h"
    1.13 +#include "TableAccessible.h"
    1.14 +
    1.15 +#include "nsIMutableArray.h"
    1.16 +#include "nsComponentManagerUtils.h"
    1.17 +
    1.18 +using namespace mozilla::a11y;
    1.19 +
    1.20 +static const uint32_t XPC_TABLE_DEFAULT_SIZE = 40;
    1.21 +
    1.22 +nsresult
    1.23 +xpcAccessibleTable::GetCaption(nsIAccessible** aCaption)
    1.24 +{
    1.25 +  NS_ENSURE_ARG_POINTER(aCaption);
    1.26 +  *aCaption = nullptr;
    1.27 +  if (!mTable)
    1.28 +    return NS_ERROR_FAILURE;
    1.29 +
    1.30 +  NS_IF_ADDREF(*aCaption = mTable->Caption());
    1.31 +  return NS_OK;
    1.32 +}
    1.33 +
    1.34 +nsresult
    1.35 +xpcAccessibleTable::GetColumnCount(int32_t* aColumnCount)
    1.36 +{
    1.37 +  NS_ENSURE_ARG_POINTER(aColumnCount);
    1.38 +  *aColumnCount = 0;
    1.39 +
    1.40 +  if (!mTable)
    1.41 +    return NS_ERROR_FAILURE;
    1.42 +
    1.43 +  *aColumnCount = mTable->ColCount();
    1.44 +  return NS_OK;
    1.45 +}
    1.46 +
    1.47 +nsresult
    1.48 +xpcAccessibleTable::GetRowCount(int32_t* aRowCount)
    1.49 +{
    1.50 +  NS_ENSURE_ARG_POINTER(aRowCount);
    1.51 +  *aRowCount = 0;
    1.52 +
    1.53 +  if (!mTable)
    1.54 +    return NS_ERROR_FAILURE;
    1.55 +
    1.56 +  *aRowCount = mTable->RowCount();
    1.57 +  return NS_OK;
    1.58 +}
    1.59 +
    1.60 +nsresult
    1.61 +xpcAccessibleTable::GetCellAt(int32_t aRowIdx, int32_t aColIdx,
    1.62 +                              nsIAccessible** aCell)
    1.63 +{
    1.64 +  NS_ENSURE_ARG_POINTER(aCell);
    1.65 +  *aCell = nullptr;
    1.66 +
    1.67 +  if (!mTable)
    1.68 +    return NS_ERROR_FAILURE;
    1.69 +
    1.70 +  if (aRowIdx < 0 || static_cast<uint32_t>(aRowIdx) >= mTable->RowCount() ||
    1.71 +      aColIdx < 0 || static_cast<uint32_t>(aColIdx) >= mTable->ColCount())
    1.72 +    return NS_ERROR_INVALID_ARG;
    1.73 +
    1.74 +  NS_IF_ADDREF(*aCell = mTable->CellAt(aRowIdx, aColIdx));
    1.75 +  return NS_OK;
    1.76 +}
    1.77 +
    1.78 +nsresult
    1.79 +xpcAccessibleTable::GetCellIndexAt(int32_t aRowIdx, int32_t aColIdx,
    1.80 +                                   int32_t* aCellIdx)
    1.81 +{
    1.82 +  NS_ENSURE_ARG_POINTER(aCellIdx);
    1.83 +  *aCellIdx = -1;
    1.84 +
    1.85 +  if (!mTable)
    1.86 +    return NS_ERROR_FAILURE;
    1.87 +
    1.88 +  if (aRowIdx < 0 || static_cast<uint32_t>(aRowIdx) >= mTable->RowCount() ||
    1.89 +      aColIdx < 0 || static_cast<uint32_t>(aColIdx) >= mTable->ColCount())
    1.90 +    return NS_ERROR_INVALID_ARG;
    1.91 +
    1.92 +  *aCellIdx = mTable->CellIndexAt(aRowIdx, aColIdx);
    1.93 +  return NS_OK;
    1.94 +}
    1.95 +
    1.96 +nsresult
    1.97 +xpcAccessibleTable::GetColumnExtentAt(int32_t aRowIdx, int32_t aColIdx,
    1.98 +                                      int32_t* aColumnExtent)
    1.99 +{
   1.100 +  NS_ENSURE_ARG_POINTER(aColumnExtent);
   1.101 +  *aColumnExtent = -1;
   1.102 +
   1.103 +  if (!mTable)
   1.104 +    return NS_ERROR_FAILURE;
   1.105 +
   1.106 +  if (aRowIdx < 0 || static_cast<uint32_t>(aRowIdx) >= mTable->RowCount() ||
   1.107 +      aColIdx < 0 || static_cast<uint32_t>(aColIdx) >= mTable->ColCount())
   1.108 +    return NS_ERROR_INVALID_ARG;
   1.109 +
   1.110 +  *aColumnExtent = mTable->ColExtentAt(aRowIdx, aColIdx);
   1.111 +  return NS_OK;
   1.112 +}
   1.113 +
   1.114 +nsresult
   1.115 +xpcAccessibleTable::GetRowExtentAt(int32_t aRowIdx, int32_t aColIdx,
   1.116 +                                   int32_t* aRowExtent)
   1.117 +{
   1.118 +  NS_ENSURE_ARG_POINTER(aRowExtent);
   1.119 +  *aRowExtent = -1;
   1.120 +
   1.121 +  if (!mTable)
   1.122 +    return NS_ERROR_FAILURE;
   1.123 +
   1.124 +  if (aRowIdx < 0 || static_cast<uint32_t>(aRowIdx) >= mTable->RowCount() ||
   1.125 +      aColIdx < 0 || static_cast<uint32_t>(aColIdx) >= mTable->ColCount())
   1.126 +    return NS_ERROR_INVALID_ARG;
   1.127 +
   1.128 +  *aRowExtent = mTable->RowExtentAt(aRowIdx, aColIdx);
   1.129 +  return NS_OK;
   1.130 +}
   1.131 +
   1.132 +nsresult
   1.133 +xpcAccessibleTable::GetColumnDescription(int32_t aColIdx,
   1.134 +                                         nsAString& aDescription)
   1.135 +{
   1.136 +  if (!mTable)
   1.137 +    return NS_ERROR_FAILURE;
   1.138 +
   1.139 +  if (aColIdx < 0 || static_cast<uint32_t>(aColIdx) >= mTable->ColCount())
   1.140 +    return NS_ERROR_INVALID_ARG;
   1.141 +
   1.142 +  nsAutoString description;
   1.143 +  mTable->ColDescription(aColIdx, description);
   1.144 +  aDescription.Assign(description);
   1.145 +
   1.146 +  return NS_OK;
   1.147 +}
   1.148 +
   1.149 +nsresult
   1.150 +xpcAccessibleTable::GetRowDescription(int32_t aRowIdx, nsAString& aDescription)
   1.151 +{
   1.152 +  if (!mTable)
   1.153 +    return NS_ERROR_FAILURE;
   1.154 +
   1.155 +  if (aRowIdx < 0 || static_cast<uint32_t>(aRowIdx) >= mTable->ColCount())
   1.156 +    return NS_ERROR_INVALID_ARG;
   1.157 +
   1.158 +  nsAutoString description;
   1.159 +  mTable->RowDescription(aRowIdx, description);
   1.160 +  aDescription.Assign(description);
   1.161 +
   1.162 +  return NS_OK;
   1.163 +}
   1.164 +
   1.165 +nsresult
   1.166 +xpcAccessibleTable::IsColumnSelected(int32_t aColIdx, bool* aIsSelected)
   1.167 +{
   1.168 +  NS_ENSURE_ARG_POINTER(aIsSelected);
   1.169 +  *aIsSelected = false;
   1.170 +
   1.171 +  if (!mTable)
   1.172 +    return NS_ERROR_FAILURE;
   1.173 +
   1.174 +  if (aColIdx < 0 || static_cast<uint32_t>(aColIdx) >= mTable->ColCount())
   1.175 +    return NS_ERROR_INVALID_ARG;
   1.176 +
   1.177 +  *aIsSelected = mTable->IsColSelected(aColIdx);
   1.178 +  return NS_OK;
   1.179 +}
   1.180 +
   1.181 +nsresult
   1.182 +xpcAccessibleTable::IsRowSelected(int32_t aRowIdx, bool* aIsSelected)
   1.183 +{
   1.184 +  NS_ENSURE_ARG_POINTER(aIsSelected);
   1.185 +  *aIsSelected = false;
   1.186 +
   1.187 +  if (!mTable)
   1.188 +    return NS_ERROR_FAILURE;
   1.189 +
   1.190 +  if (aRowIdx < 0 || static_cast<uint32_t>(aRowIdx) >= mTable->RowCount())
   1.191 +    return NS_ERROR_INVALID_ARG;
   1.192 +
   1.193 +  *aIsSelected = mTable->IsRowSelected(aRowIdx);
   1.194 +  return NS_OK;
   1.195 +}
   1.196 +
   1.197 +nsresult
   1.198 +xpcAccessibleTable::IsCellSelected(int32_t aRowIdx, int32_t aColIdx,
   1.199 +                                   bool* aIsSelected)
   1.200 +{
   1.201 +  NS_ENSURE_ARG_POINTER(aIsSelected);
   1.202 +  *aIsSelected = false;
   1.203 +
   1.204 +  if (!mTable)
   1.205 +    return NS_ERROR_FAILURE;
   1.206 +
   1.207 +  if (aRowIdx < 0 || static_cast<uint32_t>(aRowIdx) >= mTable->RowCount() ||
   1.208 +      aColIdx < 0 || static_cast<uint32_t>(aColIdx) >= mTable->ColCount())
   1.209 +    return NS_ERROR_INVALID_ARG;
   1.210 +
   1.211 +  *aIsSelected = mTable->IsCellSelected(aRowIdx, aColIdx);
   1.212 +  return NS_OK;
   1.213 +}
   1.214 +
   1.215 +nsresult
   1.216 +xpcAccessibleTable::GetSelectedCellCount(uint32_t* aSelectedCellCount)
   1.217 +{
   1.218 +  NS_ENSURE_ARG_POINTER(aSelectedCellCount);
   1.219 +  *aSelectedCellCount = 0;
   1.220 +
   1.221 +  if (!mTable)
   1.222 +    return NS_ERROR_FAILURE;
   1.223 +
   1.224 +  *aSelectedCellCount = mTable->SelectedCellCount();
   1.225 +  return NS_OK;
   1.226 +}
   1.227 +
   1.228 +nsresult
   1.229 +xpcAccessibleTable::GetSelectedColumnCount(uint32_t* aSelectedColumnCount)
   1.230 +{
   1.231 +  NS_ENSURE_ARG_POINTER(aSelectedColumnCount);
   1.232 +  *aSelectedColumnCount = 0;
   1.233 +
   1.234 +  if (!mTable)
   1.235 +    return NS_ERROR_FAILURE;
   1.236 +
   1.237 +  *aSelectedColumnCount = mTable->SelectedColCount();
   1.238 +  return NS_OK;
   1.239 +}
   1.240 +
   1.241 +nsresult
   1.242 +xpcAccessibleTable::GetSelectedRowCount(uint32_t* aSelectedRowCount)
   1.243 +{
   1.244 +  NS_ENSURE_ARG_POINTER(aSelectedRowCount);
   1.245 +  *aSelectedRowCount = 0;
   1.246 +
   1.247 +  if (!mTable)
   1.248 +    return NS_ERROR_FAILURE;
   1.249 +
   1.250 +  *aSelectedRowCount = mTable->SelectedRowCount();
   1.251 +  return NS_OK;
   1.252 +}
   1.253 +
   1.254 +nsresult
   1.255 +xpcAccessibleTable::GetSelectedCells(nsIArray** aSelectedCells)
   1.256 +{
   1.257 +  NS_ENSURE_ARG_POINTER(aSelectedCells);
   1.258 +  *aSelectedCells = nullptr;
   1.259 +
   1.260 +  if (!mTable)
   1.261 +    return NS_ERROR_FAILURE;
   1.262 +
   1.263 +  nsresult rv = NS_OK;
   1.264 +  nsCOMPtr<nsIMutableArray> selCells = 
   1.265 +    do_CreateInstance(NS_ARRAY_CONTRACTID, &rv);
   1.266 +  NS_ENSURE_SUCCESS(rv, rv);
   1.267 +
   1.268 +  nsAutoTArray<Accessible*, XPC_TABLE_DEFAULT_SIZE> cellsArray;
   1.269 +  mTable->SelectedCells(&cellsArray);
   1.270 +
   1.271 +  uint32_t totalCount = cellsArray.Length();
   1.272 +  for (uint32_t idx = 0; idx < totalCount; idx++) {
   1.273 +    Accessible* cell = cellsArray.ElementAt(idx);
   1.274 +    selCells -> AppendElement(static_cast<nsIAccessible*>(cell), false);
   1.275 +  }
   1.276 +
   1.277 +  NS_ADDREF(*aSelectedCells = selCells);
   1.278 +  return NS_OK;
   1.279 +}
   1.280 +
   1.281 +nsresult
   1.282 +xpcAccessibleTable::GetSelectedCellIndices(uint32_t* aCellsArraySize,
   1.283 +                                           int32_t** aCellsArray)
   1.284 +{
   1.285 +  NS_ENSURE_ARG_POINTER(aCellsArraySize);
   1.286 +  *aCellsArraySize = 0;
   1.287 +
   1.288 +  NS_ENSURE_ARG_POINTER(aCellsArray);
   1.289 +  *aCellsArray = 0;
   1.290 +
   1.291 +  if (!mTable)
   1.292 +    return NS_ERROR_FAILURE;
   1.293 +
   1.294 +  nsAutoTArray<uint32_t, XPC_TABLE_DEFAULT_SIZE> cellsArray;
   1.295 +  mTable->SelectedCellIndices(&cellsArray);
   1.296 +
   1.297 +  *aCellsArraySize = cellsArray.Length();
   1.298 +  *aCellsArray = static_cast<int32_t*>
   1.299 +    (moz_xmalloc(*aCellsArraySize * sizeof(int32_t)));
   1.300 +  memcpy(*aCellsArray, cellsArray.Elements(),
   1.301 +    *aCellsArraySize * sizeof(int32_t));
   1.302 +
   1.303 +  return NS_OK;
   1.304 +}
   1.305 +
   1.306 +nsresult
   1.307 +xpcAccessibleTable::GetSelectedColumnIndices(uint32_t* aColsArraySize,
   1.308 +                                             int32_t** aColsArray)
   1.309 +{
   1.310 +  NS_ENSURE_ARG_POINTER(aColsArraySize);
   1.311 +  *aColsArraySize = 0;
   1.312 +
   1.313 +  NS_ENSURE_ARG_POINTER(aColsArray);
   1.314 +  *aColsArray = 0;
   1.315 +
   1.316 +  if (!mTable)
   1.317 +    return NS_ERROR_FAILURE;
   1.318 +
   1.319 +  nsAutoTArray<uint32_t, XPC_TABLE_DEFAULT_SIZE> colsArray;
   1.320 +  mTable->SelectedColIndices(&colsArray);
   1.321 +
   1.322 +  *aColsArraySize = colsArray.Length();
   1.323 +  *aColsArray = static_cast<int32_t*>
   1.324 +    (moz_xmalloc(*aColsArraySize * sizeof(int32_t)));
   1.325 +  memcpy(*aColsArray, colsArray.Elements(),
   1.326 +    *aColsArraySize * sizeof(int32_t));
   1.327 +
   1.328 +  return NS_OK;
   1.329 +}
   1.330 +
   1.331 +nsresult
   1.332 +xpcAccessibleTable::GetSelectedRowIndices(uint32_t* aRowsArraySize,
   1.333 +                                          int32_t** aRowsArray)
   1.334 +{
   1.335 +  NS_ENSURE_ARG_POINTER(aRowsArraySize);
   1.336 +  *aRowsArraySize = 0;
   1.337 +
   1.338 +  NS_ENSURE_ARG_POINTER(aRowsArray);
   1.339 +  *aRowsArray = 0;
   1.340 +
   1.341 +  if (!mTable)
   1.342 +    return NS_ERROR_FAILURE;
   1.343 +
   1.344 +  nsAutoTArray<uint32_t, XPC_TABLE_DEFAULT_SIZE> rowsArray;
   1.345 +  mTable->SelectedRowIndices(&rowsArray);
   1.346 +
   1.347 +  *aRowsArraySize = rowsArray.Length();
   1.348 +  *aRowsArray = static_cast<int32_t*>
   1.349 +    (moz_xmalloc(*aRowsArraySize * sizeof(int32_t)));
   1.350 +  memcpy(*aRowsArray, rowsArray.Elements(),
   1.351 +    *aRowsArraySize * sizeof(int32_t));
   1.352 +
   1.353 +  return NS_OK;
   1.354 +}
   1.355 +
   1.356 +nsresult 
   1.357 +xpcAccessibleTable::GetColumnIndexAt(int32_t aCellIdx, int32_t* aColIdx)
   1.358 +{
   1.359 +  NS_ENSURE_ARG_POINTER(aColIdx);
   1.360 +  *aColIdx = -1;
   1.361 +
   1.362 +  if (!mTable)
   1.363 +    return NS_ERROR_FAILURE;
   1.364 +
   1.365 +  if (aCellIdx < 0 
   1.366 +      || static_cast<uint32_t>(aCellIdx) 
   1.367 +      >= mTable->RowCount() * mTable->ColCount())
   1.368 +    return NS_ERROR_INVALID_ARG;
   1.369 +
   1.370 +  *aColIdx = mTable->ColIndexAt(aCellIdx);
   1.371 +  return NS_OK;
   1.372 +}
   1.373 +
   1.374 +nsresult 
   1.375 +xpcAccessibleTable::GetRowIndexAt(int32_t aCellIdx, int32_t* aRowIdx)
   1.376 +{
   1.377 +  NS_ENSURE_ARG_POINTER(aRowIdx);
   1.378 +  *aRowIdx = -1;
   1.379 +
   1.380 +  if (!mTable)
   1.381 +    return NS_ERROR_FAILURE;
   1.382 +
   1.383 +  if (aCellIdx < 0 
   1.384 +      || static_cast<uint32_t>(aCellIdx) 
   1.385 +      >= mTable->RowCount() * mTable->ColCount())
   1.386 +    return NS_ERROR_INVALID_ARG;
   1.387 +
   1.388 +  *aRowIdx = mTable->RowIndexAt(aCellIdx);
   1.389 +  return NS_OK;
   1.390 +}
   1.391 +
   1.392 +nsresult
   1.393 +xpcAccessibleTable::GetRowAndColumnIndicesAt(int32_t aCellIdx, int32_t* aRowIdx,
   1.394 +                                             int32_t* aColIdx)
   1.395 +{
   1.396 +  NS_ENSURE_ARG_POINTER(aRowIdx);
   1.397 +  *aRowIdx = -1;
   1.398 +  NS_ENSURE_ARG_POINTER(aColIdx);
   1.399 +  *aColIdx = -1;
   1.400 +
   1.401 +  if (!mTable)
   1.402 +    return NS_ERROR_FAILURE;
   1.403 +
   1.404 +  if (aCellIdx < 0 
   1.405 +      || static_cast<uint32_t>(aCellIdx) 
   1.406 +      >= mTable->RowCount() * mTable->ColCount())
   1.407 +    return NS_ERROR_INVALID_ARG;
   1.408 +
   1.409 +  mTable->RowAndColIndicesAt(aCellIdx, aRowIdx, aColIdx);
   1.410 +  return NS_OK;  
   1.411 +}
   1.412 +
   1.413 +nsresult
   1.414 +xpcAccessibleTable::GetSummary(nsAString& aSummary)
   1.415 +{
   1.416 +  if (!mTable)
   1.417 +    return NS_ERROR_FAILURE;
   1.418 +
   1.419 +  nsAutoString summary;
   1.420 +  mTable->Summary(summary);
   1.421 +  aSummary.Assign(summary);
   1.422 +
   1.423 +  return NS_OK;
   1.424 +}
   1.425 +
   1.426 +nsresult
   1.427 +xpcAccessibleTable::IsProbablyForLayout(bool* aResult)
   1.428 +{
   1.429 +  NS_ENSURE_ARG_POINTER(aResult);
   1.430 +  *aResult = false;
   1.431 +  if (!mTable)
   1.432 +    return NS_ERROR_FAILURE;
   1.433 +
   1.434 +  *aResult = mTable->IsProbablyLayoutTable();
   1.435 +  return NS_OK;
   1.436 +}
   1.437 +
   1.438 +nsresult
   1.439 +xpcAccessibleTable::SelectColumn(int32_t aColIdx)
   1.440 +{
   1.441 +  if (!mTable)
   1.442 +    return NS_ERROR_FAILURE;
   1.443 +
   1.444 +  if (aColIdx < 0 || static_cast<uint32_t>(aColIdx) >= mTable->ColCount())
   1.445 +    return NS_ERROR_INVALID_ARG;
   1.446 +
   1.447 +  mTable->SelectCol(aColIdx);
   1.448 +  return NS_OK;
   1.449 +}
   1.450 +
   1.451 +nsresult
   1.452 +xpcAccessibleTable::SelectRow(int32_t aRowIdx)
   1.453 +{
   1.454 +  if (!mTable)
   1.455 +    return NS_ERROR_FAILURE;
   1.456 +
   1.457 +  if (aRowIdx < 0 || static_cast<uint32_t>(aRowIdx) >= mTable->RowCount())
   1.458 +    return NS_ERROR_INVALID_ARG;
   1.459 +
   1.460 +  mTable->SelectRow(aRowIdx);
   1.461 +  return NS_OK;
   1.462 +}
   1.463 +
   1.464 +nsresult
   1.465 +xpcAccessibleTable::UnselectColumn(int32_t aColIdx)
   1.466 +{
   1.467 +  if (!mTable)
   1.468 +    return NS_ERROR_FAILURE;
   1.469 +
   1.470 +  if (aColIdx < 0 || static_cast<uint32_t>(aColIdx) >= mTable->ColCount())
   1.471 +    return NS_ERROR_INVALID_ARG;
   1.472 +
   1.473 +  mTable->UnselectCol(aColIdx);
   1.474 +  return NS_OK;
   1.475 +}
   1.476 +
   1.477 +nsresult
   1.478 +xpcAccessibleTable::UnselectRow(int32_t aRowIdx)
   1.479 +{
   1.480 +  if (!mTable)
   1.481 +    return NS_ERROR_FAILURE;
   1.482 +
   1.483 +  if (aRowIdx < 0 || static_cast<uint32_t>(aRowIdx) >= mTable->RowCount())
   1.484 +    return NS_ERROR_INVALID_ARG;
   1.485 +
   1.486 +  mTable->UnselectRow(aRowIdx);
   1.487 +  return NS_OK;
   1.488 +}
   1.489 +
   1.490 +

mercurial