sw/source/core/access/accmap.cxx |  270 +++++++++++++++++++--------------------
 1 file changed, 132 insertions(+), 138 deletions(-)

New commits:
commit 43f5bf0439c05cd54925ac8fae683531d929d23d
Author:     Michael Weghorn <[email protected]>
AuthorDate: Thu Apr 17 11:18:23 2025 +0200
Commit:     Michael Weghorn <[email protected]>
CommitDate: Fri Apr 18 08:29:20 2025 +0200

    sw a11y: Merge variable decl and assignment
    
    `bOldShapeSelected` can also be const now.
    
    Change-Id: Idd24c9ce22238e74b41b34c781920acafec0083f
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/184330
    Reviewed-by: Michael Weghorn <[email protected]>
    Tested-by: Jenkins

diff --git a/sw/source/core/access/accmap.cxx b/sw/source/core/access/accmap.cxx
index 6a2f4abc05c0..d56fa98645ad 100644
--- a/sw/source/core/access/accmap.cxx
+++ b/sw/source/core/access/accmap.cxx
@@ -2394,16 +2394,13 @@ void SwAccessibleMap::InvalidateCursorPosition( const 
SwFrame *pFrame )
     OSL_ENSURE(bShapeSelected || 
aFrameOrObj.IsAccessible(GetShell().IsPreview()),
             "frame is not accessible" );
 
-    rtl::Reference < SwAccessibleContext > xOldAcc;
-    rtl::Reference < SwAccessibleContext > xAcc;
-    bool bOldShapeSelected = false;
-
-    xOldAcc = mxCursorContext;
+    rtl::Reference <SwAccessibleContext> xOldAcc = mxCursorContext;
     mxCursorContext.clear();
 
-    bOldShapeSelected = mbShapeSelected;
+    const bool bOldShapeSelected = mbShapeSelected;
     mbShapeSelected = bShapeSelected;
 
