accessibility/inc/extended/AccessibleGridControlTableBase.hxx     |    4 +-
 accessibility/source/extended/AccessibleGridControlHeaderCell.cxx |    6 ++-
 accessibility/source/extended/AccessibleGridControlTableBase.cxx  |   18 
++++++---
 accessibility/source/extended/AccessibleGridControlTableCell.cxx  |   19 
++--------
 4 files changed, 24 insertions(+), 23 deletions(-)

New commits:
commit 18aed6fc4ff5b981ae7deb6584197b661721e7df
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Wed Aug 2 13:00:21 2023 +0200
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Thu Aug 3 16:53:58 2023 +0200

    tdf#156473 a11y: Use actual row/col index/count in grid control header
    
    The row header bar of a grid control is a table with
    just one column, containing a row header cell for
    each of the rows in the table holding the actual data.
    Likewise, a column header bar just has one row.
    
    This was previously incorrectly reported on the a11y layer,
    as could e.g. be seen in Accerciser with the sample macro
    from tdf#156473.
    
    Also make the `AccessibleGridControlCell` ctor pass the
    `_nColumnRowId` as what it actually is (a row index
    in case of a row header cell, a column index in case
    of a column header cell) instead of always as a row
    index, and then having special handling for that
    elsewhere again
    (s. `AccessibleGridControlCell::getAccessibleName`).
    
    Also move an assert from
    `AccessibleGridControlCell::getAccessibleName` to
    the ctor and check the indices there.
    
    With this in place, the row and column header bars
    for the example from tdf#156473 now report the correct
    amount of rows and columns, and the row/column header
    cells report the correct row and column indices.
    
    Change-Id: I29f71ac46b6d841e26d68ca01bd05ba9412aed13
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155224
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>

diff --git a/accessibility/inc/extended/AccessibleGridControlTableBase.hxx 
b/accessibility/inc/extended/AccessibleGridControlTableBase.hxx
index e8cf6bfe9b92..39de903ec855 100644
--- a/accessibility/inc/extended/AccessibleGridControlTableBase.hxx
+++ b/accessibility/inc/extended/AccessibleGridControlTableBase.hxx
@@ -139,10 +139,10 @@ protected:
 
     /** @attention  This method requires locked mutex's and a living object.
         @return  The row index of the specified cell index. */
-    sal_Int32 implGetRow( sal_Int64 nChildIndex ) const;
+    sal_Int32 implGetRow( sal_Int64 nChildIndex );
     /** @attention  This method requires locked mutex's and a living object.
         @return  The column index of the specified cell index. */
-    sal_Int32 implGetColumn( sal_Int64 nChildIndex ) const;
+    sal_Int32 implGetColumn( sal_Int64 nChildIndex );
 
     /** Fills a sequence with sorted indexes of completely selected rows.
         @attention  This method requires locked mutex's and a living object.
diff --git a/accessibility/source/extended/AccessibleGridControlHeaderCell.cxx 
b/accessibility/source/extended/AccessibleGridControlHeaderCell.cxx
index a174afd00556..00b3e60d7d92 100644
--- a/accessibility/source/extended/AccessibleGridControlHeaderCell.cxx
+++ b/accessibility/source/extended/AccessibleGridControlHeaderCell.cxx
@@ -35,9 +35,13 @@ 
AccessibleGridControlHeaderCell::AccessibleGridControlHeaderCell(sal_Int32 _nCol
                                   const Reference< XAccessible >& rxParent,
                                   IAccessibleTable& rTable,
                                   AccessibleTableControlObjType  eObjType)
-: AccessibleGridControlCell( rxParent, rTable, _nColumnRowId, 0, eObjType)
+: AccessibleGridControlCell(rxParent, rTable,
+                            (eObjType == 
AccessibleTableControlObjType::ROWHEADERCELL) ? _nColumnRowId : 0,
+                            (eObjType == 
AccessibleTableControlObjType::ROWHEADERCELL) ? 0 : _nColumnRowId,
+                            eObjType)
 , m_nColumnRowId(_nColumnRowId)
 {
+    assert(eObjType == AccessibleTableControlObjType::ROWHEADERCELL || 
eObjType == AccessibleTableControlObjType::COLUMNHEADERCELL);
 }
 /** Return a bitset of states of the current object.
 */
diff --git a/accessibility/source/extended/AccessibleGridControlTableBase.cxx 
b/accessibility/source/extended/AccessibleGridControlTableBase.cxx
index 691568a6341a..499a3cec23cb 100644
--- a/accessibility/source/extended/AccessibleGridControlTableBase.cxx
+++ b/accessibility/source/extended/AccessibleGridControlTableBase.cxx
@@ -77,6 +77,9 @@ sal_Int32 SAL_CALL 
AccessibleGridControlTableBase::getAccessibleRowCount()
     SolarMutexGuard aSolarGuard;
 
     ensureIsAlive();
