sw/qa/core/accessibilitycheck/AccessibilityCheckTest.cxx |    3 
 sw/qa/core/accessibilitycheck/data/HyperlinkTest.odt     |binary
 sw/source/core/access/AccessibilityCheck.cxx             |  123 ++++++---------
 3 files changed, 58 insertions(+), 68 deletions(-)

New commits:
commit 61ac2cfa14aa3dd225687b43f429647b8fbb2d97
Author:     Balazs Varga <balazs.varga.ext...@allotropia.de>
AuthorDate: Tue Sep 17 14:32:20 2024 +0200
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Thu Sep 19 07:25:54 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/+/173560
    Reviewed-by: Balazs Varga <balazs.varga.ext...@allotropia.de>
    Tested-by: Jenkins
    (cherry picked from commit 5b6f384f940d40b8d40675306e103cfdd29bf700)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/173500
    Reviewed-by: Michael Stahl <michael.st...@allotropia.de>

diff --git a/sw/qa/core/accessibilitycheck/AccessibilityCheckTest.cxx 
b/sw/qa/core/accessibilitycheck/AccessibilityCheckTest.cxx
index 044ecf8312bf..d15eeaf70da9 100644
--- a/sw/qa/core/accessibilitycheck/AccessibilityCheckTest.cxx
+++ b/sw/qa/core/accessibilitycheck/AccessibilityCheckTest.cxx
@@ -133,11 +133,12 @@ CPPUNIT_TEST_FIXTURE(AccessibilityCheckTest, 
testHyperlinks)
     sw::AccessibilityCheck aCheck(pDoc);
     aCheck.check();
     auto& aIssues = aCheck.getIssueCollection().getIssues();
-    CPPUNIT_ASSERT_EQUAL(size_t(4), aIssues.size());
+    CPPUNIT_ASSERT_EQUAL(size_t(5), aIssues.size());
     CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::HYPERLINK_SHORT, 
aIssues[0]->m_eIssueID);
     CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::HYPERLINK_NO_NAME, 
aIssues[1]->m_eIssueID);
     CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::HYPERLINK_IS_TEXT, 
aIssues[2]->m_eIssueID);
     CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::HYPERLINK_NO_NAME, 
aIssues[3]->m_eIssueID);
+    CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::DIRECT_FORMATTING, 
aIssues[4]->m_eIssueID);
 }
 
 CPPUNIT_TEST_FIXTURE(AccessibilityCheckTest, testCheckHighlightedText)
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 3f2b8906ba83..ff7a6b1b2d3c 100644
--- a/sw/source/core/access/AccessibilityCheck.cxx
+++ b/sw/source/core/access/AccessibilityCheck.cxx
@@ -371,66 +371,67 @@ 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(u"HyperLinkURL"_ustr))
-            return;
-
-        OUString sHyperlink;
-        xProperties->getPropertyValue(u"HyperLinkURL"_ustr) >>= 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);
-            }
-
-            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)
-            {
-                // Check if the Hyperlink have Name settled.
-                if 
(!xProperties->getPropertySetInfo()->hasPropertyByName(u"HyperLinkName"_ustr))
-                    return;
-
-                OUString sHyperlinkName;
-                xProperties->getPropertyValue(u"HyperLinkName"_ustr) >>= 
sHyperlinkName;
-                if (sHyperlinkName.isEmpty())
+                OUString sHyperlink = pTextAttr->GetINetFormat().GetValue();
+                if (!sHyperlink.isEmpty())
                 {
-                    std::shared_ptr<sw::AccessibilityIssue> pNameIssue
-                        = lclAddIssue(m_rIssueCollection, 
SwResId(STR_HYPERLINK_NO_NAME),
-                                      
sfx::AccessibilityIssueID::HYPERLINK_NO_NAME);
+                    INetURLObject aHyperlink(sHyperlink);
+                    std::shared_ptr<sw::AccessibilityIssue> pIssue;
+                    sal_Int32 nStart = pTextAttr->GetStart();
+                    OUString sRunText = sParagraphText.copy(nStart, 
*pTextAttr->GetEnd() - nStart);
 
-                    if (pNameIssue)
+                    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)
                     {
-                        pNameIssue->setIssueObject(IssueObject::HYPERLINKTEXT);
-                        pNameIssue->setNode(pTextNode);
+                        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();
-                        pNameIssue->setDoc(rDocument);
-                        pNameIssue->setStart(nStart);
-                        pNameIssue->setEnd(nStart + sText.getLength());
+                        pIssue->setDoc(rDocument);
+                        pIssue->setStart(nStart);
+                        pIssue->setEnd(nStart + sRunText.getLength());
+                    }
+
+                    if (aHyperlink.GetProtocol() != INetProtocol::NotValid)
+                    {
+                        OUString sHyperlinkName = 
pTextAttr->GetINetFormat().GetName();
+                        if (sHyperlinkName.isEmpty())
+                        {
+                            std::shared_ptr<sw::AccessibilityIssue> pNameIssue
+                                = lclAddIssue(m_rIssueCollection, 
SwResId(STR_HYPERLINK_NO_NAME),
+                                              
sfx::AccessibilityIssueID::HYPERLINK_NO_NAME);
+
+                            if (pNameIssue)
+                            {
+                                
pNameIssue->setIssueObject(IssueObject::HYPERLINKTEXT);
+                                pNameIssue->setNode(pTextNode);
+                                SwDoc& rDocument = pTextNode->GetDoc();
+                                pNameIssue->setDoc(rDocument);
+                                pNameIssue->setStart(nStart);
+                                pNameIssue->setEnd(nStart + 
sRunText.getLength());
+                            }
+                        }
                     }
                 }
             }
@@ -449,21 +450,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