Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qwindowsuiaprovidercache.cpp
Go to the documentation of this file.
1
// Copyright (C) 2017 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
// Qt-Security score:significant reason:default
4
5
#
include
<
QtGui
/
qtguiglobal
.
h
>
6
#
if
QT_CONFIG
(
accessibility
)
7
8
#
include
"qwindowsuiaprovidercache.h"
9
#
include
"qwindowsuiautils.h"
10
#
include
"qwindowscontext.h"
11
12
QT_BEGIN_NAMESPACE
13
14
using
namespace
QWindowsUiAutomation;
15
16
17
// Private constructor
18
QWindowsUiaProviderCache::QWindowsUiaProviderCache()
19
{
20
}
21
22
// shared instance
23
QWindowsUiaProviderCache *QWindowsUiaProviderCache::instance()
24
{
25
static
QWindowsUiaProviderCache providerCache;
26
return
&providerCache;
27
}
28
29
// Returns the provider instance associated with the ID, or nullptr.
30
ComPtr<QWindowsUiaMainProvider> QWindowsUiaProviderCache::providerForId(QAccessible::Id id)
const
31
{
32
QMutexLocker guard{ &m_tableMutex };
33
34
// Make sure lifetime is extended while holding the mutex
35
ComPtr<QWindowsUiaMainProvider> provider = m_providerTable.value(id);
36
37
return
provider;
38
}
39
40
// Inserts a provider in the cache and associates it with an accessibility ID.
41
void
QWindowsUiaProviderCache::insert(QAccessible::Id id, QWindowsUiaMainProvider *provider)
42
{
43
QMutexLocker guard{ &m_tableMutex };
44
// Remove id if it already exists
45
m_inverseTable.remove(m_providerTable.value(id));
46
m_providerTable.remove(id);
47
48
// Add new provider
49
if
(provider) {
50
m_providerTable[id] = provider;
51
m_inverseTable[provider] = id;
52
guard.unlock();
53
// Connects the destroyed signal to our slot, to remove deleted objects from the cache.
54
QObject::connect(provider, &QObject::destroyed,
this
, &QWindowsUiaProviderCache::remove, Qt::DirectConnection);
55
}
56
}
57
58
// Removes deleted provider objects from the cache.
59
void
QWindowsUiaProviderCache::remove(QObject *obj)
60
{
61
// We have to use the inverse table to map the object address back to its ID,
62
// since at this point (called from QObject destructor), it has already been
63
// partially destroyed and we cannot treat it as a provider.
64
QMutexLocker guard{ &m_tableMutex };
65
auto
it = m_inverseTable.find(obj);
66
if
(it != m_inverseTable.end()) {
67
m_providerTable.remove(*it);
68
m_inverseTable.remove(obj);
69
}
70
}
71
72
QT_END_NAMESPACE
73
74
#
endif
// QT_CONFIG(accessibility)
qtbase
src
plugins
platforms
windows
uiautomation
qwindowsuiaprovidercache.cpp
Generated on
for Qt by
1.18.0