diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2020-01-05 19:08:19 +0100 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2020-01-06 23:14:28 +0100 |
commit | bc62883e07d6795edfb70571f90e1b85fcfdd399 (patch) | |
tree | cfe84383bb2aa646a76adaf3aea053ed7c51e085 /sw | |
parent | b8669df1622f699357478aad7c6a4439b5d5aee3 (diff) |
acc. check: check headings are in incremental order
This adds an accessibility check for headings. Headings should
be in increemntal order. This means for example that the document
can't start with "Heading 2" without first having a "Heading 1",
or to skip a heading - for example to go from "Heading 1" and
next have "Heading 3", skipping "Heading 2".
Change-Id: I6fd3189cc659ad0756cc950b7c0b83b3ec8abf84
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/86246
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'sw')
-rw-r--r-- | sw/source/core/access/AccessibilityCheck.cxx | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/sw/source/core/access/AccessibilityCheck.cxx b/sw/source/core/access/AccessibilityCheck.cxx index 0d07cb4f0357..f33f88b57e61 100644 --- a/sw/source/core/access/AccessibilityCheck.cxx +++ b/sw/source/core/access/AccessibilityCheck.cxx @@ -45,6 +45,7 @@ OUString sTextContrast("Text contrast is too low."); OUString sTextBlinking("Blinking text."); OUString sAvoidFootnotes("Avoid footnotes."); OUString sAvoidEndnotes("Avoid endnotes."); +OUString sHeadingsOrder("Headings not in order."); std::shared_ptr<sw::AccessibilityIssue> lclAddIssue(svx::AccessibilityIssueCollection& rIssueCollection, OUString const& rText, @@ -465,6 +466,37 @@ public: } }; +class HeaderCheck : public NodeCheck +{ +private: + int nPreviousLevel; + +public: + HeaderCheck(svx::AccessibilityIssueCollection& rIssueCollection) + : NodeCheck(rIssueCollection) + , nPreviousLevel(0) + { + } + + void check(SwNode* pCurrent) override + { + if (pCurrent->IsTextNode()) + { + SwTextNode* pTextNode = pCurrent->GetTextNode(); + SwTextFormatColl* pCollection = pTextNode->GetTextColl(); + int nLevel = pCollection->GetAssignedOutlineStyleLevel(); + if (nLevel < 0) + return; + + if (nLevel > nPreviousLevel && std::abs(nLevel - nPreviousLevel) > 1) + { + lclAddIssue(m_rIssueCollection, sHeadingsOrder); + } + nPreviousLevel = nLevel; + } + } +}; + class DocumentCheck : public BaseCheck { public: @@ -606,6 +638,7 @@ void AccessibilityCheck::check() 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)); auto const& pNodes = m_pDoc->GetNodes(); SwNode* pNode = nullptr; |