sw/source/core/access/accmap.cxx |  179 ++++++++++++++++++---------------------
 1 file changed, 87 insertions(+), 92 deletions(-)

New commits:
commit fc4bd80e9d2ab0b6746aee7399b4a00030bcfd2c
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Thu Apr 24 12:47:09 2025 +0200
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Fri Apr 25 07:30:35 2025 +0200

    sw a11y: Reduce var scope + move into only relevant block
    
    See
    
        Change-Id: I29824c442f41310af0aff15ebac0e0de9b9fd4a9
        Author: Michael Weghorn <m.wegh...@posteo.de>
        Date:   Thu Apr 24 12:36:08 2025 +0200
    
            sw a11y: Move code into only block where it's relevant
    
    for a similar earlier change.
    
    Change-Id: I9d39681272ce146342d0c1790128d0c3b3de7045
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/184576
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>
    Tested-by: Jenkins

diff --git a/sw/source/core/access/accmap.cxx b/sw/source/core/access/accmap.cxx
index de77b5b453bf..22318f4c7c84 100644
--- a/sw/source/core/access/accmap.cxx
+++ b/sw/source/core/access/accmap.cxx
@@ -1675,9 +1675,6 @@ rtl::Reference<SwAccessibleContext> 
SwAccessibleMap::GetContextImpl(const SwFram
     if (xAcc.is() || !bCreate)
         return xAcc;
 
-    rtl::Reference<SwAccessibleContext> xOldCursorAcc;
-    bool bOldShapeSelected = false;
-
     switch( pFrame->GetType() )
     {
     case SwFrameType::Txt:
@@ -1762,19 +1759,18 @@ rtl::Reference<SwAccessibleContext> 
SwAccessibleMap::GetContextImpl(const SwFram
         // no one except us knows it. In any case, we remember
         // the new context as the one that has the focus
         // currently.
-
-        xOldCursorAcc = mxCursorContext;
+        rtl::Reference<SwAccessibleContext> xOldCursorAcc = mxCursorContext;
         mxCursorContext = xAcc.get();
 
-        bOldShapeSelected = mbShapeSelected;
+        const bool bOldShapeSelected = mbShapeSelected;
         mbShapeSelected = false;
-    }
 
-    // Invalidate focus for old object when map is not locked
-    if (xOldCursorAcc.is())
-        InvalidateCursorPosition(xOldCursorAcc);
-    if (bOldShapeSelected)
-        InvalidateShapeSelection();
+        // Invalidate focus for old object when map is not locked
+        if (xOldCursorAcc.is())
+            InvalidateCursorPosition(xOldCursorAcc);
+        if (bOldShapeSelected)
+            InvalidateShapeSelection();
+    }
 
     return xAcc;
 }
commit 75b445fe58889a3af3af5d611e7dbd95f2b1f5f2
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Thu Apr 24 12:41:45 2025 +0200
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Fri Apr 25 07:30:28 2025 +0200

    sw a11y: Return early in SwAccessibleMap::GetContextImpl
    
    With previous commit
    
        Change-Id: I29824c442f41310af0aff15ebac0e0de9b9fd4a9
        Author: Michael Weghorn <m.wegh...@posteo.de>
        Date:   Thu Apr 24 12:36:08 2025 +0200
    
            sw a11y: Move code into only block where it's relevant
    
    in place, it's now more easily visible that nothing
    else happens here for the case where `xAcc` is non-empty
    or `bCreate` is false. Therefore, return early, which allows
    to drop one level of indentation for the following code.
    
    Change-Id: Ia27352127b0ef804fb103a1e7914d614605ec4ac
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/184575
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>
    Tested-by: Jenkins