+    rtl::Reference <SwAccessibleContext> xAcc;
     if( aFrameOrObj.GetSwFrame() && mpFrameMap )
     {
         SwAccessibleContextMap_Impl::iterator aIter =
commit 562b0b063b443bf3f6ae97d0a1fa3d07f1ed7ec8
Author:     Michael Weghorn <[email protected]>
AuthorDate: Thu Apr 17 11:16:27 2025 +0200
Commit:     Michael Weghorn <[email protected]>
CommitDate: Fri Apr 18 08:28:51 2025 +0200

    sw a11y: Explicitly clear WeakReference
    
    ... instead of assigning an empty ref, and having
    an explaining comment that this is done to clear it.
    
    Change-Id: Ic4f7c5f64406ed77a66b05c0ec471a23ea3f68bb
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/184329
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <[email protected]>

diff --git a/sw/source/core/access/accmap.cxx b/sw/source/core/access/accmap.cxx
index 756568487483..6a2f4abc05c0 100644
--- a/sw/source/core/access/accmap.cxx
+++ b/sw/source/core/access/accmap.cxx
@@ -2399,7 +2399,7 @@ void SwAccessibleMap::InvalidateCursorPosition( const 
SwFrame *pFrame )
     bool bOldShapeSelected = false;
 
     xOldAcc = mxCursorContext;
-    mxCursorContext = xAcc.get(); // clear reference
+    mxCursorContext.clear();
 
     bOldShapeSelected = mbShapeSelected;
     mbShapeSelected = bShapeSelected;
commit 86cef6d3d14098a472c470f901b887f3d361d2b3
Author:     Michael Weghorn <[email protected]>
AuthorDate: Thu Apr 17 11:06:12 2025 +0200
Commit:     Michael Weghorn <[email protected]>
CommitDate: Fri Apr 18 08:28:36 2025 +0200

    sw a11y: Drop extra block scopes
    
    Before
    
        commit 59036776b92c0f4ad2edd1bafd332f7a4ee87cdc
        Date:   Wed Apr 26 15:15:01 2023 +0200
    
            tdf#136749 no need to use maMutex in SwAccessibleMap
    
    , these were relevant for the lifetime of an
    
        osl::MutexGuard aGuard( maMutex );
    
    , but that one was dropped in the above commit, so drop
    the extra scopes and indentation level as well.
    
    (`git show --ignore-space change` helps to see the
    "actual" changes more easily.)
    
    Change-Id: I28f9957cea59aeb1836a2a44543d2abc2f114401
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/184328
    Reviewed-by: Michael Weghorn <[email protected]>
    Tested-by: Jenkins

diff --git a/sw/source/core/access/accmap.cxx b/sw/source/core/access/accmap.cxx
index 59c4b42e302a..756568487483 100644
--- a/sw/source/core/access/accmap.cxx
+++ b/sw/source/core/access/accmap.cxx
@@ -2072,52 +2072,51 @@ void SwAccessibleMap::A11yDispose( const SwFrame 
*pFrame,
     ::rtl::Reference< SwAccessibleContext > xAccImpl;
     ::rtl::Reference< SwAccessibleContext > xParentAccImpl;
     ::rtl::Reference< ::accessibility::AccessibleShape > xShapeAccImpl;
+
     // get accessible context for frame
+    // First of all look for an accessible context for a frame
+    if( aFrameOrObj.GetSwFrame() && mpFrameMap )
+    {
+        SwAccessibleContextMap_Impl::iterator aIter =
+            mpFrameMap->find( aFrameOrObj.GetSwFrame() );
+        if( aIter != mpFrameMap->end() )
+            xAccImpl = (*aIter).second;
+    }
+    if( !xAccImpl.is() && mpFrameMap )
     {
-        // First of all look for an accessible context for a frame
-        if( aFrameOrObj.GetSwFrame() && mpFrameMap )
+        // If there is none, look if the parent is accessible.
+        const SwFrame *pParent =
+                SwAccessibleFrame::GetParent( aFrameOrObj,
+                                              GetShell().IsPreview());
+
+        if( pParent )
         {
             SwAccessibleContextMap_Impl::iterator aIter =
-                mpFrameMap->find( aFrameOrObj.GetSwFrame() );
+                mpFrameMap->find( pParent );
             if( aIter != mpFrameMap->end() )
-                xAccImpl = (*aIter).second;
-        }
-        if( !xAccImpl.is() && mpFrameMap )
-        {
-            // If there is none, look if the parent is accessible.
-            const SwFrame *pParent =
-                    SwAccessibleFrame::GetParent( aFrameOrObj,
-                                                  GetShell().IsPreview());
-
-            if( pParent )
-            {
-                SwAccessibleContextMap_Impl::iterator aIter =
-                    mpFrameMap->find( pParent );
-                if( aIter != mpFrameMap->end() )
-                    xParentAccImpl = (*aIter).second;
-            }
+                xParentAccImpl = (*aIter).second;
         }
-        if( !xParentAccImpl.is() && !aFrameOrObj.GetSwFrame() && mpShapeMap )
+    }
+    if( !xParentAccImpl.is() && !aFrameOrObj.GetSwFrame() && mpShapeMap )
+    {
+        SwAccessibleShapeMap_Impl::iterator aIter =
+            mpShapeMap->find( aFrameOrObj.GetDrawObject() );
+        if( aIter != mpShapeMap->end() )
         {
-            SwAccessibleShapeMap_Impl::iterator aIter =
-                mpShapeMap->find( aFrameOrObj.GetDrawObject() );
-            if( aIter != mpShapeMap->end() )
-            {
-                xShapeAccImpl = aIter->second;
-            }
+            xShapeAccImpl = aIter->second;
         }
-        if (pObj && GetShell().ActionPend() &&
-            (xParentAccImpl.is() || xShapeAccImpl.is()) )
+    }
+    if (pObj && GetShell().ActionPend() &&
+        (xParentAccImpl.is() || xShapeAccImpl.is()) )
+    {
+        // Keep a reference to the XShape to avoid that it
+        // is deleted with a SwFrameFormat::SwClientNotify.
+        uno::Reference < drawing::XShape > xShape(
+            const_cast< SdrObject * >( pObj )->getUnoShape(),
+            uno::UNO_QUERY );
+        if( xShape.is() )
         {
-            // Keep a reference to the XShape to avoid that it
-            // is deleted with a SwFrameFormat::SwClientNotify.
-            uno::Reference < drawing::XShape > xShape(
-                const_cast< SdrObject * >( pObj )->getUnoShape(),
-                uno::UNO_QUERY );
-            if( xShape.is() )
-            {
-                mvShapes.push_back( xShape );
-            }
+            mvShapes.push_back( xShape );
         }
     }
 
@@ -2399,133 +2398,131 @@ void SwAccessibleMap::InvalidateCursorPosition( const 
SwFrame *pFrame )
     rtl::Reference < SwAccessibleContext > xAcc;
     bool bOldShapeSelected = false;
 
-    {
-        xOldAcc = mxCursorContext;
-        mxCursorContext = xAcc.get(); // clear reference
+    xOldAcc = mxCursorContext;
+    mxCursorContext = xAcc.get(); // clear reference
 
-        bOldShapeSelected = mbShapeSelected;
-        mbShapeSelected = bShapeSelected;
+    bOldShapeSelected = mbShapeSelected;
+    mbShapeSelected = bShapeSelected;
 
-        if( aFrameOrObj.GetSwFrame() && mpFrameMap )
+    if( aFrameOrObj.GetSwFrame() && mpFrameMap )
+    {
+        SwAccessibleContextMap_Impl::iterator aIter =
+            mpFrameMap->find( aFrameOrObj.GetSwFrame() );
+        if( aIter != mpFrameMap->end() )
+            xAcc = (*aIter).second;
+        else
         {
-            SwAccessibleContextMap_Impl::iterator aIter =
-                mpFrameMap->find( aFrameOrObj.GetSwFrame() );
-            if( aIter != mpFrameMap->end() )
-                xAcc = (*aIter).second;
+            SwRect rcEmpty;
+            const SwTabFrame* pTabFrame = 
aFrameOrObj.GetSwFrame()->FindTabFrame();
+            if (pTabFrame)
+            {
+                InvalidatePosOrSize(pTabFrame, nullptr, nullptr, rcEmpty);
+            }
             else
             {
-                SwRect rcEmpty;
-                const SwTabFrame* pTabFrame = 
aFrameOrObj.GetSwFrame()->FindTabFrame();
-                if (pTabFrame)
-                {
-                    InvalidatePosOrSize(pTabFrame, nullptr, nullptr, rcEmpty);
-                }
-                else
-                {
-                    InvalidatePosOrSize(aFrameOrObj.GetSwFrame(), nullptr, 
nullptr, rcEmpty);
-                }
+                InvalidatePosOrSize(aFrameOrObj.GetSwFrame(), nullptr, 
nullptr, rcEmpty);
+            }
 
-                aIter = mpFrameMap->find( aFrameOrObj.GetSwFrame() );
-                if( aIter != mpFrameMap->end() )
-                {
-                    xAcc = (*aIter).second;
-                }
+            aIter = mpFrameMap->find( aFrameOrObj.GetSwFrame() );
+            if( aIter != mpFrameMap->end() )
+            {
+                xAcc = (*aIter).second;
             }
+        }
 
-            // For cells, some extra thoughts are necessary,
-            // because invalidating the cursor for one cell
-            // invalidates the cursor for all cells of the same
-            // table. For this reason, we don't want to
-            // invalidate the cursor for the old cursor object
-            // and the new one if they are within the same table,
-            // because this would result in doing the work twice.
-            // Moreover, we have to make sure to invalidate the
-            // cursor even if the current cell has no accessible object.
-            // If the old cursor objects exists and is in the same
-            // table, it's the best choice, because using it avoids
-            // an unnecessary cursor invalidation cycle when creating
-            // a new object for the current cell.
-            if( aFrameOrObj.GetSwFrame()->IsCellFrame() )
+        // For cells, some extra thoughts are necessary,
+        // because invalidating the cursor for one cell
+        // invalidates the cursor for all cells of the same
+        // table. For this reason, we don't want to
+        // invalidate the cursor for the old cursor object
+        // and the new one if they are within the same table,
+        // because this would result in doing the work twice.
+        // Moreover, we have to make sure to invalidate the
+        // cursor even if the current cell has no accessible object.
+        // If the old cursor objects exists and is in the same
+        // table, it's the best choice, because using it avoids
+        // an unnecessary cursor invalidation cycle when creating
+        // a new object for the current cell.
+        if( aFrameOrObj.GetSwFrame()->IsCellFrame() )
+        {
+            if( xOldAcc.is() &&
+                AreInSameTable( xOldAcc, aFrameOrObj.GetSwFrame() ) )
             {
-                if( xOldAcc.is() &&
-                    AreInSameTable( xOldAcc, aFrameOrObj.GetSwFrame() ) )
-                {
-                    if( xAcc.is() )
-                        xOldAcc = xAcc; // avoid extra invalidation
-                    else
-                        xAcc = xOldAcc; // make sure at least one
-                }
-                if( !xAcc.is() )
-                    xAcc = GetContextImpl( aFrameOrObj.GetSwFrame() );
+                if( xAcc.is() )
+                    xOldAcc = xAcc; // avoid extra invalidation
+                else
+                    xAcc = xOldAcc; // make sure at least one
             }
+            if( !xAcc.is() )
+                xAcc = GetContextImpl( aFrameOrObj.GetSwFrame() );
         }
-        else if (bShapeSelected)
+    }
+    else if (bShapeSelected)
+    {
+        const SwFEShell* pFESh = static_cast<const SwFEShell*>(&rVSh);
+        const SdrMarkList *pMarkList = pFESh->GetMarkList();
+        if (pMarkList != nullptr && pMarkList->GetMarkCount() == 1)
         {
-            const SwFEShell* pFESh = static_cast<const SwFEShell*>(&rVSh);
-            const SdrMarkList *pMarkList = pFESh->GetMarkList();
-            if (pMarkList != nullptr && pMarkList->GetMarkCount() == 1)
+            SdrObject *pObj = pMarkList->GetMark( 0 )->GetMarkedSdrObj();
+            ::rtl::Reference < ::accessibility::AccessibleShape > 
pAccShapeImpl = GetContextImpl(pObj,nullptr,false);
+            if (!pAccShapeImpl.is())
             {
-                SdrObject *pObj = pMarkList->GetMark( 0 )->GetMarkedSdrObj();
-                ::rtl::Reference < ::accessibility::AccessibleShape > 
pAccShapeImpl = GetContextImpl(pObj,nullptr,false);
-                if (!pAccShapeImpl.is())
+                while (pObj && pObj->getParentSdrObjectFromSdrObject())
                 {
-                    while (pObj && pObj->getParentSdrObjectFromSdrObject())
-                    {
-                        pObj = pObj->getParentSdrObjectFromSdrObject();
-                    }
-                    if (pObj != nullptr)
+                    pObj = pObj->getParentSdrObjectFromSdrObject();
+                }
+                if (pObj != nullptr)
+                {
+                    const SwFrame *pParent = 
SwAccessibleFrame::GetParent(SwAccessibleChild(pObj), GetShell().IsPreview());
+                    if( pParent )
                     {
-                        const SwFrame *pParent = 
SwAccessibleFrame::GetParent(SwAccessibleChild(pObj), GetShell().IsPreview());
-                        if( pParent )
+                        ::rtl::Reference< SwAccessibleContext > xParentAccImpl 
= GetContextImpl(pParent,false);
+                        if (!xParentAccImpl.is())
                         {
-                            ::rtl::Reference< SwAccessibleContext > 
xParentAccImpl = GetContextImpl(pParent,false);
-                            if (!xParentAccImpl.is())
+                            const SwTabFrame* pTabFrame = 
pParent->FindTabFrame();
+                            if (pTabFrame)
                             {
-                                const SwTabFrame* pTabFrame = 
pParent->FindTabFrame();
-                                if (pTabFrame)
-                                {
-                                    //The Table should not add in acc.because 
the "pParent" is not add to acc .
-                                    uno::Reference< XAccessible>  
xAccParentTab = GetContext(pTabFrame);//Should Create.
+                                //The Table should not add in acc.because the 
"pParent" is not add to acc .
+                                uno::Reference< XAccessible>  xAccParentTab = 
GetContext(pTabFrame);//Should Create.
 
-                                    const SwFrame *pParentRoot = 
SwAccessibleFrame::GetParent(SwAccessibleChild(pTabFrame), 
GetShell().IsPreview());
-                                    if (pParentRoot)
-                                    {
-                                        ::rtl::Reference< SwAccessibleContext 
> xParentAccImplRoot = GetContextImpl(pParentRoot,false);
-                                        if(xParentAccImplRoot.is())
-                                        {
-                                            
xParentAccImplRoot->FireAccessibleEvent(
-                                                AccessibleEventId::CHILD, 
uno::Any(),
-                                                uno::Any(xAccParentTab));
-                                        }
-                                    }
-
-                                    //Get "pParent" acc again.
-                                    xParentAccImpl = 
GetContextImpl(pParent,false);
-                                }
-                                else
+                                const SwFrame *pParentRoot = 
SwAccessibleFrame::GetParent(SwAccessibleChild(pTabFrame), 
GetShell().IsPreview());
+                                if (pParentRoot)
                                 {
-                                    //directly create this acc para .
-                                    xParentAccImpl = 
GetContextImpl(pParent);//Should Create.
-
-                                    const SwFrame *pParentRoot = 
SwAccessibleFrame::GetParent(SwAccessibleChild(pParent), 
GetShell().IsPreview());
-
                                     ::rtl::Reference< SwAccessibleContext > 
xParentAccImplRoot = GetContextImpl(pParentRoot,false);
                                     if(xParentAccImplRoot.is())
                                     {
                                         
xParentAccImplRoot->FireAccessibleEvent(
                                             AccessibleEventId::CHILD, 
uno::Any(),
-                                            
uno::Any(uno::Reference<XAccessible>(xParentAccImpl)));
+                                            uno::Any(xAccParentTab));
                                     }
                                 }
+
+                                //Get "pParent" acc again.
+                                xParentAccImpl = GetContextImpl(pParent,false);
                             }
-                            if (xParentAccImpl.is())
+                            else
                             {
-                                uno::Reference< XAccessible>  xAccShape =
-                                    GetContext(pObj,xParentAccImpl.get());
-                                xParentAccImpl->FireAccessibleEvent(
-                                    AccessibleEventId::CHILD, uno::Any(), 
uno::Any(xAccShape));
+                                //directly create this acc para .
+                                xParentAccImpl = 
GetContextImpl(pParent);//Should Create.
+
+                                const SwFrame *pParentRoot = 
SwAccessibleFrame::GetParent(SwAccessibleChild(pParent), 
GetShell().IsPreview());
+
+                                ::rtl::Reference< SwAccessibleContext > 
xParentAccImplRoot = GetContextImpl(pParentRoot,false);
+                                if(xParentAccImplRoot.is())
+                                {
+                                    xParentAccImplRoot->FireAccessibleEvent(
+                                        AccessibleEventId::CHILD, uno::Any(),
+                                        
uno::Any(uno::Reference<XAccessible>(xParentAccImpl)));
+                                }
                             }
                         }
+                        if (xParentAccImpl.is())
+                        {
+                            uno::Reference< XAccessible>  xAccShape =
+                                GetContext(pObj,xParentAccImpl.get());
+                            xParentAccImpl->FireAccessibleEvent(
+                                AccessibleEventId::CHILD, uno::Any(), 
uno::Any(xAccShape));
+                        }
                     }
                 }
             }

Reply via email to