plat/a11y.rs#
Source: lib/plat/a11y.rs
a11y -- the accessibility tree for screen readers and other assistive technology
The UI (ui/a11y.rs) turns the semantic records of every frame into a Snapshot and publishes
it here; the platform bridge serves it from threads of its own and hands the actions of the
assistive technology back to the UI thread:
start(app) start the bridge (once; the UI's first window frame)
active() -> bool assistive technology may be listening: publish snapshots
publish(Snapshot) the new tree; its differences to the last one become events
(focus, states, names, values, text, children, windows)
take() -> Vec<Request> the actions asked for since the last call (UI thread)
request(Request) (bridges, tests) queue an action and wake the UI thread
take_ops() / request_op(OpRequest) the same for the further actions (Op: scroll into
view, expand / collapse, increment / decrement, select items)
announce(win, text, politeness) (UI thread) a text for the screen reader to say; the next
publish hands it to the bridge (Change::Announce)
current() -> Option<Arc<Snapshot>> (bridges) the tree last published
set_translator(f) / role_name(role) / role_text(k) the names of the roles the bridges
give (UIA LocalizedControlType, AT-SPI GetLocalizedRoleName) in
the UI language: ROLE_TEXTS holds them in German, the keys of
the UI's translation (ui registers i18n::tr; plat cannot ask
ui itself); without one they stay German
Linux: AT-SPI2 on the accessibility bus (linux_atspi.rs). Windows: UI Automation providers
answering WM_GETOBJECT (win_uia.rs). macOS: NSAccessibility elements under each window's view,
turned on by the first question of an assistive technology (apple_mac_a11y.rs, VoiceOver). iOS:
UIAccessibility elements under the host's view while VoiceOver runs (apple_ios_a11y.rs). The
browser and Android (web_a11y.rs): the host keeps a mirror of the tree -- an ARIA shadow tree
in the DOM (web/a11y.js), virtual views of an
AccessibilityNodeProvider (android/GalleryAccessibility.java) -- fed with the differences
of every published tree (a11y_wire.rs: Mirror, the wire format); the host turns the mirror
on (active() follows it) and sends the actions back.
A Snapshot holds every shown window (WinTree) with its nodes in the order of the UI's
records; Node::parent gives the hierarchy (NONE: a top-level node of the window), link()
adds the sibling links and the key index the bridges navigate with. A node's key stays the
same from frame to frame while its widget does (the UI derives it from the widget id).
Rich nodes (the records of a web page's tree, ui's Sem setters): Node::sub says what a node
is more exactly than its role (a table, a cell, a landmark, a tree item ...); a bridge that
knows Sub maps it to a role of its own, one that does not (yet) shows Node::role, the nearest
basic role -- so a new Sub never breaks a bridge. Further fields: a description, a link's
address, the place in a set, a level, a cell's place and a table's size, a live region's
politeness; states S_REQUIRED .. S_SELECTABLE; actions A_EXPAND .. A_SELECT, which come back
as Op requests (take_ops).
/// no node (Node::parent of a top-level node, WinTree::focus without a focused node)
NONE: u32 = u32::MAX
enum Rolewhat a node isGroup-- a container without a meaning of its own (a titled box)LabelButtonCheckBoxRadioSwitch-- an on / off switchSliderProgressTextBoxLinkList-- a selectable list and its rowsListItemMenuBar-- the menu bar, a menu (a menu bar entry or a popup menu) and its entriesMenuMenuItemTabList-- the strip of tabs and one tabTabCombo-- a drop-down list (Node::text: the current choice)ImageCanvas-- a drawing surface (charts, the app's own views)DialogHeading-- a heading of a document or section (Node::value: its level, level())
enum SubWhat a node is more exactly than its role (Node::sub; the wire format sends it as its number in declaration order). A bridge that knows it maps it to a role of its own; the others show Node::role, the nearest basic role, whichrole()gives.None-- nothing more than the roleTable-- a table or grid (role Group; Node::grid: its rows and columns), one of its rows (Group)RowCell-- a cell (role Label; Node::cell: its place), a column header, a row header (Label)ColumnHeaderRowHeaderBanner-- the landmarks of a page (role Group): its banner, its main content, a navigation, complementary content, the content information (a footer), a search, a form, a named regionMainNavigationComplementaryContentInfoSearchFormRegionTree-- a tree (role List) and its items (ListItem; Node::level(): its depth, 1 the top)TreeItemRadioGroup-- a group of radio buttons, a tool bar (Group), a tooltip (Label), a separator (Group)ToolbarTooltipSeparatorAlert-- live regions (role Label): an alert (assertive), a status line and a log (polite)StatusLogMeter-- a meter (role Progress), a spin button and a scroll bar (Slider)SpinButtonScrollBarArticle-- an article, a figure (Group)Figure
/// the number of Sub values (SUB_TEXTS)
SUB_COUNT: usize = 28
impl Sub
fn role(self) -> Option<Role>the nearest basic role (what a bridge that does not know Sub shows; None: no rule)fn landmark(self) -> boola landmark (Banner ..= Region)fn aria(self) -> &'static strits WAI-ARIA role ("" for None)
/// Node::state: the keyboard focus is on the node
S_FOCUSED: u32 = 1
/// it can take the keyboard focus
S_FOCUSABLE: u32 = 2
/// greyed out: no input, no actions
S_DISABLED: u32 = 4
/// a check box, radio button or switch that is on
S_CHECKED: u32 = 8
/// a check box in the third state ("some")
S_MIXED: u32 = 16
/// a selected list row or tab
S_SELECTED: u32 = 32
/// an open drop-down, menu or dialog
S_EXPANDED: u32 = 64
/// a button shown pressed (a toggle or tool button that is on)
S_PRESSED: u32 = 128
/// a text box with several lines
S_MULTILINE: u32 = 256
/// a password box (its text: one dot per character)
S_PROTECTED: u32 = 512
/// a text box that can be read and selected but not edited
S_READONLY: u32 = 1024
/// a field that must be filled in
S_REQUIRED: u32 = 1 << 11
/// a field whose content is not valid
S_INVALID: u32 = 1 << 12
/// its content is being changed (a live region says nothing meanwhile)
S_BUSY: u32 = 1 << 13
/// it opens a popup (a menu, a list, a dialog)
S_HASPOPUP: u32 = 1 << 14
/// a link to an address that was visited
S_VISITED: u32 = 1 << 15
/// a modal dialog (nothing else of the window takes input)
S_MODAL: u32 = 1 << 16
/// a list, tree or table that allows several selected items
S_MULTISELECT: u32 = 1 << 17
/// it can be expanded and is closed now (S_EXPANDED: open)
S_COLLAPSED: u32 = 1 << 18
/// outside the visible area (scrolled away, clipped): browse modes reach it, the pointer does not
S_OFFSCREEN: u32 = 1 << 19
/// it can be selected (rows and cells of a grid; list rows and tabs are anyway)
S_SELECTABLE: u32 = 1 << 20
/// Node::actions: press, toggle, select, open / close -- what a click on the widget does
A_CLICK: u32 = 1
/// give it the keyboard focus
A_FOCUS: u32 = 2
/// set a number (sliders)
A_VALUE: u32 = 4
/// set the text (text boxes)
A_TEXT: u32 = 8
/// expand and collapse it (Op::Expand / Op::Collapse)
A_EXPAND: u32 = 16
/// one step up or down (Op::Increment / Op::Decrement)
A_STEP: u32 = 32
/// scroll it into view (Op::ScrollIntoView)
A_SCROLL: u32 = 64
/// select it (Op::SelectItem; in a S_MULTISELECT container also Op::AddToSelection /
/// Op::RemoveFromSelection)
A_SELECT: u32 = 128
/// Node::live, Change::Announce: said when the person is idle
LIVE_POLITE: u8 = 1
/// at once, interrupting
LIVE_ASSERTIVE: u8 = 2
struct Nodeone element of a windowkey: u64-- identity within its window, the same from frame to frame (never 0)role: Rolestate: u32-- S_*actions: u32-- A_*rect: [i32; 4]-- x, y, w, h: physical px of the window's client areaname: Stringtext: String-- text boxes: their text; combo boxes: the current choice; else emptycaret: i32-- text boxes: the caret in characters (-1 unknown)anchor: i32-- text boxes: the other end of the selection in characters (== caret: nothing selected)caret_rect: [i32; 4]-- text boxes: the caret's rectangle, physical px of the client area (w, h 0: unknown) -- screen magnifiers follow it (char_rect)value: f64-- sliders and progress bars: value in min ..= max (value < min: progress unknown); headings: the level (1 ..= 9)min: f64max: f64step: f64parent: u32-- index of the parent node in WinTree::nodes (NONE: a top-level node)first: u32-- (link) first child, next and previous sibling (NONE: none), number of children, position among the siblingsnext: u32prev: u32count: u32index: u32sub: Sub-- what it is more exactly than its role (Sub::None: the role says it)desc: String-- a description beside the name (a hint, a page's aria-describedby); empty: noneurl: String-- a link's address; empty: noneset: [u32; 2]-- its position in its set (1-based) and the set's size: list and tree items, tabs, radio buttons, rows (0: unknown)item_level: u32-- the level of a tree item, list item or row (1 the top; 0: none); a heading's is its value (level() gives both)cell: [u32; 4]-- cells and headers: row, column (0-based), row span, column span (spans 0: no place)grid: [u32; 2]-- tables and grids: the number of rows and columns (0: unknown)live: u8-- a live region's root: LIVE_POLITE / LIVE_ASSERTIVE (0: none) -- changes inside it are said
struct WinTreeone shown windowwin: u8-- the UI's window index (0 = the main window)pw: i32-- its platform window (plat::win_*; -1 none)title: Stringdialog: bool-- a dialog window (modal)active: bool-- it has the keyboardorigin: [i32; 2]-- screen position of the client area (px; 0, 0 when the platform does not tell)size: [i32; 2]-- client size (px)nodes: Vec<Node>focus: u32-- the focused node (NONE: the window itself)first: u32-- (link) the first top-level node, their numbercount: u32keys: Vec<(u64, u32)>-- (link) key -> node index, sorted by key
struct Snapshotthe whole applicationapp: String-- the application's namewins: Vec<WinTree>
impl Node
fn text_str(&self) -> &strthe text the text interfaces see: text boxes and drop-downs their text, labels their namefn level(&self) -> u32a heading's level 1 ..= 9; a tree item's, list item's or row's level (item_level; 0: none)fn cell_place(&self) -> Option<[u32; 4]>a cell's place: row, column (0-based), row span, column span (None: no place)fn role_text(&self) -> &'static strwhat the bridges call the node, in the UI language: its Sub's name, else its role'sfn selection(&self) -> (i32, i32)the selection of a text box: (start, end) in characters, start == end at the caretfn char_rect(&self, k: i32) -> [i32; 4]the rectangle of character k (client px): exact at the caret of a focused text box (caret_rect), around it estimated from the line height (lines after '\n', columns of about half a line height); without a caret the characters share the node's widthfn offset_at(&self, x: i32, y: i32) -> i32the character offset nearest to client point x, y (char_rect's inverse; -1: outside)
impl WinTree
fn link(&mut self)fill the links (first / next / prev / count / index, the key index) from the parentsfn find(&self, key: u64) -> Option<usize>the node with this keyfn children(&self, parent: u32) -> impl Iterator<Item = usize> + '_the children of a node (NONE: the top-level nodes), in orderfn child(&self, parent: u32, k: usize) -> Option<usize>the child number k of a node (NONE: of the window)fn at_point(&self, x: i32, y: i32) -> Option<usize>the deepest node at a client point (px): among siblings the last one wins (drawn on top); nodes outside the visible area (S_OFFSCREEN) are not hitfn on_screen(&self, n: &Node) -> boolthe node lies (partly) inside the window's client area (else it is scrolled away) and is not marked S_OFFSCREENfn live_root(&self, k: usize) -> Option<usize>the nearest ancestor of node k (or k itself) that is a live region's root (Node::live)fn subtree_end(&self, k: usize) -> usizethe nodes below node k (its subtree without itself) are k + 1 .. the returned index (the nodes are in tree order: parents first, a subtree in one piece)fn ancestor(&self, a: usize, b: usize) -> boolnode a is an ancestor of node bfn up_to(&self, k: usize, sub: Sub) -> Option<usize>the nearest ancestor of node k with this Sub (a cell's table)fn grid_size(&self, table: usize) -> (u32, u32)a table's number of rows and columns: Node::grid, else counted from its cells' places (and its rows)fn cell_at(&self, table: usize, row: u32, col: u32) -> Option<usize>the cell of a table at row, column (one that spans it too)fn headers_of(&self, cell: usize, rows: bool) -> Vec<usize>the headers of a cell: column headers over its columns (rows false), or row headers in its rows (rows true), of the same tablefn headers(&self, table: usize, rows: bool) -> Vec<usize>the headers of a table: its column headers (rows false) or row headersfn focus_key(&self) -> u64the focused node's key (0: the window itself)
impl Snapshot
fn win(&self, win: u8) -> Option<&WinTree>the tree of the UI's window index winfn pw(&self, pw: i32) -> Option<&WinTree>the tree of platform window pwenum Changewhat changed between two snapshots (window: the UI's window index; key 0: the window)Window(u8, bool)-- a window appeared (true) or went awayActivate(u8, bool)-- a window got (true) or lost the keyboardFocus(u8, u64)-- the keyboard focus moved to this node (in the active window)State(u8, u64, u32, bool)-- state bit S_* of a node went on (true) or offName(u8, u64)Value(u8, u64)-- the number of a slider / progress bar, the level of a headingText(u8, u64, String)-- the text of a text box / combo box (the old text)Caret(u8, u64, i32)-- the caret of a text box (characters)Added(u8, u64, u64)-- a node (with its subtree) appeared: parent key (0: the window), its key; in the order of the new tree, so its index there is right when the event arrivesRemoved(u8, u64, u64, u32)-- a node (with its subtree) went away: parent key (0: the window), its key, its index there before; the last index of a parent firstLive(u8, u64)-- something inside a live region changed (a name, a text, a value, nodes that came or went): the region's root (Node::live says how urgently)Announce(u8, String, u8)-- a text for the screen reader to say (announce): window, text, LIVE_POLITE / LIVE_ASSERTIVE
fn diff(old: &Snapshot, new: &Snapshot) -> Vec<Change>the changes from old to newenum Actan action of the assistive technologyClick-- press, toggle, select, open / close: what a click does (A_CLICK)Focus-- the keyboard focus (A_FOCUS)Value(f64)-- a new number (A_VALUE)Text(String)-- a new text (A_TEXT)Select(i32, i32)-- (text boxes, A_FOCUS) the selection from anchor to caret in characters (equal: the caret alone); a box without the focus gets it first
struct Requestan action for a nodewin: u8-- the UI's window indexkey: u64act: Act
enum Opa further action of the assistive technology (OpRequest; the node's Node::actions allow it)ScrollIntoView-- scroll the node into view (A_SCROLL)Expand-- open / close it (A_EXPAND)CollapseIncrement-- one step up / down (A_STEP)DecrementSelectItem-- select it alone; add it to / take it out of the selection (A_SELECT)AddToSelectionRemoveFromSelection
struct OpRequesta further action for a node (request_op)win: u8-- the UI's window indexkey: u64op: Op
fn start(app: &str)start the platform bridge (once): Linux connects to the accessibility bus when assistive technology is enabled (jfgui_A11Y=1 forces it, jfgui_A11Y=0 or NO_AT_BRIDGE=1 turn it off); Windows answers WM_GETOBJECT from now on, macOS the accessibility questions of its views; the browser and Android hosts turn their mirror on themselves (jfgui_a11y), jfgui_A11Y=0 keeps it off there toofn active() -> boolassistive technology may be listening (the UI publishes snapshots only then); on Windows it turns false again 10 s after the last question of a UI Automation client unless a screen reader (SPI_GETSCREENREADER) or Magnifier listens for events, and true with the next question (win_uia.rs idle)fn check_due() -> Option<u64>when (time_us) active() wants to be asked again although nothing happens: the platform's fallback that notices a client is gone (Windows: at most every 2 s while active); None: never. The UI's window loop waits at most until then and asks, so an idle app learns it too (UIC_A11Y)fn epoch() -> u32a number that changes whenever a bridge turned on or off (set_active): the UI publishes a tree equal to the last one again only after it changed (an unchanged frame publishes nothing)fn current() -> Option<Arc<Snapshot>>the tree last publishedfn publish(mut s: Snapshot)publish a new tree: the links are filled, the differences to the last tree go to the bridgefn request(r: Request)(bridges, tests) queue an action and wake the UI thread (the oldest is dropped when 64 wait)fn take() -> Vec<Request>the actions asked for since the last call, oldest first (UI thread)fn request_op(r: OpRequest)(bridges, tests) queue a further action (Op) and wake the UI thread (the oldest is dropped when 64 wait)fn take_ops() -> Vec<OpRequest>the further actions asked for since the last call, oldest first (UI thread)fn announce(win: u8, text: &str, politeness: u8)(UI thread) a text for the screen reader to say in window win: LIVE_POLITE when the person is idle, LIVE_ASSERTIVE at once. The next publish hands it to the bridge (Change::Announce: UI Automation's notification event, AT-SPI2's announcement, the browser's live region); nothing is kept while no assistive technology listens, at most 16 wait.
the texts of the bridges
/// what the bridges call the roles (UIA LocalizedControlType, AT-SPI GetLocalizedRoleName) in
/// Role order, then a window (AT-SPI frame), the application and an unknown role: in German,
/// the keys of their translations (set_translator; ui's i18n::tr has them in its languages)
ROLE_TEXTS: [&str; 25] = [ "Bereich", "Bezeichnung", "Schaltfläche", "Kontrollkäst ...
/// ROLE_TEXTS: a window
ROLE_WINDOW: usize = 22
/// ROLE_TEXTS: the application
ROLE_APP: usize = 23
/// ROLE_TEXTS: an unknown role
ROLE_UNKNOWN: usize = 24
fn set_translator(f: fn(&'static str) -> &'static str)the translation of the bridges' texts into the UI language (ui sets i18n::tr with its first frame; it reads the language each time, so the texts follow a change of it); without one they stay Germanfn role_text(k: usize) -> &'static strROLE_TEXTS[k] in the UI languagefn role_name(r: Role) -> &'static strwhat the bridges call a role, in the UI language
/// what the bridges call the Sub values (UIA LocalizedControlType and LocalizedLandmarkType,
/// AT-SPI GetLocalizedRoleName) in Sub order, in German: the keys of their translations as for
/// ROLE_TEXTS (Sub::None has none)
SUB_TEXTS: [&str; SUB_COUNT] = [ "", "Tabelle", "Tabellenzeile", "Tabellenzelle", "Spalt ...
fn sub_name(s: Sub) -> &'static strwhat the bridges call a Sub, in the UI language ("" for Sub::None)