JFLib

plat/win_uia.rs (Windows)#

Source: lib/plat/win_uia.rs

win_uia -- (a11y.rs) the accessibility tree as UI Automation providers

  get_object(hwnd, pw, wp, lp)   (wndproc, WM_GETOBJECT) UiaRootObjectId: the provider of the
                                 window's root (UiaReturnRawElementProvider); assistive
                                 technology is there from now on (a11y::set_active)
  destroyed(hwnd)                (WM_DESTROY) UIA lets go of the window's providers
  changed(snapshot, changes)     the UI published a new tree: UIA events (only while clients
                                 listen: UiaClientsAreListening)
  uia_test_hwnd / uia_test_tree / uia_test_act / uia_test_listen / uia_test_events /
  uia_test_unlisten              (tests) a UI Automation client (IUIAutomation) that reads a
                                 window, acts and listens to events as a screen reader does

Every element is a small COM object of our own (Elem): the window's root (key 0) and one per
node, created on demand and identified by (platform window, node key); its methods answer
from a11y::current() on whatever thread UIA calls them (the provider is free-threaded: no
UseComThreading) and fail with UIA_E_ELEMENTNOTAVAILABLE once the node is gone.  Interfaces:
IRawElementProviderSimple, IRawElementProviderFragment, IRawElementProviderFragmentRoot (the
root; its host provider comes from UiaHostProviderFromHwnd) and the patterns Invoke (buttons,
links, menu items), Toggle (check boxes, switches), Value (text boxes; drop-downs read-only),
RangeValue (sliders; progress bars read-only), SelectionItem (radio buttons, tabs, list rows),
ExpandCollapse (drop-downs, menus), Text / Text2 (text boxes: ranges, the caret and the
selection; win_uia_text.rs).  Headings are Text elements with HeadingLevel1 .. 9 (and the
AriaRole "heading", AriaProperties "level=N").  Dialogs, switches and headings name their
control type themselves (LocalizedControlType: a11y::role_name, in the UI language), the
others leave it to UIA.  Actions become a11y::request.  Events: focus
changed, property changes (toggle state, selected, expand state, enabled, name, value, range
value, heading level), text selection changed (the caret moved: screen readers and Magnifier
follow it), text changed, structure changed (children invalidated).  UIAutomationCore.dll
and oleaut32.dll are loaded on the first WM_GETOBJECT.

Rich nodes (Node::sub and the further fields): control types of their own (Table, DataItem
rows and cells, HeaderItem headers, Tree / TreeItem, ToolBar, ToolTip, Separator, StatusBar,
Spinner, ScrollBar; landmarks are Groups with LandmarkType / LocalizedLandmarkType, the rest
name their type themselves), AriaRole / AriaProperties, FullDescription and HelpText,
IsRequiredForForm, IsDataValidForForm, PositionInSet / SizeOfSet / Level, LiveSetting,
IsDialog; the patterns Grid + Table (tables), GridItem + TableItem (cells and headers with a
place), ScrollItem (A_SCROLL), Selection (lists, tab strips, trees, multi-select containers),
ExpandCollapse (A_EXPAND), SelectionItem (A_SELECT: Select, AddToSelection,
RemoveFromSelection), Invoke (any other A_CLICK node), Value (a link: its address).  The further
actions become a11y::request_op.  Events: LiveRegionChanged (Change::Live), SystemAlert (an
alert appears), the notification event (UiaRaiseNotificationEvent, Windows 10 1709 and later)
for a11y::announce.
  • struct UiaTestElem (tests) one element as a UI Automation client sees it

    • name: String
    • control_type: i32
    • localized_type: String -- LocalizedControlType (UIA's own name of the control type unless the provider gives one)
    • depth: u32 -- below the window's element (1 = a child of it)
    • enabled: bool
    • focused: bool
    • toggle: i32 -- Toggle state (-1: no Toggle pattern)
    • value: Option<String> -- Value (None: no Value pattern)
    • range: Option<(f64, f64, f64)> -- RangeValue: value, minimum, maximum
    • selected: Option<bool> -- SelectionItem: selected
    • expand: i32 -- ExpandCollapse state (-1: no pattern)
    • heading: i32 -- HeadingLevel 1 ..= 9 (0: HeadingLevel_None)
    • rect: [i32; 4] -- the bounding rectangle: x, y, w, h (screen px)
    • aria_role: String -- AriaRole, AriaProperties ("" without)
    • aria_properties: String
    • landmark: i32 -- LandmarkType (0: none), LocalizedLandmarkType
    • landmark_name: String
    • desc: String -- FullDescription
    • pos_in_set: i32 -- PositionInSet, SizeOfSet, Level (0: none)
    • size_of_set: i32
    • level: i32
    • live: i32 -- LiveSetting (0: off), IsRequiredForForm, IsDataValidForForm, IsOffscreen
    • required: bool
    • valid: bool
    • offscreen: bool
    • cell: Option<[i32; 4]> -- GridItem: row, column, row span, column span (None: no GridItem pattern)
    • grid: Option<(i32, i32)> -- Grid: rows, columns (None: no Grid pattern)
    • col_headers: Vec<String> -- TableItem: the names of its column headers
    • scroll_item: bool -- the ScrollItem pattern is there; Selection: CanSelectMultiple (None: no pattern)
    • multiple: Option<bool>
  • enum UiaTestAct (tests) what uia_test_act does to an element

    • Invoke
    • Toggle
    • Select
    • Expand
    • Collapse
    • Focus
    • SetValue(String)
    • SetRange(f64)
    • ScrollIntoView -- ScrollItem.ScrollIntoView
    • AddToSelection -- SelectionItem.AddToSelection / RemoveFromSelection
    • RemoveFromSelection
  • fn uia_test_hwnd(pw: i32) -> isize (tests; UI thread) the HWND of platform window pw

  • fn uia_test_tree(hwnd: isize) -> Option<Vec<UiaTestElem>> (tests; not on the UI thread) the elements below window hwnd as a UI Automation client sees them (the raw view, depth first); None: no UI Automation

  • fn uia_test_act(hwnd: isize, name: &str, control_type: i32, a: UiaTestAct) -> bool (tests; not on the UI thread) act on the first element with this name and control type through its pattern -> the call succeeded

  • struct UiaTestCaret (tests) the caret of a text box as a UI Automation client sees it

    • active: bool -- GetCaretRange: the caret is active (the box has the keyboard focus)
    • rects: Vec<[f64; 4]> -- the caret range's bounding rectangles (screen px: x, y, w, h each)
    • text: String -- the text of the document range and of the selection
    • selected: String
  • fn uia_test_caret(hwnd: isize, name: &str) -> Option<UiaTestCaret> (tests; not on the UI thread) the caret of the first text box with this name through IUIAutomationTextPattern2: GetCaretRange and its rectangles, the document's text, the selection's text; None: no such box / no Text pattern

  • fn uia_test_caret_move(hwnd: isize, name: &str, chars: i32, extend: i32) -> bool (tests; not on the UI thread) move the caret of the first text box with this name: its caret range moved by chars characters (ITextRangeProvider::Move), then, with extend > 0, its end moved extend more characters, and Select() -> the calls succeeded

  • fn uia_test_system_caret(hwnd: isize) -> Option<(isize, [i32; 4])> (tests; any thread) the system caret of hwnd's thread as magnifiers read it (GetGUIThreadInfo): its window and its rectangle on the screen (left, top, right, bottom)

  • fn uia_test_listen(hwnd: isize) -> bool (tests; not on the UI thread) listen to focus changes everywhere, to the property changes below window hwnd (toggle state, selected, expand state, enabled, name, value, range value) and to its text events (the caret moved: TextSelectionChanged, TextChanged) -> registered

  • fn uia_test_events() -> Vec<String> (tests) the events since the last call: "focus:<name>", "prop:<id>:<name>=<value>", "event:<id>:<name>", "notify:<text>:<processing>"

  • fn uia_test_unlisten() (tests; the thread of uia_test_listen) remove the handlers

Source: docs/API.md in the JFLib repository.