Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
atspi_mapping.hpp
Go to the documentation of this file.
1#pragma once
2
3// Linux AT-SPI2 mapping for Pulp AccessRole.
4//
5// Pure-constant header — no AT-SPI / ATK runtime dependency — so the same
6// mapping compiles on every platform and can be unit-tested offline. The Linux
7// accessibility provider (accessibility_linux.cpp) consumes these constants
8// when it answers org.a11y.atspi.Accessible.GetRole over D-Bus.
9//
10// AT-SPI exports roles as plain `uint32` enum NUMBERS on the wire (the
11// AtspiRole / Atspi_Role enumeration in the published AT-SPI2 IDL). They are
12// part of the wire protocol — a screen reader (Orca) reads the number and looks
13// up its own label — so they are stable and safe to hard-code without pulling
14// in libatspi headers. They DIFFER from the legacy ATK AtkRole numbers the
15// pre-L7 stub hard-coded (AtkRole and AtspiRole are distinct enumerations);
16// the table test locks the AT-SPI numbers so a future edit can't silently
17// regress to the ATK values.
18//
19// Reference: AT-SPI2 `Accessible.GetRole` returns `u`; the AtspiRole values
20// below are from the freedesktop AT-SPI2 enumeration (xml/Accessible role list).
21
23#include <pulp/view/view.hpp>
24
25#include <cstdint>
26
28
29// ── AtspiRole values (subset Pulp exposes) ───────────────────────────────────
30// The full enumeration lives in the AT-SPI2 IDL. These are the AtspiRole
31// numbers (NOT AtkRole) for the roles Pulp declares today. Additional roles
32// land as widgets need them.
33inline constexpr uint32_t kRoleCheckBox = 7; // ATSPI_ROLE_CHECK_BOX
34inline constexpr uint32_t kRoleComboBox = 11; // ATSPI_ROLE_COMBO_BOX
35inline constexpr uint32_t kRoleDialog = 16; // ATSPI_ROLE_DIALOG
36inline constexpr uint32_t kRoleImage = 27; // ATSPI_ROLE_IMAGE
37inline constexpr uint32_t kRoleLabel = 29; // ATSPI_ROLE_LABEL
38inline constexpr uint32_t kRoleList = 31; // ATSPI_ROLE_LIST
39inline constexpr uint32_t kRoleListItem = 32; // ATSPI_ROLE_LIST_ITEM
40inline constexpr uint32_t kRoleMenu = 33; // ATSPI_ROLE_MENU
41inline constexpr uint32_t kRoleMenuItem = 35; // ATSPI_ROLE_MENU_ITEM
42inline constexpr uint32_t kRolePageTab = 37; // ATSPI_ROLE_PAGE_TAB
43inline constexpr uint32_t kRolePageTabList = 38; // ATSPI_ROLE_PAGE_TAB_LIST
44inline constexpr uint32_t kRolePanel = 39; // ATSPI_ROLE_PANEL
45inline constexpr uint32_t kRoleProgressBar = 42; // ATSPI_ROLE_PROGRESS_BAR
46inline constexpr uint32_t kRolePushButton = 43; // ATSPI_ROLE_PUSH_BUTTON
47inline constexpr uint32_t kRoleRadioButton = 44; // ATSPI_ROLE_RADIO_BUTTON
48inline constexpr uint32_t kRoleScrollBar = 48; // ATSPI_ROLE_SCROLL_BAR
49inline constexpr uint32_t kRoleSlider = 51; // ATSPI_ROLE_SLIDER
50inline constexpr uint32_t kRoleTable = 55; // ATSPI_ROLE_TABLE
51inline constexpr uint32_t kRoleTableCell = 56; // ATSPI_ROLE_TABLE_CELL
52inline constexpr uint32_t kRoleToggleButton = 62; // ATSPI_ROLE_TOGGLE_BUTTON
53inline constexpr uint32_t kRoleApplication = 75; // ATSPI_ROLE_APPLICATION
54inline constexpr uint32_t kRoleEntry = 79; // ATSPI_ROLE_ENTRY
55inline constexpr uint32_t kRoleHeading = 83; // ATSPI_ROLE_HEADING
56inline constexpr uint32_t kRoleLink = 88; // ATSPI_ROLE_LINK
57inline constexpr uint32_t kRoleTableRow = 90; // ATSPI_ROLE_TABLE_ROW
58inline constexpr uint32_t kRoleInvalid = 0; // ATSPI_ROLE_INVALID
59
63constexpr uint32_t role_to_atspi_role(View::AccessRole role) {
64 switch (role) {
69 // AT-SPI also has LEVEL_BAR, which is arguably the better fit for a
70 // read-only gauge, but its enum number sits past the range this table
71 // has verified against the AT-SPI2 IDL, so `meter` keeps PROGRESS_BAR
72 // (unchanged behavior) until it can be checked against atspi headers.
95 }
96 return kRolePanel;
97}
98
105constexpr const char* role_to_atspi_role_name(View::AccessRole role) {
106 switch (role) {
107 case View::AccessRole::slider: return "slider";
108 case View::AccessRole::toggle: return "toggle button";
109 case View::AccessRole::label: return "label";
110 case View::AccessRole::group: return "panel";
111 case View::AccessRole::meter: return "progress bar";
112 case View::AccessRole::image: return "image";
113 case View::AccessRole::button: return "push button";
114 case View::AccessRole::link: return "link";
115 case View::AccessRole::checkbox: return "check box";
116 case View::AccessRole::radio: return "radio button";
117 case View::AccessRole::text_field: return "entry";
118 case View::AccessRole::combo_box: return "combo box";
119 case View::AccessRole::list: return "list";
120 case View::AccessRole::list_item: return "list item";
121 case View::AccessRole::table: return "table";
122 case View::AccessRole::row: return "table row";
123 case View::AccessRole::cell: return "table cell";
124 case View::AccessRole::tab: return "page tab";
125 case View::AccessRole::tab_list: return "page tab list";
126 case View::AccessRole::menu: return "menu";
127 case View::AccessRole::menu_item: return "menu item";
128 case View::AccessRole::progress_bar: return "progress bar";
129 case View::AccessRole::dialog: return "dialog";
130 case View::AccessRole::heading: return "heading";
131 case View::AccessRole::scroll_bar: return "scroll bar";
132 case View::AccessRole::none: return "panel";
133 }
134 return "panel";
135}
136
137// ── AtspiStateType values (subset) ───────────────────────────────────────────
138// AT-SPI's GetState returns a 64-bit state bitfield marshalled as two uint32
139// words (au of length 2: low word = states 0..31, high word = states 32..63).
140// These are the AtspiStateType bit INDICES Pulp sets today. Helpers below build
141// the two-word representation so the provider and the offline test agree.
142//
143// The numbers are the ORDINALS of AtspiStateType in at-spi2-core's
144// atspi-constants.h (ATSPI_STATE_INVALID = 0, ATSPI_STATE_ACTIVE = 1, ...,
145// ATSPI_STATE_LAST_DEFINED = 44) — the same enumeration Orca reads back off the
146// bus. kStateShowing / kStateVisible used to carry 26 / 28, which are
147// ATSPI_STATE_SINGLE_LINE and ATSPI_STATE_TRANSIENT: every Pulp accessible
148// reported itself as neither showing nor visible (and as a single-line,
149// transient object), which is exactly the state set Orca skips over. Locked by
150// the ordinal table in test/test_atspi_mapping.cpp.
151inline constexpr uint32_t kStateChecked = 4; // ATSPI_STATE_CHECKED
152inline constexpr uint32_t kStateEditable = 7; // ATSPI_STATE_EDITABLE
153inline constexpr uint32_t kStateEnabled = 8; // ATSPI_STATE_ENABLED
154inline constexpr uint32_t kStateFocusable = 11; // ATSPI_STATE_FOCUSABLE
155inline constexpr uint32_t kStateFocused = 12; // ATSPI_STATE_FOCUSED
156inline constexpr uint32_t kStatePressed = 20; // ATSPI_STATE_PRESSED
157inline constexpr uint32_t kStateSensitive = 24; // ATSPI_STATE_SENSITIVE
158inline constexpr uint32_t kStateShowing = 25; // ATSPI_STATE_SHOWING
159inline constexpr uint32_t kStateVisible = 30; // ATSPI_STATE_VISIBLE
160inline constexpr uint32_t kStateIndeterminate = 32; // ATSPI_STATE_INDETERMINATE
161inline constexpr uint32_t kStateCheckable = 41; // ATSPI_STATE_CHECKABLE
162
164struct StateSet {
165 uint32_t low = 0;
166 uint32_t high = 0;
167};
168
170constexpr void set_state(StateSet& s, uint32_t index) {
171 if (index < 32) {
172 s.low |= (1u << index);
173 } else {
174 s.high |= (1u << (index - 32));
175 }
176}
177
179constexpr bool has_state(const StateSet& s, uint32_t index) {
180 if (index < 32) return (s.low & (1u << index)) != 0;
181 return (s.high & (1u << (index - 32))) != 0;
182}
183
194
207 bool from_checked) {
208 if (state == AccessToggleState::unset) return s;
209 if (from_checked) set_state(s, kStateCheckable);
212 return s;
213 }
215 set_state(s, from_checked ? kStateChecked : kStatePressed);
216 return s;
217}
218
221constexpr StateSet with_editable(StateSet s, bool editable) {
222 if (editable) set_state(s, kStateEditable);
223 return s;
224}
225
226} // namespace pulp::view::atspi
AccessRole
Screen-reader role.
Definition view.hpp:988
@ list
Definition view.hpp:991
@ slider
Definition view.hpp:989
@ list_item
Definition view.hpp:991
@ link
Definition view.hpp:990
@ none
Definition view.hpp:989
@ toggle
Definition view.hpp:989
@ meter
Definition view.hpp:989
@ image
Definition view.hpp:989
@ menu_item
Definition view.hpp:992
@ cell
Definition view.hpp:991
@ menu
Definition view.hpp:992
@ dialog
Definition view.hpp:992
@ checkbox
Definition view.hpp:990
@ radio
Definition view.hpp:990
@ tab_list
Definition view.hpp:991
@ table
Definition view.hpp:991
@ scroll_bar
Definition view.hpp:992
@ button
Definition view.hpp:990
@ label
Definition view.hpp:989
@ group
Definition view.hpp:989
@ tab
Definition view.hpp:991
@ text_field
Definition view.hpp:990
@ progress_bar
Definition view.hpp:992
@ row
Definition view.hpp:991
@ heading
Definition view.hpp:992
@ combo_box
Definition view.hpp:990
SequencerStateChannel is the audio-safe transport for a plugin's structured NON-parameter state: the ...
Definition audio_device_manager.hpp:48
Definition atspi_mapping.hpp:27
constexpr uint32_t kRoleToggleButton
Definition atspi_mapping.hpp:52
constexpr uint32_t kRoleMenu
Definition atspi_mapping.hpp:40
constexpr uint32_t kRoleProgressBar
Definition atspi_mapping.hpp:45
constexpr uint32_t kStateCheckable
Definition atspi_mapping.hpp:161
constexpr uint32_t role_to_atspi_role(View::AccessRole role)
Map a Pulp AccessRole to the best-fit AtspiRole number.
Definition atspi_mapping.hpp:63
constexpr uint32_t kRolePageTabList
Definition atspi_mapping.hpp:43
constexpr uint32_t kRoleComboBox
Definition atspi_mapping.hpp:34
constexpr uint32_t kRoleLabel
Definition atspi_mapping.hpp:37
constexpr StateSet with_editable(StateSet s, bool editable)
EDITABLE — an editable text interface.
Definition atspi_mapping.hpp:221
constexpr uint32_t kRoleTableCell
Definition atspi_mapping.hpp:51
constexpr uint32_t kRoleRadioButton
Definition atspi_mapping.hpp:47
constexpr uint32_t kStateShowing
Definition atspi_mapping.hpp:158
constexpr StateSet with_toggle_state(StateSet s, AccessToggleState state, bool from_checked)
Fold a View's check/press state into an AT-SPI state set.
Definition atspi_mapping.hpp:206
constexpr uint32_t kRolePageTab
Definition atspi_mapping.hpp:42
constexpr uint32_t kStatePressed
Definition atspi_mapping.hpp:156
constexpr uint32_t kRoleEntry
Definition atspi_mapping.hpp:54
constexpr uint32_t kStateSensitive
Definition atspi_mapping.hpp:157
constexpr uint32_t kStateEditable
Definition atspi_mapping.hpp:152
constexpr uint32_t kStateVisible
Definition atspi_mapping.hpp:159
constexpr uint32_t kRoleTableRow
Definition atspi_mapping.hpp:57
constexpr uint32_t kStateFocusable
Definition atspi_mapping.hpp:154
constexpr uint32_t kRoleCheckBox
Definition atspi_mapping.hpp:33
constexpr uint32_t kRoleApplication
Definition atspi_mapping.hpp:53
constexpr uint32_t kRoleTable
Definition atspi_mapping.hpp:50
constexpr void set_state(StateSet &s, uint32_t index)
Set the bit for AtspiStateType index (0..63) in a two-word StateSet.
Definition atspi_mapping.hpp:170
constexpr uint32_t kRoleListItem
Definition atspi_mapping.hpp:39
constexpr uint32_t kRolePanel
Definition atspi_mapping.hpp:44
constexpr uint32_t kRoleInvalid
Definition atspi_mapping.hpp:58
constexpr uint32_t kRoleLink
Definition atspi_mapping.hpp:56
constexpr uint32_t kStateChecked
Definition atspi_mapping.hpp:151
constexpr uint32_t kRoleMenuItem
Definition atspi_mapping.hpp:41
constexpr uint32_t kRoleList
Definition atspi_mapping.hpp:38
constexpr uint32_t kRoleImage
Definition atspi_mapping.hpp:36
constexpr uint32_t kStateFocused
Definition atspi_mapping.hpp:155
constexpr uint32_t kRolePushButton
Definition atspi_mapping.hpp:46
constexpr StateSet default_states()
The default state for an enabled, visible, showing accessible object — the baseline every Pulp access...
Definition atspi_mapping.hpp:186
constexpr uint32_t kRoleSlider
Definition atspi_mapping.hpp:49
constexpr uint32_t kStateEnabled
Definition atspi_mapping.hpp:153
constexpr uint32_t kRoleDialog
Definition atspi_mapping.hpp:35
constexpr uint32_t kStateIndeterminate
Definition atspi_mapping.hpp:160
constexpr bool has_state(const StateSet &s, uint32_t index)
True if AtspiStateType index is set in s.
Definition atspi_mapping.hpp:179
constexpr uint32_t kRoleHeading
Definition atspi_mapping.hpp:55
constexpr const char * role_to_atspi_role_name(View::AccessRole role)
The AT-SPI role NAME for a Pulp AccessRole, returned by org.a11y.atspi.Accessible....
Definition atspi_mapping.hpp:105
constexpr uint32_t kRoleScrollBar
Definition atspi_mapping.hpp:48
@ s
Definition input_events.hpp:41
AccessToggleState
Tri-state check/press state, resolved from the ARIA slots a View carries (aria-checked first,...
Definition accessibility.hpp:132
@ mixed
Definition accessibility.hpp:132
@ unset
Definition accessibility.hpp:132
@ on
Definition accessibility.hpp:132
Two-word AT-SPI state bitfield (the au GetState returns: [low, high]).
Definition atspi_mapping.hpp:164
uint32_t low
Definition atspi_mapping.hpp:165
uint32_t high
Definition atspi_mapping.hpp:166