toolkit/inc/controls/table/AccessibleGridControl.hxx              |    3 -
 toolkit/inc/controls/table/AccessibleGridControlBase.hxx          |    8 ++-
 toolkit/inc/controls/table/AccessibleGridControlHeader.hxx        |    3 -
 toolkit/inc/controls/table/AccessibleGridControlHeaderCell.hxx    |    2 
 toolkit/inc/controls/table/AccessibleGridControlTable.hxx         |    3 -
 toolkit/inc/controls/table/AccessibleGridControlTableCell.hxx     |    1 
 toolkit/source/controls/table/AccessibleGridControl.cxx           |    7 --
 toolkit/source/controls/table/AccessibleGridControlBase.cxx       |   16 ++++++
 toolkit/source/controls/table/AccessibleGridControlHeader.cxx     |   12 ----
 toolkit/source/controls/table/AccessibleGridControlHeaderCell.cxx |   14 -----
 toolkit/source/controls/table/AccessibleGridControlTable.cxx      |   14 -----
 toolkit/source/controls/table/AccessibleGridControlTableCell.cxx  |   12 ----
 toolkit/source/controls/table/tablecontrol_impl.cxx               |   25 
++--------
 toolkit/source/controls/table/tablecontrol_impl.hxx               |    4 -
 14 files changed, 26 insertions(+), 98 deletions(-)

New commits:
commit d1d2afa7dd9591664c72fffd6cd941220bb05999
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Fri Jan 24 17:51:05 2025 +0100
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Fri Jan 24 22:01:56 2025 +0100

    toolkit a11y: Return parent-relative coords if requested
    
    As its documentation described, the (so far) purely virtual
    AccessibleGridControlBase::implGetBoundingBox was implemented
    by all subclasses to return the bounding box relative to the
    TableControl's vcl::Window parent.
    
    However, this method is used to implement methods like
    XAccessibleComponent::containsPoint,
    XAccessibleComponent::getBounds and
    XAccessibleComponent::getLocation, all of which are supposed
    to be using the position relative to the *immediate* accessible
    parent.
    
    This mismatch could e.g. be seen with the grid control
    in attachment 198647 of tdf#164783 and the gtk3 VCL plugin
    as follows:
    
    1) allow macros
    2) open sample file
    3) click "Grid in dialog" to start the dialog containing a grid
    4) start Accerciser
    5) In Accerciser's treeview of the LO a11y hierarchy, select the
       "Grid control" object with a11y table role.
    6) Select its first child, which is a table cell.
    
    What could be seen is that the top-left corner of the highlighted
    area for the first cell (step 6) is shifted to the right and down
    as compareed to the highlighted area for the table (step 5), even
    though the first cell in reality has the exact same origin, (because
    the table area is defined by the cells it contains).
    
    The AccessibleGridControlBase::implGetBoundingBoxOnScreen overrides
    correctly return the bounding box on screen and duplicated much
    of the logic.
    
    Fix the problem and deduplicate code by implementing
    AccessibleGridControlBase::implGetBoundingBox directly in
    AccessibleGridControlBase: Let it calculate the position
    relative to the parent from the absolute position of the parent
    and of the object itself.
    
    With this in place, the scenario described above now results in
    the area highlighted in steps 5) and 6) to have the same top-left
    corner.
    
    Change-Id: If28de14d440706bd6493626586f82859e5570e75
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/180720
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>
    Tested-by: Jenkins

diff --git a/toolkit/inc/controls/table/AccessibleGridControl.hxx 
b/toolkit/inc/controls/table/AccessibleGridControl.hxx
index de28396fc402..ffeacebe43f4 100644
--- a/toolkit/inc/controls/table/AccessibleGridControl.hxx
+++ b/toolkit/inc/controls/table/AccessibleGridControl.hxx
@@ -106,9 +106,6 @@ public:
 private:
     // internal virtual methods -----------------------------------------------
 
-    /** @attention  This method requires locked mutex's and a living object.
-        @return  The bounding box (VCL rect.) relative to the parent window. */
-    virtual tools::Rectangle implGetBoundingBox() override;
     /** @attention  This method requires locked mutex's and a living object.
         @return  The bounding box (VCL rect.) in screen coordinates. */
     virtual AbsoluteScreenPixelRectangle implGetBoundingBoxOnScreen() override;
