a11y
import "github.com/tangoui/tango/ui/a11y"本页由
site/tools/apigen从源码注释生成(按 darwin 构建标签选文件),请勿手改。
Package a11y defines the platform-neutral accessibility (semantics) tree produced by the Tango UI runner.
Every frame in which a host asks for it (ui.AccessibilityHost), the runner derives a Tree from the widget tree: one Node per semantic element (a button, a text field, a table cell, a dialog …) with a stable ID, a Role, an accessible name, value, states, bounds and the actions a screen reader may perform. Nodes that carry no meaning (layout rows, decorations) are flattened away. The runner compares the new tree with the previous one and reports only the IDs that were added, changed or removed, so a platform bridge (NSAccessibility, UI Automation, AT-SPI, UIAccessibility, AccessibilityNodeInfo) can update its proxy objects incrementally.
The package has no dependency on the ui package; bridges only need the Tree, the Node fields and the role mapping in Mappings (documented in docs/accessibility.md).
变量
var Mappings = map[Role]Platform{
RoleWindow: {"AXGroup", "Pane", "PANEL", "container", "android.view.View"},
RoleGroup: {"AXGroup", "Group", "PANEL", "container", "android.view.ViewGroup"},
RoleText: {"AXStaticText", "Text", "STATIC", "staticText", "android.widget.TextView"},
RoleHeading: {"AXHeading", "Text", "HEADING", "header", "android.widget.TextView"},
RoleParagraph: {"AXStaticText", "Text", "PARAGRAPH", "staticText", "android.widget.TextView"},
RoleLink: {"AXLink", "Hyperlink", "LINK", "link", "android.widget.TextView"},
RoleButton: {"AXButton", "Button", "PUSH_BUTTON", "button", "android.widget.Button"},
RoleCheckbox: {"AXCheckBox", "CheckBox", "CHECK_BOX", "button+toggleButton", "android.widget.CheckBox"},
RoleRadio: {"AXRadioButton", "RadioButton", "RADIO_BUTTON", "button", "android.widget.RadioButton"},
RoleRadioGroup: {"AXRadioGroup", "Group", "GROUPING", "container", "android.widget.RadioGroup"},
RoleSwitch: {"AXCheckBox/AXSwitch", "Button", "TOGGLE_BUTTON", "button+toggleButton", "android.widget.Switch"},
RoleTextbox: {"AXTextField", "Edit", "ENTRY", "none (UITextInput)", "android.widget.EditText"},
RoleSearchbox: {"AXTextField/AXSearchField", "Edit", "ENTRY", "searchField", "android.widget.EditText"},
RoleSpinButton: {"AXIncrementor", "Spinner", "SPIN_BUTTON", "adjustable", "android.widget.EditText"},
RoleCombobox: {"AXComboBox", "ComboBox", "COMBO_BOX", "button", "android.widget.Spinner"},
RoleListbox: {"AXList", "List", "LIST_BOX", "container", "android.widget.ListView"},
RoleOption: {"AXStaticText", "ListItem", "LIST_ITEM", "button", "android.widget.CheckedTextView"},
RoleMenu: {"AXMenu", "Menu", "MENU", "container", "android.widget.ListView"},
RoleMenuBar: {"AXMenuBar", "MenuBar", "MENU_BAR", "container", "android.view.ViewGroup"},
RoleMenuItem: {"AXMenuItem", "MenuItem", "MENU_ITEM", "button", "android.view.View"},
RoleMenuItemRadio: {"AXMenuItem", "MenuItem", "RADIO_MENU_ITEM", "button", "android.view.View"},
RoleTab: {"AXRadioButton/AXTabButton", "TabItem", "PAGE_TAB", "button", "android.view.View"},
RoleTabList: {"AXTabGroup", "Tab", "PAGE_TAB_LIST", "tabBar", "android.widget.TabWidget"},
RoleTabPanel: {"AXGroup", "Pane", "SCROLL_PANE", "container", "android.view.ViewGroup"},
RoleDialog: {"AXGroup/AXApplicationDialog", "Pane", "DIALOG", "container (accessibilityViewIsModal)", "android.view.ViewGroup"},
RoleAlertDialog: {"AXGroup/AXApplicationAlertDialog", "Pane", "ALERT", "container (accessibilityViewIsModal)", "android.view.ViewGroup"},
RoleAlert: {"AXGroup/AXApplicationAlert", "Group", "NOTIFICATION", "staticText", "android.view.View"},
RoleStatus: {"AXGroup/AXApplicationStatus", "StatusBar", "STATUS_BAR", "staticText", "android.view.View"},
RoleTooltip: {"AXGroup/AXUserInterfaceTooltip", "ToolTip", "TOOL_TIP", "staticText", "android.widget.TextView"},
RoleSlider: {"AXSlider", "Slider", "SLIDER", "adjustable", "android.widget.SeekBar"},
RoleProgressBar: {"AXProgressIndicator", "ProgressBar", "PROGRESS_BAR", "updatesFrequently", "android.widget.ProgressBar"},
RoleTable: {"AXTable", "Table", "TABLE", "container (dataTable)", "android.widget.GridView"},
RoleGrid: {"AXTable", "DataGrid", "TABLE", "container (dataTable)", "android.widget.GridView"},
RoleRow: {"AXRow", "DataItem", "TABLE_ROW", "container", "android.view.View"},
RoleCell: {"AXCell", "DataItem", "TABLE_CELL", "staticText", "android.view.View"},
RoleColumnHeader: {"AXCell", "HeaderItem", "COLUMN_HEADER", "header", "android.view.View"},
RoleRowHeader: {"AXCell", "HeaderItem", "ROW_HEADER", "header", "android.view.View"},
RoleTree: {"AXOutline", "Tree", "TREE", "container", "android.widget.ExpandableListView"},
RoleTreeItem: {"AXRow/AXOutlineRow", "TreeItem", "TREE_ITEM", "button", "android.view.View"},
RoleList: {"AXList", "List", "LIST", "container", "android.widget.ListView"},
RoleListItem: {"AXGroup", "ListItem", "LIST_ITEM", "staticText", "android.view.View"},
RoleImage: {"AXImage", "Image", "IMAGE", "image", "android.widget.ImageView"},
RoleNavigation: {"AXGroup/AXLandmarkNavigation", "Group", "LANDMARK", "container", "android.view.ViewGroup"},
RoleToolbar: {"AXToolbar", "ToolBar", "TOOL_BAR", "container", "android.widget.Toolbar"},
RoleSeparator: {"AXSplitter", "Separator", "SEPARATOR", "adjustable (splitter only)", "android.view.View"},
RoleScrollArea: {"AXScrollArea", "Pane", "SCROLL_PANE", "container", "android.widget.ScrollView"},
RoleForm: {"AXGroup/AXLandmarkForm", "Group", "FORM", "container", "android.view.ViewGroup"},
RoleFigure: {"AXGroup", "Group", "CHART", "image (AXChart descriptor)", "android.view.View"},
RoleTimer: {"AXGroup/AXApplicationTimer", "Text", "TIMER", "staticText+updatesFrequently", "android.widget.TextView"},
RoleMeter: {"AXLevelIndicator", "ProgressBar", "LEVEL_BAR", "staticText", "android.widget.ProgressBar"},
}Mappings maps every exposed role to its native counterparts.
类型
Action
type Action uint16Action is a set of operations a host may ask a node to perform (ui.Runner.PerformAction).
Append-only: a new flag takes the next free bit; existing bits never change.
const (
Press Action = 1 << iota // activate (click, toggle, select an option)
Increment // step a slider / spin button up
Decrement // step it down
Expand // open a combobox, expand a tree item / collapse panel
Collapse // close it
SetValue // replace the value (text, or a number for ranges)
Focus // move keyboard focus here
ScrollIntoView // scroll ancestors so the node is visible
Dismiss // close a dialog, popup or message (Escape)
)func (Action) Has
func (a Action) Has(x Action) boolHas reports whether every action of x is supported.
func (Action) String
func (a Action) String() stringString lists the actions ("press|focus").
Announcement
type Announcement struct {
Text string
Live Live
}Announcement is a message for the screen reader that is not tied to a persistent node (ui.Context.Announce). Hosts speak it once.
Live
type Live uint8Live is the politeness of a live region: how a screen reader announces changes of its content.
Append-only: never reorder or insert; the zero value stays LiveOff.
const (
LiveOff Live = iota
LivePolite // announce when the user is idle (status, toast)
LiveAssertive // interrupt (errors, alerts)
)func (Live) String
func (l Live) String() stringNode
type Node struct {
ID NodeID
Parent NodeID // 0 for the root
Children []NodeID // in reading order
Role Role
Name string // accessible name (label)
Description string // longer help / validation message / chart summary
Value string // text value (text field content, selected option, "3 of 5")
Placeholder string // hint shown in an empty text field
// RoleDescription refines the role for speech ("chart", "color picker").
RoleDescription string
// Range values (slider, progress bar, spin button, meter); valid when
// HasRange.
HasRange bool
ValueNow, ValueMin, ValueMax, Step float64
States State
Actions Action
Bounds Rect
Live Live
Level int // heading level 1-6, tree item depth (1 = top level)
PosInSet, SetSize int // 1-based position among siblings of a set (options, tabs, tree items)
RowIndex, ColIndex int // 1-based position in a table / grid (rows, cells, headers)
RowCount, ColCount int // table / grid size (including rows not built by virtualization)
Sort Sort
// Relations (IDs of other nodes in the same tree, 0 = none).
LabelledBy NodeID // node whose text is the name (form label)
DescribedBy NodeID // node whose text is the description (error message)
Controls NodeID // popup / panel this node opens or drives
ActiveDescendant NodeID // focused item of a composite that keeps focus itself
Shortcut string // keyboard shortcut, e.g. "Ctrl+K"
// RTL reports that the node's content lays out and reads right to
// left (its ConfigProvider scope; nested scopes may differ from the
// window, see Tree.RTL). It is informational for bridges that expose a
// text direction: Bounds are already the mirrored screen rectangles and
// Children stay in reading order, so hosts must not flip either.
RTL bool
}Node is one element of the semantics tree. Zero fields mean "not applicable"; hosts should not expose them.
func (*Node) Equal
func (a *Node) Equal(b *Node) boolEqual reports whether a and b describe the same node (all fields, including the order of children).
func (*Node) String
func (n *Node) String() stringString formats the node for logs and test failures.
NodeID
type NodeID uint64NodeID identifies a node across frames. It equals the ui.ID of the widget the node was derived from, so it stays stable as long as the widget does.
func Diff
func Diff(prev, next *Tree) []NodeIDDiff returns the IDs of nodes added or changed in next, followed by the IDs of nodes of prev that next no longer has (look them up in next: a nil Node means "removed"). A nil prev reports every node of next.
Platform
type Platform struct {
Mac string // NSAccessibility role, "/Subrole" when one is needed
UIA string // UI Automation ControlType (UIA_<X>ControlTypeId)
ATSPI string // AT-SPI role (ATSPI_ROLE_<X>)
IOS string // UIAccessibilityTraits (or a note for containers)
Android string // AccessibilityNodeInfo.className (TalkBack derives the spoken role from it)
}Platform names how a role is exposed by each native accessibility API. Bridges look roles up in Mappings; docs/accessibility.md prints the same table (TestMappingsDocumented keeps them in sync).
Rect
type Rect struct{ X, Y, W, H float32 }Rect is a rectangle in window logical pixels (the coordinates of ui.Window.Size; multiply by Window.Scale for device pixels).
Role
type Role uint8Role is the semantic type of a node (WAI-ARIA vocabulary).
Append-only: never reorder or insert; the zero value stays RoleNone.
const (
RoleNone Role = iota // not exposed (internal use)
RoleWindow // the root of a tree: the window content
RoleGroup // generic grouping (card, form item, fieldset)
RoleText // static text
RoleHeading // title; Node.Level is 1-6
RoleParagraph // block of text
RoleLink
RoleButton // push button; a toggle button carries Toggleable (+ Pressed)
RoleCheckbox
RoleRadio
RoleRadioGroup
RoleSwitch
RoleTextbox // single or multi-line (Multiline) text input; Protected for passwords
RoleSearchbox // text input for searching
RoleSpinButton // numeric input with step buttons
RoleCombobox // input or button that opens a listbox / tree / grid
RoleListbox
RoleOption
RoleMenu
RoleMenuBar
RoleMenuItem
RoleTab
RoleTabList
RoleTabPanel
RoleDialog
RoleAlertDialog
RoleAlert // important, usually time-sensitive message (assertive)
RoleStatus // advisory message (polite)
RoleTooltip
RoleSlider
RoleProgressBar
RoleTable
RoleGrid // interactive table (keyboard moves between cells)
RoleRow
RoleCell
RoleColumnHeader
RoleRowHeader
RoleTree
RoleTreeItem
RoleList
RoleListItem
RoleImage
RoleNavigation // breadcrumb, pagination, anchor
RoleToolbar
RoleSeparator // static divider; focusable (with Value range) when it resizes panes
RoleScrollArea
RoleForm
RoleFigure // chart: Name + Description summary
RoleTimer // countdown
RoleMeter // read-only scalar (Statistic, Gauge)
RoleMenuItemRadio // a checkable single-choice menu item
)func ParseRole
func ParseRole(s string) (Role, bool)ParseRole returns the role named s (as printed by Role.String).
func Roles
func Roles() []RoleRoles returns every exposed role (RoleNone excluded) in declaration order.
func (Role) Atomic
func (r Role) Atomic() boolAtomic reports whether the role's descendants are presentational: their text becomes the node's name and plain text children are not exposed separately (a button's label, an option's text).
func (Role) Interactive
func (r Role) Interactive() boolInteractive reports whether the role is a control a user operates (and therefore needs an accessible name and keyboard access).
func (Role) NameFromContent
func (r Role) NameFromContent() boolNameFromContent reports whether a node of this role without an explicit name is named by the text it contains (WAI-ARIA "name from content").
func (Role) String
func (r Role) String() stringString returns the WAI-ARIA style role name ("button", "treeitem").
Sort
type Sort uint8Sort is the sort direction of a column header.
Append-only: never reorder or insert; the zero value stays SortNone.
const (
SortNone Sort = iota
SortAscending
SortDescending
)func (Sort) String
func (s Sort) String() stringState
type State uint32State is a set of boolean node states.
Append-only: a new flag takes the next free bit; existing bits never change.
const (
Disabled State = 1 << iota
Focusable // can take keyboard focus
Focused // has keyboard focus
Checkable // has a checked state (checkbox, radio, switch, menu item)
Checked // checked / on
Mixed // indeterminate (checkbox, tri-state tree item)
Selectable // can be selected (option, tab, row, cell, tree item)
Selected // selected / current tab
Expandable // has an expanded state
Expanded // expanded / open
Toggleable // toggle button: has a pressed state
Pressed // toggle button pressed
Required // form field must be filled
Invalid // failed validation; Description holds the message
ReadOnly // value can be read and focused but not edited
Multiline // multi-line text input
Protected // password input: Value is not exposed
Modal // dialog that makes the rest of the window inert
Multiselectable // listbox / tree / table allows several selected items
Busy // loading; content may change
Offscreen // scrolled out of the visible area
Current // current item of a set (page, step, breadcrumb)
HasPopup // opens a menu, listbox or dialog
Visited // visited link
Vertical // orientation (sliders, separators, tab lists, menus)
Horizontal
Editable // text can be typed (combobox with search)
)func (State) Has
func (s State) Has(x State) boolHas reports whether every state of x is set.
func (State) String
func (s State) String() stringString lists the set states ("focusable|checked").
Tree
type Tree struct {
Root NodeID
Focus NodeID // node with keyboard focus (0: none)
// Announcements made during the frame that produced this tree.
Announcements []Announcement
// RTL is the window's default direction (its root scope). Nodes carry
// their own scope's direction in Node.RTL.
RTL bool
// contains filtered or unexported fields
}Tree is a snapshot of the semantics of one window. It is immutable once handed to a host: the runner builds a new Tree every frame it reports.
func NewTree
func NewTree(root NodeID) *TreeNewTree returns an empty tree; Add nodes parent-first.
func (*Tree) Add
func (t *Tree) Add(n *Node)Add inserts n (its ID must be unique in the tree). Builders add nodes in depth-first order so that Walk and Nodes follow reading order.
func (*Tree) Ancestor
func (t *Tree) Ancestor(id NodeID, role Role) *NodeAncestor returns the nearest ancestor of id with role, or nil.
func (*Tree) Dump
func (t *Tree) Dump() stringDump formats the tree as an indented outline (debugging, golden tests).
func (*Tree) Find
func (t *Tree) Find(role Role, name string) *NodeFind returns the first node (reading order) with role and name; role RoleNone matches any role and name "" any name.
func (*Tree) FindAll
func (t *Tree) FindAll(role Role, name string) []*NodeFindAll returns every node with role and name (see Find).
func (*Tree) Len
func (t *Tree) Len() intLen returns the number of nodes.
func (*Tree) Node
func (t *Tree) Node(id NodeID) *NodeNode returns the node with id, or nil.
func (*Tree) Nodes
func (t *Tree) Nodes() []*NodeNodes returns every node in depth-first (reading) order.
func (*Tree) Remove
func (t *Tree) Remove(id NodeID)Remove deletes node id (not its children) from the tree. Builders use it to fold presentational children into their parent; the caller fixes the parent's Children.
func (*Tree) Text
func (t *Tree) Text(id NodeID) stringText returns the names of n and its descendants joined by spaces (useful to read the content of a dialog or a live region).
func (*Tree) Walk
func (t *Tree) Walk(fn func(n *Node, depth int) bool)Walk calls fn for every node depth first starting at the root; depth is 0 for the root. Returning false skips the node's children.