123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622 |
- /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
- /* vim:expandtab:shiftwidth=2:tabstop=2:
- */
- /* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
- #include "ia2AccessibleTable.h"
- #include "Accessible2.h"
- #include "AccessibleTable_i.c"
- #include "AccessibleTable2_i.c"
- #include "AccessibleWrap.h"
- #include "IUnknownImpl.h"
- #include "TableAccessible.h"
- #include "nsCOMPtr.h"
- #include "nsString.h"
- using namespace mozilla::a11y;
- // IUnknown
- STDMETHODIMP
- ia2AccessibleTable::QueryInterface(REFIID iid, void** ppv)
- {
- if (!ppv)
- return E_INVALIDARG;
- *ppv = nullptr;
- if (IID_IAccessibleTable == iid) {
- *ppv = static_cast<IAccessibleTable*>(this);
- (reinterpret_cast<IUnknown*>(*ppv))->AddRef();
- return S_OK;
- }
- if (IID_IAccessibleTable2 == iid) {
- *ppv = static_cast<IAccessibleTable2*>(this);
- (reinterpret_cast<IUnknown*>(*ppv))->AddRef();
- return S_OK;
- }
- return E_NOINTERFACE;
- }
- ////////////////////////////////////////////////////////////////////////////////
- // IAccessibleTable
- STDMETHODIMP
- ia2AccessibleTable::get_accessibleAt(long aRowIdx, long aColIdx,
- IUnknown** aAccessible)
- {
- return get_cellAt(aRowIdx, aColIdx, aAccessible);
- }
- STDMETHODIMP
- ia2AccessibleTable::get_caption(IUnknown** aAccessible)
- {
- if (!aAccessible)
- return E_INVALIDARG;
- *aAccessible = nullptr;
- if (!mTable)
- return CO_E_OBJNOTCONNECTED;
- AccessibleWrap* caption = static_cast<AccessibleWrap*>(mTable->Caption());
- if (!caption)
- return S_FALSE;
- (*aAccessible = static_cast<IAccessible*>(caption))->AddRef();
- return S_OK;
- }
- STDMETHODIMP
- ia2AccessibleTable::get_childIndex(long aRowIdx, long aColIdx,
- long* aChildIdx)
- {
- if (!aChildIdx)
- return E_INVALIDARG;
- *aChildIdx = 0;
- if (!mTable)
- return CO_E_OBJNOTCONNECTED;
- if (aRowIdx < 0 || aColIdx < 0 ||
- static_cast<uint32_t>(aRowIdx) >= mTable->RowCount() ||
- static_cast<uint32_t>(aColIdx) >= mTable->ColCount())
- return E_INVALIDARG;
- *aChildIdx = mTable->CellIndexAt(aRowIdx, aColIdx);
- return S_OK;
- }
- STDMETHODIMP
- ia2AccessibleTable::get_columnDescription(long aColIdx, BSTR* aDescription)
- {
- if (!aDescription)
- return E_INVALIDARG;
- *aDescription = nullptr;
- if (!mTable)
- return CO_E_OBJNOTCONNECTED;
- if (aColIdx < 0 || static_cast<uint32_t>(aColIdx) >= mTable->ColCount())
- return E_INVALIDARG;
- nsAutoString descr;
- mTable->ColDescription(aColIdx, descr);
- if (descr.IsEmpty())
- return S_FALSE;
- *aDescription = ::SysAllocStringLen(descr.get(), descr.Length());
- return *aDescription ? S_OK : E_OUTOFMEMORY;
- }
- STDMETHODIMP
- ia2AccessibleTable::get_columnExtentAt(long aRowIdx, long aColIdx,
- long* aSpan)
- {
- if (!aSpan)
- return E_INVALIDARG;
- *aSpan = 0;
- if (!mTable)
- return CO_E_OBJNOTCONNECTED;
- if (aRowIdx < 0 || aColIdx < 0 ||
- static_cast<uint32_t>(aRowIdx) >= mTable->RowCount() ||
- static_cast<uint32_t>(aColIdx) >= mTable->ColCount())
- return E_INVALIDARG;
- *aSpan = mTable->ColExtentAt(aRowIdx, aColIdx);
- return S_OK;
- }
- STDMETHODIMP
- ia2AccessibleTable::get_columnHeader(IAccessibleTable** aAccessibleTable,
- long* aStartingRowIndex)
- {
- if (!aAccessibleTable || !aStartingRowIndex)
- return E_INVALIDARG;
- *aAccessibleTable = nullptr;
- *aStartingRowIndex = -1;
- return E_NOTIMPL;
- }
- STDMETHODIMP
- ia2AccessibleTable::get_columnIndex(long aCellIdx, long* aColIdx)
- {
- if (!aColIdx)
- return E_INVALIDARG;
- *aColIdx = 0;
- if (!mTable)
- return CO_E_OBJNOTCONNECTED;
- if (aCellIdx < 0 ||
- static_cast<uint32_t>(aCellIdx) >= mTable->ColCount() * mTable->RowCount())
- return E_INVALIDARG;
- *aColIdx = mTable->ColIndexAt(aCellIdx);
- return S_OK;
- }
- STDMETHODIMP
- ia2AccessibleTable::get_nColumns(long* aColCount)
- {
- if (!aColCount)
- return E_INVALIDARG;
- *aColCount = 0;
- if (!mTable)
- return CO_E_OBJNOTCONNECTED;
- *aColCount = mTable->ColCount();
- return S_OK;
- }
- STDMETHODIMP
- ia2AccessibleTable::get_nRows(long* aRowCount)
- {
- if (!aRowCount)
- return E_INVALIDARG;
- *aRowCount = 0;
- if (!mTable)
- return CO_E_OBJNOTCONNECTED;
- *aRowCount = mTable->RowCount();
- return S_OK;
- }
- STDMETHODIMP
- ia2AccessibleTable::get_nSelectedChildren(long* aChildCount)
- {
- return get_nSelectedCells(aChildCount);
- }
- STDMETHODIMP
- ia2AccessibleTable::get_nSelectedColumns(long* aColCount)
- {
- if (!aColCount)
- return E_INVALIDARG;
- *aColCount = 0;
- if (!mTable)
- return CO_E_OBJNOTCONNECTED;
- *aColCount = mTable->SelectedColCount();
- return S_OK;
- }
- STDMETHODIMP
- ia2AccessibleTable::get_nSelectedRows(long* aRowCount)
- {
- if (!aRowCount)
- return E_INVALIDARG;
- *aRowCount = 0;
- if (!mTable)
- return CO_E_OBJNOTCONNECTED;
- *aRowCount = mTable->SelectedRowCount();
- return S_OK;
- }
- STDMETHODIMP
- ia2AccessibleTable::get_rowDescription(long aRowIdx, BSTR* aDescription)
- {
- if (!aDescription)
- return E_INVALIDARG;
- *aDescription = nullptr;
- if (!mTable)
- return CO_E_OBJNOTCONNECTED;
- if (aRowIdx < 0 || static_cast<uint32_t>(aRowIdx) >= mTable->RowCount())
- return E_INVALIDARG;
- nsAutoString descr;
- mTable->RowDescription(aRowIdx, descr);
- if (descr.IsEmpty())
- return S_FALSE;
- *aDescription = ::SysAllocStringLen(descr.get(), descr.Length());
- return *aDescription ? S_OK : E_OUTOFMEMORY;
- }
- STDMETHODIMP
- ia2AccessibleTable::get_rowExtentAt(long aRowIdx, long aColIdx, long* aSpan)
- {
- if (!aSpan)
- return E_INVALIDARG;
- *aSpan = 0;
- if (!mTable)
- return CO_E_OBJNOTCONNECTED;
- if (aRowIdx < 0 || aColIdx < 0 ||
- static_cast<uint32_t>(aRowIdx) >= mTable->RowCount() ||
- static_cast<uint32_t>(aColIdx) >= mTable->ColCount())
- return E_INVALIDARG;
- *aSpan = mTable->RowExtentAt(aRowIdx, aColIdx);
- return S_OK;
- }
- STDMETHODIMP
- ia2AccessibleTable::get_rowHeader(IAccessibleTable** aAccessibleTable,
- long* aStartingColumnIndex)
- {
- if (!aAccessibleTable || !aStartingColumnIndex)
- return E_INVALIDARG;
- *aAccessibleTable = nullptr;
- *aStartingColumnIndex = -1;
- return E_NOTIMPL;
- }
- STDMETHODIMP
- ia2AccessibleTable::get_rowIndex(long aCellIdx, long* aRowIdx)
- {
- if (!aRowIdx)
- return E_INVALIDARG;
- *aRowIdx = 0;
- if (!mTable)
- return CO_E_OBJNOTCONNECTED;
- if (aCellIdx < 0 ||
- static_cast<uint32_t>(aCellIdx) >= mTable->ColCount() * mTable->RowCount())
- return E_INVALIDARG;
- *aRowIdx = mTable->RowIndexAt(aCellIdx);
- return S_OK;
- }
- STDMETHODIMP
- ia2AccessibleTable::get_selectedChildren(long aMaxChildren, long** aChildren,
- long* aNChildren)
- {
- if (!aChildren || !aNChildren)
- return E_INVALIDARG;
- *aChildren = nullptr;
- *aNChildren = 0;
- if (!mTable)
- return CO_E_OBJNOTCONNECTED;
- AutoTArray<uint32_t, 30> cellIndices;
- mTable->SelectedCellIndices(&cellIndices);
- uint32_t maxCells = cellIndices.Length();
- if (maxCells == 0)
- return S_FALSE;
- *aChildren = static_cast<LONG*>(moz_xmalloc(sizeof(LONG) * maxCells));
- *aNChildren = maxCells;
- for (uint32_t i = 0; i < maxCells; i++)
- (*aChildren)[i] = cellIndices[i];
- return S_OK;
- }
- STDMETHODIMP
- ia2AccessibleTable::get_selectedColumns(long aMaxColumns, long** aColumns,
- long* aNColumns)
- {
- return get_selectedColumns(aColumns, aNColumns);
- }
- STDMETHODIMP
- ia2AccessibleTable::get_selectedRows(long aMaxRows, long** aRows, long* aNRows)
- {
- return get_selectedRows(aRows, aNRows);
- }
- STDMETHODIMP
- ia2AccessibleTable::get_summary(IUnknown** aAccessible)
- {
- if (!aAccessible)
- return E_INVALIDARG;
- // Neither html:table nor xul:tree nor ARIA grid/tree have an ability to
- // link an accessible object to specify a summary. There is closes method
- // in Table::summary to get a summary as a string which is not mapped
- // directly to IAccessible2.
- *aAccessible = nullptr;
- return S_FALSE;
- }
- STDMETHODIMP
- ia2AccessibleTable::get_isColumnSelected(long aColIdx, boolean* aIsSelected)
- {
- if (!aIsSelected)
- return E_INVALIDARG;
- *aIsSelected = false;
- if (!mTable)
- return CO_E_OBJNOTCONNECTED;
- if (aColIdx < 0 || static_cast<uint32_t>(aColIdx) >= mTable->ColCount())
- return E_INVALIDARG;
- *aIsSelected = mTable->IsColSelected(aColIdx);
- return S_OK;
- }
- STDMETHODIMP
- ia2AccessibleTable::get_isRowSelected(long aRowIdx, boolean* aIsSelected)
- {
- if (!aIsSelected)
- return E_INVALIDARG;
- *aIsSelected = false;
- if (!mTable)
- return CO_E_OBJNOTCONNECTED;
- if (aRowIdx < 0 || static_cast<uint32_t>(aRowIdx) >= mTable->RowCount())
- return E_INVALIDARG;
- *aIsSelected = mTable->IsRowSelected(aRowIdx);
- return S_OK;
- }
- STDMETHODIMP
- ia2AccessibleTable::get_isSelected(long aRowIdx, long aColIdx,
- boolean* aIsSelected)
- {
- if (!aIsSelected)
- return E_INVALIDARG;
- *aIsSelected = false;
- if (!mTable)
- return CO_E_OBJNOTCONNECTED;
- if (aRowIdx < 0 || aColIdx < 0 ||
- static_cast<uint32_t>(aColIdx) >= mTable->ColCount() ||
- static_cast<uint32_t>(aRowIdx) >= mTable->RowCount())
- return E_INVALIDARG;
- *aIsSelected = mTable->IsCellSelected(aRowIdx, aColIdx);
- return S_OK;
- }
- STDMETHODIMP
- ia2AccessibleTable::selectRow(long aRowIdx)
- {
- if (!mTable)
- return CO_E_OBJNOTCONNECTED;
- if (aRowIdx < 0 || static_cast<uint32_t>(aRowIdx) >= mTable->RowCount())
- return E_INVALIDARG;
- mTable->SelectRow(aRowIdx);
- return S_OK;
- }
- STDMETHODIMP
- ia2AccessibleTable::selectColumn(long aColIdx)
- {
- if (!mTable)
- return CO_E_OBJNOTCONNECTED;
- if (aColIdx < 0 || static_cast<uint32_t>(aColIdx) >= mTable->ColCount())
- return E_INVALIDARG;
- mTable->SelectCol(aColIdx);
- return S_OK;
- }
- STDMETHODIMP
- ia2AccessibleTable::unselectRow(long aRowIdx)
- {
- if (!mTable)
- return CO_E_OBJNOTCONNECTED;
- if (aRowIdx < 0 || static_cast<uint32_t>(aRowIdx) >= mTable->RowCount())
- return E_INVALIDARG;
- mTable->UnselectRow(aRowIdx);
- return S_OK;
- }
- STDMETHODIMP
- ia2AccessibleTable::unselectColumn(long aColIdx)
- {
- if (!mTable)
- return CO_E_OBJNOTCONNECTED;
- if (aColIdx < 0 || static_cast<uint32_t>(aColIdx) >= mTable->ColCount())
- return E_INVALIDARG;
- mTable->UnselectCol(aColIdx);
- return S_OK;
- }
- STDMETHODIMP
- ia2AccessibleTable::get_rowColumnExtentsAtIndex(long aCellIdx, long* aRowIdx,
- long* aColIdx,
- long* aRowExtents,
- long* aColExtents,
- boolean* aIsSelected)
- {
- if (!aRowIdx || !aColIdx || !aRowExtents || !aColExtents || !aIsSelected)
- return E_INVALIDARG;
- *aRowIdx = 0;
- *aColIdx = 0;
- *aRowExtents = 0;
- *aColExtents = 0;
- *aIsSelected = false;
- if (!mTable)
- return CO_E_OBJNOTCONNECTED;
- if (aCellIdx < 0 ||
- static_cast<uint32_t>(aCellIdx) >= mTable->ColCount() * mTable->RowCount())
- return E_INVALIDARG;
- int32_t colIdx = 0, rowIdx = 0;
- mTable->RowAndColIndicesAt(aCellIdx, &rowIdx, &colIdx);
- *aRowIdx = rowIdx;
- *aColIdx = colIdx;
- *aRowExtents = mTable->RowExtentAt(rowIdx, colIdx);
- *aColExtents = mTable->ColExtentAt(rowIdx, colIdx);
- *aIsSelected = mTable->IsCellSelected(rowIdx, colIdx);
- return S_OK;
- }
- STDMETHODIMP
- ia2AccessibleTable::get_modelChange(IA2TableModelChange* aModelChange)
- {
- return E_NOTIMPL;
- }
- ////////////////////////////////////////////////////////////////////////////////
- // IAccessibleTable2
- STDMETHODIMP
- ia2AccessibleTable::get_cellAt(long aRowIdx, long aColIdx, IUnknown** aCell)
- {
- if (!aCell)
- return E_INVALIDARG;
- *aCell = nullptr;
- if (!mTable)
- return CO_E_OBJNOTCONNECTED;
- AccessibleWrap* cell =
- static_cast<AccessibleWrap*>(mTable->CellAt(aRowIdx, aColIdx));
- if (!cell)
- return E_INVALIDARG;
- (*aCell = static_cast<IAccessible*>(cell))->AddRef();
- return S_OK;
- }
- STDMETHODIMP
- ia2AccessibleTable::get_nSelectedCells(long* aCellCount)
- {
- if (!aCellCount)
- return E_INVALIDARG;
- *aCellCount = 0;
- if (!mTable)
- return CO_E_OBJNOTCONNECTED;
- *aCellCount = mTable->SelectedCellCount();
- return S_OK;
- }
- STDMETHODIMP
- ia2AccessibleTable::get_selectedCells(IUnknown*** aCells, long* aNSelectedCells)
- {
- if (!aCells || !aNSelectedCells)
- return E_INVALIDARG;
- *aCells = nullptr;
- *aNSelectedCells = 0;
- if (!mTable)
- return CO_E_OBJNOTCONNECTED;
- AutoTArray<Accessible*, 30> cells;
- mTable->SelectedCells(&cells);
- if (cells.IsEmpty())
- return S_FALSE;
- *aCells =
- static_cast<IUnknown**>(::CoTaskMemAlloc(sizeof(IUnknown*) *
- cells.Length()));
- if (!*aCells)
- return E_OUTOFMEMORY;
- for (uint32_t i = 0; i < cells.Length(); i++) {
- (*aCells)[i] =
- static_cast<IAccessible*>(static_cast<AccessibleWrap*>(cells[i]));
- ((*aCells)[i])->AddRef();
- }
- *aNSelectedCells = cells.Length();
- return S_OK;
- }
- STDMETHODIMP
- ia2AccessibleTable::get_selectedColumns(long** aColumns, long* aNColumns)
- {
- if (!aColumns || !aNColumns)
- return E_INVALIDARG;
- *aColumns = nullptr;
- *aNColumns = 0;
- if (!mTable)
- return CO_E_OBJNOTCONNECTED;
- AutoTArray<uint32_t, 30> colIndices;
- mTable->SelectedColIndices(&colIndices);
- uint32_t maxCols = colIndices.Length();
- if (maxCols == 0)
- return S_FALSE;
- *aColumns = static_cast<LONG*>(moz_xmalloc(sizeof(LONG) * maxCols));
- *aNColumns = maxCols;
- for (uint32_t i = 0; i < maxCols; i++)
- (*aColumns)[i] = colIndices[i];
- return S_OK;
- }
- STDMETHODIMP
- ia2AccessibleTable::get_selectedRows(long** aRows, long* aNRows)
- {
- if (!aRows || !aNRows)
- return E_INVALIDARG;
- *aRows = nullptr;
- *aNRows = 0;
- if (!mTable)
- return CO_E_OBJNOTCONNECTED;
- AutoTArray<uint32_t, 30> rowIndices;
- mTable->SelectedRowIndices(&rowIndices);
- uint32_t maxRows = rowIndices.Length();
- if (maxRows == 0)
- return S_FALSE;
- *aRows = static_cast<LONG*>(moz_xmalloc(sizeof(LONG) * maxRows));
- *aNRows = maxRows;
- for (uint32_t i = 0; i < maxRows; i++)
- (*aRows)[i] = rowIndices[i];
- return S_OK;
- }
|