vcl/inc/accessibility/listboxhelper.hxx             |    5 --
 vcl/inc/accessibility/vclxaccessiblelist.hxx        |    6 +-
 vcl/inc/accessibility/vclxaccessiblelistitem.hxx    |    3 +
 vcl/source/accessibility/vclxaccessiblelist.cxx     |   30 ++++--------
 vcl/source/accessibility/vclxaccessiblelistitem.cxx |   50 +++++++-------------
 5 files changed, 36 insertions(+), 58 deletions(-)

New commits:
commit 59640987b0e45b6b58ca48dda0ac036ba47e42ca
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Tue Feb 11 14:58:34 2025 +0100
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Wed Feb 12 08:07:14 2025 +0100

    list a11y: Fix parent-relative position
    
    So far, VCLXAccessibleList::implGetBounds
    (which is supposed to report the bounds relative
    to the direct parent) and VCLXAccessibleList::getLocationOnScreen
    (which is supposed to report the absolte screen position)
    were mostly duplicating the logic.
    
    VCLXAccessibleList::getLocationOnScreen seems correct,
    but VCLXAccessibleList::implGetBounds reported an
    incorrect position for an expanded combobox list.
    
    This is because VCLListBoxHelper::GetDropDownPosSizePixel
    was returning a screen position, not a position relative
    to the parent.
    
    Fix this by:
    
    * Making VCLListBoxHelper::GetDropDownPosSizePixel return
      a parent-relative position instead.
    * Adjusting VCLXAccessibleList::getLocationOnScreen to
      not duplicate most of the logic, but calling
      VCLXAccessibleList::implGetBounds to get the
      parent-relative position and then adding the
      parent's screen position to get the own screen
      position.
    
    The fact that the parent-relative position is incorrect
    was noticed while working on fixing the parent-relative
    position reported by VCLXAccessibleListItem and even
    with an issue in the implementation there, the incorrect
    position was still reported.
    (The VCLXAccessibleListItem will be done in a separate
    upcoming commit.)
    
    Change-Id: I322327753ceec7bc7912ec13c45e208a79dd6976
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/181431
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>
    Tested-by: Jenkins

diff --git a/vcl/inc/accessibility/listboxhelper.hxx 
b/vcl/inc/accessibility/listboxhelper.hxx
index 5fd43e6eedd1..907524641734 100644
--- a/vcl/inc/accessibility/listboxhelper.hxx
+++ b/vcl/inc/accessibility/listboxhelper.hxx
@@ -49,10 +49,7 @@ public:
 
     virtual tools::Rectangle       GetDropDownPosSizePixel() const override
     {
-        AbsoluteScreenPixelRectangle aTemp = 
m_aComboListBox.GetWindowExtentsAbsolute();
-        tools::Rectangle aRet = m_aComboListBox.GetDropDownPosSizePixel();
-        aRet.Move(aTemp.Left(), aTemp.Top());
-        return aRet;
+        return m_aComboListBox.GetDropDownPosSizePixel();
     }
 
     virtual tools::Rectangle       GetBoundingRectangle( sal_uInt16 nItem ) 
const override
diff --git a/vcl/source/accessibility/vclxaccessiblelist.cxx 
b/vcl/source/accessibility/vclxaccessiblelist.cxx
index ed166c7274be..784c04cfbd9f 100644
--- a/vcl/source/accessibility/vclxaccessiblelist.cxx
+++ b/vcl/source/accessibility/vclxaccessiblelist.cxx
@@ -882,7 +882,8 @@ awt::Rectangle VCLXAccessibleList::implGetBounds()
     else
     {
         // a list has the same bounds as his parent but starts at (0,0)
-        aBounds = VCLXAccessibleComponent::implGetBounds();
+        if (m_xParent)
+            aBounds = m_xParent->getBounds();
         aBounds.X = 0;
         aBounds.Y = 0;
         if ( m_aBoxType == COMBOBOX )
@@ -905,26 +906,15 @@ awt::Point VCLXAccessibleList::getLocationOnScreen(  )
     SolarMutexGuard aSolarGuard;
     ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
 
-    awt::Point aPos;
-    if ( m_pListBoxHelper
-        && (m_pListBoxHelper->GetStyle() & WB_DROPDOWN ) == WB_DROPDOWN )
+    awt::Rectangle aBounds = implGetBounds();
+    awt::Point aPos(aBounds.X, aBounds.Y);
+    if (m_xParent.is())
     {
-        if ( m_pListBoxHelper->IsInDropDown() )
-            aPos = vcl::unohelper::ConvertToAWTPoint(
-                m_pListBoxHelper->GetDropDownPosSizePixel().TopLeft());
-    }
-    else
-    {
-        aPos = VCLXAccessibleComponent::getLocationOnScreen();
-        if ( m_aBoxType == COMBOBOX )
-        {
-            VclPtr< ComboBox > pBox = GetAs< ComboBox >();
-            if ( pBox )
-            {
-                aPos.Y += pBox->GetSubEdit()->GetSizePixel().Height();
-            }
-        }
+        awt::Point aParentLocation = m_xParent->getLocationOnScreen();
+        aPos.X += aParentLocation.X;
+        aPos.Y += aParentLocation.Y;
     }
+
     return aPos;
 }
 
