summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBalazs Varga <balazs.varga.extern@allotropia.de>2024-09-17 14:32:20 +0200
committerThorsten Behrens <thorsten.behrens@allotropia.de>2024-09-17 18:04:38 +0200
commitb7a49b42d612e2bd65c38f5a3da4c67f7ceca20e (patch)
tree4f9ab633788abd3b9a5b66fed8ad849b97a50615
parent85d7d20444b0eee9a542846f06eff8813811e3a6 (diff)
tdf#162988 - A11Y sidebar: fix hyperlinks false warningcib_contract49c-24.2.6.2.M2
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 <thorsten.behrens@allotropia.de> Tested-by: allotropia jenkins <jenkins@allotropia.de>
-rw-r--r--sw/qa/core/accessibilitycheck/data/HyperlinkTest.odtbin8663 -> 11092 bytes
-rw-r--r--sw/source/core/access/AccessibilityCheck.cxx86
2 files changed, 40 insertions, 46 deletions
diff --git a/sw/qa/core/accessibilitycheck/data/HyperlinkTest.odt b/sw/qa/core/accessibilitycheck/data/HyperlinkTest.odt
index 1eba1932ce21..92240fb1d67f 100644
--- a/sw/qa/core/accessibilitycheck/data/HyperlinkTest.odt
+++ b/sw/qa/core/accessibilitycheck/data/HyperlinkTest.odt
Binary files 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);
}
}
};