sw/source/core/access/accpara.cxx |  104 +++++++++++++++++---------------------
 1 file changed, 47 insertions(+), 57 deletions(-)

New commits:
commit 3f19e3aacf727d779d508d5f0d65adc6adcf845f
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Thu Apr 24 10:25:32 2025 +0200
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Fri Apr 25 07:28:43 2025 +0200

    sw a11y: Just pass 'this'
    
    No need to use an explicit rtl::Reference to `this`
    here.
    
    Change-Id: I4c1ea4d63bb6fcbfd437607a309f01cde11950a3
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/184548
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>
    Tested-by: Jenkins

diff --git a/sw/source/core/access/accpara.cxx 
b/sw/source/core/access/accpara.cxx
index 963dcdec2ec1..a5e51a557ac0 100644
--- a/sw/source/core/access/accpara.cxx
+++ b/sw/source/core/access/accpara.cxx
@@ -300,8 +300,7 @@ void SwAccessibleParagraph::InvalidateCursorPos_()
     {
         // remember that object as the one that has the caret. This is
         // necessary to notify that object if the cursor leaves it.
-        ::rtl::Reference < SwAccessibleContext > xThis( this );
-        GetMap()->SetCursorContext( xThis );
+        GetMap()->SetCursorContext(this);
     }
 
     vcl::Window *pWin = GetWindow();
commit 151550bbe7951b7a8ba70aa41106b5d2ad161df2
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Thu Apr 24 10:13:09 2025 +0200
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Fri Apr 25 07:28:35 2025 +0200

    sw a11y: Simplify paragraph parent retrieval in one place
    
    The general way to retrieve the XAccessibleContext
    from an XAccessible is to call XAccessible::getAccessibleContext,
    not to query the XAccessible for the XAccessibleContext
    interface.
    (Doing the latter - as was done here - should still give the correct
    result in practice at least, because 
SwAccessibleContext::getAccessibleParent
    returns a reference to self.)
    
    For SwAccessibleParagraph as a SwAccessibleContext subclass
    however, there is SwAccessibleContext::getAccessibleParentImpl
    (which also gets called by SwAccessibleContext::getAccessibleParent)
    which returns a SwAccessibleContext right away, so use that
    which is simpler and also removes the need to static_cast the
    accessible to SwAccessibleContext altogether.
    
    As a side not, using `pPara` for the var name of an accessible with
    role TABLE_CELL also seemed a little misleading.
    
    Change-Id: I38991674e806eb8f5ecf75327686651b6779c8ed
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/184547
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>
    Tested-by: Jenkins

diff --git a/sw/source/core/access/accpara.cxx 
b/sw/source/core/access/accpara.cxx
index ed5002945f5b..963dcdec2ec1 100644
--- a/sw/source/core/access/accpara.cxx
+++ b/sw/source/core/access/accpara.cxx
@@ -255,17 +255,9 @@ void SwAccessibleParagraph::InvalidateContent_( bool 
bVisibleDataFired )
                                                                           