+
+    if (m_eObjType == AccessibleTableControlObjType::COLUMNHEADERBAR)
+        return 1;
     return  m_aTable.GetRowCount();
 }
 
@@ -85,6 +88,9 @@ sal_Int32 SAL_CALL 
AccessibleGridControlTableBase::getAccessibleColumnCount()
     SolarMutexGuard aSolarGuard;
 
     ensureIsAlive();
+
+    if (m_eObjType == AccessibleTableControlObjType::ROWHEADERBAR)
+        return 1;
     return m_aTable.GetColumnCount();
 }
 
@@ -187,15 +193,15 @@ Sequence< sal_Int8 > SAL_CALL 
AccessibleGridControlTableBase::getImplementationI
 
 // internal helper methods ----------------------------------------------------
 
-sal_Int32 AccessibleGridControlTableBase::implGetRow( sal_Int64 nChildIndex ) 
const
+sal_Int32 AccessibleGridControlTableBase::implGetRow( sal_Int64 nChildIndex )
 {
-    sal_Int32 nColumns = m_aTable.GetColumnCount();
+    sal_Int32 nColumns = getAccessibleColumnCount();
     return nColumns ? (nChildIndex / nColumns) : 0;
 }
 
-sal_Int32 AccessibleGridControlTableBase::implGetColumn( sal_Int64 nChildIndex 
) const
+sal_Int32 AccessibleGridControlTableBase::implGetColumn( sal_Int64 nChildIndex 
)
 {
-    sal_Int32 nColumns = m_aTable.GetColumnCount();
+    sal_Int32 nColumns = getAccessibleColumnCount();
     return nColumns ? (nChildIndex % nColumns) : 0;
 }
 
@@ -210,13 +216,13 @@ void AccessibleGridControlTableBase::implGetSelectedRows( 
Sequence< sal_Int32 >&
 
 void AccessibleGridControlTableBase::ensureIsValidRow( sal_Int32 nRow )
 {
-    if( nRow >= m_aTable.GetRowCount() )
+    if (nRow >= getAccessibleRowCount())
         throw lang::IndexOutOfBoundsException( "row index is invalid", *this );
 }
 
 void AccessibleGridControlTableBase::ensureIsValidColumn( sal_Int32 nColumn )
 {
-    if( nColumn >= m_aTable.GetColumnCount() )
+    if (nColumn >= getAccessibleColumnCount())
         throw lang::IndexOutOfBoundsException( "column index is invalid", 
*this );
 }
 
diff --git a/accessibility/source/extended/AccessibleGridControlTableCell.cxx 
b/accessibility/source/extended/AccessibleGridControlTableCell.cxx
index 3f3a59bb508d..43e56aefae7e 100644
--- a/accessibility/source/extended/AccessibleGridControlTableCell.cxx
+++ b/accessibility/source/extended/AccessibleGridControlTableCell.cxx
@@ -58,6 +58,10 @@ namespace accessibility
         ,m_nRowPos( _nRowPos )
         ,m_nColPos( _nColPos )
     {
+        assert(((m_eObjType == AccessibleTableControlObjType::TABLECELL)
+                || ((m_eObjType == 
AccessibleTableControlObjType::ROWHEADERCELL) && _nColPos == 0)
+                || ((m_eObjType == 
AccessibleTableControlObjType::COLUMNHEADERCELL) && _nRowPos == 0))
+               && "Unhandled table cell type");
     }
 
     void SAL_CALL AccessibleGridControlCell::grabFocus()
@@ -72,20 +76,7 @@ namespace accessibility
         SolarMutexGuard g;
 
         ensureIsAlive();
-
-        OUString sAccName;
-        if (m_eObjType == AccessibleTableControlObjType::TABLECELL)
-            sAccName = 
m_aTable.GetAccessibleObjectName(AccessibleTableControlObjType::TABLECELL,
-                                                        m_nRowPos, m_nColPos);
-        else if (m_eObjType == AccessibleTableControlObjType::ROWHEADERCELL)
-            sAccName = 
m_aTable.GetAccessibleObjectName(AccessibleTableControlObjType::ROWHEADERCELL,
-                                                        m_nRowPos, 0);
-        else if (m_eObjType == AccessibleTableControlObjType::COLUMNHEADERCELL)
-            sAccName = 
m_aTable.GetAccessibleObjectName(AccessibleTableControlObjType::COLUMNHEADERCELL,
-                                                        0, m_nRowPos);
-        else
-            assert(false && "Unhandled table cell type");
-        return sAccName;
+        return m_aTable.GetAccessibleObjectName(m_eObjType, m_nRowPos, 
m_nColPos);
     }
 
     // implementation of a table cell

Reply via email to