sw/qa/core/accessibilitycheck/data/HyperlinkTest.odt |binary
 sw/source/core/access/AccessibilityCheck.cxx         |   86 ++++++++-----------
 2 files changed, 40 insertions(+), 46 deletions(-)

New commits:
commit b7a49b42d612e2bd65c38f5a3da4c67f7ceca20e
Author:     Balazs Varga <[email protected]>
AuthorDate: Tue Sep 17 14:32:20 2024 +0200
Commit:     Thorsten Behrens <[email protected]>
CommitDate: Tue Sep 17 18:04:38 2024 +0200

    tdf#162988 - A11Y sidebar: fix hyperlinks false warning
    
    Better to check the SwpHints of the textnodes then iterate
    through on the xParagraph's xTextRanges to search for a11y
    hyperlink warnings.
    
    Change-Id: I19a3eddd53f122bd4290e5b93e4784b89f65427d
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/173563
    Reviewed-by: Thorsten Behrens <[email protected]>
    Tested-by: allotropia jenkins <[email protected]>

diff --git a/sw/qa/core/accessibilitycheck/data/HyperlinkTest.odt 
b/sw/qa/core/accessibilitycheck/data/HyperlinkTest.odt
index 1eba1932ce21..92240fb1d67f 100644
Binary files a/sw/qa/core/accessibilitycheck/data/HyperlinkTest.odt and 
b/sw/qa/core/accessibilitycheck/data/HyperlinkTest.odt differ
diff --git a/sw/source/core/access/AccessibilityCheck.cxx 
b/sw/source/core/access/AccessibilityCheck.cxx
index 83ff5de88ff1..96260cc19a95 100644
--- a/sw/source/core/access/AccessibilityCheck.cxx
+++ b/sw/source/core/access/AccessibilityCheck.cxx
@@ -370,42 +370,48 @@ public:
 class HyperlinkCheck : public NodeCheck
 {
 private:
-    void checkTextRange(uno::Reference<text::XTextRange> const& xTextRange, 
SwTextNode* pTextNode,
-                        sal_Int32 nStart)
+    void checkHyperLinks(SwTextNode* pTextNode)
     {
-        uno::Reference<beans::XPropertySet> xProperties(xTextRange, 
uno::UNO_QUERY);
-        if 
(!xProperties->getPropertySetInfo()->hasPropertyByName("HyperLinkURL"))
-            return;
-
-        OUString sHyperlink;
-        xProperties->getPropertyValue("HyperLinkURL") >>= sHyperlink;
-        if (!sHyperlink.isEmpty())
+        const OUString& sParagraphText = pTextNode->GetText();
+        SwpHints& rHints = pTextNode->GetSwpHints();
+        for (size_t i = 0; i < rHints.Count(); ++i)
         {
-            OUString sText = xTextRange->getString();
-            INetURLObject aHyperlink(sHyperlink);
-            std::shared_ptr<sw::AccessibilityIssue> pIssue;
-            if (aHyperlink.GetProtocol() != INetProtocol::NotValid
-                && INetURLObject(sText) == aHyperlink)
+            const SwTextAttr* pTextAttr = rHints.Get(i);
+            if (pTextAttr->Which() == RES_TXTATR_INETFMT)
             {
-                OUString sIssueText
-                    = 
SwResId(STR_HYPERLINK_TEXT_IS_LINK).replaceFirst("%LINK%", sHyperlink);
-                pIssue = lclAddIssue(m_rIssueCollection, sIssueText,
-                                     
sfx::AccessibilityIssueID::HYPERLINK_IS_TEXT);
-            }
-            else if (sText.getLength() <= 5)
-            {
-                pIssue = lclAddIssue(m_rIssueCollection, 
SwResId(STR_HYPERLINK_TEXT_IS_SHORT),
-                                     
sfx::AccessibilityIssueID::HYPERLINK_SHORT);
-            }
+                OUString sHyperlink = pTextAttr->GetINetFormat().GetValue();
+                if (!sHyperlink.isEmpty())
+                {
+                    INetURLObject aHyperlink(sHyperlink);
+                    std::shared_ptr<sw::AccessibilityIssue> pIssue;
+                    sal_Int32 nStart = pTextAttr->GetStart();
+                    OUString sRunText = sParagraphText.copy(nStart, 
*pTextAttr->GetEnd() - nStart);
 
-            if (pIssue)
-            {
-                pIssue->setIssueObject(IssueObject::TEXT);
-                pIssue->setNode(pTextNode);
-                SwDoc& rDocument = pTextNode->GetDoc();
-                pIssue->setDoc(rDocument);
-                pIssue->setStart(nStart);
-                pIssue->setEnd(nStart + sText.getLength());
+                    if (aHyperlink.GetProtocol() != INetProtocol::NotValid
+                        && INetURLObject(sRunText) == aHyperlink)
+                    {
+                        OUString sIssueText = 
SwResId(STR_HYPERLINK_TEXT_IS_LINK)
+                                                  .replaceFirst("%LINK%", 
sHyperlink);
+                        pIssue = lclAddIssue(m_rIssueCollection, sIssueText,
+                                             
sfx::AccessibilityIssueID::HYPERLINK_IS_TEXT);
+                    }
+                    else if (sRunText.getLength() <= 5)
+                    {
+                        pIssue
+                            = lclAddIssue(m_rIssueCollection, 
SwResId(STR_HYPERLINK_TEXT_IS_SHORT),
+                                          
sfx::AccessibilityIssueID::HYPERLINK_SHORT);
+                    }
+
+                    if (pIssue)
+                    {
+                        pIssue->setIssueObject(IssueObject::TEXT);
+                        pIssue->setNode(pTextNode);
+                        SwDoc& rDocument = pTextNode->GetDoc();
+                        pIssue->setDoc(rDocument);
+                        pIssue->setStart(nStart);
+                        pIssue->setEnd(nStart + sRunText.getLength());
+                    }
+                }
             }
         }
     }
@@ -422,21 +428,9 @@ public:
             return;
 
         SwTextNode* pTextNode = pCurrent->GetTextNode();
-        rtl::Reference<SwXParagraph> xParagraph
-            = SwXParagraph::CreateXParagraph(pTextNode->GetDoc(), pTextNode, 
nullptr);
-        if (!xParagraph.is())
-            return;
-
-        uno::Reference<container::XEnumeration> xRunEnum = 
xParagraph->createEnumeration();
-        sal_Int32 nStart = 0;
-        while (xRunEnum->hasMoreElements())
+        if (pTextNode->HasHints())
         {
-            uno::Reference<text::XTextRange> xRun(xRunEnum->nextElement(), 
uno::UNO_QUERY);
-            if (xRun.is())
-            {
-                checkTextRange(xRun, pTextNode, nStart);
-                nStart += xRun->getString().getLength();
-            }
+            checkHyperLinks(pTextNode);
         }
     }
 };

Reply via email to