aOldValue, aNewValue);
 
         FireAccessibleEvent(AccessibleEventId::TEXT_CHANGED, aOldValue, 
aNewValue);
-        uno::Reference< XAccessible > xparent = getAccessibleParent();
-        uno::Reference< XAccessibleContext > 
xAccContext(xparent,uno::UNO_QUERY);
-        if (xAccContext.is() && xAccContext->getAccessibleRole() == 
AccessibleRole::TABLE_CELL)
-        {
-            SwAccessibleContext* pPara = static_cast< SwAccessibleContext* 
>(xparent.get());
-            if(pPara)
-            {
-                pPara->FireAccessibleEvent(AccessibleEventId::VALUE_CHANGED, 
uno::Any(),
-                                           uno::Any());
-            }
-        }
+        rtl::Reference<SwAccessibleContext> xParent = 
getAccessibleParentImpl();
+        if (xParent.is() && xParent->getAccessibleRole() == 
AccessibleRole::TABLE_CELL)
+            xParent->FireAccessibleEvent(AccessibleEventId::VALUE_CHANGED, 
uno::Any(), uno::Any());
     }
     else if( !bVisibleDataFired )
     {
commit 85cbe675d352ab0e9dbf0bf8bad3c8fc3a7e6768
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Thu Apr 24 09:56:15 2025 +0200
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Fri Apr 25 07:28:28 2025 +0200

    sw a11y: Drop class qualifier when calling method
    
    `GetCursorShell` is a non-virtual method of
    the SwAccessibleContext base class, so explicitly
    calling it as SwAccessibleParagraph::GetCursorShell
    from within SwAccessibleParagraph itself
    is unnecessary and rather confusing.
    
    Change-Id: I069d2d2b0d56962b6aac388d0dd0e299e5bc98cb
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/184539
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>

diff --git a/sw/source/core/access/accpara.cxx 
b/sw/source/core/access/accpara.cxx
index 05f85d172058..ed5002945f5b 100644
--- a/sw/source/core/access/accpara.cxx
+++ b/sw/source/core/access/accpara.cxx
@@ -181,7 +181,7 @@ SwPaM* SwAccessibleParagraph::GetCursor( const bool 
_bForSelection )
     // get the cursor shell; if we don't have any, we don't have a
     // cursor/selection either
     SwPaM* pCursor = nullptr;
-    SwCursorShell* pCursorShell = SwAccessibleParagraph::GetCursorShell();
+    SwCursorShell* pCursorShell = GetCursorShell();
     // #i27301# - if cursor is retrieved for selection, the cursors for
     // a table selection has to be returned.
     if ( pCursorShell != nullptr &&
commit d310e84bca42178e01cfbe1fac114b719490a889
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Thu Apr 24 09:43:07 2025 +0200
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Fri Apr 25 07:28:20 2025 +0200

    sw a11y: Return early in SwAccessibleParagraph::GetCaretPos
    
    (`git show --ignore-space-change` helps to see the
    "actual" change more easily.)
    
    Change-Id: I5cb1e84a1db91b19fd6eddd1c72b6184aecead04
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/184538
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>

diff --git a/sw/source/core/access/accpara.cxx 
b/sw/source/core/access/accpara.cxx
index b0080c3ece7b..05f85d172058 100644
--- a/sw/source/core/access/accpara.cxx
+++ b/sw/source/core/access/accpara.cxx
@@ -121,57 +121,56 @@ OUString const & SwAccessibleParagraph::GetString()
 
 sal_Int32 SwAccessibleParagraph::GetCaretPos()
 {
-    sal_Int32 nRet = -1;
-
     // get the selection's point, and test whether it's in our node
     // #i27301# - consider adjusted method signature
     SwPaM* pCaret = GetCursor( false );  // caret is first PaM in PaM-ring
+    if (!pCaret)
+        // no cursor -> no caret
+        return -1;
 
-    if( pCaret != nullptr )
-    {
-        const SwTextFrame* const pTextFrame = GetTextFrame();
-        assert(pTextFrame);
+    const SwTextFrame* const pTextFrame = GetTextFrame();
+    assert(pTextFrame);
 
-        // check whether the point points into 'our' node
-        SwPosition* pPoint = pCaret->GetPoint();
-        if (sw::FrameContainsNode(*pTextFrame, pPoint->GetNodeIndex()))
-        {
-            // same node? Then check whether it's also within 'our' part
-            // of the paragraph
-            const TextFrameIndex nIndex = 
pTextFrame->MapModelToViewPos(*pPoint);
-            if(!GetPortionData().IsValidCorePosition( nIndex ) ||
-                (GetPortionData().IsZeroCorePositionData()
-                  && nIndex == TextFrameIndex(0)))
-            {
-                bool bFormat = pTextFrame->HasPara();
-                if(bFormat)
-                {
-                    ClearPortionData();
-                    UpdatePortionData();
-                }
-            }
-            if( GetPortionData().IsValidCorePosition( nIndex ) )
-            {
-                // Yes, it's us!
-                // consider that cursor/caret is in front of the list label
-                if ( pCaret->IsInFrontOfLabel() )
-                {
-                    nRet = 0;
-                }
-                else
-                {
-                    nRet = GetPortionData().GetAccessiblePosition( nIndex );
-                }
+    // check whether the point points into 'our' node
+    SwPosition* pPoint = pCaret->GetPoint();
 
-                OSL_ENSURE( nRet >= 0, "invalid cursor?" );
-                OSL_ENSURE( nRet <= GetPortionData().GetAccessibleString().
-                                              getLength(), "invalid cursor?" );
-            }
-            // else: in this paragraph, but in different frame
+    if (!sw::FrameContainsNode(*pTextFrame, pPoint->GetNodeIndex()))
+        // not in this paragraph
+        return -1;
+
+    sal_Int32 nRet = -1;
+
+    // check whether it's also within 'our' part of the paragraph
+    const TextFrameIndex nIndex = pTextFrame->MapModelToViewPos(*pPoint);
+    if(!GetPortionData().IsValidCorePosition( nIndex ) ||
+        (GetPortionData().IsZeroCorePositionData()
+          && nIndex == TextFrameIndex(0)))
+    {
+        bool bFormat = pTextFrame->HasPara();
+        if(bFormat)
+        {
+            ClearPortionData();
+            UpdatePortionData();
         }
-        // else: not in this paragraph
     }
-    // else: no cursor -> no caret
+    if( GetPortionData().IsValidCorePosition( nIndex ) )
+    {
+        // Yes, it's us!
+        // consider that cursor/caret is in front of the list label
+        if ( pCaret->IsInFrontOfLabel() )
+        {
+            nRet = 0;
+        }
+        else
+        {
+            nRet = GetPortionData().GetAccessiblePosition( nIndex );
+        }
+
+        OSL_ENSURE( nRet >= 0, "invalid cursor?" );
+        OSL_ENSURE( nRet <= GetPortionData().GetAccessibleString().
+                                      getLength(), "invalid cursor?" );
+    }
+    // else: in this paragraph, but in different frame
 
     return nRet;
 }

Reply via email to