summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2022-10-20 22:23:06 +0200
committerTomaž Vajngerl <quikee@gmail.com>2022-11-14 04:15:37 +0100
commit6e66b5d75b4cda0314b64f4d12ef9e4350751470 (patch)
treef8def0d3e1925c8208061496776f98c09d82a7ea /sw
parent517d05dbfd1e25e51d4b813f5a4c53b89464aa43 (diff)
sw: refactor to make a11y check for nodes independent
Add checkNodes, which will only check the current node for a11y issues. This prepares for online a11y check. Change-Id: I069cd200ceb58223b05baaafb7d796148e28398b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141603 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'sw')
-rw-r--r--sw/source/core/access/AccessibilityCheck.cxx97
-rw-r--r--sw/source/core/inc/AccessibilityCheck.hxx28
2 files changed, 80 insertions, 45 deletions
diff --git a/sw/source/core/access/AccessibilityCheck.cxx b/sw/source/core/access/AccessibilityCheck.cxx
index 897ee0d43c58..802dda2b95cd 100644
--- a/sw/source/core/access/AccessibilityCheck.cxx
+++ b/sw/source/core/access/AccessibilityCheck.cxx
@@ -77,19 +77,6 @@ lclAddIssue(sfx::AccessibilityIssueCollection& rIssueCollection, OUString const&
return pIssue;
}
-class BaseCheck
-{
-protected:
- sfx::AccessibilityIssueCollection& m_rIssueCollection;
-
-public:
- BaseCheck(sfx::AccessibilityIssueCollection& rIssueCollection)
- : m_rIssueCollection(rIssueCollection)
- {
- }
- virtual ~BaseCheck() {}
-};
-
class NodeCheck : public BaseCheck
{
public:
@@ -1377,41 +1364,67 @@ void AccessibilityCheck::checkObject(SdrObject* pObject)
}
}
+void AccessibilityCheck::init()
+{
+ if (m_aDocumentChecks.empty())
+ {
+ m_aDocumentChecks.emplace_back(new DocumentDefaultLanguageCheck(m_aIssueCollection));
+ m_aDocumentChecks.emplace_back(new DocumentTitleCheck(m_aIssueCollection));
+ m_aDocumentChecks.emplace_back(new FootnoteEndnoteCheck(m_aIssueCollection));
+ m_aDocumentChecks.emplace_back(new BackgroundImageCheck(m_aIssueCollection));
+ }
+
+ if (m_aNodeChecks.empty())
+ {
+ m_aNodeChecks.emplace_back(new NoTextNodeAltTextCheck(m_aIssueCollection));
+ m_aNodeChecks.emplace_back(new TableNodeMergeSplitCheck(m_aIssueCollection));
+ m_aNodeChecks.emplace_back(new TableFormattingCheck(m_aIssueCollection));
+ m_aNodeChecks.emplace_back(new NumberingCheck(m_aIssueCollection));
+ m_aNodeChecks.emplace_back(new HyperlinkCheck(m_aIssueCollection));
+ m_aNodeChecks.emplace_back(new TextContrastCheck(m_aIssueCollection));
+ m_aNodeChecks.emplace_back(new BlinkingTextCheck(m_aIssueCollection));
+ m_aNodeChecks.emplace_back(new HeaderCheck(m_aIssueCollection));
+ m_aNodeChecks.emplace_back(new TextFormattingCheck(m_aIssueCollection));
+ m_aNodeChecks.emplace_back(new NonInteractiveFormCheck(m_aIssueCollection));
+ m_aNodeChecks.emplace_back(new FloatingTextCheck(m_aIssueCollection));
+ m_aNodeChecks.emplace_back(new TableHeadingCheck(m_aIssueCollection));
+ m_aNodeChecks.emplace_back(new HeadingOrderCheck(m_aIssueCollection));
+ m_aNodeChecks.emplace_back(new NewlineSpacingCheck(m_aIssueCollection));
+ m_aNodeChecks.emplace_back(new SpaceSpacingCheck(m_aIssueCollection));
+ m_aNodeChecks.emplace_back(new FakeFootnoteCheck(m_aIssueCollection));
+ m_aNodeChecks.emplace_back(new FakeCaptionCheck(m_aIssueCollection));
+ }
+}
+
+void AccessibilityCheck::checkNode(SwNode* pNode)
+{
+ if (m_pDoc == nullptr || pNode == nullptr)
+ return;
+
+ init();
+
+ for (std::shared_ptr<BaseCheck>& rpNodeCheck : m_aNodeChecks)
+ {
+ auto pNodeCheck = dynamic_cast<NodeCheck*>(rpNodeCheck.get());
+ if (pNodeCheck)
+ pNodeCheck->check(pNode);
+ }
+}
+
void AccessibilityCheck::check()
{
if (m_pDoc == nullptr)
return;
- std::vector<std::unique_ptr<DocumentCheck>> aDocumentChecks;
- aDocumentChecks.push_back(std::make_unique<DocumentDefaultLanguageCheck>(m_aIssueCollection));
- aDocumentChecks.push_back(std::make_unique<DocumentTitleCheck>(m_aIssueCollection));
- aDocumentChecks.push_back(std::make_unique<FootnoteEndnoteCheck>(m_aIssueCollection));
- aDocumentChecks.push_back(std::make_unique<BackgroundImageCheck>(m_aIssueCollection));
+ init();
- for (std::unique_ptr<DocumentCheck>& rpDocumentCheck : aDocumentChecks)
+ for (std::shared_ptr<BaseCheck>& rpDocumentCheck : m_aDocumentChecks)
{
- rpDocumentCheck->check(m_pDoc);
+ auto pDocumentCheck = dynamic_cast<DocumentCheck*>(rpDocumentCheck.get());
+ if (pDocumentCheck)
+ pDocumentCheck->check(m_pDoc);
}
- std::vector<std::unique_ptr<NodeCheck>> aNodeChecks;
- aNodeChecks.push_back(std::make_unique<NoTextNodeAltTextCheck>(m_aIssueCollection));
- aNodeChecks.push_back(std::make_unique<TableNodeMergeSplitCheck>(m_aIssueCollection));
- aNodeChecks.push_back(std::make_unique<TableFormattingCheck>(m_aIssueCollection));
- aNodeChecks.push_back(std::make_unique<NumberingCheck>(m_aIssueCollection));
- aNodeChecks.push_back(std::make_unique<HyperlinkCheck>(m_aIssueCollection));
- aNodeChecks.push_back(std::make_unique<TextContrastCheck>(m_aIssueCollection));
- aNodeChecks.push_back(std::make_unique<BlinkingTextCheck>(m_aIssueCollection));
- aNodeChecks.push_back(std::make_unique<HeaderCheck>(m_aIssueCollection));
- aNodeChecks.push_back(std::make_unique<TextFormattingCheck>(m_aIssueCollection));
- aNodeChecks.push_back(std::make_unique<NonInteractiveFormCheck>(m_aIssueCollection));
- aNodeChecks.push_back(std::make_unique<FloatingTextCheck>(m_aIssueCollection));
- aNodeChecks.push_back(std::make_unique<TableHeadingCheck>(m_aIssueCollection));
- aNodeChecks.push_back(std::make_unique<HeadingOrderCheck>(m_aIssueCollection));
- aNodeChecks.push_back(std::make_unique<NewlineSpacingCheck>(m_aIssueCollection));
- aNodeChecks.push_back(std::make_unique<SpaceSpacingCheck>(m_aIssueCollection));
- aNodeChecks.push_back(std::make_unique<FakeFootnoteCheck>(m_aIssueCollection));
- aNodeChecks.push_back(std::make_unique<FakeCaptionCheck>(m_aIssueCollection));
-
auto const& pNodes = m_pDoc->GetNodes();
SwNode* pNode = nullptr;
for (SwNodeOffset n(0); n < pNodes.Count(); ++n)
@@ -1419,9 +1432,11 @@ void AccessibilityCheck::check()
pNode = pNodes[n];
if (pNode)
{
- for (std::unique_ptr<NodeCheck>& rpNodeCheck : aNodeChecks)
+ for (std::shared_ptr<BaseCheck>& rpNodeCheck : m_aNodeChecks)
{
- rpNodeCheck->check(pNode);
+ auto pNodeCheck = dynamic_cast<NodeCheck*>(rpNodeCheck.get());
+ if (pNodeCheck)
+ pNodeCheck->check(pNode);
}
}
}
diff --git a/sw/source/core/inc/AccessibilityCheck.hxx b/sw/source/core/inc/AccessibilityCheck.hxx
index 4bcc56000bc4..1ff4cf5b16f7 100644
--- a/sw/source/core/inc/AccessibilityCheck.hxx
+++ b/sw/source/core/inc/AccessibilityCheck.hxx
@@ -8,19 +8,40 @@
*
*/
-#ifndef INCLUDED_SW_SOURCE_CORE_ACCESSIBILITYCHECK_HXX
-#define INCLUDED_SW_SOURCE_CORE_ACCESSIBILITYCHECK_HXX
+#pragma once
#include <sfx2/AccessibilityCheck.hxx>
#include <doc.hxx>
+#include <node.hxx>
namespace sw
{
+/** Base class for accessibility checks */
+class BaseCheck
+{
+protected:
+ sfx::AccessibilityIssueCollection& m_rIssueCollection;
+
+public:
+ BaseCheck(sfx::AccessibilityIssueCollection& rIssueCollection)
+ : m_rIssueCollection(rIssueCollection)
+ {
+ }
+ virtual ~BaseCheck() {}
+};
+
class SW_DLLPUBLIC AccessibilityCheck final : public sfx::AccessibilityCheck
{
private:
SwDoc* m_pDoc;
+ std::vector<std::shared_ptr<BaseCheck>> m_aDocumentChecks;
+ std::vector<std::shared_ptr<BaseCheck>> m_aNodeChecks;
+
+ AccessibilityCheck() = delete;
+
+ void init();
+
public:
AccessibilityCheck(SwDoc* pDoc)
: m_pDoc(pDoc)
@@ -29,10 +50,9 @@ public:
void check() override;
void checkObject(SdrObject* pObject);
+ void checkNode(SwNode* pNode);
};
} // end sw namespace
-#endif
-
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */