summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2022-11-16 17:59:31 +0900
committerTomaž Vajngerl <quikee@gmail.com>2022-11-22 14:56:54 +0100
commit6f8bd9785c3f01ac711bfe0647dc7d02a68d45a8 (patch)
treedda99e0257ce7174142de9ee70f50248773e5e4f /sw
parentbada1fc45d6ec65c12cf9ed36e15927b27d6d49c (diff)
sw: use WeakNodeContainer for m_pPreviousNode in OnlineA11yCheck
Change-Id: Iae2158ff4de0cab4307379c48011d5b6ca844b13 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/142821 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'sw')
-rw-r--r--sw/inc/OnlineAccessibilityCheck.hxx4
-rw-r--r--sw/source/core/txtnode/OnlineAccessibilityCheck.cxx32
2 files changed, 17 insertions, 19 deletions
diff --git a/sw/inc/OnlineAccessibilityCheck.hxx b/sw/inc/OnlineAccessibilityCheck.hxx
index 8f52b73f35bd..0d9c65902905 100644
--- a/sw/inc/OnlineAccessibilityCheck.hxx
+++ b/sw/inc/OnlineAccessibilityCheck.hxx
@@ -41,14 +41,14 @@ public:
SwNode* getNode();
};
-class OnlineAccessibilityCheck : public SvtListener
+class OnlineAccessibilityCheck
{
private:
std::map<SwNode*, std::unique_ptr<WeakNodeContainer>> m_aNodes;
SwDoc& m_rDocument;
sw::AccessibilityCheck m_aAccessibilityCheck;
- SwNode* m_pPreviousNode;
+ std::unique_ptr<WeakNodeContainer> m_pPreviousNode;
SwNodeOffset m_nPreviousNodeIndex;
sal_Int32 m_nAccessibilityIssues;
bool m_bInitialCheck;
diff --git a/sw/source/core/txtnode/OnlineAccessibilityCheck.cxx b/sw/source/core/txtnode/OnlineAccessibilityCheck.cxx
index 6c03293705f7..063c2d586e12 100644
--- a/sw/source/core/txtnode/OnlineAccessibilityCheck.cxx
+++ b/sw/source/core/txtnode/OnlineAccessibilityCheck.cxx
@@ -35,12 +35,16 @@ WeakNodeContainer::WeakNodeContainer(SwNode* pNode)
{
if (m_pNode)
{
- auto* pBroadcast = dynamic_cast<sw::BroadcastingModify*>(pNode);
+ auto* pBroadcast = dynamic_cast<sw::BroadcastingModify*>(m_pNode);
if (pBroadcast)
{
EndListeningAll();
StartListening(pBroadcast->GetNotifier());
}
+ else
+ {
+ m_pNode = nullptr;
+ }
}
}
@@ -48,6 +52,8 @@ WeakNodeContainer::~WeakNodeContainer() { EndListeningAll(); }
bool WeakNodeContainer::isAlive()
{
+ if (!m_pNode)
+ return false;
if (!HasBroadcaster())
m_pNode = nullptr;
return m_pNode;
@@ -63,7 +69,6 @@ SwNode* WeakNodeContainer::getNode()
OnlineAccessibilityCheck::OnlineAccessibilityCheck(SwDoc& rDocument)
: m_rDocument(rDocument)
, m_aAccessibilityCheck(&m_rDocument)
- , m_pPreviousNode(nullptr)
, m_nPreviousNodeIndex(-1)
, m_nAccessibilityIssues(0)
, m_bInitialCheck(false)
@@ -177,8 +182,7 @@ void OnlineAccessibilityCheck::updateCheckerActivity()
if (bOnlineCheckStatus != m_bOnlineCheckStatus)
{
- EndListeningAll();
- m_pPreviousNode = nullptr;
+ m_pPreviousNode.reset();
m_nPreviousNodeIndex = SwNodeOffset(-1);
m_bInitialCheck = false; // force initial check
@@ -218,16 +222,14 @@ void OnlineAccessibilityCheck::lookForPreviousNodeAndUpdate(const SwPosition& rN
if (!pCurrentNode->IsContentNode() && !pCurrentNode->IsTableNode())
return;
- auto* pCurrentBroadcast = dynamic_cast<sw::BroadcastingModify*>(pCurrentNode);
- if (!pCurrentBroadcast)
+ auto pCurrentWeak = std::make_unique<WeakNodeContainer>(pCurrentNode);
+ if (!pCurrentWeak->isAlive())
return;
// Check if previous node was deleted
- if (!HasBroadcaster())
+ if (!m_pPreviousNode || !m_pPreviousNode->isAlive())
{
- EndListeningAll();
- StartListening(pCurrentBroadcast->GetNotifier());
- m_pPreviousNode = pCurrentNode;
+ m_pPreviousNode = std::move(pCurrentWeak);
m_nPreviousNodeIndex = nCurrenNodeIndex;
return;
}
@@ -240,9 +242,7 @@ void OnlineAccessibilityCheck::lookForPreviousNodeAndUpdate(const SwPosition& rN
if (m_nPreviousNodeIndex < SwNodeOffset(0)
|| m_nPreviousNodeIndex >= pCurrentNode->GetNodes().Count())
{
- EndListeningAll();
- StartListening(pCurrentBroadcast->GetNotifier());
- m_pPreviousNode = pCurrentNode;
+ m_pPreviousNode = std::move(pCurrentWeak);
m_nPreviousNodeIndex = nCurrenNodeIndex;
return;
}
@@ -257,14 +257,12 @@ void OnlineAccessibilityCheck::lookForPreviousNodeAndUpdate(const SwPosition& rN
updateStatusbar();
// Assign previous node and index
- EndListeningAll();
- StartListening(pCurrentBroadcast->GetNotifier());
- m_pPreviousNode = pCurrentNode;
+ m_pPreviousNode = std::move(pCurrentWeak);
m_nPreviousNodeIndex = nCurrenNodeIndex;
}
else
{
- m_pPreviousNode = nullptr;
+ m_pPreviousNode.reset();
m_nPreviousNodeIndex = SwNodeOffset(-1);
}
}