plat/apple_mac_a11y.rs (Apple)#
Source: lib/plat/apple_mac_a11y.rs
apple_mac_a11y -- (a11y.rs) the accessibility tree as NSAccessibility elements (VoiceOver on the
Mac, docs/VOICEOVER.md)
start(app) the bridge may turn on (a11y::start): the first question of an
assistive technology makes a11y::active() true
view_methods() (apple_mac.rs) JFView's accessibility: its children (the top-level
nodes of its window), the focused element, the hit test; a view
itself stays ignored, so the window holds the nodes
changed(snapshot, changes) the UI published a new tree: notifications (NSAccessibilityPost-
Notification), the elements of nodes that went away are destroyed
forget(pw) (win_destroy) the elements of a window go
ax_test_tree / ax_test_act / ax_test_listen / ax_test_events (tests) read and drive the
tree through AppKit's own entry points on the main thread
(accessibilityAttributeValue: and friends, which serve VoiceOver's
requests), from any thread
Every node is an object of our class JFAXElement (a subclass of NSAccessibilityElement), made on
demand and kept while its node exists, so that VoiceOver sees the same element from frame to
frame; its instance variable is a slot of the registry, which names (platform window, node key).
The methods answer from a11y::current() on the main thread, where AppKit asks them and the UI
runs (never from a frame being built); a node that is gone answers nothing. Which attributes
and actions an element has follows its role (isAccessibilitySelectorAllowed:). Rectangles are
the node's client pixels / the window's scale, converted to screen points by the view. Actions
become a11y::request. Popups (menus, lists) are panels of their own whose nodes stay in their
owner's tree (their rectangles lie over the panel); a popup's view answers hit tests with them.
Roles (role / subrole; where the name goes: T title, L label (AXDescription), V value):
Label AXStaticText V; Heading AXHeading T, value its level; Button AXButton T; CheckBox
AXCheckBox T, value 0 / 1 / 2 (mixed); Radio AXRadioButton T, value 0 / 1; Switch AXCheckBox /
AXSwitch T, value 0 / 1; Slider AXSlider L, value, min, max, increment / decrement (5 % of the
range, as Android's scrolling); Progress AXProgressIndicator L, value, min, max; TextBox
AXTextField / AXTextArea (multi-line) / AXSecureTextField (password) L, value the text; Link
AXLink T; List AXList L; ListItem AXStaticText V, selected; MenuBar AXMenuBar; Menu a menu bar
entry AXMenuBarItem T, a popup menu AXMenu; MenuItem AXMenuItem T; TabList AXTabGroup L; Tab
AXRadioButton / AXTabButton T, value 0 / 1; Combo AXPopUpButton L, value the choice, expanded;
Image AXImage L; Group, Canvas AXGroup L; Dialog AXGroup T with the role description "Dialog"
(a::role_name, the UI language; a dialog window is an NSWindow of its own anyway).
struct AxTestEleman element as VoiceOver reads it (AppKit's attributes)depth: u32role: Stringsubrole: Stringrole_desc: Stringtitle: Stringlabel: String-- AXDescriptionvalue: String-- AXValue as text (numbers: their description, "1", "75")ident: Stringenabled: boolfocused: boolselected: boolexpanded: boolframe: [f64; 4]-- AXPosition (top left of the primary screen) and AXSize, pointsactions: Vec<String>attrs: Vec<String>value_settable: bool
impl AxTestElem
fn name(&self) -> &strthe name VoiceOver reads: title, else description, else valueenum AxTestActan action of a testPressIncrementDecrementNumber(f64)-- AXValue := a number (sliders)Text(String)-- AXValue := a text (text boxes)Focus-- AXFocused := YESSelect-- AXSelected := YESRange(usize, usize)-- AXSelectedTextRange := location, length (UTF-16)
enum AxTestTexta question of a test about a text box's text (the answers: numbers as text, ranges "location,length", rectangles "x,y,w,h" in points from the top left of the primary screen)Count-- AXNumberOfCharactersSelected-- AXSelectedTextSelRange-- AXSelectedTextRangeLine-- AXInsertionPointLineNumberStringFor(usize, usize)-- AXStringForRange (location, length)AttrFor(usize, usize)-- AXAttributedStringForRange: its stringFrameFor(usize, usize)-- AXBoundsForRangeRangeAt(f64, f64)-- AXRangeForPosition (a point as AXPosition)RangeFor(usize)-- AXRangeForIndexLineFor(usize)-- AXLineForIndexRangeForLine(usize)-- AXRangeForLine
fn ax_test_tree(pw: i32) -> Option<Vec<AxTestElem>>(tests, any thread) the elements of platform window pw as VoiceOver reads themfn ax_test_act(pw: i32, role: &str, name: &str, a: AxTestAct) -> bool(tests, any thread) act on the element with this role and name (AxTestElem::name) as VoiceOver does: false when there is none or AppKit does not offer the action (disabled, not settable)fn ax_test_text(pw: i32, role: &str, name: &str, q: AxTestText) -> Option<String>(tests, any thread) ask the element with this role and name about its text as VoiceOver does (None: no such element, or it does not offer the attribute)fn ax_test_window(pw: i32) -> ([i32; 4], i32, bool)(tests, any thread) window pw on the main thread, where its state lives (UiOnly): its client area in px of the screen, its dpi and whether it is the key windowfn ax_test_focused() -> Option<(String, String)>(tests, any thread) the focused element of the application as VoiceOver asks it (role, name)fn ax_test_hit(x: f64, y: f64) -> Option<(String, String)>(tests, any thread) the element at screen point x, y (points from the top left of the primary screen, as AXPosition) as VoiceOver's pointer finds it: role, namefn ax_test_listen(on: bool)(tests) note the notifications the bridge posts from now on (false: stop)fn ax_test_events() -> Vec<String>(tests) the notifications noted since the last call: "AXValueChanged:Name"