Coverage Report

Created: 2025-12-31 10:39

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/unotools/source/accessibility/accessiblerelationsethelper.cxx
Line
Count
Source
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
/*
3
 * This file is part of the LibreOffice project.
4
 *
5
 * This Source Code Form is subject to the terms of the Mozilla Public
6
 * License, v. 2.0. If a copy of the MPL was not distributed with this
7
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8
 *
9
 * This file incorporates work covered by the following license notice:
10
 *
11
 *   Licensed to the Apache Software Foundation (ASF) under one or more
12
 *   contributor license agreements. See the NOTICE file distributed
13
 *   with this work for additional information regarding copyright
14
 *   ownership. The ASF licenses this file to you under the Apache
15
 *   License, Version 2.0 (the "License"); you may not use this file
16
 *   except in compliance with the License. You may obtain a copy of
17
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
18
 */
19
20
#include <sal/config.h>
21
22
#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
23
#include <o3tl/safeint.hxx>
24
#include <unotools/accessiblerelationsethelper.hxx>
25
#include <comphelper/sequence.hxx>
26
27
using namespace ::utl;
28
using namespace ::com::sun::star;
29
using namespace ::com::sun::star::accessibility;
30
31
namespace
32
{
33
    AccessibleRelation lcl_getRelationByType( std::vector<AccessibleRelation>& raRelations, AccessibleRelationType eRelationType)
34
0
    {
35
0
        for (const auto& aRelation: raRelations)
36
0
        {
37
0
            if (aRelation.RelationType == eRelationType)
38
0
                return aRelation;
39
0
        }
40
0
        return AccessibleRelation();
41
0
    }
42
}
43
44
AccessibleRelationSetHelper::AccessibleRelationSetHelper ()
45
0
{
46
0
}
47
48
AccessibleRelationSetHelper::AccessibleRelationSetHelper (const AccessibleRelationSetHelper& rHelper)
49
0
    : cppu::WeakImplHelper<XAccessibleRelationSet>(rHelper),
50
0
      maRelations(rHelper.maRelations)
51
0
{
52
0
}
53
54
css::uno::Reference<css::accessibility::XAccessibleRelationSet> AccessibleRelationSetHelper::Clone() const
55
0
{
56
0
    std::scoped_lock aGuard (maMutex);
57
0
    return new AccessibleRelationSetHelper(*this);
58
0
}
59
60
AccessibleRelationSetHelper::~AccessibleRelationSetHelper()
61
0
{
62
0
}
63
64
//=====  XAccessibleRelationSet  ==============================================
65
66
    /** Returns the number of relations in this relation set.
67
68
        @return
69
            Returns the number of relations or zero if there are none.
70
    */
71
sal_Int32 SAL_CALL
72
    AccessibleRelationSetHelper::getRelationCount(  )
73
0
{
74
0
    std::scoped_lock aGuard (maMutex);
75
76
0
    return maRelations.size();
77
0
}
78
79
    /** Returns the relation of this relation set that is specified by
80
        the given index.
81
82
        @param nIndex
83
            This index specifies the relatio to return.
84
85
        @return
86
            For a valid index, i.e. inside the range 0 to the number of
87
            relations minus one, the returned value is the requested
88
            relation.  If the index is invalid then the returned relation
89
            has the type INVALID.
90
91
    */
92
 AccessibleRelation SAL_CALL
93
        AccessibleRelationSetHelper::getRelation( sal_Int32 nIndex )
94
0
{
95
0
    std::scoped_lock aGuard (maMutex);
96
97
0
    if ((nIndex < 0) || (o3tl::make_unsigned(nIndex) >= maRelations.size()))
98
0
        throw lang::IndexOutOfBoundsException();
99
100
0
    return maRelations[nIndex];
101
0
}
102
103
    /** Tests whether the relation set contains a relation matching the
104
        specified key.
105
106
        @param aRelationType
107
            The type of relation to look for in this set of relations.  This
108
            has to be one of the constants of
109
            <type>AccessibleRelationType</type>.
110
111
        @return
112
            Returns <TRUE/> if there is a (at least one) relation of the
113
            given type and <FALSE/> if there is no such relation in the set.
114
    */
115
sal_Bool SAL_CALL
116
    AccessibleRelationSetHelper::containsRelation(AccessibleRelationType eRelationType)
117
0
{
118
0
    std::scoped_lock aGuard (maMutex);
119
120
0
    AccessibleRelation defaultRelation; // default is INVALID
121
0
    AccessibleRelation relationByType = lcl_getRelationByType(maRelations, eRelationType);
122
0
    return relationByType.RelationType != defaultRelation.RelationType;
123
0
}
124
125
    /** Retrieve and return the relation with the given relation type.
126
127
        @param eRelationType
128
            The type of the relation to return.
129
130
        @return
131
            If a relation with the given type could be found, then (a copy
132
            of) this relation is returned.  Otherwise a relation with the
133
            type INVALID is returned.
134
    */
135
AccessibleRelation SAL_CALL
136
        AccessibleRelationSetHelper::getRelationByType(AccessibleRelationType eRelationType)
137
0
{
138
0
    std::scoped_lock aGuard (maMutex);
139
140
0
    return lcl_getRelationByType(maRelations, eRelationType);
141
0
}
142
143
void AccessibleRelationSetHelper::AddRelation(const AccessibleRelation& rRelation)
144
0
{
145
0
    std::scoped_lock aGuard (maMutex);
146
147
0
    for (auto& aRelation: maRelations)
148
0
    {
149
0
        if (aRelation.RelationType == rRelation.RelationType)
150
0
        {
151
0
            aRelation.TargetSet = comphelper::concatSequences(aRelation.TargetSet, rRelation.TargetSet);
152
0
            return;
153
0
        }
154
0
    }
155
0
    maRelations.push_back(rRelation);
156
0
}
157
158
//=====  XTypeProvider  =======================================================
159
160
uno::Sequence< css::uno::Type> AccessibleRelationSetHelper::getTypes()
161
0
{
162
0
    static const uno::Sequence< css::uno::Type> aTypes {
163
0
        cppu::UnoType<XAccessibleRelationSet>::get(),
164
0
        cppu::UnoType<lang::XTypeProvider>::get()
165
0
    };
166
0
    return aTypes;
167
0
}
168
169
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */