michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim:expandtab:shiftwidth=2:tabstop=2: michael@0: */ 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 michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "ia2AccessibleTableCell.h" michael@0: michael@0: #include "Accessible2.h" michael@0: #include "AccessibleTable2_i.c" michael@0: #include "AccessibleTableCell_i.c" michael@0: michael@0: #include "AccessibleWrap.h" michael@0: #include "TableAccessible.h" michael@0: #include "TableCellAccessible.h" michael@0: #include "IUnknownImpl.h" michael@0: michael@0: #include "nsCOMPtr.h" michael@0: #include "nsString.h" michael@0: michael@0: using namespace mozilla::a11y; michael@0: michael@0: // IUnknown michael@0: michael@0: STDMETHODIMP michael@0: ia2AccessibleTableCell::QueryInterface(REFIID iid, void** ppv) michael@0: { michael@0: if (!ppv) michael@0: return E_INVALIDARG; michael@0: michael@0: *ppv = nullptr; michael@0: michael@0: if (IID_IAccessibleTableCell == iid) { michael@0: *ppv = static_cast(this); michael@0: (reinterpret_cast(*ppv))->AddRef(); michael@0: return S_OK; michael@0: } michael@0: michael@0: return E_NOINTERFACE; michael@0: } michael@0: michael@0: //////////////////////////////////////////////////////////////////////////////// michael@0: // IAccessibleTableCell michael@0: michael@0: STDMETHODIMP michael@0: ia2AccessibleTableCell::get_table(IUnknown** aTable) michael@0: { michael@0: A11Y_TRYBLOCK_BEGIN michael@0: michael@0: if (!aTable) michael@0: return E_INVALIDARG; michael@0: michael@0: *aTable = nullptr; michael@0: if (!mTableCell) michael@0: return CO_E_OBJNOTCONNECTED; michael@0: michael@0: TableAccessible* table = mTableCell->Table(); michael@0: if (!table) michael@0: return E_FAIL; michael@0: michael@0: AccessibleWrap* wrap = static_cast(table->AsAccessible()); michael@0: *aTable = static_cast(wrap); michael@0: (*aTable)->AddRef(); michael@0: return S_OK; michael@0: michael@0: A11Y_TRYBLOCK_END michael@0: } michael@0: michael@0: STDMETHODIMP michael@0: ia2AccessibleTableCell::get_columnExtent(long* aSpan) michael@0: { michael@0: A11Y_TRYBLOCK_BEGIN michael@0: michael@0: if (!aSpan) michael@0: return E_INVALIDARG; michael@0: michael@0: *aSpan = 0; michael@0: if (!mTableCell) michael@0: return CO_E_OBJNOTCONNECTED; michael@0: michael@0: *aSpan = mTableCell->ColExtent(); michael@0: michael@0: return S_OK; michael@0: michael@0: A11Y_TRYBLOCK_END michael@0: } michael@0: michael@0: STDMETHODIMP michael@0: ia2AccessibleTableCell::get_columnHeaderCells(IUnknown*** aCellAccessibles, michael@0: long* aNColumnHeaderCells) michael@0: { michael@0: A11Y_TRYBLOCK_BEGIN michael@0: michael@0: if (!aCellAccessibles || !aNColumnHeaderCells) michael@0: return E_INVALIDARG; michael@0: michael@0: *aCellAccessibles = nullptr; michael@0: *aNColumnHeaderCells = 0; michael@0: if (!mTableCell) michael@0: return CO_E_OBJNOTCONNECTED; michael@0: michael@0: nsAutoTArray cells; michael@0: mTableCell->ColHeaderCells(&cells); michael@0: michael@0: *aNColumnHeaderCells = cells.Length(); michael@0: *aCellAccessibles = michael@0: static_cast(::CoTaskMemAlloc(sizeof(IUnknown*) * michael@0: cells.Length())); michael@0: michael@0: if (!*aCellAccessibles) michael@0: return E_OUTOFMEMORY; michael@0: michael@0: for (uint32_t i = 0; i < cells.Length(); i++) { michael@0: AccessibleWrap* cell = static_cast(cells[i]); michael@0: (*aCellAccessibles)[i] = static_cast(cell); michael@0: (*aCellAccessibles)[i]->AddRef(); michael@0: } michael@0: michael@0: return S_OK; michael@0: michael@0: A11Y_TRYBLOCK_END michael@0: } michael@0: michael@0: STDMETHODIMP michael@0: ia2AccessibleTableCell::get_columnIndex(long* aColIdx) michael@0: { michael@0: A11Y_TRYBLOCK_BEGIN michael@0: michael@0: if (!aColIdx) michael@0: return E_INVALIDARG; michael@0: michael@0: *aColIdx = -1; michael@0: if (!mTableCell) michael@0: return CO_E_OBJNOTCONNECTED; michael@0: michael@0: *aColIdx = mTableCell->ColIdx(); michael@0: return S_OK; michael@0: michael@0: A11Y_TRYBLOCK_END michael@0: } michael@0: michael@0: STDMETHODIMP michael@0: ia2AccessibleTableCell::get_rowExtent(long* aSpan) michael@0: { michael@0: A11Y_TRYBLOCK_BEGIN michael@0: michael@0: if (!aSpan) michael@0: return E_INVALIDARG; michael@0: michael@0: *aSpan = 0; michael@0: if (!mTableCell) michael@0: return CO_E_OBJNOTCONNECTED; michael@0: michael@0: *aSpan = mTableCell->RowExtent(); michael@0: return S_OK; michael@0: michael@0: A11Y_TRYBLOCK_END michael@0: } michael@0: michael@0: STDMETHODIMP michael@0: ia2AccessibleTableCell::get_rowHeaderCells(IUnknown*** aCellAccessibles, michael@0: long* aNRowHeaderCells) michael@0: { michael@0: A11Y_TRYBLOCK_BEGIN michael@0: michael@0: if (!aCellAccessibles || !aNRowHeaderCells) michael@0: return E_INVALIDARG; michael@0: michael@0: *aCellAccessibles = nullptr; michael@0: *aNRowHeaderCells = 0; michael@0: if (!mTableCell) michael@0: return CO_E_OBJNOTCONNECTED; michael@0: michael@0: nsAutoTArray cells; michael@0: mTableCell->RowHeaderCells(&cells); michael@0: michael@0: *aNRowHeaderCells = cells.Length(); michael@0: *aCellAccessibles = michael@0: static_cast(::CoTaskMemAlloc(sizeof(IUnknown*) * michael@0: cells.Length())); michael@0: if (!*aCellAccessibles) michael@0: return E_OUTOFMEMORY; michael@0: michael@0: for (uint32_t i = 0; i < cells.Length(); i++) { michael@0: AccessibleWrap* cell = static_cast(cells[i]); michael@0: (*aCellAccessibles)[i] = static_cast(cell); michael@0: (*aCellAccessibles)[i]->AddRef(); michael@0: } michael@0: michael@0: return S_OK; michael@0: michael@0: A11Y_TRYBLOCK_END michael@0: } michael@0: michael@0: STDMETHODIMP michael@0: ia2AccessibleTableCell::get_rowIndex(long* aRowIdx) michael@0: { michael@0: A11Y_TRYBLOCK_BEGIN michael@0: michael@0: if (!aRowIdx) michael@0: return E_INVALIDARG; michael@0: michael@0: *aRowIdx = -1; michael@0: if (!mTableCell) michael@0: return CO_E_OBJNOTCONNECTED; michael@0: michael@0: *aRowIdx = mTableCell->RowIdx(); michael@0: return S_OK; michael@0: michael@0: A11Y_TRYBLOCK_END michael@0: } michael@0: michael@0: STDMETHODIMP michael@0: ia2AccessibleTableCell::get_rowColumnExtents(long* aRowIdx, long* aColIdx, michael@0: long* aRowExtents, michael@0: long* aColExtents, michael@0: boolean* aIsSelected) michael@0: { michael@0: A11Y_TRYBLOCK_BEGIN michael@0: michael@0: if (!aRowIdx || !aColIdx || !aRowExtents || !aColExtents || !aIsSelected) michael@0: return E_INVALIDARG; michael@0: michael@0: *aRowIdx = *aColIdx = *aRowExtents = *aColExtents = 0; michael@0: *aIsSelected = false; michael@0: if (!mTableCell) michael@0: return CO_E_OBJNOTCONNECTED; michael@0: michael@0: *aRowIdx = mTableCell->RowIdx(); michael@0: *aColIdx = mTableCell->ColIdx(); michael@0: *aRowExtents = mTableCell->RowExtent(); michael@0: *aColExtents = mTableCell->ColExtent(); michael@0: *aIsSelected = mTableCell->Selected(); michael@0: michael@0: return S_OK; michael@0: michael@0: A11Y_TRYBLOCK_END michael@0: } michael@0: michael@0: STDMETHODIMP michael@0: ia2AccessibleTableCell::get_isSelected(boolean* aIsSelected) michael@0: { michael@0: A11Y_TRYBLOCK_BEGIN michael@0: michael@0: if (!aIsSelected) michael@0: return E_INVALIDARG; michael@0: michael@0: *aIsSelected = false; michael@0: if (!mTableCell) michael@0: return CO_E_OBJNOTCONNECTED; michael@0: michael@0: *aIsSelected = mTableCell->Selected(); michael@0: return S_OK; michael@0: michael@0: A11Y_TRYBLOCK_END michael@0: }