winaccessibility/source/UAccCOM/AccRelation.cxx |   18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

New commits:
commit 4ac1015b58a676324443de54188c16abf28d642f
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Wed Aug 21 17:02:04 2024 +0100
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Wed Aug 21 20:12:20 2024 +0200

    tdf#91739 wina11y: Ensure IAccessible for relation target exists
    
    When retrieving the `IAccessible` for the relation
    target's `XAccessible` and
    `CMAccessible::get_IAccessibleFromXAccessible` initially
    returns nullptr, insert the a corresponding object
    and retrieve it then.
    
    The same is already done in most places calling
    `CMAccessible::get_IAccessibleFromXAccessible`, e.g.
    `CAccTableCell::get_columnHeaderCells` or
    `CEnumVariant::Next`.
    
    This makes sure that a proper `IAccessible` is
    returned instead of triggering an error if no
    such object has been created yet.
    
    This is the case e.g. for off-screen paragraph
    objects in Writer that can still be accessed
    on the UNO a11y level via the
    `AccessibleRelationType::CONTENT_FLOWS_TO` relation.
    However, when testing with the test docs from tdf#91739,
    the issue even occured much earlier, with on-screen
    paragraphs already that weren't available via the
    FLOWS_TO relation from their preceding paragraphs.
    
    With this commit in place, having NVDA read out
    the whole sample documents using the NVDA + Down shortcut
    works now for the tdf#91739 sample docs, in the same way
    it already does for Orca on Linux.
    
    For more details, see also the previous analysis in
    NVDA ticket [1].
    
    [1] https://github.com/nvaccess/nvda/issues/4115#issuecomment-2299084993
    
    Change-Id: I2ef06c6efa368f10dcf5d917d781dabc8ce9a65f
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/172215
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>

diff --git a/winaccessibility/source/UAccCOM/AccRelation.cxx 
b/winaccessibility/source/UAccCOM/AccRelation.cxx
index 464de28eda17..cd245d7f4567 100644
--- a/winaccessibility/source/UAccCOM/AccRelation.cxx
+++ b/winaccessibility/source/UAccCOM/AccRelation.cxx
@@ -104,8 +104,22 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP 
CAccRelation::get_target(long targetIndex, IUn
         if (targetIndex >= nCount)
             return E_FAIL;
 
-        Reference<XAccessible> xRAcc = xTargets[targetIndex];
-        IAccessible* pRet = 
CMAccessible::get_IAccessibleFromXAccessible(xRAcc.get());
+        Reference<XAccessible> xTarget = xTargets[targetIndex];
+        if (!xTarget.is())
+            return E_FAIL;
+
+        IAccessible* pRet = 
CMAccessible::get_IAccessibleFromXAccessible(xTarget.get());
+        if (!pRet)
+        {
+            Reference<XAccessibleContext> xTargetContext = 
xTarget->getAccessibleContext();
+            if (!xTargetContext.is())
+                return E_FAIL;
+
+            Reference<XAccessible> xParent = 
xTargetContext->getAccessibleParent();
+            CMAccessible::g_pAccObjectManager->InsertAccObj(xTarget.get(), 
xParent.get());
+            pRet = CMAccessible::get_IAccessibleFromXAccessible(xTarget.get());
+        }
+
         if (pRet)
         {
             *target = pRet;

Reply via email to