commit 7bcd976db8b29b86b49bdb4c33d07ef156f1fa8f
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Tue Feb 11 14:44:30 2025 +0100
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Wed Feb 12 08:07:08 2025 +0100

    list a11y: Use ref to concrete VCLXAccessibleBox
    
    This will come in handy when simplifying and fixing
    VCLXAccessibleList::implGetBounds and
    VCLXAccessibleList::getLocationOnScreen in
    upcoming commits.
    
    Change-Id: I8b969243d9731ab997cc1a02c187491dbf171952
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/181430
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>

diff --git a/vcl/inc/accessibility/vclxaccessiblelist.hxx 
b/vcl/inc/accessibility/vclxaccessiblelist.hxx
index 54a214021632..ed377a03fa75 100644
--- a/vcl/inc/accessibility/vclxaccessiblelist.hxx
+++ b/vcl/inc/accessibility/vclxaccessiblelist.hxx
@@ -19,6 +19,8 @@
 
 #pragma once
 
+#include <accessibility/vclxaccessiblebox.hxx>
+
 #include <memory>
 #include <vector>
 #include <com/sun/star/accessibility/XAccessibleSelection.hpp>
@@ -43,7 +45,7 @@ public:
     enum BoxType {COMBOBOX, LISTBOX};
 
     VCLXAccessibleList(vcl::Window* pWindow, BoxType aBoxType,
-                       const 
css::uno::Reference<css::accessibility::XAccessible>& _xParent);
+                       const rtl::Reference<VCLXAccessibleBox>& _xParent);
 
     /** The index that is passed to this method is returned on following
         calls to getAccessibleIndexInParent.
@@ -155,7 +157,7 @@ private:
     /** We need to save the accessible parent to return it in 
getAccessibleParent(),
         because this method of the base class returns the wrong parent.
     */
-    css::uno::Reference< css::accessibility::XAccessible >  m_xParent;
+    rtl::Reference<VCLXAccessibleBox> m_xParent;
 
     void UpdateEntryRange_Impl();
     void UpdateSelection_Impl(sal_Int32 nPos = 0);
diff --git a/vcl/source/accessibility/vclxaccessiblelist.cxx 
b/vcl/source/accessibility/vclxaccessiblelist.cxx
index 616d306d1730..ed166c7274be 100644
--- a/vcl/source/accessibility/vclxaccessiblelist.cxx
+++ b/vcl/source/accessibility/vclxaccessiblelist.cxx
@@ -54,7 +54,7 @@ namespace
 }
 
 VCLXAccessibleList::VCLXAccessibleList(vcl::Window* pWindow, BoxType aBoxType,
-                                       const Reference< XAccessible >& 
_xParent)
+                                       const 
rtl::Reference<VCLXAccessibleBox>& _xParent)
     : ImplInheritanceHelper     (pWindow),
       m_aBoxType                (aBoxType),
       m_nVisibleLineCount       (0),
commit 5be1a099570d26df816327ce7a2f91d05118aba4
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Tue Feb 11 13:48:31 2025 +0100
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Wed Feb 12 08:07:03 2025 +0100

    list item a11y: Deduplicate bounds calculation
    
    Introduce and use new helper method
    VCLXAccessibleListItem::implGetBounds
    instead of duplicating the code to calculate
    the parent-relative bounds in multiple places.
    
    This is also in preparation of fixing parent-relative
    coordinates (in a single rather than multiple places).
    
    Change-Id: Ie2791a73a392ed1c0d6872d2131cc59785c214b5
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/181429
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>
    Tested-by: Jenkins

diff --git a/vcl/inc/accessibility/vclxaccessiblelistitem.hxx 
b/vcl/inc/accessibility/vclxaccessiblelistitem.hxx
index 271db9613648..5345de57ffe9 100644
--- a/vcl/inc/accessibility/vclxaccessiblelistitem.hxx
+++ b/vcl/inc/accessibility/vclxaccessiblelistitem.hxx
@@ -29,6 +29,7 @@
 #include <comphelper/compbase.hxx>
 #include <comphelper/accessibletexthelper.hxx>
 #include <accessibility/vclxaccessiblelist.hxx>
+#include <tools/gen.hxx>
 
 // forward ---------------------------------------------------------------
 
@@ -75,6 +76,8 @@ private:
     virtual css::lang::Locale               implGetLocale() override;
     virtual void                            implGetSelection( sal_Int32& 
nStartIndex, sal_Int32& nEndIndex ) override;
 
+    tools::Rectangle implGetBounds();
+
     OUString getTextRangeImpl(sal_Int32 nStartIndex, sal_Int32 nEndIndex);
 
 public:
diff --git a/vcl/source/accessibility/vclxaccessiblelistitem.cxx 
b/vcl/source/accessibility/vclxaccessiblelistitem.cxx
index 4810324f08c3..5437f0f58627 100644
--- a/vcl/source/accessibility/vclxaccessiblelistitem.cxx
+++ b/vcl/source/accessibility/vclxaccessiblelistitem.cxx
@@ -132,6 +132,16 @@ void VCLXAccessibleListItem::implGetSelection( sal_Int32& 
nStartIndex, sal_Int32
     nEndIndex = 0;
 }
 
+tools::Rectangle VCLXAccessibleListItem::implGetBounds()
+{
+    tools::Rectangle aRect;
+    IComboListBoxHelper* pListBoxHelper = m_xParent.is() ? 
m_xParent->getListBoxHelper() : nullptr;
+    if (pListBoxHelper)
+        aRect = 
pListBoxHelper->GetBoundingRectangle(static_cast<sal_uInt16>(m_nIndexInParent));
+
+    return aRect;
+}
+
 // XTypeProvider
 
 Sequence< sal_Int8 > VCLXAccessibleListItem::getImplementationId()
@@ -281,14 +291,9 @@ sal_Bool SAL_CALL VCLXAccessibleListItem::containsPoint( 
const awt::Point& _aPoi
 {
     SolarMutexGuard aSolarGuard;
 
-    bool bInside = false;
-    IComboListBoxHelper* pListBoxHelper = m_xParent.is() ? 
m_xParent->getListBoxHelper() : nullptr;
-    if (pListBoxHelper)
-    {
-        tools::Rectangle 
aRect(pListBoxHelper->GetBoundingRectangle(static_cast<sal_uInt16>(m_nIndexInParent)));
-        aRect.Move(-aRect.Left(), -aRect.Top());
-        bInside = aRect.Contains(vcl::unohelper::ConvertToVCLPoint(_aPoint));
-    }
+    tools::Rectangle aRect = implGetBounds();
+    aRect.SetPos(Point(0, 0));
+    const bool bInside = 
aRect.Contains(vcl::unohelper::ConvertToVCLPoint(_aPoint));
     return bInside;
 }
 
@@ -301,26 +306,14 @@ awt::Rectangle SAL_CALL 
VCLXAccessibleListItem::getBounds(  )
 {
     SolarMutexGuard aSolarGuard;
 
-    awt::Rectangle aRect;
-    IComboListBoxHelper* pListBoxHelper = m_xParent.is() ? 
m_xParent->getListBoxHelper() : nullptr;
-    if (pListBoxHelper)
-        aRect = vcl::unohelper::ConvertToAWTRect(
-            
pListBoxHelper->GetBoundingRectangle(static_cast<sal_uInt16>(m_nIndexInParent)));
-
-    return aRect;
+    return vcl::unohelper::ConvertToAWTRect(implGetBounds());
 }
 
 awt::Point SAL_CALL VCLXAccessibleListItem::getLocation(  )
 {
     SolarMutexGuard aSolarGuard;
 
-    Point aPoint(0,0);
-    IComboListBoxHelper* pListBoxHelper = m_xParent.is() ? 
m_xParent->getListBoxHelper() : nullptr;
-    if (pListBoxHelper)
-    {
-        tools::Rectangle aRect = pListBoxHelper->GetBoundingRectangle( 
static_cast<sal_uInt16>(m_nIndexInParent) );
-        aPoint = aRect.TopLeft();
-    }
+    const Point aPoint = implGetBounds().TopLeft();
     return vcl::unohelper::ConvertToAWTPoint(aPoint);
 }
 
@@ -328,14 +321,11 @@ awt::Point SAL_CALL 
VCLXAccessibleListItem::getLocationOnScreen(  )
 {
     SolarMutexGuard aSolarGuard;
 
-    Point aPoint(0,0);
+    Point aPoint = implGetBounds().TopLeft();
     IComboListBoxHelper* pListBoxHelper = m_xParent.is() ? 
m_xParent->getListBoxHelper() : nullptr;
     if (pListBoxHelper)
-    {
-        tools::Rectangle aRect = 
pListBoxHelper->GetBoundingRectangle(static_cast<sal_uInt16>(m_nIndexInParent));
-        aPoint = aRect.TopLeft();
         aPoint += Point(pListBoxHelper->GetWindowExtentsAbsolute().TopLeft());
-    }
+
     return vcl::unohelper::ConvertToAWTPoint(aPoint);
 }
 
@@ -343,11 +333,7 @@ awt::Size SAL_CALL VCLXAccessibleListItem::getSize(  )
 {
     SolarMutexGuard aSolarGuard;
 
-    Size aSize;
-    IComboListBoxHelper* pListBoxHelper = m_xParent.is() ? 
m_xParent->getListBoxHelper() : nullptr;
-    if (pListBoxHelper)
-        aSize = pListBoxHelper->GetBoundingRectangle( 
static_cast<sal_uInt16>(m_nIndexInParent) ).GetSize();
-
+    Size aSize = implGetBounds().GetSize();
     return vcl::unohelper::ConvertToAWTSize(aSize);
 }
 

Reply via email to