diff --git a/sw/source/core/access/accmap.cxx b/sw/source/core/access/accmap.cxx
index d8d11e5002d4..de77b5b453bf 100644
--- a/sw/source/core/access/accmap.cxx
+++ b/sw/source/core/access/accmap.cxx
@@ -1672,111 +1672,110 @@ rtl::Reference<SwAccessibleContext> 
SwAccessibleMap::GetContextImpl(const SwFram
     if (aIter != maFrameMap.end())
         xAcc = (*aIter).second;
 
-    if (!xAcc.is() && bCreate)
-    {
-        rtl::Reference<SwAccessibleContext> xOldCursorAcc;
-        bool bOldShapeSelected = false;
-
-        switch( pFrame->GetType() )
+    if (xAcc.is() || !bCreate)
+        return xAcc;
+
+    rtl::Reference<SwAccessibleContext> xOldCursorAcc;
+    bool bOldShapeSelected = false;
+
+    switch( pFrame->GetType() )
+    {
+    case SwFrameType::Txt:
+        xAcc = new SwAccessibleParagraph(shared_from_this(),
+                        static_cast< const SwTextFrame& >( *pFrame ) );
+        break;
+    case SwFrameType::Header:
+        xAcc = new SwAccessibleHeaderFooter(shared_from_this(),
+                        static_cast< const SwHeaderFrame *>( pFrame ) );
+        break;
+    case SwFrameType::Footer:
+        xAcc = new SwAccessibleHeaderFooter(shared_from_this(),
+                        static_cast< const SwFooterFrame *>( pFrame ) );
+        break;
+    case SwFrameType::Ftn:
+        {
+            const SwFootnoteFrame *pFootnoteFrame =
+                static_cast < const SwFootnoteFrame * >( pFrame );
+            bool bIsEndnote =
+                SwAccessibleFootnote::IsEndnote( pFootnoteFrame );
+            xAcc = new SwAccessibleFootnote(shared_from_this(), bIsEndnote,
+                        /*(bIsEndnote ? mnEndnote++ : mnFootnote++),*/
+                        pFootnoteFrame );
+        }
+        break;
+    case SwFrameType::Fly:
         {
-        case SwFrameType::Txt:
-            xAcc = new SwAccessibleParagraph(shared_from_this(),
-                            static_cast< const SwTextFrame& >( *pFrame ) );
-            break;
-        case SwFrameType::Header:
-            xAcc = new SwAccessibleHeaderFooter(shared_from_this(),
-                            static_cast< const SwHeaderFrame *>( pFrame ) );
-            break;
-        case SwFrameType::Footer:
-            xAcc = new SwAccessibleHeaderFooter(shared_from_this(),
-                            static_cast< const SwFooterFrame *>( pFrame ) );
-            break;
-        case SwFrameType::Ftn:
+            const SwFlyFrame *pFlyFrame =
+                static_cast < const SwFlyFrame * >( pFrame );
+            switch( SwAccessibleFrameBase::GetNodeType( pFlyFrame ) )
             {
-                const SwFootnoteFrame *pFootnoteFrame =
-                    static_cast < const SwFootnoteFrame * >( pFrame );
-                bool bIsEndnote =
-                    SwAccessibleFootnote::IsEndnote( pFootnoteFrame );
-                xAcc = new SwAccessibleFootnote(shared_from_this(), bIsEndnote,
-                            /*(bIsEndnote ? mnEndnote++ : mnFootnote++),*/
-                            pFootnoteFrame );
-            }
-            break;
-        case SwFrameType::Fly:
-            {
-                const SwFlyFrame *pFlyFrame =
-                    static_cast < const SwFlyFrame * >( pFrame );
-                switch( SwAccessibleFrameBase::GetNodeType( pFlyFrame ) )
-                {
-                case SwNodeType::Grf:
-                    xAcc = new SwAccessibleGraphic(shared_from_this(), 
pFlyFrame );
-                    break;
-                case SwNodeType::Ole:
-                    xAcc = new SwAccessibleEmbeddedObject(shared_from_this(), 
pFlyFrame );
-                    break;
-                default:
-                    xAcc = new SwAccessibleTextFrame(shared_from_this(), 
*pFlyFrame );
-                    break;
-                }
+            case SwNodeType::Grf:
+                xAcc = new SwAccessibleGraphic(shared_from_this(), pFlyFrame );
+                break;
+            case SwNodeType::Ole:
+                xAcc = new SwAccessibleEmbeddedObject(shared_from_this(), 
pFlyFrame );
+                break;
+            default:
+                xAcc = new SwAccessibleTextFrame(shared_from_this(), 
*pFlyFrame );
+                break;
             }
-            break;
-        case SwFrameType::Cell:
-            xAcc = new SwAccessibleCell(shared_from_this(),
-                            static_cast< const SwCellFrame *>( pFrame ) );
-            break;
-        case SwFrameType::Tab:
-            xAcc = new SwAccessibleTable(shared_from_this(),
-                            static_cast< const SwTabFrame *>( pFrame ) );
-            break;
-        case SwFrameType::Page:
-            OSL_ENSURE(GetShell().IsPreview(),
-                        "accessible page frames only in PagePreview" );
-            xAcc = new SwAccessiblePage(shared_from_this(), pFrame);
-            break;
-        default: break;
         }
-        assert(xAcc.is());
+        break;
+    case SwFrameType::Cell:
+        xAcc = new SwAccessibleCell(shared_from_this(),
+                        static_cast< const SwCellFrame *>( pFrame ) );
+        break;
+    case SwFrameType::Tab:
+        xAcc = new SwAccessibleTable(shared_from_this(),
+                        static_cast< const SwTabFrame *>( pFrame ) );
+        break;
+    case SwFrameType::Page:
+        OSL_ENSURE(GetShell().IsPreview(),
+                    "accessible page frames only in PagePreview" );
+        xAcc = new SwAccessiblePage(shared_from_this(), pFrame);
+        break;
+    default: break;
+    }
+    assert(xAcc.is());
 
-        if (aIter != maFrameMap.end())
-        {
-            (*aIter).second = xAcc.get();
-        }
-        else
-        {
-            maFrameMap.emplace(pFrame, xAcc);
-        }
+    if (aIter != maFrameMap.end())
+    {
+        (*aIter).second = xAcc.get();
+    }
+    else
+    {
+        maFrameMap.emplace(pFrame, xAcc);
+    }
 
-        if (xAcc->HasCursor() &&
-            !AreInSameTable( mxCursorContext, pFrame ) )
-        {
-            // If the new context has the focus, and if we know
-            // another context that had the focus, then the focus
-            // just moves from the old context to the new one. We
-            // then have to send a focus event and a caret event for
-            // the old context. We have to do that now,
-            // because after we have left this method, anyone might
-            // call getStates for the new context and will get a
-            // focused state then. Sending the focus changes event
-            // after that seems to be strange. However, we cannot
-            // send a focus event for the new context now, because
-            // no one except us knows it. In any case, we remember
-            // the new context as the one that has the focus
-            // currently.
-
-            xOldCursorAcc = mxCursorContext;
-            mxCursorContext = xAcc.get();
-
-            bOldShapeSelected = mbShapeSelected;
-            mbShapeSelected = false;
-        }
+    if (xAcc->HasCursor() && !AreInSameTable(mxCursorContext, pFrame))
+    {
+        // If the new context has the focus, and if we know
+        // another context that had the focus, then the focus
+        // just moves from the old context to the new one. We
+        // then have to send a focus event and a caret event for
+        // the old context. We have to do that now,
+        // because after we have left this method, anyone might
+        // call getStates for the new context and will get a
+        // focused state then. Sending the focus changes event
+        // after that seems to be strange. However, we cannot
+        // send a focus event for the new context now, because
+        // no one except us knows it. In any case, we remember
+        // the new context as the one that has the focus
+        // currently.
+
+        xOldCursorAcc = mxCursorContext;
+        mxCursorContext = xAcc.get();
 
-        // Invalidate focus for old object when map is not locked
-        if (xOldCursorAcc.is())
-            InvalidateCursorPosition(xOldCursorAcc);
-        if (bOldShapeSelected)
-            InvalidateShapeSelection();
+        bOldShapeSelected = mbShapeSelected;
+        mbShapeSelected = false;
     }
 
+    // Invalidate focus for old object when map is not locked
+    if (xOldCursorAcc.is())
+        InvalidateCursorPosition(xOldCursorAcc);
+    if (bOldShapeSelected)
+        InvalidateShapeSelection();
+
     return xAcc;
 }
 

Reply via email to