michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim: set ts=2 et sw=2 tw=80: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "xpcAccessibleTableCell.h" michael@0: michael@0: #include "Accessible.h" michael@0: #include "TableAccessible.h" michael@0: #include "TableCellAccessible.h" michael@0: michael@0: #include "nsIAccessibleTable.h" michael@0: michael@0: #include "nsComponentManagerUtils.h" michael@0: #include "nsIMutableArray.h" michael@0: michael@0: using namespace mozilla; michael@0: using namespace mozilla::a11y; michael@0: michael@0: nsresult michael@0: xpcAccessibleTableCell::GetTable(nsIAccessibleTable** aTable) michael@0: { michael@0: NS_ENSURE_ARG_POINTER(aTable); michael@0: *aTable = nullptr; michael@0: michael@0: if (!mTableCell) michael@0: return NS_ERROR_FAILURE; michael@0: michael@0: TableAccessible* table = mTableCell->Table(); michael@0: if (!table) michael@0: return NS_ERROR_FAILURE; michael@0: michael@0: nsCOMPtr xpcTable = michael@0: do_QueryInterface(static_cast(table->AsAccessible())); michael@0: xpcTable.forget(aTable); michael@0: michael@0: return NS_OK; michael@0: } michael@0: michael@0: nsresult michael@0: xpcAccessibleTableCell::GetColumnIndex(int32_t* aColIdx) michael@0: { michael@0: NS_ENSURE_ARG_POINTER(aColIdx); michael@0: *aColIdx = -1; michael@0: michael@0: if (!mTableCell) michael@0: return NS_ERROR_FAILURE; michael@0: michael@0: *aColIdx = mTableCell->ColIdx(); michael@0: return NS_OK; michael@0: } michael@0: michael@0: nsresult michael@0: xpcAccessibleTableCell::GetRowIndex(int32_t* aRowIdx) michael@0: { michael@0: NS_ENSURE_ARG_POINTER(aRowIdx); michael@0: *aRowIdx = -1; michael@0: michael@0: if (!mTableCell) michael@0: return NS_ERROR_FAILURE; michael@0: michael@0: *aRowIdx = mTableCell->RowIdx(); michael@0: michael@0: return NS_OK; michael@0: } michael@0: michael@0: nsresult michael@0: xpcAccessibleTableCell::GetColumnExtent(int32_t* aExtent) michael@0: { michael@0: NS_ENSURE_ARG_POINTER(aExtent); michael@0: *aExtent = -1; michael@0: michael@0: if (!mTableCell) michael@0: return NS_ERROR_FAILURE; michael@0: michael@0: *aExtent = mTableCell->ColExtent(); michael@0: michael@0: return NS_OK; michael@0: } michael@0: michael@0: nsresult michael@0: xpcAccessibleTableCell::GetRowExtent(int32_t* aExtent) michael@0: { michael@0: NS_ENSURE_ARG_POINTER(aExtent); michael@0: *aExtent = -1; michael@0: michael@0: if (!mTableCell) michael@0: return NS_ERROR_FAILURE; michael@0: michael@0: *aExtent = mTableCell->RowExtent(); michael@0: michael@0: return NS_OK; michael@0: } michael@0: michael@0: nsresult michael@0: xpcAccessibleTableCell::GetColumnHeaderCells(nsIArray** aHeaderCells) michael@0: { michael@0: NS_ENSURE_ARG_POINTER(aHeaderCells); michael@0: *aHeaderCells = nullptr; michael@0: michael@0: if (!mTableCell) michael@0: return NS_ERROR_FAILURE; michael@0: michael@0: nsAutoTArray headerCells; michael@0: mTableCell->ColHeaderCells(&headerCells); michael@0: michael@0: nsCOMPtr cells = do_CreateInstance(NS_ARRAY_CONTRACTID); michael@0: NS_ENSURE_TRUE(cells, NS_ERROR_FAILURE); michael@0: michael@0: for (uint32_t idx = 0; idx < headerCells.Length(); idx++) { michael@0: cells-> michael@0: AppendElement(static_cast(headerCells.ElementAt(idx)), michael@0: false); michael@0: } michael@0: michael@0: NS_ADDREF(*aHeaderCells = cells); michael@0: return NS_OK; michael@0: } michael@0: michael@0: nsresult michael@0: xpcAccessibleTableCell::GetRowHeaderCells(nsIArray** aHeaderCells) michael@0: { michael@0: NS_ENSURE_ARG_POINTER(aHeaderCells); michael@0: *aHeaderCells = nullptr; michael@0: michael@0: if (!mTableCell) michael@0: return NS_ERROR_FAILURE; michael@0: michael@0: nsAutoTArray headerCells; michael@0: mTableCell->RowHeaderCells(&headerCells); michael@0: michael@0: nsCOMPtr cells = do_CreateInstance(NS_ARRAY_CONTRACTID); michael@0: NS_ENSURE_TRUE(cells, NS_ERROR_FAILURE); michael@0: michael@0: for (uint32_t idx = 0; idx < headerCells.Length(); idx++) { michael@0: cells-> michael@0: AppendElement(static_cast(headerCells.ElementAt(idx)), michael@0: false); michael@0: } michael@0: michael@0: NS_ADDREF(*aHeaderCells = cells); michael@0: return NS_OK; michael@0: } michael@0: michael@0: nsresult michael@0: xpcAccessibleTableCell::IsSelected(bool* aSelected) michael@0: { michael@0: NS_ENSURE_ARG_POINTER(aSelected); michael@0: *aSelected = false; michael@0: michael@0: if (!mTableCell) michael@0: return NS_ERROR_FAILURE; michael@0: michael@0: *aSelected = mTableCell->Selected(); michael@0: michael@0: return NS_OK; michael@0: }