| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
| 4 | ** Contact: https://www.qt.io/licensing/ |
| 5 | ** |
| 6 | ** This file is part of the QtGui module of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ |
| 9 | ** Commercial License Usage |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 11 | ** accordance with the commercial license agreement provided with the |
| 12 | ** Software or, alternatively, in accordance with the terms contained in |
| 13 | ** a written agreement between you and The Qt Company. For licensing terms |
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
| 15 | ** information use the contact form at https://www.qt.io/contact-us. |
| 16 | ** |
| 17 | ** GNU Lesser General Public License Usage |
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
| 19 | ** General Public License version 3 as published by the Free Software |
| 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
| 21 | ** packaging of this file. Please review the following information to |
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements |
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
| 24 | ** |
| 25 | ** GNU General Public License Usage |
| 26 | ** Alternatively, this file may be used under the terms of the GNU |
| 27 | ** General Public License version 2.0 or (at your option) the GNU General |
| 28 | ** Public license version 3 or any later version approved by the KDE Free |
| 29 | ** Qt Foundation. The licenses are as published by the Free Software |
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
| 31 | ** included in the packaging of this file. Please review the following |
| 32 | ** information to ensure the GNU General Public License requirements will |
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
| 35 | ** |
| 36 | ** $QT_END_LICENSE$ |
| 37 | ** |
| 38 | ****************************************************************************/ |
| 39 | |
| 40 | |
| 41 | #include "constant_mappings_p.h" |
| 42 | |
| 43 | #include <qobject.h> |
| 44 | #include <qdebug.h> |
| 45 | |
| 46 | // FIXME the assignment of roles is quite arbitrary, at some point go through this list and sort and check that it makes sense |
| 47 | // "calendar" "check menu item" "color chooser" "column header" "dateeditor" "desktop icon" "desktop frame" |
| 48 | // "directory pane" "drawing area" "file chooser" "fontchooser" "frame" "glass pane" "html container" "icon" |
| 49 | // "internal frame" "option pane" "password text" "radio menu item" "root pane" "row header" "scroll pane" |
| 50 | // "tear off menu item" "terminal" "toggle button" "tree table" "unknown" "viewport" "header" "footer" "paragraph" |
| 51 | // "ruler" "autocomplete" "edit bar" "embedded component" "entry" "caption" |
| 52 | // "heading" "page" "section" "redundant object" "form" "input method window" "menu" |
| 53 | |
| 54 | #ifndef QT_NO_ACCESSIBILITY |
| 55 | QT_BEGIN_NAMESPACE |
| 56 | |
| 57 | QHash <QAccessible::Role, RoleNames> qSpiRoleMapping; |
| 58 | |
| 59 | quint64 spiStatesFromQState(QAccessible::State state) |
| 60 | { |
| 61 | quint64 spiState = 0; |
| 62 | |
| 63 | if (state.active) |
| 64 | setSpiStateBit(state: &spiState, spiState: ATSPI_STATE_ACTIVE); |
| 65 | if (state.editable) |
| 66 | setSpiStateBit(state: &spiState, spiState: ATSPI_STATE_EDITABLE); |
| 67 | if (!state.disabled) { |
| 68 | setSpiStateBit(state: &spiState, spiState: ATSPI_STATE_ENABLED); |
| 69 | setSpiStateBit(state: &spiState, spiState: ATSPI_STATE_SENSITIVE); |
| 70 | } |
| 71 | if (state.selected) |
| 72 | setSpiStateBit(state: &spiState, spiState: ATSPI_STATE_SELECTED); |
| 73 | if (state.focused) |
| 74 | setSpiStateBit(state: &spiState, spiState: ATSPI_STATE_FOCUSED); |
| 75 | if (state.pressed) |
| 76 | setSpiStateBit(state: &spiState, spiState: ATSPI_STATE_PRESSED); |
| 77 | if (state.checked) |
| 78 | setSpiStateBit(state: &spiState, spiState: ATSPI_STATE_CHECKED); |
| 79 | if (state.checkStateMixed) |
| 80 | setSpiStateBit(state: &spiState, spiState: ATSPI_STATE_INDETERMINATE); |
| 81 | if (state.readOnly) |
| 82 | setSpiStateBit(state: &spiState, spiState: ATSPI_STATE_READ_ONLY); |
| 83 | // if (state.HotTracked) |
| 84 | if (state.defaultButton) |
| 85 | setSpiStateBit(state: &spiState, spiState: ATSPI_STATE_IS_DEFAULT); |
| 86 | if (state.expandable) |
| 87 | setSpiStateBit(state: &spiState, spiState: ATSPI_STATE_EXPANDABLE); |
| 88 | if (state.expanded) |
| 89 | setSpiStateBit(state: &spiState, spiState: ATSPI_STATE_EXPANDED); |
| 90 | if (state.collapsed) |
| 91 | setSpiStateBit(state: &spiState, spiState: ATSPI_STATE_COLLAPSED); |
| 92 | if (state.busy) |
| 93 | setSpiStateBit(state: &spiState, spiState: ATSPI_STATE_BUSY); |
| 94 | if (state.marqueed || state.animated) |
| 95 | setSpiStateBit(state: &spiState, spiState: ATSPI_STATE_ANIMATED); |
| 96 | if (!state.invisible && !state.offscreen) { |
| 97 | setSpiStateBit(state: &spiState, spiState: ATSPI_STATE_SHOWING); |
| 98 | setSpiStateBit(state: &spiState, spiState: ATSPI_STATE_VISIBLE); |
| 99 | } |
| 100 | if (state.sizeable) |
| 101 | setSpiStateBit(state: &spiState, spiState: ATSPI_STATE_RESIZABLE); |
| 102 | // if (state.Movable) |
| 103 | // if (state.SelfVoicing) |
| 104 | if (state.focusable) |
| 105 | setSpiStateBit(state: &spiState, spiState: ATSPI_STATE_FOCUSABLE); |
| 106 | if (state.selectable) |
| 107 | setSpiStateBit(state: &spiState, spiState: ATSPI_STATE_SELECTABLE); |
| 108 | // if (state.Linked) |
| 109 | if (state.traversed) |
| 110 | setSpiStateBit(state: &spiState, spiState: ATSPI_STATE_VISITED); |
| 111 | if (state.multiSelectable) |
| 112 | setSpiStateBit(state: &spiState, spiState: ATSPI_STATE_MULTISELECTABLE); |
| 113 | if (state.extSelectable) |
| 114 | setSpiStateBit(state: &spiState, spiState: ATSPI_STATE_SELECTABLE); |
| 115 | // if (state.Protected) |
| 116 | // if (state.HasPopup) |
| 117 | if (state.modal) |
| 118 | setSpiStateBit(state: &spiState, spiState: ATSPI_STATE_MODAL); |
| 119 | if (state.multiLine) |
| 120 | setSpiStateBit(state: &spiState, spiState: ATSPI_STATE_MULTI_LINE); |
| 121 | |
| 122 | return spiState; |
| 123 | } |
| 124 | |
| 125 | QSpiUIntList spiStateSetFromSpiStates(quint64 states) |
| 126 | { |
| 127 | uint low = states & 0xFFFFFFFF; |
| 128 | uint high = (states >> 32) & 0xFFFFFFFF; |
| 129 | |
| 130 | QSpiUIntList stateList; |
| 131 | stateList.append(t: low); |
| 132 | stateList.append(t: high); |
| 133 | return stateList; |
| 134 | } |
| 135 | |
| 136 | AtspiRelationType qAccessibleRelationToAtSpiRelation(QAccessible::Relation relation) |
| 137 | { |
| 138 | switch (relation) { |
| 139 | case QAccessible::Label: |
| 140 | return ATSPI_RELATION_LABELLED_BY; |
| 141 | case QAccessible::Labelled: |
| 142 | return ATSPI_RELATION_LABEL_FOR; |
| 143 | case QAccessible::Controller: |
| 144 | return ATSPI_RELATION_CONTROLLED_BY; |
| 145 | case QAccessible::Controlled: |
| 146 | return ATSPI_RELATION_CONTROLLER_FOR; |
| 147 | default: |
| 148 | qWarning() << "Cannot return AT-SPI relation for:" << relation; |
| 149 | } |
| 150 | return ATSPI_RELATION_NULL; |
| 151 | } |
| 152 | |
| 153 | QT_END_NAMESPACE |
| 154 | #endif //QT_NO_ACCESSIBILITY |
| 155 | |