summaryrefslogtreecommitdiff
path: root/sw/inc/OnlineAccessibilityCheck.hxx
blob: 1e320554f8fcda423dd871b7a207cad63af3938e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 */

#pragma once

#include "ndindex.hxx"
#include "ndtxt.hxx"
#include <svl/listener.hxx>
#include <vcl/timer.hxx>
#include <AccessibilityCheck.hxx>
#include <map>

struct SwPosition;
class SwTextNode;

namespace sw
{
/// Contains the node and tracks if the node gets deleted.
/// Note: the node needs to extend sw::BroadcastingModify.
class WeakNodeContainer final : public SvtListener
{
private:
    SwNode* m_pNode;

public:
    WeakNodeContainer(SwNode* pNode);
    ~WeakNodeContainer();

    /// Is the node still alive or it was deleted?
    bool isAlive();

    /// Returns the pointer of the node or nullptr if the node
    /// got deleted.
    SwNode* getNode();
};

class OnlineAccessibilityCheck
{
private:
    std::map<SwNode*, std::unique_ptr<WeakNodeContainer>> m_aNodes;

    SwDoc& m_rDocument;
    sw::AccessibilityCheck m_aAccessibilityCheck;
    std::unique_ptr<WeakNodeContainer> m_pPreviousNode;
    SwNodeOffset m_nPreviousNodeIndex;
    sal_Int32 m_nAccessibilityIssues;
    bool m_bInitialCheck;
    bool m_bOnlineCheckStatus;
    std::unique_ptr<sfx::AccessibilityIssueCollection> m_pDocumentAccessibilityIssues;

    void runAccessibilityCheck(SwNode* pNode);
    void updateStatusbar();
    void updateNodeStatus(SwNode* pContentNode, bool bIssueObjectNameChanged = false);
    void initialCheck();
    void lookForPreviousNodeAndUpdate(SwPosition const& rNewPos);
    void clearAccessibilityIssuesFromAllNodes();
    void runDocumentLevelAccessibilityCheck();

public:
    OnlineAccessibilityCheck(SwDoc& rDocument);
    void update(SwPosition const& rNewPos);
    void resetAndQueue(SwNode* pNode, bool bIssueObjectNameChanged = false);
    void resetAndQueueDocumentLevel();
    void updateCheckerActivity();
    sal_Int32 getNumberOfAccessibilityIssues() { return m_nAccessibilityIssues; }
    sal_Int32 getNumberOfDocumentLevelAccessibilityIssues()
    {
        return m_pDocumentAccessibilityIssues ? m_pDocumentAccessibilityIssues->getIssues().size()
                                              : sal_Int32(0);
    }
};

} // end sw

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */