[Libreoffice-commits] core.git: sw/source
Tomaž Vajngerl (via logerrit)
logerrit at kemper.freedesktop.org
Thu Dec 26 20:53:16 UTC 2019
sw/source/core/access/AccessibilityCheck.cxx | 166 +++++++++++++++++----------
sw/source/core/inc/AccessibilityCheck.hxx | 4
2 files changed, 110 insertions(+), 60 deletions(-)
New commits:
commit 87f7414c071d80b627ffca6d0602f9b4e21448b4
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Sun Dec 8 20:59:43 2019 +0100
Commit: Tomaž Vajngerl <quikee at gmail.com>
CommitDate: Thu Dec 26 21:52:38 2019 +0100
acc. check: Introduce NodeCheck for accessibility checks on nodes
NodeCheck responsibility is to check a node for accessibility
issues. For each node there are multiple node checks executed and
currently there are 2 node check implementations:
- NoTextNodeAltTextCheck
- TableNodeMergeSplitCheck
These 2 checks are converted from the current checks in the code.
Change-Id: Idde7092536f094d936aa3d353f4512949ca36a60
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/85839
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 165b3da43483..c75122de54bb 100644
--- a/sw/source/core/access/AccessibilityCheck.cxx
+++ b/sw/source/core/access/AccessibilityCheck.cxx
@@ -24,71 +24,126 @@ namespace
// TODO move these to string file and look for a better name.
OUString sNoAlt("No alt text for graphic '%OBJECT_NAME%'");
OUString sTableMergeSplit("Table '%OBJECT_NAME%' contains merges or splits");
-}
-void AccessibilityCheck::checkTableNode(SwTableNode* pTableNode)
+class NodeCheck
{
- if (!pTableNode)
- return;
+protected:
+ std::vector<svx::AccessibilityIssue>& m_rAccessibilityIssueCollection;
- SwTable const& rTable = pTableNode->GetTable();
- if (rTable.IsTableComplex())
+public:
+ NodeCheck(std::vector<svx::AccessibilityIssue>& rAccessibilityIssueCollection)
+ : m_rAccessibilityIssueCollection(rAccessibilityIssueCollection)
{
- OUString sName = rTable.GetTableStyleName();
- svx::AccessibilityIssue aIssue;
- aIssue.m_aIssueText = sTableMergeSplit.replaceAll("%OBJECT_NAME%", sName);
- m_aAccessibilityIssueCollection.push_back(aIssue);
}
- else
+ virtual ~NodeCheck() {}
+ virtual void check(SwNode* pCurrent) = 0;
+};
+
+// Check NoTextNodes: Graphic, OLE for alt (title) text
+class NoTextNodeAltTextCheck : public NodeCheck
+{
+ void checkNoTextNode(SwNoTextNode* pNoTextNode)
{
- if (rTable.GetTabLines().size() > 1)
+ if (!pNoTextNode)
+ return;
+
+ OUString sAlternative = pNoTextNode->GetTitle();
+ if (sAlternative.isEmpty())
{
- int i = 0;
- size_t nFirstLineSize = 0;
- bool bAllColumnsSameSize = true;
+ OUString sName = pNoTextNode->GetFlyFormat()->GetName();
+ svx::AccessibilityIssue aIssue;
+ aIssue.m_aIssueText = sNoAlt.replaceAll("%OBJECT_NAME%", sName);
+ m_rAccessibilityIssueCollection.push_back(aIssue);
+ }
+ }
- for (SwTableLine const* pTableLine : rTable.GetTabLines())
+public:
+ NoTextNodeAltTextCheck(std::vector<svx::AccessibilityIssue>& rAccessibilityIssueCollection)
+ : NodeCheck(rAccessibilityIssueCollection)
+ {
+ }
+
+ void check(SwNode* pCurrent) override
+ {
+ if (pCurrent->GetNodeType() & SwNodeType::NoTextMask)
+ {
+ SwNoTextNode* pNoTextNode = pCurrent->GetNoTextNode();
+ if (pNoTextNode)
+ checkNoTextNode(pNoTextNode);
+ }
+ }
+};
+
+// Check Table node if the table is merged and splitted.
+class TableNodeMergeSplitCheck : public NodeCheck
+{
+private:
+ void checkTableNode(SwTableNode* pTableNode)
+ {
+ if (!pTableNode)
+ return;
+
+ SwTable const& rTable = pTableNode->GetTable();
+ if (rTable.IsTableComplex())
+ {
+ OUString sName = rTable.GetTableStyleName();
+ svx::AccessibilityIssue aIssue;
+ aIssue.m_aIssueText = sTableMergeSplit.replaceAll("%OBJECT_NAME%", sName);
+ m_rAccessibilityIssueCollection.push_back(aIssue);
+ }
+ else
+ {
+ if (rTable.GetTabLines().size() > 1)
{
- if (i == 0)
- {
- nFirstLineSize = pTableLine->GetTabBoxes().size();
- }
- else
+ int i = 0;
+ size_t nFirstLineSize = 0;
+ bool bAllColumnsSameSize = true;
+
+ for (SwTableLine const* pTableLine : rTable.GetTabLines())
{
- size_t nLineSize = pTableLine->GetTabBoxes().size();
- if (nFirstLineSize != nLineSize)
+ if (i == 0)
+ {
+ nFirstLineSize = pTableLine->GetTabBoxes().size();
+ }
+ else
{
- bAllColumnsSameSize = false;
+ size_t nLineSize = pTableLine->GetTabBoxes().size();
+ if (nFirstLineSize != nLineSize)
+ {
+ bAllColumnsSameSize = false;
+ }
}
+ i++;
+ }
+ if (!bAllColumnsSameSize)
+ {
+ OUString sName = rTable.GetTableStyleName();
+ svx::AccessibilityIssue aIssue;
+ aIssue.m_aIssueText = sTableMergeSplit.replaceAll("%OBJECT_NAME%", sName);
+ m_rAccessibilityIssueCollection.push_back(aIssue);
}
- i++;
- }
- if (!bAllColumnsSameSize)
- {
- OUString sName = rTable.GetTableStyleName();
- svx::AccessibilityIssue aIssue;
- aIssue.m_aIssueText = sTableMergeSplit.replaceAll("%OBJECT_NAME%", sName);
- m_aAccessibilityIssueCollection.push_back(aIssue);
}
}
}
-}
-// Check NoTextNodes: Graphic, OLE
-void AccessibilityCheck::checkNoTextNode(SwNoTextNode* pNoTextNode)
-{
- if (!pNoTextNode)
- return;
+public:
+ TableNodeMergeSplitCheck(std::vector<svx::AccessibilityIssue>& rAccessibilityIssueCollection)
+ : NodeCheck(rAccessibilityIssueCollection)
+ {
+ }
- OUString sAlternative = pNoTextNode->GetTitle();
- if (sAlternative.isEmpty())
+ void check(SwNode* pCurrent) override
{
- OUString sName = pNoTextNode->GetFlyFormat()->GetName();
- svx::AccessibilityIssue aIssue;
- aIssue.m_aIssueText = sNoAlt.replaceAll("%OBJECT_NAME%", sName);
- m_aAccessibilityIssueCollection.push_back(aIssue);
+ if (pCurrent->GetNodeType() & SwNodeType::Table)
+ {
+ SwTableNode* pTableNode = pCurrent->GetTableNode();
+ if (pTableNode)
+ checkTableNode(pTableNode);
+ }
}
-}
+};
+
+} // end anonymous namespace
// Check Shapes, TextBox
void AccessibilityCheck::checkObject(SdrObject* pObject)
@@ -114,23 +169,22 @@ void AccessibilityCheck::check()
if (m_pDoc == nullptr)
return;
+ std::vector<std::unique_ptr<NodeCheck>> aNodeChecks;
+ aNodeChecks.push_back(
+ std::make_unique<NoTextNodeAltTextCheck>(m_aAccessibilityIssueCollection));
+ aNodeChecks.push_back(
+ std::make_unique<TableNodeMergeSplitCheck>(m_aAccessibilityIssueCollection));
+
auto const& pNodes = m_pDoc->GetNodes();
+ SwNode* pNode = nullptr;
for (sal_uLong n = 0; n < pNodes.Count(); ++n)
{
- SwNode* pNode = pNodes[n];
+ pNode = pNodes[n];
if (pNode)
{
- if (pNode->GetNodeType() & SwNodeType::NoTextMask)
- {
- SwNoTextNode* pNoTextNode = pNode->GetNoTextNode();
- if (pNoTextNode)
- checkNoTextNode(pNoTextNode);
- }
- if (pNode->GetNodeType() & SwNodeType::Table)
+ for (std::unique_ptr<NodeCheck>& rpNodeCheck : aNodeChecks)
{
- SwTableNode* pTableNode = pNode->GetTableNode();
- if (pTableNode)
- checkTableNode(pTableNode);
+ rpNodeCheck->check(pNode);
}
}
}
diff --git a/sw/source/core/inc/AccessibilityCheck.hxx b/sw/source/core/inc/AccessibilityCheck.hxx
index 513e862e7e6f..9e77ca15e125 100644
--- a/sw/source/core/inc/AccessibilityCheck.hxx
+++ b/sw/source/core/inc/AccessibilityCheck.hxx
@@ -13,7 +13,6 @@
#include <svx/AccessibilityCheck.hxx>
#include <doc.hxx>
-#include <node.hxx>
namespace sw
{
@@ -29,9 +28,6 @@ public:
}
void check() override;
-
- void checkTableNode(SwTableNode* pTableNode);
- void checkNoTextNode(SwNoTextNode* pNoTextNode);
void checkObject(SdrObject* pObject);
};
More information about the Libreoffice-commits
mailing list