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
4
5#include "qspi_constant_mappings_p.h"
6
7#include <qobject.h>
8#include <qdebug.h>
9
10// FIXME the assignment of roles is quite arbitrary, at some point go through this list and sort and check that it makes sense
11// "calendar" "check menu item" "color chooser" "column header" "dateeditor" "desktop icon" "desktop frame"
12// "directory pane" "drawing area" "file chooser" "fontchooser" "frame" "glass pane" "html container" "icon"
13// "internal frame" "option pane" "password text" "radio menu item" "root pane" "row header" "scroll pane"
14// "tear off menu item" "terminal" "toggle button" "tree table" "unknown" "viewport" "header" "footer" "paragraph"
15// "ruler" "autocomplete" "edit bar" "embedded component" "entry" "caption"
16// "heading" "page" "section" "redundant object" "form" "input method window" "menu"
17
18#if QT_CONFIG(accessibility)
19QT_BEGIN_NAMESPACE
20
21quint64 spiStatesFromQState(QAccessible::State state)
22{
23 quint64 spiState = 0;
24
25 if (state.active)
26 setSpiStateBit(state: &spiState, spiState: ATSPI_STATE_ACTIVE);
27 if (state.editable)
28 setSpiStateBit(state: &spiState, spiState: ATSPI_STATE_EDITABLE);
29 if (!state.disabled) {
30 setSpiStateBit(state: &spiState, spiState: ATSPI_STATE_ENABLED);
31 setSpiStateBit(state: &spiState, spiState: ATSPI_STATE_SENSITIVE);
32 }
33 if (state.selected)
34 setSpiStateBit(state: &spiState, spiState: ATSPI_STATE_SELECTED);
35 if (state.focused)
36 setSpiStateBit(state: &spiState, spiState: ATSPI_STATE_FOCUSED);
37 if (state.pressed)
38 setSpiStateBit(state: &spiState, spiState: ATSPI_STATE_PRESSED);
39 if (state.checked)
40 setSpiStateBit(state: &spiState, spiState: ATSPI_STATE_CHECKED);
41 if (state.checkStateMixed)
42 setSpiStateBit(state: &spiState, spiState: ATSPI_STATE_INDETERMINATE);
43 if (state.readOnly)
44 setSpiStateBit(state: &spiState, spiState: ATSPI_STATE_READ_ONLY);
45 // if (state.HotTracked)
46 if (state.defaultButton)
47 setSpiStateBit(state: &spiState, spiState: ATSPI_STATE_IS_DEFAULT);
48 if (state.expandable)
49 setSpiStateBit(state: &spiState, spiState: ATSPI_STATE_EXPANDABLE);
50 if (state.expanded)
51 setSpiStateBit(state: &spiState, spiState: ATSPI_STATE_EXPANDED);
52 if (state.collapsed)
53 setSpiStateBit(state: &spiState, spiState: ATSPI_STATE_COLLAPSED);
54 if (state.busy)
55 setSpiStateBit(state: &spiState, spiState: ATSPI_STATE_BUSY);
56 if (state.marqueed || state.animated)
57 setSpiStateBit(state: &spiState, spiState: ATSPI_STATE_ANIMATED);
58 if (!state.invisible && !state.offscreen) {
59 setSpiStateBit(state: &spiState, spiState: ATSPI_STATE_SHOWING);
60 setSpiStateBit(state: &spiState, spiState: ATSPI_STATE_VISIBLE);
61 }
62 if (state.sizeable)
63 setSpiStateBit(state: &spiState, spiState: ATSPI_STATE_RESIZABLE);
64 // if (state.Movable)
65 // if (state.SelfVoicing)
66 if (state.focusable)
67 setSpiStateBit(state: &spiState, spiState: ATSPI_STATE_FOCUSABLE);
68 if (state.selectable)
69 setSpiStateBit(state: &spiState, spiState: ATSPI_STATE_SELECTABLE);
70 // if (state.Linked)
71 if (state.traversed)
72 setSpiStateBit(state: &spiState, spiState: ATSPI_STATE_VISITED);
73 if (state.multiSelectable)
74 setSpiStateBit(state: &spiState, spiState: ATSPI_STATE_MULTISELECTABLE);
75 if (state.extSelectable)
76 setSpiStateBit(state: &spiState, spiState: ATSPI_STATE_SELECTABLE);
77 // if (state.Protected)
78 // if (state.HasPopup)
79 if (state.modal)
80 setSpiStateBit(state: &spiState, spiState: ATSPI_STATE_MODAL);
81 if (state.multiLine)
82 setSpiStateBit(state: &spiState, spiState: ATSPI_STATE_MULTI_LINE);
83
84 return spiState;
85}
86
87QSpiUIntList spiStateSetFromSpiStates(quint64 states)
88{
89 uint low = states & 0xFFFFFFFF;
90 uint high = (states >> 32) & 0xFFFFFFFF;
91
92 QSpiUIntList stateList;
93 stateList.append(t: low);
94 stateList.append(t: high);
95 return stateList;
96}
97
98AtspiRelationType qAccessibleRelationToAtSpiRelation(QAccessible::Relation relation)
99{
100 // direction of the relation is "inversed" in Qt and AT-SPI
101 switch (relation) {
102 case QAccessible::Label:
103 return ATSPI_RELATION_LABELLED_BY;
104 case QAccessible::Labelled:
105 return ATSPI_RELATION_LABEL_FOR;
106 case QAccessible::Controller:
107 return ATSPI_RELATION_CONTROLLED_BY;
108 case QAccessible::Controlled:
109 return ATSPI_RELATION_CONTROLLER_FOR;
110 case QAccessible::DescriptionFor:
111 return ATSPI_RELATION_DESCRIBED_BY;
112 case QAccessible::Described:
113 return ATSPI_RELATION_DESCRIPTION_FOR;
114 case QAccessible::FlowsFrom:
115 return ATSPI_RELATION_FLOWS_TO;
116 case QAccessible::FlowsTo:
117 return ATSPI_RELATION_FLOWS_FROM;
118 default:
119 qWarning() << "Cannot return AT-SPI relation for:" << relation;
120 }
121 return ATSPI_RELATION_NULL;
122}
123
124QT_END_NAMESPACE
125#endif // QT_CONFIG(accessibility)
126

source code of qtbase/src/gui/accessible/linux/qspi_constant_mappings.cpp