diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2022-10-24 22:19:06 +0200 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2022-11-17 05:47:03 +0100 |
commit | ca03ea5c1ce7f1fa0702c004068a2592a723e669 (patch) | |
tree | 5f38078787af9d499062e41e475c75ca52fa2a09 /sw/source/core | |
parent | a81e957f5026373f3935390c786c21416fc74fcc (diff) |
sw: track content node with a11y issues, so the number is correct
Track all content node with a11y issues and handle when they are
deleted (with WeakContentNodeContainer). At update, recount the
number of a11y issues that are contained in the content nodes and
update the overall number.
Change-Id: I254c62aba0d73a365f011b1609bcddec4dd71615
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141785
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'sw/source/core')
-rw-r--r-- | sw/source/core/txtnode/OnlineAccessibilityCheck.cxx | 89 |
1 files changed, 70 insertions, 19 deletions
diff --git a/sw/source/core/txtnode/OnlineAccessibilityCheck.cxx b/sw/source/core/txtnode/OnlineAccessibilityCheck.cxx index e34738466d99..a2a9783c3fd1 100644 --- a/sw/source/core/txtnode/OnlineAccessibilityCheck.cxx +++ b/sw/source/core/txtnode/OnlineAccessibilityCheck.cxx @@ -29,6 +29,32 @@ namespace sw { +WeakContentNodeContainer::WeakContentNodeContainer(SwContentNode* pNode) + : m_pNode(pNode) +{ + if (m_pNode) + { + EndListeningAll(); + StartListening(m_pNode->GetNotifier()); + } +} + +WeakContentNodeContainer::~WeakContentNodeContainer() { EndListeningAll(); } + +bool WeakContentNodeContainer::isAlive() +{ + if (!HasBroadcaster()) + m_pNode = nullptr; + return m_pNode; +} + +SwContentNode* WeakContentNodeContainer::getNode() +{ + if (isAlive()) + return m_pNode; + return nullptr; +} + OnlineAccessibilityCheck::OnlineAccessibilityCheck(SwDoc& rDocument) : m_rDocument(rDocument) , m_aAccessibilityCheck(&m_rDocument) @@ -38,6 +64,48 @@ OnlineAccessibilityCheck::OnlineAccessibilityCheck(SwDoc& rDocument) { } +void OnlineAccessibilityCheck::updateNodeStatus(SwContentNode* pContentNode) +{ + m_nAccessibilityIssues = 0; + + auto it = m_aNodes.find(pContentNode); + if (it == m_aNodes.end()) + { + m_aNodes.emplace(pContentNode, std::make_unique<WeakContentNodeContainer>(pContentNode)); + } + + for (auto iterator = m_aNodes.begin(); iterator != m_aNodes.end();) + { + auto& pWeakContentNode = iterator->second; + if (pWeakContentNode->isAlive()) + { + auto& rStatus = pWeakContentNode->getNode()->getAccessibilityCheckStatus(); + if (rStatus.pCollection) + { + m_nAccessibilityIssues += rStatus.pCollection->getIssues().size(); + ++iterator; + } + else + { + iterator = m_aNodes.erase(iterator); + } + } + else + { + iterator = m_aNodes.erase(iterator); + } + } +} + +void OnlineAccessibilityCheck::updateStatusbar() +{ + SfxBindings* pBindings = m_rDocument.GetDocShell() && m_rDocument.GetDocShell()->GetDispatcher() + ? m_rDocument.GetDocShell()->GetDispatcher()->GetBindings() + : nullptr; + if (pBindings) + pBindings->Invalidate(FN_STAT_ACCESSIBILITY_CHECK); +} + void OnlineAccessibilityCheck::runCheck(SwContentNode* pContentNode) { m_aAccessibilityCheck.getIssueCollection().clear(); @@ -56,25 +124,8 @@ void OnlineAccessibilityCheck::runCheck(SwContentNode* pContentNode) pContentNode->getAccessibilityCheckStatus().pCollection = std::make_unique<sfx::AccessibilityIssueCollection>(aCollection); - m_nAccessibilityIssues = 0; - auto const& pNodes = m_rDocument.GetNodes(); - for (SwNodeOffset n(0); n < pNodes.Count(); ++n) - { - SwNode* pCurrent = pNodes[n]; - if (pCurrent && pCurrent->IsTextNode()) - { - auto* pCurrentTextNode = pCurrent->GetTextNode(); - auto& rStatus = pCurrentTextNode->getAccessibilityCheckStatus(); - if (rStatus.pCollection) - m_nAccessibilityIssues += rStatus.pCollection->getIssues().size(); - } - } - - SfxBindings* pBindings = m_rDocument.GetDocShell() && m_rDocument.GetDocShell()->GetDispatcher() - ? m_rDocument.GetDocShell()->GetDispatcher()->GetBindings() - : nullptr; - if (pBindings) - pBindings->Invalidate(FN_STAT_ACCESSIBILITY_CHECK); + updateNodeStatus(pContentNode); + updateStatusbar(); } void OnlineAccessibilityCheck::update(const SwPosition& rNewPos) |