Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
quiview_accessibility.mm
Go to the documentation of this file.
1// Copyright (C) 2016 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
7
8#include <QtGui/private/qguiapplication_p.h>
9
10@implementation QUIView (Accessibility)
11
12- (void)createAccessibleElement:(QAccessibleInterface *)iface
13{
14 if (!iface || iface->state().invisible || (iface->text(QAccessible::Name).isEmpty() && iface->text(QAccessible::Value).isEmpty() && iface->text(QAccessible::Description).isEmpty()))
15 return;
16 QAccessible::Id accessibleId = QAccessible::uniqueId(iface);
17 if (UIAccessibilityElement *elem = [QT_MANGLE_NAMESPACE(QMacAccessibilityElement) elementWithId:accessibleId])
18 [m_accessibleElements addObject:elem];
19}
20
21- (void)createAccessibleContainer:(QAccessibleInterface *)iface
22{
23 if (!iface || iface->state().invisible)
24 return;
25
26 for (int i = 0; i < iface->childCount(); ++i)
27 [self createAccessibleContainer: iface->child(i)];
28
29 // The container element must go last, so that it underlays all its children
30 [self createAccessibleElement:iface];
31}
32
33- (void)initAccessibility
34{
35 // The window may have gone away, but with the view
36 // temporarily caught in the a11y subsystem.
37 if (!self.platformWindow)
38 return;
39
40 static bool init = false;
41 if (!init)
42 QGuiApplicationPrivate::platformIntegration()->accessibility()->setActive(true);
43 init = true;
44
45 if ([m_accessibleElements count])
46 return;
47
48 QWindow *win = self.platformWindow->window();
49 QAccessibleInterface *iface = win->accessibleRoot();
50 if (iface)
51 [self createAccessibleContainer: iface];
52}
53
54- (void)clearAccessibleCache
55{
56 [m_accessibleElements removeAllObjects];
57}
58
59// this is a container, returning yes here means the functions below will never be called
60- (BOOL)isAccessibilityElement
61{
62 return NO;
63}
64
65- (NSInteger)accessibilityElementCount
66{
67 [self initAccessibility];
68 return [m_accessibleElements count];
69}
70
71- (id)accessibilityElementAtIndex:(NSInteger)index
72{
73 [self initAccessibility];
74 if (NSUInteger(index) >= [m_accessibleElements count])
75 return nil;
76 return m_accessibleElements[index];
77}
78
79- (NSInteger)indexOfAccessibilityElement:(id)element
80{
81 [self initAccessibility];
82 return [m_accessibleElements indexOfObject:element];
83}
84
85- (NSArray *)accessibilityElements
86{
87 [self initAccessibility];
88 return m_accessibleElements;
89}
90
91@end
long NSInteger