diff --git a/toolkit/inc/controls/table/AccessibleGridControlBase.hxx 
b/toolkit/inc/controls/table/AccessibleGridControlBase.hxx
index a5b961f2c88a..92c78652f198 100644
--- a/toolkit/inc/controls/table/AccessibleGridControlBase.hxx
+++ b/toolkit/inc/controls/table/AccessibleGridControlBase.hxx
@@ -198,10 +198,12 @@ protected:
         @return  TRUE, if the object is really showing. */
     bool implIsShowing();
 
-    /** Derived classes return the bounding box relative to the parent window.
+    /** Return the bounding box relative to the parent.
         @attention  This method requires locked mutex's and a living object.
-        @return  The bounding box (VCL rect.) relative to the parent window. */
-    virtual tools::Rectangle implGetBoundingBox() = 0;
+        @return  The bounding box (VCL rect.) relative to the parent. */
+    tools::Rectangle implGetBoundingBox();
+
+
     ///** Derived classes return the bounding box in screen coordinates.
     //    @attention  This method requires locked mutex's and a living object.
     //    @return  The bounding box (VCL rect.) in screen coordinates. */
diff --git a/toolkit/inc/controls/table/AccessibleGridControlHeader.hxx 
b/toolkit/inc/controls/table/AccessibleGridControlHeader.hxx
index f6cd074a71d7..6f0dd179a015 100644
--- a/toolkit/inc/controls/table/AccessibleGridControlHeader.hxx
+++ b/toolkit/inc/controls/table/AccessibleGridControlHeader.hxx
@@ -121,9 +121,6 @@ private:
         @return  The XAccessible interface of the specified column/row. */
     css::uno::Reference< css::accessibility::XAccessible >
     implGetChild( sal_Int32 nRow, sal_uInt32 nColumnPos );
-    /** @attention  This method requires locked mutex's and a living object.
-        @return  The bounding box (VCL rect.) relative to the parent window. */
-    virtual tools::Rectangle implGetBoundingBox() override;
    /** @attention  This method requires locked mutex's and a living object.
         @return  The bounding box (VCL rect.) in screen coordinates. */
     virtual AbsoluteScreenPixelRectangle implGetBoundingBoxOnScreen() override;
diff --git a/toolkit/inc/controls/table/AccessibleGridControlHeaderCell.hxx 
b/toolkit/inc/controls/table/AccessibleGridControlHeaderCell.hxx
index 20d71e381b45..57b348333fc1 100644
--- a/toolkit/inc/controls/table/AccessibleGridControlHeaderCell.hxx
+++ b/toolkit/inc/controls/table/AccessibleGridControlHeaderCell.hxx
@@ -70,8 +70,6 @@ namespace accessibility
         sal_Int64 implCreateStateSet() override;
 
     private:
-        virtual tools::Rectangle implGetBoundingBox() override;
-
         virtual AbsoluteScreenPixelRectangle implGetBoundingBoxOnScreen() 
override;
     };
 }
diff --git a/toolkit/inc/controls/table/AccessibleGridControlTable.hxx 
b/toolkit/inc/controls/table/AccessibleGridControlTable.hxx
index b4ebfa3b2f85..79031f56d74e 100644
--- a/toolkit/inc/controls/table/AccessibleGridControlTable.hxx
+++ b/toolkit/inc/controls/table/AccessibleGridControlTable.hxx
@@ -149,9 +149,6 @@ public:
 private:
     // internal virtual methods
 
-    /** @attention  This method requires locked mutex's and a living object.
-        @return  The bounding box (VCL rect.) relative to the parent window. */
-    virtual tools::Rectangle implGetBoundingBox() override;
     ///** @attention  This method requires locked mutex's and a living object.
     //    @return  The bounding box (VCL rect.) in screen coordinates. */
     virtual AbsoluteScreenPixelRectangle implGetBoundingBoxOnScreen() override;
diff --git a/toolkit/inc/controls/table/AccessibleGridControlTableCell.hxx 
b/toolkit/inc/controls/table/AccessibleGridControlTableCell.hxx
index dbc62ff09796..58ed164e1dbc 100644
--- a/toolkit/inc/controls/table/AccessibleGridControlTableCell.hxx
+++ b/toolkit/inc/controls/table/AccessibleGridControlTableCell.hxx
@@ -75,7 +75,6 @@ namespace accessibility
         virtual OUString                        implGetText() override;
         virtual css::lang::Locale               implGetLocale() override;
         virtual void                            implGetSelection( sal_Int32& 
nStartIndex, sal_Int32& nEndIndex ) override final;
-        virtual tools::Rectangle implGetBoundingBox() override;
         virtual AbsoluteScreenPixelRectangle implGetBoundingBoxOnScreen() 
override;
 
     public:
diff --git a/toolkit/source/controls/table/AccessibleGridControl.cxx 
b/toolkit/source/controls/table/AccessibleGridControl.cxx
index ebfbd809b5a7..277929ca56ac 100644
--- a/toolkit/source/controls/table/AccessibleGridControl.cxx
+++ b/toolkit/source/controls/table/AccessibleGridControl.cxx
@@ -185,13 +185,6 @@ OUString SAL_CALL 
AccessibleGridControl::getImplementationName()
 
 // internal virtual methods ---------------------------------------------------
 
-tools::Rectangle AccessibleGridControl::implGetBoundingBox()
-{
-    vcl::Window* pParent = m_aTable.GetAccessibleParentWindow();
-    assert(pParent && "implGetBoundingBox - missing parent window");
-    return m_aTable.GetWindowExtentsRelative( *pParent );
-}
-
 AbsoluteScreenPixelRectangle 
AccessibleGridControl::implGetBoundingBoxOnScreen()
 {
     return m_aTable.GetWindowExtentsAbsolute();
diff --git a/toolkit/source/controls/table/AccessibleGridControlBase.cxx 
b/toolkit/source/controls/table/AccessibleGridControlBase.cxx
index 9fc195a0b68c..e62a7b9ea907 100644
--- a/toolkit/source/controls/table/AccessibleGridControlBase.cxx
+++ b/toolkit/source/controls/table/AccessibleGridControlBase.cxx
@@ -280,6 +280,22 @@ bool AccessibleGridControlBase::implIsShowing()
     return bShowing;
 }
 
+tools::Rectangle AccessibleGridControlBase::implGetBoundingBox()
+{
+    // calculate parent-relative position from own and parent's absolute 
position
+    tools::Rectangle aBound(implGetBoundingBoxOnScreen());
+    if (!m_xParent.is())
+        return aBound;
+
+    uno::Reference<css::accessibility::XAccessibleComponent> 
xParentComponent(m_xParent->getAccessibleContext(), uno::UNO_QUERY);
+    if (!xParentComponent.is())
+        return aBound;
+
+    awt::Point aParentPos = xParentComponent->getLocationOnScreen();
+    aBound.Move(-aParentPos.X, -aParentPos.Y);
+    return aBound;
+}
+
 sal_Int64 AccessibleGridControlBase::implCreateStateSet()
 {
     sal_Int64 nStateSet = 0;
diff --git a/toolkit/source/controls/table/AccessibleGridControlHeader.cxx 
b/toolkit/source/controls/table/AccessibleGridControlHeader.cxx
index 6bee8e8b99ac..ea1c71b138eb 100644
--- a/toolkit/source/controls/table/AccessibleGridControlHeader.cxx
+++ b/toolkit/source/controls/table/AccessibleGridControlHeader.cxx
@@ -194,18 +194,6 @@ Sequence< sal_Int8 > SAL_CALL 
AccessibleGridControlHeader::getImplementationId()
 
 // internal virtual methods ---------------------------------------------------
 
-tools::Rectangle AccessibleGridControlHeader::implGetBoundingBox()
-{
-    vcl::Window* pParent = m_aTable.GetAccessibleParentWindow();
-    tools::Rectangle aGridRect( m_aTable.GetWindowExtentsRelative( *pParent ) 
);
-    tools::Rectangle aHeaderRect (m_aTable.calcHeaderRect(isColumnBar()));
-    if(isColumnBar())
-        return tools::Rectangle(aGridRect.TopLeft(), 
Size(aGridRect.getOpenWidth(),aHeaderRect.getOpenHeight()));
-    else
-        return tools::Rectangle(aGridRect.TopLeft(), 
Size(aHeaderRect.getOpenWidth(),aGridRect.getOpenHeight()));
-
-}
-
 AbsoluteScreenPixelRectangle 
AccessibleGridControlHeader::implGetBoundingBoxOnScreen()
 {
     AbsoluteScreenPixelRectangle aGridRect( 
m_aTable.GetWindowExtentsAbsolute() );
diff --git a/toolkit/source/controls/table/AccessibleGridControlHeaderCell.cxx 
b/toolkit/source/controls/table/AccessibleGridControlHeaderCell.cxx
index f0b50675a00a..4bf68ec3a047 100644
--- a/toolkit/source/controls/table/AccessibleGridControlHeaderCell.cxx
+++ b/toolkit/source/controls/table/AccessibleGridControlHeaderCell.cxx
@@ -126,20 +126,6 @@ OUString SAL_CALL 
AccessibleGridControlHeaderCell::getImplementationName()
     return u"com.sun.star.accessibility.AccessibleGridControlHeaderCell"_ustr;
 }
 
-tools::Rectangle AccessibleGridControlHeaderCell::implGetBoundingBox()
-{
-    vcl::Window* pParent = m_aTable.GetAccessibleParentWindow();
-    tools::Rectangle aGridRect( m_aTable.GetWindowExtentsRelative( *pParent ) 
);
-    sal_Int32 nIndex = getAccessibleIndexInParent();
-    tools::Rectangle aCellRect;
-    if (m_eObjType == AccessibleTableControlObjType::COLUMNHEADERCELL)
-        aCellRect = m_aTable.calcHeaderCellRect(true, nIndex);
-    else
-        aCellRect = m_aTable.calcHeaderCellRect(false, nIndex);
-    return 
tools::Rectangle(Point(aGridRect.Left()+aCellRect.Left(),aGridRect.Top()+aCellRect.Top()),
 aCellRect.GetSize());
-}
-
-
 AbsoluteScreenPixelRectangle 
AccessibleGridControlHeaderCell::implGetBoundingBoxOnScreen()
 {
     AbsoluteScreenPixelRectangle aGridRect( 
m_aTable.GetWindowExtentsAbsolute() );
diff --git a/toolkit/source/controls/table/AccessibleGridControlTable.cxx 
b/toolkit/source/controls/table/AccessibleGridControlTable.cxx
index 2e5bd46797f7..d9c9e5fd2853 100644
--- a/toolkit/source/controls/table/AccessibleGridControlTable.cxx
+++ b/toolkit/source/controls/table/AccessibleGridControlTable.cxx
@@ -342,20 +342,6 @@ void AccessibleGridControlTable::commitEvent(sal_Int16 
nEventId, const css::uno:
 
 // internal virtual methods ---------------------------------------------------
 
-tools::Rectangle AccessibleGridControlTable::implGetBoundingBox()
-{
-    vcl::Window* pParent = m_aTable.GetAccessibleParentWindow();
-    assert(pParent && "implGetBoundingBox - missing parent window");
-    tools::Rectangle aGridRect( m_aTable.GetWindowExtentsRelative( *pParent ));
-    tools::Rectangle aTableRect( m_aTable.calcTableRect() );
-    tools::Long nX = aGridRect.Left() + aTableRect.Left();
-    tools::Long nY = aGridRect.Top() + aTableRect.Top();
-    tools::Long nWidth = aGridRect.GetSize().Width()-aTableRect.Left();
-    tools::Long nHeight = aGridRect.GetSize().Height()-aTableRect.Top();
-    tools::Rectangle aTable( Point( nX, nY ), Size( nWidth, nHeight ));
-    return aTable;
-}
-
 AbsoluteScreenPixelRectangle 
AccessibleGridControlTable::implGetBoundingBoxOnScreen()
 {
     tools::Rectangle aGridRect( m_aTable.GetWindowExtentsAbsolute());
diff --git a/toolkit/source/controls/table/AccessibleGridControlTableCell.cxx 
b/toolkit/source/controls/table/AccessibleGridControlTableCell.cxx
index 7b134fe46a36..151972ab7535 100644
--- a/toolkit/source/controls/table/AccessibleGridControlTableCell.cxx
+++ b/toolkit/source/controls/table/AccessibleGridControlTableCell.cxx
@@ -318,18 +318,6 @@ namespace accessibility
         return false;
     }
 
-    tools::Rectangle AccessibleGridControlTableCell::implGetBoundingBox()
-    {
-        vcl::Window* pParent = m_aTable.GetAccessibleParentWindow();
-        assert(pParent && "implGetBoundingBox - missing parent window");
-        tools::Rectangle aGridRect = m_aTable.GetWindowExtentsRelative( 
*pParent );
-        tools::Rectangle aCellRect = m_aTable.calcCellRect(getRowPos(), 
getColumnPos());
-        tools::Long nX = aGridRect.Left() + aCellRect.Left();
-        tools::Long nY = aGridRect.Top() + aCellRect.Top();
-        tools::Rectangle aCell( Point( nX, nY ), aCellRect.GetSize());
-        return aCell;
-    }
-
     AbsoluteScreenPixelRectangle 
AccessibleGridControlTableCell::implGetBoundingBoxOnScreen()
     {
         AbsoluteScreenPixelRectangle aGridRect = 
m_aTable.GetWindowExtentsAbsolute();
commit 16684da3f18b8747714a7ddd44810cb429eab5ae
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Fri Jan 24 16:09:25 2025 +0100
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Fri Jan 24 22:01:49 2025 +0100

    toolkit: Merge TableControl_Impl::{calc,impl_get}CellRect
    
    Move logic from TableControl_Impl::impl_getCellRect
    to TableControl_Impl::calcCellRect and drop the
    former.
    
    Change-Id: I2c44e72a4e781130661deebd0882939ad34c050a
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/180718
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>
    Tested-by: Jenkins

diff --git a/toolkit/source/controls/table/tablecontrol_impl.cxx 
b/toolkit/source/controls/table/tablecontrol_impl.cxx
index 2a3112cc8841..ac04b86a2255 100644
--- a/toolkit/source/controls/table/tablecontrol_impl.cxx
+++ b/toolkit/source/controls/table/tablecontrol_impl.cxx
@@ -1665,23 +1665,6 @@ namespace svt::table
         }
     }
 
-
-    void TableControl_Impl::impl_getCellRect( ColPos _nColumn, RowPos _nRow, 
tools::Rectangle& _rCellRect ) const
-    {
-        if  (   !m_pModel
-            ||  ( COL_INVALID == _nColumn )
-            ||  ( ROW_INVALID == _nRow )
-            )
-        {
-            _rCellRect.SetEmpty();
-            return;
-        }
-
-        TableCellGeometry aCell( *this, impl_getAllVisibleCellsArea(), 
_nColumn, _nRow );
-        _rCellRect = aCell.getRect();
-    }
-
-
     RowPos TableControl_Impl::getRowAtPoint( const Point& rPoint ) const
     {
         return impl_getRowForAbscissa( rPoint.Y() );
@@ -2339,9 +2322,11 @@ namespace svt::table
 
     tools::Rectangle TableControl_Impl::calcCellRect( sal_Int32 nRow, 
sal_Int32 nCol ) const
     {
-        tools::Rectangle aCellRect;
-        impl_getCellRect(nCol, nRow, aCellRect);
-        return aCellRect;
+        if (!m_pModel || (nRow == ROW_INVALID) || (nCol == COL_INVALID))
+            return tools::Rectangle();
+
+        TableCellGeometry aCell(*this, impl_getAllVisibleCellsArea(), nCol, 
nRow);
+        return aCell.getRect();
     }
 
 
diff --git a/toolkit/source/controls/table/tablecontrol_impl.hxx 
b/toolkit/source/controls/table/tablecontrol_impl.hxx
index 8fa77c18b975..07409773705a 100644
--- a/toolkit/source/controls/table/tablecontrol_impl.hxx
+++ b/toolkit/source/controls/table/tablecontrol_impl.hxx
@@ -342,10 +342,6 @@ namespace svt::table
         */
         TableSize   impl_getVisibleColumns( bool _bAcceptPartialCol ) const;
 
-        /** determines the rectangle occupied by the given cell
-        */
-        void        impl_getCellRect( ColPos _nColumn, RowPos _nRow, 
tools::Rectangle& _rCellRect ) const;
-
         /** updates all cached model values
 
             The method is not bound to the classes public invariants, as it's 
used in

Reply via email to