[Libreoffice-commits] core.git: sw/source
Tomaž Vajngerl (via logerrit)
logerrit at kemper.freedesktop.org
Fri Dec 27 08:10:03 UTC 2019
sw/source/core/access/AccessibilityCheck.cxx | 60 +++++++++++++++++++++++++++
1 file changed, 60 insertions(+)
New commits:
commit 30794f8d24824f4a540d8eb384f29c43a3f06b1a
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Sun Dec 15 10:12:01 2019 +0100
Commit: Tomaž Vajngerl <quikee at gmail.com>
CommitDate: Fri Dec 27 09:09:28 2019 +0100
acc. check: check hyperlink text doesn't contain the link
The hyperlink text shouldn't be the URL too - for example the
text shouldn't be "http://www.example.com"
Change-Id: I69f7a742705aaa25da1a832ab05922d138b8ea0f
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/85853
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>
diff --git a/sw/source/core/access/AccessibilityCheck.cxx b/sw/source/core/access/AccessibilityCheck.cxx
index 24f11fd0ffa3..400e4edd5087 100644
--- a/sw/source/core/access/AccessibilityCheck.cxx
+++ b/sw/source/core/access/AccessibilityCheck.cxx
@@ -16,6 +16,9 @@
#include <drawdoc.hxx>
#include <svx/svdpage.hxx>
#include <swtable.hxx>
+#include <com/sun/star/text/XTextContent.hpp>
+#include <unoparagraph.hxx>
+#include <tools/urlobj.hxx>
namespace sw
{
@@ -25,6 +28,7 @@ namespace
OUString sNoAlt("No alt text for graphic '%OBJECT_NAME%'");
OUString sTableMergeSplit("Table '%OBJECT_NAME%' contains merges or splits");
OUString sFakeNumbering("Fake numbering '%NUMBERING%'");
+OUString sHyperlinkTextIsLink("Hyperlink text is the same as the link address '%LINK%'");
class NodeCheck
{
@@ -184,6 +188,61 @@ public:
}
};
+class HyperlinkCheck : public NodeCheck
+{
+private:
+ void checkTextRange(uno::Reference<text::XTextRange> const& xTextRange)
+ {
+ uno::Reference<beans::XPropertySet> xProperties(xTextRange, uno::UNO_QUERY);
+ if (xProperties->getPropertySetInfo()->hasPropertyByName("HyperLinkURL"))
+ {
+ OUString sHyperlink;
+ xProperties->getPropertyValue("HyperLinkURL") >>= sHyperlink;
+ if (!sHyperlink.isEmpty())
+ {
+ OUString sText = xTextRange->getString();
+ if (INetURLObject(sText) == INetURLObject(sHyperlink))
+ {
+ svx::AccessibilityIssue aIssue;
+ aIssue.m_aIssueText = sHyperlinkTextIsLink.replaceFirst("%LINK%", sHyperlink);
+ m_rIssueCollection.push_back(aIssue);
+ }
+ }
+ }
+ }
+
+public:
+ HyperlinkCheck(std::vector<svx::AccessibilityIssue>& rIssueCollection)
+ : NodeCheck(rIssueCollection)
+ {
+ }
+
+ void check(SwNode* pCurrent) override
+ {
+ if (pCurrent->IsTextNode())
+ {
+ SwTextNode* pTextNode = pCurrent->GetTextNode();
+ uno::Reference<text::XTextContent> xParagraph
+ = SwXParagraph::CreateXParagraph(*pTextNode->GetDoc(), pTextNode);
+ if (xParagraph.is())
+ {
+ uno::Reference<container::XEnumerationAccess> xRunEnumAccess(xParagraph,
+ uno::UNO_QUERY);
+ uno::Reference<container::XEnumeration> xRunEnum
+ = xRunEnumAccess->createEnumeration();
+ while (xRunEnum->hasMoreElements())
+ {
+ uno::Reference<text::XTextRange> xRun(xRunEnum->nextElement(), uno::UNO_QUERY);
+ if (xRun.is())
+ {
+ checkTextRange(xRun);
+ }
+ }
+ }
+ }
+ }
+};
+
} // end anonymous namespace
// Check Shapes, TextBox
@@ -214,6 +273,7 @@ void AccessibilityCheck::check()
aNodeChecks.push_back(std::make_unique<NoTextNodeAltTextCheck>(m_aIssueCollection));
aNodeChecks.push_back(std::make_unique<TableNodeMergeSplitCheck>(m_aIssueCollection));
aNodeChecks.push_back(std::make_unique<NumberingCheck>(m_aIssueCollection));
+ aNodeChecks.push_back(std::make_unique<HyperlinkCheck>(m_aIssueCollection));
auto const& pNodes = m_pDoc->GetNodes();
SwNode* pNode = nullptr;
More information about the Libreoffice-commits
mailing list