diff --git a/accessible/src/msaa/ARIAGridAccessibleWrap.cpp b/accessible/src/msaa/ARIAGridAccessibleWrap.cpp index d95bd971a97d..0f4f20255224 100644 --- a/accessible/src/msaa/ARIAGridAccessibleWrap.cpp +++ b/accessible/src/msaa/ARIAGridAccessibleWrap.cpp @@ -21,6 +21,12 @@ IMPL_IUNKNOWN_INHERITED1(ARIAGridAccessibleWrap, AccessibleWrap, ia2AccessibleTable) +void +ARIAGridAccessibleWrap::Shutdown() +{ + ia2AccessibleTable::mTable = nullptr; + ARIAGridAccessible::Shutdown(); +} //////////////////////////////////////////////////////////////////////////////// // ARIAGridCellAccessibleWrap diff --git a/accessible/src/msaa/ARIAGridAccessibleWrap.h b/accessible/src/msaa/ARIAGridAccessibleWrap.h index 1ebc2fed8128..7babc5843d7f 100644 --- a/accessible/src/msaa/ARIAGridAccessibleWrap.h +++ b/accessible/src/msaa/ARIAGridAccessibleWrap.h @@ -24,13 +24,15 @@ class ARIAGridAccessibleWrap : public ARIAGridAccessible, { public: ARIAGridAccessibleWrap(nsIContent* aContent, DocAccessible* aDoc) : - ARIAGridAccessible(aContent, aDoc) {} + ARIAGridAccessible(aContent, aDoc), ia2AccessibleTable(this) {} // IUnknown DECL_IUNKNOWN_INHERITED // nsISupports NS_DECL_ISUPPORTS_INHERITED + + virtual void Shutdown() MOZ_OVERRIDE; }; /** diff --git a/accessible/src/msaa/HTMLTableAccessibleWrap.cpp b/accessible/src/msaa/HTMLTableAccessibleWrap.cpp index c0a3d5661e2d..a87cfea0bb5f 100644 --- a/accessible/src/msaa/HTMLTableAccessibleWrap.cpp +++ b/accessible/src/msaa/HTMLTableAccessibleWrap.cpp @@ -20,6 +20,12 @@ IMPL_IUNKNOWN_INHERITED1(HTMLTableAccessibleWrap, AccessibleWrap, ia2AccessibleTable) +void +HTMLTableAccessibleWrap::Shutdown() +{ + ia2AccessibleTable::mTable = nullptr; + HTMLTableAccessible::Shutdown(); +} //////////////////////////////////////////////////////////////////////////////// // HTMLTableCellAccessibleWrap diff --git a/accessible/src/msaa/HTMLTableAccessibleWrap.h b/accessible/src/msaa/HTMLTableAccessibleWrap.h index 84df5eaa56de..55529db2e90a 100644 --- a/accessible/src/msaa/HTMLTableAccessibleWrap.h +++ b/accessible/src/msaa/HTMLTableAccessibleWrap.h @@ -25,13 +25,15 @@ class HTMLTableAccessibleWrap : public HTMLTableAccessible, { public: HTMLTableAccessibleWrap(nsIContent* aContent, DocAccessible* aDoc) : - HTMLTableAccessible(aContent, aDoc) {} + HTMLTableAccessible(aContent, aDoc), ia2AccessibleTable(this) {} // IUnknown DECL_IUNKNOWN_INHERITED // nsISupports NS_DECL_ISUPPORTS_INHERITED + + virtual void Shutdown() MOZ_OVERRIDE; }; diff --git a/accessible/src/msaa/XULListboxAccessibleWrap.cpp b/accessible/src/msaa/XULListboxAccessibleWrap.cpp index 1d744871ac0e..d9f768a90740 100644 --- a/accessible/src/msaa/XULListboxAccessibleWrap.cpp +++ b/accessible/src/msaa/XULListboxAccessibleWrap.cpp @@ -11,12 +11,6 @@ using namespace mozilla::a11y; // XULListboxAccessibleWrap //////////////////////////////////////////////////////////////////////////////// -XULListboxAccessibleWrap:: - XULListboxAccessibleWrap(nsIContent* aContent, DocAccessible* aDoc) : - XULListboxAccessible(aContent, aDoc) -{ -} - NS_IMPL_ISUPPORTS_INHERITED0(XULListboxAccessibleWrap, XULListboxAccessible) @@ -25,6 +19,12 @@ IMPL_IUNKNOWN_QUERY_CLASS_COND(ia2AccessibleTable, IsMulticolumn()); IMPL_IUNKNOWN_QUERY_CLASS(AccessibleWrap) IMPL_IUNKNOWN_QUERY_TAIL +void +XULListboxAccessibleWrap::Shutdown() +{ + ia2AccessibleTable::mTable = nullptr; + XULListboxAccessible::Shutdown(); +} //////////////////////////////////////////////////////////////////////////////// // XULListCellAccessibleWrap diff --git a/accessible/src/msaa/XULListboxAccessibleWrap.h b/accessible/src/msaa/XULListboxAccessibleWrap.h index 389c30278a9a..75f08b7e18fb 100644 --- a/accessible/src/msaa/XULListboxAccessibleWrap.h +++ b/accessible/src/msaa/XULListboxAccessibleWrap.h @@ -22,13 +22,16 @@ class XULListboxAccessibleWrap : public XULListboxAccessible, public ia2AccessibleTable { public: - XULListboxAccessibleWrap(nsIContent* aContent, DocAccessible* aDoc); + XULListboxAccessibleWrap(nsIContent* aContent, DocAccessible* aDoc) : + XULListboxAccessible(aContent, aDoc), ia2AccessibleTable(this) {} // IUnknown DECL_IUNKNOWN_INHERITED // nsISupports NS_DECL_ISUPPORTS_INHERITED + + virtual void Shutdown() MOZ_OVERRIDE; }; /** diff --git a/accessible/src/msaa/XULTreeGridAccessibleWrap.cpp b/accessible/src/msaa/XULTreeGridAccessibleWrap.cpp index d327d173394b..233eac562fbd 100644 --- a/accessible/src/msaa/XULTreeGridAccessibleWrap.cpp +++ b/accessible/src/msaa/XULTreeGridAccessibleWrap.cpp @@ -11,12 +11,6 @@ using namespace mozilla::a11y; // XULTreeGridAccessibleWrap //////////////////////////////////////////////////////////////////////////////// -XULTreeGridAccessibleWrap:: - XULTreeGridAccessibleWrap(nsIContent* aContent, DocAccessible* aDoc) : - XULTreeGridAccessible(aContent, aDoc) -{ -} - NS_IMPL_ISUPPORTS_INHERITED0(XULTreeGridAccessibleWrap, XULTreeGridAccessible) @@ -24,6 +18,12 @@ IMPL_IUNKNOWN_INHERITED1(XULTreeGridAccessibleWrap, AccessibleWrap, ia2AccessibleTable) +void +XULTreeGridAccessibleWrap::Shutdown() +{ + ia2AccessibleTable::mTable = nullptr; + XULTreeGridAccessible::Shutdown(); +} //////////////////////////////////////////////////////////////////////////////// // XULTreeGridCellAccessibleWrap diff --git a/accessible/src/msaa/XULTreeGridAccessibleWrap.h b/accessible/src/msaa/XULTreeGridAccessibleWrap.h index 44aaf8e7ffcf..c56dddbced18 100644 --- a/accessible/src/msaa/XULTreeGridAccessibleWrap.h +++ b/accessible/src/msaa/XULTreeGridAccessibleWrap.h @@ -22,13 +22,16 @@ class XULTreeGridAccessibleWrap : public XULTreeGridAccessible, public ia2AccessibleTable { public: - XULTreeGridAccessibleWrap(nsIContent* aContent, DocAccessible* aDoc); + XULTreeGridAccessibleWrap(nsIContent* aContent, DocAccessible* aDoc) : + XULTreeGridAccessible(aContent, aDoc), ia2AccessibleTable(this) {} // IUnknown DECL_IUNKNOWN_INHERITED // nsISupports NS_DECL_ISUPPORTS_INHERITED + + virtual void Shutdown() MOZ_OVERRIDE; }; /** diff --git a/accessible/src/windows/ia2/ia2AccessibleTable.cpp b/accessible/src/windows/ia2/ia2AccessibleTable.cpp index a8fc92b44e26..fe196e8e8e41 100644 --- a/accessible/src/windows/ia2/ia2AccessibleTable.cpp +++ b/accessible/src/windows/ia2/ia2AccessibleTable.cpp @@ -11,21 +11,15 @@ #include "AccessibleTable_i.c" #include "AccessibleTable2_i.c" -#include "nsIAccessible.h" -#include "nsIAccessibleTable.h" -#include "nsIWinAccessNode.h" -#include "nsAccessNodeWrap.h" -#include "nsWinUtils.h" +#include "AccessibleWrap.h" #include "Statistics.h" +#include "TableAccessible.h" #include "nsCOMPtr.h" #include "nsString.h" using namespace mozilla::a11y; -#define CANT_QUERY_ASSERTION_MSG \ -"Subclass of ia2AccessibleTable doesn't implement nsIAccessibleTable"\ - // IUnknown STDMETHODIMP @@ -53,36 +47,10 @@ ia2AccessibleTable::QueryInterface(REFIID iid, void** ppv) // IAccessibleTable STDMETHODIMP -ia2AccessibleTable::get_accessibleAt(long aRow, long aColumn, - IUnknown **aAccessible) +ia2AccessibleTable::get_accessibleAt(long aRowIdx, long aColIdx, + IUnknown** aAccessible) { - A11Y_TRYBLOCK_BEGIN - - *aAccessible = NULL; - - nsCOMPtr tableAcc(do_QueryObject(this)); - NS_ASSERTION(tableAcc, CANT_QUERY_ASSERTION_MSG); - if (!tableAcc) - return E_FAIL; - - nsCOMPtr cell; - nsresult rv = tableAcc->GetCellAt(aRow, aColumn, getter_AddRefs(cell)); - if (NS_FAILED(rv)) - return GetHRESULT(rv); - - nsCOMPtr winAccessNode(do_QueryInterface(cell)); - if (!winAccessNode) - return E_FAIL; - - void *instancePtr = NULL; - rv = winAccessNode->QueryNativeInterface(IID_IAccessible2, &instancePtr); - if (NS_FAILED(rv)) - return E_FAIL; - - *aAccessible = static_cast(instancePtr); - return S_OK; - - A11Y_TRYBLOCK_END + return get_cellAt(aRowIdx, aColIdx, aAccessible); } STDMETHODIMP @@ -91,76 +59,54 @@ ia2AccessibleTable::get_caption(IUnknown** aAccessible) A11Y_TRYBLOCK_BEGIN *aAccessible = NULL; + if (!mTable) + return CO_E_OBJNOTCONNECTED; - nsCOMPtr tableAcc(do_QueryObject(this)); - NS_ASSERTION(tableAcc, CANT_QUERY_ASSERTION_MSG); - if (!tableAcc) - return E_FAIL; - - nsCOMPtr caption; - nsresult rv = tableAcc->GetCaption(getter_AddRefs(caption)); - if (NS_FAILED(rv)) - return GetHRESULT(rv); - + AccessibleWrap* caption = static_cast(mTable->Caption()); if (!caption) return S_FALSE; - nsCOMPtr winAccessNode(do_QueryInterface(caption)); - if (!winAccessNode) - return E_FAIL; - - void *instancePtr = NULL; - rv = winAccessNode->QueryNativeInterface(IID_IAccessible2, &instancePtr); - if (NS_FAILED(rv)) - return E_FAIL; - - *aAccessible = static_cast(instancePtr); + (*aAccessible = static_cast(caption))->AddRef(); return S_OK; A11Y_TRYBLOCK_END } STDMETHODIMP -ia2AccessibleTable::get_childIndex(long aRowIndex, long aColumnIndex, - long* aChildIndex) +ia2AccessibleTable::get_childIndex(long aRowIdx, long aColIdx, + long* aChildIdx) { A11Y_TRYBLOCK_BEGIN - *aChildIndex = 0; + *aChildIdx = 0; + if (!mTable) + return CO_E_OBJNOTCONNECTED; - nsCOMPtr tableAcc(do_QueryObject(this)); - NS_ASSERTION(tableAcc, CANT_QUERY_ASSERTION_MSG); - if (!tableAcc) - return E_FAIL; + if (aRowIdx < 0 || aColIdx < 0 || + static_cast(aRowIdx) >= mTable->RowCount() || + static_cast(aColIdx) >= mTable->ColCount()) + return E_INVALIDARG; - int32_t childIndex = 0; - nsresult rv = tableAcc->GetCellIndexAt(aRowIndex, aColumnIndex, &childIndex); - if (NS_FAILED(rv)) - return GetHRESULT(rv); - - *aChildIndex = childIndex; + *aChildIdx = mTable->CellIndexAt(aRowIdx, aColIdx); return S_OK; A11Y_TRYBLOCK_END } STDMETHODIMP -ia2AccessibleTable::get_columnDescription(long aColumn, BSTR* aDescription) +ia2AccessibleTable::get_columnDescription(long aColIdx, BSTR* aDescription) { A11Y_TRYBLOCK_BEGIN *aDescription = NULL; + if (!mTable) + return CO_E_OBJNOTCONNECTED; - nsCOMPtr tableAcc(do_QueryObject(this)); - NS_ASSERTION(tableAcc, CANT_QUERY_ASSERTION_MSG); - if (!tableAcc) - return E_FAIL; + if (aColIdx < 0 || static_cast(aColIdx) >= mTable->ColCount()) + return E_INVALIDARG; nsAutoString descr; - nsresult rv = tableAcc->GetColumnDescription (aColumn, descr); - if (NS_FAILED(rv)) - return GetHRESULT(rv); - + mTable->ColDescription(aColIdx, descr); if (descr.IsEmpty()) return S_FALSE; @@ -171,24 +117,21 @@ ia2AccessibleTable::get_columnDescription(long aColumn, BSTR* aDescription) } STDMETHODIMP -ia2AccessibleTable::get_columnExtentAt(long aRow, long aColumn, - long* nColumnsSpanned) +ia2AccessibleTable::get_columnExtentAt(long aRowIdx, long aColIdx, + long* aSpan) { A11Y_TRYBLOCK_BEGIN - *nColumnsSpanned = 0; + *aSpan = 0; + if (!mTable) + return CO_E_OBJNOTCONNECTED; - nsCOMPtr tableAcc(do_QueryObject(this)); - NS_ASSERTION(tableAcc, CANT_QUERY_ASSERTION_MSG); - if (!tableAcc) - return E_FAIL; + if (aRowIdx < 0 || aColIdx < 0 || + static_cast(aRowIdx) >= mTable->RowCount() || + static_cast(aColIdx) >= mTable->ColCount()) + return E_INVALIDARG; - int32_t columnsSpanned = 0; - nsresult rv = tableAcc->GetColumnExtentAt(aRow, aColumn, &columnsSpanned); - if (NS_FAILED(rv)) - return GetHRESULT(rv); - - *nColumnsSpanned = columnsSpanned; + *aSpan = mTable->ColExtentAt(aRowIdx, aColIdx); return S_OK; A11Y_TRYBLOCK_END @@ -208,46 +151,34 @@ ia2AccessibleTable::get_columnHeader(IAccessibleTable** aAccessibleTable, } STDMETHODIMP -ia2AccessibleTable::get_columnIndex(long aChildIndex, long* aColumnIndex) +ia2AccessibleTable::get_columnIndex(long aCellIdx, long* aColIdx) { A11Y_TRYBLOCK_BEGIN - *aColumnIndex = 0; + *aColIdx = 0; + if (!mTable) + return CO_E_OBJNOTCONNECTED; - nsCOMPtr tableAcc(do_QueryObject(this)); - NS_ASSERTION(tableAcc, CANT_QUERY_ASSERTION_MSG); - if (!tableAcc) - return E_FAIL; + if (aCellIdx < 0 || + static_cast(aCellIdx) >= mTable->ColCount() * mTable->RowCount()) + return E_INVALIDARG; - int32_t columnIndex = 0; - nsresult rv = tableAcc->GetColumnIndexAt(aChildIndex, &columnIndex); - if (NS_FAILED(rv)) - return GetHRESULT(rv); - - *aColumnIndex = columnIndex; + *aColIdx = mTable->ColIndexAt(aCellIdx); return S_OK; A11Y_TRYBLOCK_END } STDMETHODIMP -ia2AccessibleTable::get_nColumns(long* aColumnCount) +ia2AccessibleTable::get_nColumns(long* aColCount) { A11Y_TRYBLOCK_BEGIN - *aColumnCount = 0; + *aColCount = 0; + if (!mTable) + return CO_E_OBJNOTCONNECTED; - nsCOMPtr tableAcc(do_QueryObject(this)); - NS_ASSERTION(tableAcc, CANT_QUERY_ASSERTION_MSG); - if (!tableAcc) - return E_FAIL; - - int32_t columnCount = 0; - nsresult rv = tableAcc->GetColumnCount(&columnCount); - if (NS_FAILED(rv)) - return GetHRESULT(rv); - - *aColumnCount = columnCount; + *aColCount = mTable->ColCount(); return S_OK; A11Y_TRYBLOCK_END @@ -259,18 +190,10 @@ ia2AccessibleTable::get_nRows(long* aRowCount) A11Y_TRYBLOCK_BEGIN *aRowCount = 0; + if (!mTable) + return CO_E_OBJNOTCONNECTED; - nsCOMPtr tableAcc(do_QueryObject(this)); - NS_ASSERTION(tableAcc, CANT_QUERY_ASSERTION_MSG); - if (!tableAcc) - return E_FAIL; - - int32_t rowCount = 0; - nsresult rv = tableAcc->GetRowCount(&rowCount); - if (NS_FAILED(rv)) - return GetHRESULT(rv); - - *aRowCount = rowCount; + *aRowCount = mTable->RowCount(); return S_OK; A11Y_TRYBLOCK_END @@ -279,44 +202,19 @@ ia2AccessibleTable::get_nRows(long* aRowCount) STDMETHODIMP ia2AccessibleTable::get_nSelectedChildren(long* aChildCount) { - A11Y_TRYBLOCK_BEGIN - - *aChildCount = 0; - - nsCOMPtr tableAcc(do_QueryObject(this)); - NS_ASSERTION(tableAcc, CANT_QUERY_ASSERTION_MSG); - if (!tableAcc) - return E_FAIL; - - uint32_t count = 0; - nsresult rv = tableAcc->GetSelectedCellCount(&count); - if (NS_FAILED(rv)) - return GetHRESULT(rv); - - *aChildCount = count; - return S_OK; - - A11Y_TRYBLOCK_END + return get_nSelectedCells(aChildCount); } STDMETHODIMP -ia2AccessibleTable::get_nSelectedColumns(long* aColumnCount) +ia2AccessibleTable::get_nSelectedColumns(long* aColCount) { A11Y_TRYBLOCK_BEGIN - *aColumnCount = 0; + *aColCount = 0; + if (!mTable) + return CO_E_OBJNOTCONNECTED; - nsCOMPtr tableAcc(do_QueryObject(this)); - NS_ASSERTION(tableAcc, CANT_QUERY_ASSERTION_MSG); - if (!tableAcc) - return E_FAIL; - - uint32_t count = 0; - nsresult rv = tableAcc->GetSelectedColumnCount(&count); - if (NS_FAILED(rv)) - return GetHRESULT(rv); - - *aColumnCount = count; + *aColCount = mTable->SelectedColCount(); return S_OK; A11Y_TRYBLOCK_END @@ -328,40 +226,30 @@ ia2AccessibleTable::get_nSelectedRows(long* aRowCount) A11Y_TRYBLOCK_BEGIN *aRowCount = 0; + if (!mTable) + return CO_E_OBJNOTCONNECTED; - nsCOMPtr tableAcc(do_QueryObject(this)); - NS_ASSERTION(tableAcc, CANT_QUERY_ASSERTION_MSG); - if (!tableAcc) - return E_FAIL; + *aRowCount = mTable->SelectedRowCount(); - uint32_t count = 0; - nsresult rv = tableAcc->GetSelectedRowCount(&count); - if (NS_FAILED(rv)) - return GetHRESULT(rv); - - *aRowCount = count; return S_OK; A11Y_TRYBLOCK_END } STDMETHODIMP -ia2AccessibleTable::get_rowDescription(long aRow, BSTR* aDescription) +ia2AccessibleTable::get_rowDescription(long aRowIdx, BSTR* aDescription) { A11Y_TRYBLOCK_BEGIN *aDescription = NULL; + if (!mTable) + return CO_E_OBJNOTCONNECTED; - nsCOMPtr tableAcc(do_QueryObject(this)); - NS_ASSERTION(tableAcc, CANT_QUERY_ASSERTION_MSG); - if (!tableAcc) - return E_FAIL; + if (aRowIdx < 0 || static_cast(aRowIdx) >= mTable->RowCount()) + return E_INVALIDARG; nsAutoString descr; - nsresult rv = tableAcc->GetRowDescription (aRow, descr); - if (NS_FAILED(rv)) - return GetHRESULT(rv); - + mTable->RowDescription(aRowIdx, descr); if (descr.IsEmpty()) return S_FALSE; @@ -372,24 +260,20 @@ ia2AccessibleTable::get_rowDescription(long aRow, BSTR* aDescription) } STDMETHODIMP -ia2AccessibleTable::get_rowExtentAt(long aRow, long aColumn, - long* aNRowsSpanned) +ia2AccessibleTable::get_rowExtentAt(long aRowIdx, long aColIdx, long* aSpan) { A11Y_TRYBLOCK_BEGIN - *aNRowsSpanned = 0; + *aSpan = 0; + if (!mTable) + return CO_E_OBJNOTCONNECTED; - nsCOMPtr tableAcc(do_QueryObject(this)); - NS_ASSERTION(tableAcc, CANT_QUERY_ASSERTION_MSG); - if (!tableAcc) - return E_FAIL; + if (aRowIdx < 0 || aColIdx < 0 || + static_cast(aRowIdx) >= mTable->RowCount() || + static_cast(aColIdx) >= mTable->ColCount()) + return E_INVALIDARG; - int32_t rowsSpanned = 0; - nsresult rv = tableAcc->GetRowExtentAt(aRow, aColumn, &rowsSpanned); - if (NS_FAILED(rv)) - return GetHRESULT(rv); - - *aNRowsSpanned = rowsSpanned; + *aSpan = mTable->RowExtentAt(aRowIdx, aColIdx); return S_OK; A11Y_TRYBLOCK_END @@ -409,23 +293,19 @@ ia2AccessibleTable::get_rowHeader(IAccessibleTable** aAccessibleTable, } STDMETHODIMP -ia2AccessibleTable::get_rowIndex(long aChildIndex, long* aRowIndex) +ia2AccessibleTable::get_rowIndex(long aCellIdx, long* aRowIdx) { A11Y_TRYBLOCK_BEGIN - *aRowIndex = 0; + *aRowIdx = 0; + if (!mTable) + return CO_E_OBJNOTCONNECTED; - nsCOMPtr tableAcc(do_QueryObject(this)); - NS_ASSERTION(tableAcc, CANT_QUERY_ASSERTION_MSG); - if (!tableAcc) - return E_FAIL; + if (aCellIdx < 0 || + static_cast(aCellIdx) >= mTable->ColCount() * mTable->RowCount()) + return E_INVALIDARG; - int32_t rowIndex = 0; - nsresult rv = tableAcc->GetRowIndexAt(aChildIndex, &rowIndex); - if (NS_FAILED(rv)) - return GetHRESULT(rv); - - *aRowIndex = rowIndex; + *aRowIdx = mTable->RowIndexAt(aCellIdx); return S_OK; A11Y_TRYBLOCK_END @@ -437,7 +317,24 @@ ia2AccessibleTable::get_selectedChildren(long aMaxChildren, long** aChildren, { A11Y_TRYBLOCK_BEGIN - return GetSelectedItems(aChildren, aNChildren, ITEMSTYPE_CELLS); + *aChildren = NULL; + *aNChildren = 0; + if (!mTable) + return CO_E_OBJNOTCONNECTED; + + nsAutoTArray cellIndices; + mTable->SelectedCellIndices(&cellIndices); + + uint32_t maxCells = cellIndices.Length(); + if (maxCells == 0) + return S_FALSE; + + *aChildren = static_cast(moz_xmalloc(sizeof(LONG) * maxCells)); + *aNChildren = maxCells; + for (uint32_t i = 0; i < maxCells; i++) + (*aChildren)[i] = cellIndices[i]; + + return S_OK; A11Y_TRYBLOCK_END } @@ -448,7 +345,7 @@ ia2AccessibleTable::get_selectedColumns(long aMaxColumns, long** aColumns, { A11Y_TRYBLOCK_BEGIN - return GetSelectedItems(aColumns, aNColumns, ITEMSTYPE_COLUMNS); + return get_selectedColumns(aColumns, aNColumns); A11Y_TRYBLOCK_END } @@ -458,7 +355,7 @@ ia2AccessibleTable::get_selectedRows(long aMaxRows, long** aRows, long* aNRows) { A11Y_TRYBLOCK_BEGIN - return GetSelectedItems(aRows, aNRows, ITEMSTYPE_ROWS); + return get_selectedRows(aRows, aNRows); A11Y_TRYBLOCK_END } @@ -480,182 +377,159 @@ ia2AccessibleTable::get_summary(IUnknown** aAccessible) } STDMETHODIMP -ia2AccessibleTable::get_isColumnSelected(long aColumn, boolean* aIsSelected) +ia2AccessibleTable::get_isColumnSelected(long aColIdx, boolean* aIsSelected) { A11Y_TRYBLOCK_BEGIN *aIsSelected = false; + if (!mTable) + return CO_E_OBJNOTCONNECTED; - nsCOMPtr tableAcc(do_QueryObject(this)); - NS_ASSERTION(tableAcc, CANT_QUERY_ASSERTION_MSG); - if (!tableAcc) - return E_FAIL; + if (aColIdx < 0 || static_cast(aColIdx) >= mTable->ColCount()) + return E_INVALIDARG; - bool isSelected = false; - nsresult rv = tableAcc->IsColumnSelected(aColumn, &isSelected); - if (NS_FAILED(rv)) - return GetHRESULT(rv); - - *aIsSelected = isSelected; + *aIsSelected = mTable->IsColSelected(aColIdx); return S_OK; A11Y_TRYBLOCK_END } STDMETHODIMP -ia2AccessibleTable::get_isRowSelected(long aRow, boolean* aIsSelected) +ia2AccessibleTable::get_isRowSelected(long aRowIdx, boolean* aIsSelected) { A11Y_TRYBLOCK_BEGIN - nsCOMPtr tableAcc(do_QueryObject(this)); - NS_ASSERTION(tableAcc, CANT_QUERY_ASSERTION_MSG); - if (!tableAcc) - return E_FAIL; + *aIsSelected = false; + if (!mTable) + return CO_E_OBJNOTCONNECTED; - bool isSelected = false; - nsresult rv = tableAcc->IsRowSelected(aRow, &isSelected); - if (NS_FAILED(rv)) - return GetHRESULT(rv); + if (aRowIdx < 0 || static_cast(aRowIdx) >= mTable->RowCount()) + return E_INVALIDARG; - *aIsSelected = isSelected; + *aIsSelected = mTable->IsRowSelected(aRowIdx); return S_OK; A11Y_TRYBLOCK_END } STDMETHODIMP -ia2AccessibleTable::get_isSelected(long aRow, long aColumn, +ia2AccessibleTable::get_isSelected(long aRowIdx, long aColIdx, boolean* aIsSelected) { A11Y_TRYBLOCK_BEGIN *aIsSelected = false; + if (!mTable) + return CO_E_OBJNOTCONNECTED; - nsCOMPtr tableAcc(do_QueryObject(this)); - NS_ASSERTION(tableAcc, CANT_QUERY_ASSERTION_MSG); - if (!tableAcc) - return E_FAIL; + if (aRowIdx < 0 || aColIdx < 0 || + static_cast(aColIdx) >= mTable->ColCount() || + static_cast(aRowIdx) >= mTable->RowCount()) + return E_INVALIDARG; - bool isSelected = false; - nsresult rv = tableAcc->IsCellSelected(aRow, aColumn, &isSelected); - if (NS_FAILED(rv)) - return GetHRESULT(rv); - - *aIsSelected = isSelected; + *aIsSelected = mTable->IsCellSelected(aRowIdx, aColIdx); return S_OK; A11Y_TRYBLOCK_END } STDMETHODIMP -ia2AccessibleTable::selectRow(long aRow) +ia2AccessibleTable::selectRow(long aRowIdx) { A11Y_TRYBLOCK_BEGIN - nsCOMPtr tableAcc(do_QueryObject(this)); - NS_ASSERTION(tableAcc, CANT_QUERY_ASSERTION_MSG); - if (!tableAcc) - return E_FAIL; + if (!mTable) + return CO_E_OBJNOTCONNECTED; - nsresult rv = tableAcc->SelectRow(aRow); - return GetHRESULT(rv); + if (aRowIdx < 0 || static_cast(aRowIdx) >= mTable->RowCount()) + return E_INVALIDARG; + + mTable->SelectRow(aRowIdx); + return S_OK; A11Y_TRYBLOCK_END } STDMETHODIMP -ia2AccessibleTable::selectColumn(long aColumn) +ia2AccessibleTable::selectColumn(long aColIdx) { A11Y_TRYBLOCK_BEGIN - nsCOMPtr tableAcc(do_QueryObject(this)); - NS_ASSERTION(tableAcc, CANT_QUERY_ASSERTION_MSG); - if (!tableAcc) - return E_FAIL; + if (!mTable) + return CO_E_OBJNOTCONNECTED; - nsresult rv = tableAcc->SelectColumn(aColumn); - return GetHRESULT(rv); + if (aColIdx < 0 || static_cast(aColIdx) >= mTable->ColCount()) + return E_INVALIDARG; + + mTable->SelectCol(aColIdx); + return S_OK; A11Y_TRYBLOCK_END } STDMETHODIMP -ia2AccessibleTable::unselectRow(long aRow) +ia2AccessibleTable::unselectRow(long aRowIdx) { A11Y_TRYBLOCK_BEGIN - nsCOMPtr tableAcc(do_QueryObject(this)); - NS_ASSERTION(tableAcc, CANT_QUERY_ASSERTION_MSG); - if (!tableAcc) - return E_FAIL; + if (!mTable) + return CO_E_OBJNOTCONNECTED; - nsresult rv = tableAcc->UnselectRow(aRow); - return GetHRESULT(rv); + if (aRowIdx < 0 || static_cast(aRowIdx) >= mTable->RowCount()) + return E_INVALIDARG; + + mTable->UnselectRow(aRowIdx); + return S_OK; A11Y_TRYBLOCK_END } STDMETHODIMP -ia2AccessibleTable::unselectColumn(long aColumn) +ia2AccessibleTable::unselectColumn(long aColIdx) { A11Y_TRYBLOCK_BEGIN - nsCOMPtr tableAcc(do_QueryObject(this)); - NS_ASSERTION(tableAcc, CANT_QUERY_ASSERTION_MSG); - if (!tableAcc) - return E_FAIL; + if (!mTable) + return CO_E_OBJNOTCONNECTED; - nsresult rv = tableAcc->UnselectColumn(aColumn); - return GetHRESULT(rv); + if (aColIdx < 0 || static_cast(aColIdx) >= mTable->ColCount()) + return E_INVALIDARG; + + mTable->UnselectCol(aColIdx); + return S_OK; A11Y_TRYBLOCK_END } STDMETHODIMP -ia2AccessibleTable::get_rowColumnExtentsAtIndex(long aIndex, long* aRow, - long* aColumn, +ia2AccessibleTable::get_rowColumnExtentsAtIndex(long aCellIdx, long* aRowIdx, + long* aColIdx, long* aRowExtents, - long* aColumnExtents, + long* aColExtents, boolean* aIsSelected) { A11Y_TRYBLOCK_BEGIN - *aRow = 0; - *aColumn = 0; + *aRowIdx = 0; + *aColIdx = 0; *aRowExtents = 0; - *aColumnExtents = 0; + *aColExtents = 0; *aIsSelected = false; + if (!mTable) + return CO_E_OBJNOTCONNECTED; - nsCOMPtr tableAcc(do_QueryObject(this)); - NS_ASSERTION(tableAcc, CANT_QUERY_ASSERTION_MSG); - if (!tableAcc) - return E_FAIL; + if (aCellIdx < 0 || + static_cast(aCellIdx) >= mTable->ColCount() * mTable->RowCount()) + return E_INVALIDARG; - int32_t rowIdx = -1, columnIdx = -1; - nsresult rv = tableAcc->GetRowAndColumnIndicesAt(aIndex, &rowIdx, &columnIdx); - if (NS_FAILED(rv)) - return GetHRESULT(rv); + 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); - int32_t rowExtents = 0; - rv = tableAcc->GetRowExtentAt(rowIdx, columnIdx, &rowExtents); - if (NS_FAILED(rv)) - return GetHRESULT(rv); - - int32_t columnExtents = 0; - rv = tableAcc->GetColumnExtentAt(rowIdx, columnIdx, &columnExtents); - if (NS_FAILED(rv)) - return GetHRESULT(rv); - - bool isSelected = false; - rv = tableAcc->IsCellSelected(rowIdx, columnIdx, &isSelected); - if (NS_FAILED(rv)) - return GetHRESULT(rv); - - *aRow = rowIdx; - *aColumn = columnIdx; - *aRowExtents = rowExtents; - *aColumnExtents = columnExtents; - *aIsSelected = isSelected; return S_OK; A11Y_TRYBLOCK_END @@ -671,15 +545,39 @@ ia2AccessibleTable::get_modelChange(IA2TableModelChange* aModelChange) // IAccessibleTable2 STDMETHODIMP -ia2AccessibleTable::get_cellAt(long aRow, long aColumn, IUnknown** aCell) +ia2AccessibleTable::get_cellAt(long aRowIdx, long aColIdx, IUnknown** aCell) { - return get_accessibleAt(aRow, aColumn, aCell); + A11Y_TRYBLOCK_BEGIN + + *aCell = NULL; + + if (!mTable) + return CO_E_OBJNOTCONNECTED; + + AccessibleWrap* cell = + static_cast(mTable->CellAt(aRowIdx, aColIdx)); + if (!cell) + return E_INVALIDARG; + + (*aCell = static_cast(cell))->AddRef(); + return S_OK; + + A11Y_TRYBLOCK_END } STDMETHODIMP ia2AccessibleTable::get_nSelectedCells(long* aCellCount) { - return get_nSelectedChildren(aCellCount); + A11Y_TRYBLOCK_BEGIN + + *aCellCount = 0; + if (!mTable) + return CO_E_OBJNOTCONNECTED; + + *aCellCount = mTable->SelectedCellCount(); + return S_OK; + + A11Y_TRYBLOCK_END } STDMETHODIMP @@ -687,17 +585,30 @@ ia2AccessibleTable::get_selectedCells(IUnknown*** aCells, long* aNSelectedCells) { A11Y_TRYBLOCK_BEGIN - nsCOMPtr tableAcc(do_QueryObject(this)); - NS_ASSERTION(tableAcc, CANT_QUERY_ASSERTION_MSG); - if (!tableAcc) - return E_FAIL; + *aCells = NULL; + *aNSelectedCells = 0; + if (!mTable) + return CO_E_OBJNOTCONNECTED; - nsCOMPtr geckoCells; - nsresult rv = tableAcc->GetSelectedCells(getter_AddRefs(geckoCells)); - if (NS_FAILED(rv)) - return GetHRESULT(rv); + nsAutoTArray cells; + mTable->SelectedCells(&cells); + if (cells.IsEmpty()) + return S_FALSE; - return nsWinUtils::ConvertToIA2Array(geckoCells, aCells, aNSelectedCells); + *aCells = + static_cast(::CoTaskMemAlloc(sizeof(IUnknown*) * + cells.Length())); + if (!*aCells) + return E_OUTOFMEMORY; + + for (uint32_t i = 0; i < cells.Length(); i++) { + (*aCells)[i] = + static_cast(static_cast(cells[i])); + ((*aCells)[i])->AddRef(); + } + + *aNSelectedCells = cells.Length(); + return S_OK; A11Y_TRYBLOCK_END } @@ -707,7 +618,24 @@ ia2AccessibleTable::get_selectedColumns(long** aColumns, long* aNColumns) { A11Y_TRYBLOCK_BEGIN - return GetSelectedItems(aColumns, aNColumns, ITEMSTYPE_COLUMNS); + *aColumns = NULL; + *aNColumns = 0; + if (!mTable) + return CO_E_OBJNOTCONNECTED; + + nsAutoTArray colIndices; + mTable->SelectedColIndices(&colIndices); + + uint32_t maxCols = colIndices.Length(); + if (maxCols == 0) + return S_FALSE; + + *aColumns = static_cast(moz_xmalloc(sizeof(LONG) * maxCols)); + *aNColumns = maxCols; + for (uint32_t i = 0; i < maxCols; i++) + (*aColumns)[i] = colIndices[i]; + + return S_OK; A11Y_TRYBLOCK_END } @@ -717,58 +645,24 @@ ia2AccessibleTable::get_selectedRows(long** aRows, long* aNRows) { A11Y_TRYBLOCK_BEGIN - return GetSelectedItems(aRows, aNRows, ITEMSTYPE_ROWS); + *aRows = NULL; + *aNRows = 0; + if (!mTable) + return CO_E_OBJNOTCONNECTED; + + nsAutoTArray rowIndices; + mTable->SelectedRowIndices(&rowIndices); + + uint32_t maxRows = rowIndices.Length(); + if (maxRows == 0) + return S_FALSE; + + *aRows = static_cast(moz_xmalloc(sizeof(LONG) * maxRows)); + *aNRows = maxRows; + for (uint32_t i = 0; i < maxRows; i++) + (*aRows)[i] = rowIndices[i]; + + return S_OK; A11Y_TRYBLOCK_END } - -//////////////////////////////////////////////////////////////////////////////// -// ia2AccessibleTable public - -HRESULT -ia2AccessibleTable::GetSelectedItems(long** aItems, long* aItemsCount, - eItemsType aType) -{ - *aItemsCount = 0; - - nsCOMPtr tableAcc(do_QueryObject(this)); - NS_ASSERTION(tableAcc, CANT_QUERY_ASSERTION_MSG); - if (!tableAcc) - return E_FAIL; - - uint32_t size = 0; - int32_t *items = nullptr; - - nsresult rv = NS_OK; - switch (aType) { - case ITEMSTYPE_CELLS: - rv = tableAcc->GetSelectedCellIndices(&size, &items); - break; - case ITEMSTYPE_COLUMNS: - rv = tableAcc->GetSelectedColumnIndices(&size, &items); - break; - case ITEMSTYPE_ROWS: - rv = tableAcc->GetSelectedRowIndices(&size, &items); - break; - default: - return E_FAIL; - } - - if (NS_FAILED(rv)) - return GetHRESULT(rv); - - if (size == 0 || !items) - return S_FALSE; - - *aItems = static_cast(nsMemory::Alloc((size) * sizeof(long))); - if (!*aItems) - return E_OUTOFMEMORY; - - *aItemsCount = size; - for (uint32_t index = 0; index < size; ++index) - (*aItems)[index] = items[index]; - - nsMemory::Free(items); - return S_OK; -} - diff --git a/accessible/src/windows/ia2/ia2AccessibleTable.h b/accessible/src/windows/ia2/ia2AccessibleTable.h index 73470bcba6ee..6738e2dfc2df 100644 --- a/accessible/src/windows/ia2/ia2AccessibleTable.h +++ b/accessible/src/windows/ia2/ia2AccessibleTable.h @@ -8,11 +8,14 @@ #ifndef _ACCESSIBLE_TABLE_H #define _ACCESSIBLE_TABLE_H -#include "nsISupports.h" - #include "AccessibleTable.h" #include "AccessibleTable2.h" +namespace mozilla { +namespace a11y { + +class TableAccessible; + class ia2AccessibleTable : public IAccessibleTable, public IAccessibleTable2 { @@ -161,17 +164,13 @@ public: /* [out, size_is(,*nRows)] */ long **selectedRows, /* [out, retval] */ long *nRows); - // nsISupports - NS_IMETHOD QueryInterface(const nsIID& uuid, void** result) = 0; +protected: + ia2AccessibleTable(TableAccessible* aTable) : mTable(aTable) {} -private: - enum eItemsType { - ITEMSTYPE_CELLS, - ITEMSTYPE_COLUMNS, - ITEMSTYPE_ROWS - }; - - HRESULT GetSelectedItems(long **aItems, long *aItemsCount, eItemsType aType); + TableAccessible* mTable; }; +} // namespace a11y +} // namespace mozilla + #endif