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
qnsview_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
5// This file is included from qnsview.mm, and only used to organize the code
6
10
11#include <QtGui/qaccessible.h>
12
13#include <AppKit/NSAccessibility.h>
14
15@implementation QNSView (Accessibility)
16
17- (void)activateQtAccessibility
18{
19 // Activate the Qt accessibility machinery for all entry points
20 // below that may be triggered by system accessibility queries,
21 // as otherwise Qt is not aware that the system needs to know
22 // about all accessibility state changes in Qt.
23 QCocoaIntegration::instance()->accessibility()->setActive(true);
24}
25
26- (id)childAccessibleElement
27{
28 QCocoaWindow *platformWindow = self.platformWindow;
29 if (!platformWindow || !platformWindow->window()->accessibleRoot())
30 return nil;
31
32 QAccessible::Id childId = QAccessible::uniqueId(platformWindow->window()->accessibleRoot());
33 return [QMacAccessibilityElement elementWithId:childId];
34}
35
36// The QNSView is a container that the user does not interact directly with:
37// Remove it from the user-visible accessibility tree.
38- (BOOL)accessibilityIsIgnored
39{
40 return YES;
41}
42
43- (id)accessibilityAttributeValue:(NSString *)attribute
44{
45 [self activateQtAccessibility];
46
47 if ([attribute isEqualToString:NSAccessibilityChildrenAttribute])
48 return NSAccessibilityUnignoredChildrenForOnlyChild([self childAccessibleElement]);
49 else
50 return [super accessibilityAttributeValue:attribute];
51}
52
53- (id)accessibilityParent
54{
55 [self activateQtAccessibility];
56
57 // An NSView reports the nearest ancestor in the view hierarchy that is also
58 // in the accessibility hierarchy, which is the enclosing NSWindow in the
59 // common case. But our window may be hosted by something that has a place in
60 // Qt's tree, such as a Widget or Quick window container, and the host is then
61 // the parent, matching the child the host reports.
62 auto parentAccessibleElement = [self]() -> id {
63 QCocoaWindow *platformWindow = self.platformWindow;
64 if (!platformWindow)
65 return nil;
66
67 QAccessibleInterface *root = platformWindow->window()->accessibleRoot();
68 if (!root)
69 return nil;
70
71 QAccessibleInterface *parent = root->parent();
72 if (!parent)
73 return nil;
74
75 if (QCocoaAccessible::isRepresentedByAppKit(parent))
76 return nil;
77
78 return [QMacAccessibilityElement elementWithInterface:parent];
79 };
80
81 if (id element = parentAccessibleElement())
82 return NSAccessibilityUnignoredAncestor(element);
83
84 return [super accessibilityParent];
85}
86
87- (id)accessibilityHitTest:(NSPoint)point
88{
89 [self activateQtAccessibility];
90 return [[self childAccessibleElement] accessibilityHitTest:point];
91}
92
93- (id)accessibilityFocusedUIElement
94{
95 [self activateQtAccessibility];
96 return [[self childAccessibleElement] accessibilityFocusedUIElement];
97}
98
99@end