sw/inc/OnlineAccessibilityCheck.hxx | 22 +++-- sw/inc/node.hxx | 38 ++++----- sw/source/core/txtnode/OnlineAccessibilityCheck.cxx | 80 ++++++++++++++------ 3 files changed, 87 insertions(+), 53 deletions(-)
New commits: commit 0ba2610a19b032dfad7e1d7fda8350ed95832956 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Mon Oct 24 23:42:44 2022 +0200 Commit: Tomaž Vajngerl <qui...@gmail.com> CommitDate: Wed Dec 21 07:11:06 2022 +0000 sw: Change online a11y checker again from SwContentNode to SwNode This is needed because SwTableNode is not a content node, so we need to work with the most generic SwNode and ask if the node derives from sw::BroadcastingModify, which is required for node tracking (SwTableNode and SwContentNode support that). Change-Id: Idc28a5a9f1f8a250e2a28bb955ed320d02b6c1b9 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141787 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <qui...@gmail.com> (cherry picked from commit 1dfb746b8ca5d5d4ef21feb67d3921ab342d782f) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/144473 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> diff --git a/sw/inc/OnlineAccessibilityCheck.hxx b/sw/inc/OnlineAccessibilityCheck.hxx index 47e42a27de29..7a37f05cc432 100644 --- a/sw/inc/OnlineAccessibilityCheck.hxx +++ b/sw/inc/OnlineAccessibilityCheck.hxx @@ -22,40 +22,40 @@ class SwTextNode; namespace sw { -/// Contains the content node and tracks if the node -/// gets deleted. +/// Contains the node and tracks if the node gets deleted. +/// Note: the node needs to extend sw::BroadcastingModify. class WeakContentNodeContainer : public SvtListener { private: - SwContentNode* m_pNode; + SwNode* m_pNode; public: - WeakContentNodeContainer(SwContentNode* pNode); + WeakContentNodeContainer(SwNode* pNode); ~WeakContentNodeContainer(); /// Is the node still alive or it was deleted? bool isAlive(); - /// Returns the pointer of the content node or nullptr if the node + /// Returns the pointer of the node or nullptr if the node /// got deleted. - SwContentNode* getNode(); + SwNode* getNode(); }; class OnlineAccessibilityCheck : public SvtListener { private: - std::map<SwContentNode*, std::unique_ptr<WeakContentNodeContainer>> m_aNodes; + std::map<SwNode*, std::unique_ptr<WeakContentNodeContainer>> m_aNodes; SwDoc& m_rDocument; sw::AccessibilityCheck m_aAccessibilityCheck; - SwContentNode* m_pPreviousNode; + SwNode* m_pPreviousNode; SwNodeOffset m_nPreviousNodeIndex; sal_Int32 m_nAccessibilityIssues; bool m_bInitialCheck; - void runAccessibilityCheck(SwContentNode* pNode); + void runAccessibilityCheck(SwNode* pNode); void updateStatusbar(); - void updateNodeStatus(SwContentNode* pContentNode); + void updateNodeStatus(SwNode* pContentNode); void initialCheck(); public: diff --git a/sw/inc/node.hxx b/sw/inc/node.hxx index eae16fe70550..ef423ba3678b 100644 --- a/sw/inc/node.hxx +++ b/sw/inc/node.hxx @@ -79,6 +79,18 @@ namespace drawinglayer::attribute { typedef std::shared_ptr< SdrAllFillAttributesHelper > SdrAllFillAttributesHelperPtr; } +// Accessibiity check + +namespace sw +{ +struct AccessibilityCheckStatus +{ + std::unique_ptr<sfx::AccessibilityIssueCollection> pCollection; + bool bDirty = true; +}; + +} + /// Base class of the Writer document model elements. class SW_DLLPUBLIC SwNode : public sw::BorderCacheOwner, private BigPtrEntry @@ -91,6 +103,8 @@ class SW_DLLPUBLIC SwNode sal_uInt8 m_nAFormatNumLvl : 3; bool m_bIgnoreDontExpand : 1; ///< for Text Attributes - ignore the flag + mutable sw::AccessibilityCheckStatus m_aAccessibilityCheckStatus; + public: /// sw_redlinehide: redline node merge state enum class Merge { None, First, NonFirst, Hidden }; @@ -306,6 +320,11 @@ public: */ virtual void dumpAsXml(xmlTextWriterPtr pWriter) const; + sw::AccessibilityCheckStatus& getAccessibilityCheckStatus() + { + return m_aAccessibilityCheckStatus; + } + private: SwNode( const SwNode & rNodes ) = delete; SwNode & operator= ( const SwNode & rNodes ) = delete; @@ -357,18 +376,6 @@ class SwEndNode final : public SwNode SwEndNode & operator= ( const SwEndNode & rNode ) = delete; }; -// Accessibiity check - -namespace sw -{ -struct AccessibilityCheckStatus -{ - std::unique_ptr<sfx::AccessibilityIssueCollection> pCollection; - bool bDirty = true; -}; - -} - // SwContentNode class SW_DLLPUBLIC SwContentNode: public sw::BroadcastingModify, public SwNode, public SwIndexReg @@ -378,8 +385,6 @@ class SW_DLLPUBLIC SwContentNode: public sw::BroadcastingModify, public SwNode, SwFormatColl* m_pCondColl; mutable bool mbSetModifyAtAttr; - mutable sw::AccessibilityCheckStatus m_aAccessibilityCheckStatus; - protected: SwContentNode( const SwNodeIndex &rWhere, const SwNodeType nNodeType, SwFormatColl *pFormatColl ); @@ -496,11 +501,6 @@ public: void UpdateAttr(const SwUpdateAttr&); - sw::AccessibilityCheckStatus& getAccessibilityCheckStatus() - { - return m_aAccessibilityCheckStatus; - } - private: SwContentNode( const SwContentNode & rNode ) = delete; SwContentNode & operator= ( const SwContentNode & rNode ) = delete; diff --git a/sw/source/core/txtnode/OnlineAccessibilityCheck.cxx b/sw/source/core/txtnode/OnlineAccessibilityCheck.cxx index 7fb93c070f0f..464cc55d2803 100644 --- a/sw/source/core/txtnode/OnlineAccessibilityCheck.cxx +++ b/sw/source/core/txtnode/OnlineAccessibilityCheck.cxx @@ -29,13 +29,17 @@ namespace sw { -WeakContentNodeContainer::WeakContentNodeContainer(SwContentNode* pNode) +WeakContentNodeContainer::WeakContentNodeContainer(SwNode* pNode) : m_pNode(pNode) { if (m_pNode) { - EndListeningAll(); - StartListening(m_pNode->GetNotifier()); + auto* pBroadcast = dynamic_cast<sw::BroadcastingModify*>(pNode); + if (pBroadcast) + { + EndListeningAll(); + StartListening(pBroadcast->GetNotifier()); + } } } @@ -48,7 +52,7 @@ bool WeakContentNodeContainer::isAlive() return m_pNode; } -SwContentNode* WeakContentNodeContainer::getNode() +SwNode* WeakContentNodeContainer::getNode() { if (isAlive()) return m_pNode; @@ -65,14 +69,17 @@ OnlineAccessibilityCheck::OnlineAccessibilityCheck(SwDoc& rDocument) { } -void OnlineAccessibilityCheck::updateNodeStatus(SwContentNode* pContentNode) +void OnlineAccessibilityCheck::updateNodeStatus(SwNode* pNode) { + if (!pNode->IsContentNode() && !pNode->IsTableNode()) + return; + m_nAccessibilityIssues = 0; - auto it = m_aNodes.find(pContentNode); + auto it = m_aNodes.find(pNode); if (it == m_aNodes.end()) { - m_aNodes.emplace(pContentNode, std::make_unique<WeakContentNodeContainer>(pContentNode)); + m_aNodes.emplace(pNode, std::make_unique<WeakContentNodeContainer>(pNode)); } for (auto iterator = m_aNodes.begin(); iterator != m_aNodes.end();) @@ -107,13 +114,13 @@ void OnlineAccessibilityCheck::updateStatusbar() pBindings->Invalidate(FN_STAT_ACCESSIBILITY_CHECK); } -void OnlineAccessibilityCheck::runAccessibilityCheck(SwContentNode* pContentNode) +void OnlineAccessibilityCheck::runAccessibilityCheck(SwNode* pNode) { m_aAccessibilityCheck.getIssueCollection().clear(); - m_aAccessibilityCheck.checkNode(pContentNode); + m_aAccessibilityCheck.checkNode(pNode); - for (SwFrameFormat* const& pFrameFormat : pContentNode->GetAnchoredFlys()) + for (SwFrameFormat* const& pFrameFormat : pNode->GetAnchoredFlys()) { SdrObject* pObject = pFrameFormat->FindSdrObject(); if (pObject) @@ -122,7 +129,7 @@ void OnlineAccessibilityCheck::runAccessibilityCheck(SwContentNode* pContentNode auto aCollection = m_aAccessibilityCheck.getIssueCollection(); - pContentNode->getAccessibilityCheckStatus().pCollection + pNode->getAccessibilityCheckStatus().pCollection = std::make_unique<sfx::AccessibilityIssueCollection>(aCollection); } @@ -135,11 +142,10 @@ void OnlineAccessibilityCheck::initialCheck() for (SwNodeOffset n(0); n < pNodes.Count(); ++n) { SwNode* pNode = pNodes[n]; - if (pNode && pNode->IsContentNode()) + if (pNode) { - auto* pCurrent = pNode->GetContentNode(); - runAccessibilityCheck(pCurrent); - updateNodeStatus(pCurrent); + runAccessibilityCheck(pNode); + updateNodeStatus(pNode); } } @@ -157,16 +163,20 @@ void OnlineAccessibilityCheck::update(const SwPosition& rNewPos) return; auto nCurrenNodeIndex = rNewPos.GetNodeIndex(); - if (!rNewPos.GetNode().IsContentNode()) + auto* pCurrentNode = &rNewPos.GetNode(); + + if (!pCurrentNode->IsContentNode() && !pCurrentNode->IsTableNode()) return; - auto* pCurrentNode = rNewPos.GetNode().GetContentNode(); + auto* pCurrentBroadcast = dynamic_cast<sw::BroadcastingModify*>(pCurrentNode); + if (!pCurrentBroadcast) + return; // Check if previous node was deleted if (!HasBroadcaster()) { EndListeningAll(); - StartListening(pCurrentNode->GetNotifier()); + StartListening(pCurrentBroadcast->GetNotifier()); m_pPreviousNode = pCurrentNode; m_nPreviousNodeIndex = nCurrenNodeIndex; return; @@ -176,31 +186,29 @@ void OnlineAccessibilityCheck::update(const SwPosition& rNewPos) if (nCurrenNodeIndex == m_nPreviousNodeIndex) return; - // Check previous node is valid + // Check if previous node is valid if (m_nPreviousNodeIndex < SwNodeOffset(0) - || m_nPreviousNodeIndex >= rNewPos.GetNode().GetNodes().Count()) + || m_nPreviousNodeIndex >= pCurrentNode->GetNodes().Count()) { EndListeningAll(); - StartListening(pCurrentNode->GetNotifier()); + StartListening(pCurrentBroadcast->GetNotifier()); m_pPreviousNode = pCurrentNode; m_nPreviousNodeIndex = nCurrenNodeIndex; return; } // Get the real previous node from index - SwNode* pNode = rNewPos.GetNode().GetNodes()[m_nPreviousNodeIndex]; + SwNode* pNode = pCurrentNode->GetNodes()[m_nPreviousNodeIndex]; - if (pNode && pNode->IsContentNode()) + if (pNode && (pNode->IsContentNode() || pNode->IsTableNode())) { - auto* pContentNode = pNode->GetContentNode(); - - runAccessibilityCheck(pContentNode); - updateNodeStatus(pContentNode); + runAccessibilityCheck(pNode); + updateNodeStatus(pNode); updateStatusbar(); // Assign previous node and index EndListeningAll(); - StartListening(pCurrentNode->GetNotifier()); + StartListening(pCurrentBroadcast->GetNotifier()); m_pPreviousNode = pCurrentNode; m_nPreviousNodeIndex = nCurrenNodeIndex; } commit fbe8c7163d4a6a32851bd1a0bb4c3bb762495134 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Mon Oct 24 22:38:56 2022 +0200 Commit: Tomaž Vajngerl <qui...@gmail.com> CommitDate: Wed Dec 21 07:10:57 2022 +0000 sw: initial a11y check - first run when the document is opened When the document is opened we first need to run the a11y check on the whole document so we can report the a11y state in the statusbar and set the a11y issues to the nodes. Change-Id: I0573e8fd695e3b0560fa0554f4702c88e7980a13 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141786 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <qui...@gmail.com> (cherry picked from commit ef0858071faf93ce48237ea3948f50e288eb702b) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143705 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> diff --git a/sw/inc/OnlineAccessibilityCheck.hxx b/sw/inc/OnlineAccessibilityCheck.hxx index 9ec6f28ba6b1..47e42a27de29 100644 --- a/sw/inc/OnlineAccessibilityCheck.hxx +++ b/sw/inc/OnlineAccessibilityCheck.hxx @@ -51,10 +51,12 @@ private: SwContentNode* m_pPreviousNode; SwNodeOffset m_nPreviousNodeIndex; sal_Int32 m_nAccessibilityIssues; + bool m_bInitialCheck; - void runCheck(SwContentNode* pNode); + void runAccessibilityCheck(SwContentNode* pNode); void updateStatusbar(); void updateNodeStatus(SwContentNode* pContentNode); + void initialCheck(); public: OnlineAccessibilityCheck(SwDoc& rDocument); diff --git a/sw/source/core/txtnode/OnlineAccessibilityCheck.cxx b/sw/source/core/txtnode/OnlineAccessibilityCheck.cxx index a2a9783c3fd1..7fb93c070f0f 100644 --- a/sw/source/core/txtnode/OnlineAccessibilityCheck.cxx +++ b/sw/source/core/txtnode/OnlineAccessibilityCheck.cxx @@ -61,6 +61,7 @@ OnlineAccessibilityCheck::OnlineAccessibilityCheck(SwDoc& rDocument) , m_pPreviousNode(nullptr) , m_nPreviousNodeIndex(-1) , m_nAccessibilityIssues(0) + , m_bInitialCheck(false) { } @@ -106,7 +107,7 @@ void OnlineAccessibilityCheck::updateStatusbar() pBindings->Invalidate(FN_STAT_ACCESSIBILITY_CHECK); } -void OnlineAccessibilityCheck::runCheck(SwContentNode* pContentNode) +void OnlineAccessibilityCheck::runAccessibilityCheck(SwContentNode* pContentNode) { m_aAccessibilityCheck.getIssueCollection().clear(); @@ -123,9 +124,28 @@ void OnlineAccessibilityCheck::runCheck(SwContentNode* pContentNode) pContentNode->getAccessibilityCheckStatus().pCollection = std::make_unique<sfx::AccessibilityIssueCollection>(aCollection); +} + +void OnlineAccessibilityCheck::initialCheck() +{ + if (m_bInitialCheck) + return; + + auto const& pNodes = m_rDocument.GetNodes(); + for (SwNodeOffset n(0); n < pNodes.Count(); ++n) + { + SwNode* pNode = pNodes[n]; + if (pNode && pNode->IsContentNode()) + { + auto* pCurrent = pNode->GetContentNode(); + runAccessibilityCheck(pCurrent); + updateNodeStatus(pCurrent); + } + } - updateNodeStatus(pContentNode); updateStatusbar(); + + m_bInitialCheck = true; } void OnlineAccessibilityCheck::update(const SwPosition& rNewPos) @@ -174,7 +194,9 @@ void OnlineAccessibilityCheck::update(const SwPosition& rNewPos) { auto* pContentNode = pNode->GetContentNode(); - runCheck(pContentNode); + runAccessibilityCheck(pContentNode); + updateNodeStatus(pContentNode); + updateStatusbar(); // Assign previous node and index EndListeningAll(); @@ -187,6 +209,8 @@ void OnlineAccessibilityCheck::update(const SwPosition& rNewPos) m_pPreviousNode = nullptr; m_nPreviousNodeIndex = SwNodeOffset(-1); } + + initialCheck(); } } // end sw