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.extern@allotropia.de> Tested-by: Jenkins
This commit is contained in:
@@ -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)
|
||||
|
||||
Binary file not shown.
@@ -570,66 +570,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)
|
||||
{
|
||||
pNameIssue->setIssueObject(IssueObject::HYPERLINKTEXT);
|
||||
pNameIssue->setNode(pTextNode);
|
||||
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();
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -648,21 +649,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);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user