ui/a11y.rs#
Source: lib/ui/a11y.rs
a11y -- the semantic records as the platform's accessibility tree (plat::a11y): after the
passes of a frame the records of every shown window become a snapshot that screen readers
read through AT-SPI2 (Linux), UI Automation (Windows), the browser's ARIA shadow tree or
Android's virtual views; their actions come back as requests that the next passes carry
out through the widgets' own behaviour.
a11y_tree() -> plat::a11y::Snapshot the tree as assistive technology gets it
Runtime (runtime.rs): a11y_frame after the passes (publishes while plat::a11y::active();
starts the bridge with the first window frame and hands it i18n::tr for the names of the
roles: plat::a11y::set_translator), a11y_poll on E_WAKE (takes the requests).
Widgets: behave asks a11y_click(id) (a pending click, toggle, select or open acts like
Space on the focused widget: EV_ACT); the sliders ask a11y_value(id), the text boxes
a11y_text(id) for a new value (both public for widgets of an app's own). A click no widget took in its passes becomes a pointer
click where the press reaches the record (a11y_aim), after the scroll views brought it into view; there is
none when the middle lies on something else.
The tree: every record of a window becomes a node in the record order -- roles from the
kinds (K_*), states from SS_* (a check box with value 2 is mixed), a heading's level from its
value (K_HEADING: Node::value, clamped to 1 ..= 9). Left out: title bars, empty texts,
records without area, boxes without a label (a box with tab records inside is the tab
strip). Containers are lists, dialogs, titled boxes and tab strips: a node's parent is the
smallest one on its layer whose rectangle holds the node's centre -- inside a scoped record
(SEM_SCOPE: a window of a window area, desk.rs) only one it holds, else itself, and scoped
records hold nothing by their place (overlapping windows are siblings). Menu bar entries
next to each other get a menu bar; the rows of a popup (menus, drop-downs) a menu or list that
hangs below the open record that opened it. Names: the label; text boxes, drop-downs (their label
is the text / the choice), sliders, progress bars and lists without one take the text or
heading record right before them (to the left, or above and aligned). The focus of a list
or tab strip is passed on to its selected row / tab.
Rich records (section 19 of the guide; a web page's accessibility tree): the kinds K_TABLE ..=
K_FIGURE become nodes with a Sub (Node::role their nearest basic role); a record's SemAx (its
setters: id64, parent, name, desc, url, value_text, states, set_pos, level, cell, span, grid,
live, range) fills the further fields of its node. A record with an id64 is keyed by it
(RICH | id), takes its name from nothing but its label / name, and every request for it --
focus, click, value, text, selection, scroll into view, expand / collapse, increment /
decrement, select items -- goes to the app (ui.a11y_request_take) instead of the widgets. A
record with a parent hangs under the record of that id64 (else that widget id) of its window
in the same frame; a left out record passes its children on to its own parent, an unknown
parent or a loop leaves the record to its rectangle.
ui.announce(text, LIVE_*) a text for the screen reader (the next frame publishes it)
ui.a11y_request_take() the next request for a record with an id64
ui.a11y_active() a client listens: publish what only it needs then
struct A11yRequestA screen reader's request for a record with an id64 (ui.a11y_request_take).win: u32-- the id of the record's window: 0 the main window, else the id its window_begin gotid: u64-- the record's id64action: A11yAction
impl A11yRequest
fn new(win: u32, id: u64, action: A11yAction) -> A11yRequestA request asui.a11y_request_takehands it out (window id, the record's id64, the action): for an app's tests of its own handling, the struct beingnon_exhaustive.enum A11yActionWhat a screen reader asks of a record (A11yRequest::action).Focus-- give it the keyboard focusClick-- its default action: press, follow, toggle, select, openScrollIntoView-- scroll it into viewExpand-- open / close it (AS_COLLAPSED, SS_OPEN)CollapseIncrement-- one step up / down (spin buttons, sliders, scroll bars)DecrementSetValue(f64)-- a new number (sliders, spin buttons, scroll bars)SetText(String)-- a new text (text boxes)SelectText(u32, u32)-- the selection of a text box: anchor, caret in characters (equal: the caret alone)Select-- select it alone (a row, a tab, a tree item)AddToSelection-- add it to / take it out of the selection (AS_MULTISELECT containers)RemoveFromSelection
impl Ui
fn a11y_tree(&self) -> SnapshotThe accessibility tree of the last pass as assistive technology gets it (screen readers through AT-SPI2 / UI Automation): every shown window with its nodes (roles, names, states, values, rectangles), built from the semantic records (see sem()).fn a11y_tree_key(&self) -> u64(benchmarks: plattest --test a11y-cost) the key a11y_frame compares with the tree published last: equal keys, equal treesfn a11y_request_take(&mut self) -> Option<A11yRequest>The next request of a screen reader for a record with an id64 (Sem::id64), oldest first: focus, click, scroll into view, expand / collapse, increment / decrement, a value, a text, a text selection, select items. Take them in every frame and carry them out (a web view hands them to its engine); at most 64 wait. Requests for the other records go to their widgets as before (EV_ACT,a11y_value,a11y_text).fn announce(&mut self, text: &str, politeness: u32)Have the screen reader saytext:LIVE_POLITEwhen the person is idle,LIVE_ASSERTIVEat once (a web page's live region announcement, "Saved"). It goes out with this frame's tree: UI Automation's notification event, AT-SPI2's announcement, the browser's live region. Nothing is said (or kept) while no assistive technology listens; at most 16 per frame.fn a11y_active(&self) -> boolA screen reader (or another client of the accessibility tree) listens: the library builds the tree from the records only then. Records that only it needs -- the content of a page out of view (AS_OFFSCREEN) -- are best published only while this is true; it turns true with a frame of its own when a client comes, and the app gets the commandUIC_A11Y(arg- then and when it leaves (arg 0; Windows: 10 s after its last question unless a screen reader listens), also while nothing else happens. Always false in headless runs.
fn a11y_value(&mut self, id: u32) -> Option<i32>A value a screen reader set for slider-like widgetid(its record's value scale), taken once: the built-in sliders apply it themselves; a widget of its own applies it like keyboard input (clamped) in the pass it is built.fn a11y_text(&mut self, id: u32) -> Option<String>A text a screen reader set for text widgetid, taken once (the built-in text boxes apply it themselves).
impl Sem
fn id64(&mut self, id: u64) -> &mut SemIts own 64-bit id (below 2^62; a web page's node id). The node keeps it from frame to frame, other records name it as their parent, and every request of a screen reader for it comes back to the app (ui.a11y_request_take) instead of going to a widget.fn parent(&mut self, id: u64) -> &mut SemThe record it hangs under: the one with this id64 (else this widget id) in the same frame and window -- the tree follows it, not the rectangles. A parent that is left out (a box without a label) passes it on to its own parent; an unknown one leaves it to its rectangle.fn name(&mut self, name: &str) -> &mut SemIts name when the label is something else: a text box's or drop-down's label is its text, so.name("Suche")names it.fn desc(&mut self, text: &str) -> &mut SemA description beside the name (a hint; a page's aria-describedby).fn url(&mut self, url: &str) -> &mut SemA link's address.fn value_text(&mut self, text: &str) -> &mut SemThe text a screen reader says for a slider's, meter's or spin button's value ("Montag").fn states(&mut self, states: u32) -> &mut SemFurther states (AS_*: required, invalid, busy, has a popup, visited, modal, multi-select, collapsed, off screen, focusable, clickable, selectable, read-only, multi-line, password), added to those it has.fn set_pos(&mut self, pos: u32, size: u32) -> &mut SemIts position in its set (1-based) and the set's size: list and tree items, tabs, rows.fn level(&mut self, level: u32) -> &mut SemThe level of a heading (1 ..= 9, in place of the value), a tree item, list item or row (1 the top).fn cell(&mut self, row: u32, col: u32) -> &mut SemA cell's or header's place in its table: row, column (0-based).fn span(&mut self, rows: u32, cols: u32) -> &mut SemThe rows and columns a cell spans (1, 1 without).fn grid(&mut self, rows: u32, cols: u32) -> &mut SemA table's number of rows and columns (without: counted from its cells).fn live(&mut self, live: u32) -> &mut SemHow it speaks as a live region:LIVE_POLITE,LIVE_ASSERTIVE,LIVE_OFF(0: as its kind says -- K_ALERT assertive, K_STATUS and K_LOG polite).fn range(&mut self, value: f64, min: f64, max: f64, step: f64) -> &mut SemA value with fractions in place ofvalue/min/max(sliders, meters, spin buttons, scroll bars, progress bars; a value below min: unknown progress), and the step of a screen reader's increment.fn text_sel(&mut self, anchor: u32, caret: u32) -> &mut SemA focused text box's selection in characters: anchor, caret (equal: the caret alone) -- a page's own field; the built-in text boxes report theirs themselves.