sw/inc/OnlineAccessibilityCheck.hxx                 |   20 +++---
 sw/inc/node.hxx                                     |   38 +++++------
 sw/source/core/txtnode/OnlineAccessibilityCheck.cxx |   64 +++++++++++---------
 3 files changed, 65 insertions(+), 57 deletions(-)

New commits:
commit 1dfb746b8ca5d5d4ef21feb67d3921ab342d782f
Author:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
AuthorDate: Mon Oct 24 23:42:44 2022 +0200
Commit:     Tomaž Vajngerl <qui...@gmail.com>
CommitDate: Thu Nov 17 10:06:39 2022 +0100

    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>

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 f62375044ca8..0d0561d6f024 100644
--- a/sw/inc/node.hxx
+++ b/sw/inc/node.hxx
@@ -80,6 +80,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
@@ -92,6 +104,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 };
@@ -317,6 +331,11 @@ public:
     bool operator>(const SwNode& rOther) const { assert(&GetNodes() == 
&rOther.GetNodes()); return GetIndex() > rOther.GetIndex(); }
     bool operator>=(const SwNode& rOther) const { assert(&GetNodes() == 
&rOther.GetNodes()); return GetIndex() >= rOther.GetIndex(); }
 
+    sw::AccessibilityCheckStatus& getAccessibilityCheckStatus()
+    {
+        return m_aAccessibilityCheckStatus;
+    }
+
 private:
     SwNode( const SwNode & rNodes ) = delete;
     SwNode & operator= ( const SwNode & rNodes ) = delete;
@@ -368,18 +387,6 @@ class SwEndNode final : public SwNode
     SwEndNode & operator= ( const SwEndNode & rNode ) = delete;
 };
 
-// Accessibility 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 SwContentIndexReg
@@ -389,8 +396,6 @@ class SW_DLLPUBLIC SwContentNode: public 
sw::BroadcastingModify, public SwNode,
     SwFormatColl* m_pCondColl;
     mutable bool mbSetModifyAtAttr;
 
-    mutable sw::AccessibilityCheckStatus m_aAccessibilityCheckStatus;
-
 protected:
     /// only used by SwContentNodeTmp in SwTextNode::Update
     SwContentNode();
@@ -515,11 +520,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;
     }

Reply via email to