access

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 23, 2026 License: Apache-2.0 Imports: 9 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package access is jamb's platform-neutral accessibility model. The ui runtime describes its UI as a tree of Nodes, each with a role, a name, states, actions and bounds. A platform adapter (platform/windows for UI Automation) translates the tree to the operating system's API, and translates the operating system's requests back into Actions on the UI thread. The package has no dependencies, so it can be used by any adapter.

The tree is published as an immutable *Tree snapshot. Adapters read it from any goroutine; the ui runtime builds a new snapshot on the UI thread only when something changed, and Diff reports what differs from the previous one. See docs/accessibility-design.md for the design.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func UTF16Prefix

func UTF16Prefix(s string, max int) string

UTF16Prefix returns the longest prefix of s that has at most max UTF-16 code units, and never splits a surrogate pair. A negative max means no limit.

Types

type Action

type Action uint8

Action is an operation a user or an assistive technology can request on a node. The ui runtime runs the request on the UI thread.

const (
	ActionClick               Action = iota // invoke: press the control
	ActionFocus                             // move keyboard focus to the node
	ActionExpand                            // open the node
	ActionCollapse                          // close the node
	ActionToggle                            // change a check box or switch
	ActionSelect                            // select a list item, tab or radio button
	ActionSetValue                          // replace a text field's value
	ActionScrollIntoView                    // scroll the node into view
	ActionIncrement                         // raise a value (a slider or spin box)
	ActionDecrement                         // lower a value
	ActionScroll                            // scroll a container by a fraction of its view (see Request)
	ActionSetScrollPercent                  // scroll a container to a percent of its range (see Request)
	ActionSetTextSelection                  // select the text between Request.Anchor and Request.Caret (byte offsets)
	ActionSetRangeValue                     // set the value of a slider or spin box to Request.X
	ActionAddToSelection                    // add the item to a multiple selection, keeping the others (Ctrl+click)
	ActionRemoveFromSelection               // remove the item from a multiple selection (Ctrl+click on a chosen item)
)

func (Action) String

func (a Action) String() string

String returns the action's name, such as "click".

type Announcement

type Announcement struct {
	// Text is the message to announce.
	Text string
	// Politeness is how urgently the message is announced.
	Politeness Politeness
	// Source names the source of the message, such as "jamb.toast:upload". The
	// messages of one source may replace each other while they wait to be spoken, so
	// a progress message that is updated is not read in full each time. Empty means
	// the default source.
	Source string
}

Announcement is text to speak for a status message that has no focused element to carry it, such as "3 results".

type Bridge

type Bridge struct {
	// contains filtered or unexported fields
}

Bridge connects the ui runtime that owns a window's tree with the platform adapter that exposes it. The runtime publishes snapshots on the UI thread; the adapter reads the latest one from any thread, asks for activation when an assistive technology first connects, and sends actions back, which the runtime runs on the UI thread.

The zero value is not usable; create one with NewBridge.

func NewBridge

func NewBridge() *Bridge

NewBridge creates a bridge with no runtime or adapter attached.

func (*Bridge) Activate

func (b *Bridge) Activate()

Activate is called by the adapter, on the UI thread, when an assistive technology first asks for the tree. It starts the runtime building the tree, once; later calls do nothing.

func (*Bridge) Active

func (b *Bridge) Active() bool

Active reports whether an assistive technology has asked for the tree. Until it has, the runtime builds nothing. Safe from any goroutine.

func (*Bridge) Do

func (b *Bridge) Do(id ID, r Request)

Do is Perform for a request that carries an argument, such as the text for ActionSetValue. The same rules apply.

func (*Bridge) Listen

func (b *Bridge) Listen(fn func(Update))

Listen registers the adapter's callback, which Publish calls on the UI thread with each Update. Only one listener is kept.

func (*Bridge) Perform

func (b *Bridge) Perform(id ID, a Action)

Perform asks the runtime to run action a on node id. It returns at once and is safe from any goroutine; the runtime runs the action on the UI thread, and ignores it if the node no longer exists.

func (*Bridge) Publish

func (b *Bridge) Publish(t *Tree, u Update)

Publish stores a new snapshot and reports the change to the adapter. The runtime calls it on the UI thread.

func (*Bridge) SetHooks

func (b *Bridge) SetHooks(activate func(), perform func(ID, Request))

SetHooks connects the runtime. activate runs on the UI thread once, when the tree is first asked for. perform receives requests from any goroutine.

func (*Bridge) Tree

func (b *Bridge) Tree() *Tree

Tree returns the latest published snapshot, or nil before the first one. Safe from any goroutine.

type ID

type ID uint64

ID identifies a node. It is stable across frames for the same element, and zero means no node. The ui runtime derives IDs from its element IDs.

const RootID ID = 1

RootID is the ID of the window's root node. The ui runtime always makes it the tree's root, and it is never the ID of an element.

type Node

type Node struct {
	// ID identifies the node in its tree.
	ID ID
	// Role is the kind of control that the node is, as assistive technology sees it.
	Role        Role
	Name        string // the accessible name: what a screen reader says first
	Description string // help text, read after the name
	// Key is the element's key in the ui package, exposed as the automation
	// ID so that tests can find a node by something other than its name.
	Key   string
	Value string // the current value of a text field
	// States are the state flags of the node, such as focused or disabled.
	States State
	// Actions are the actions that assistive technology may ask the node to perform.
	Actions []Action
	// Bounds is the rectangle of the node, in window coordinates.
	Bounds Rect
	// Parent is the ID of the node's parent, or zero for the root.
	Parent ID
	// Children are the IDs of the node's children, in order.
	Children    []ID
	LabelledBy  []ID // nodes whose names name this one, in order
	DescribedBy []ID // nodes whose text describes this one, in order
	Controls    []ID // nodes this one opens or controls, such as a menu
	Heading     int  // the level of a RoleHeading, 1 to 6
	PosInSet    int  // 1-based position among its siblings in a set, such as a row of a list; 0 when not in a set
	SetSize     int  // the number of items in the set; 0 when not in a set
	Level       int  // the nesting depth of a menu or tree item, 1 for the top; 0 when not set
	// Scroll is the scroll state of the node, when it is a scroll container.
	Scroll Scroll
	Text   *TextInfo // the text of a text field or text area, for the Text pattern; nil otherwise
	Range  *Range    // the number of a slider or spin box, for the RangeValue pattern; nil otherwise
	// GridRows and GridColumns are the number of rows and columns of a RoleDataGrid, for
	// the Grid and Table patterns. Rows counts every row of the data, built or not, and
	// not the header row.
	GridRows, GridColumns int
	// GridRow and GridColumn are the 1-based position of a RoleDataItem among the cells of
	// its grid; 0 when the node is not a cell. A RoleHeaderItem may have a GridColumn, the
	// column it heads, and has no GridRow; without one it heads the column of its place
	// among the grid's header items.
	GridRow, GridColumn int
	// ItemStatus is the status of an item, such as "sorted ascending" for a header item
	// (UI Automation ItemStatus); empty when there is none.
	ItemStatus string
}

Node is one element of the access tree. A Tree holds its nodes; a Node is not changed after the tree is published.

func (*Node) Equal

func (n *Node) Equal(o *Node) bool

Equal reports whether two nodes describe the same thing. Diff uses it to find the nodes that changed.

func (*Node) Has

func (n *Node) Has(a Action) bool

Has reports whether the node supports action a.

type Politeness

type Politeness uint8

Politeness says how urgently an announcement is spoken.

const (
	// Polite waits until the assistive technology is idle, as for "Saved".
	Polite Politeness = iota
	// Assertive interrupts the current speech, as for an error.
	Assertive
)

func (Politeness) String

func (p Politeness) String() string

String returns "polite" or "assertive".

type Popup struct {
	// ID is the node of the dialog or menu.
	ID ID
	// Role is the role of the dialog or menu.
	Role Role
}

Popup is a dialog or a menu that appeared or went away.

type Property

type Property uint8

Property names a property of a node that a client can watch for changes.

const (
	PropertyName       Property = iota // the name
	PropertyValue                      // the value of a text field
	PropertyToggle                     // the on or off state of a toggle
	PropertyExpanded                   // whether an expandable node is open
	PropertySelected                   // whether a selection item is chosen
	PropertyEnabled                    // whether the node can be operated
	PropertyRangeValue                 // the value of a slider or spin box (Node.Range)
)

type PropertyChange

type PropertyChange struct {
	// ID is the node whose property changed.
	ID ID
	// Property is the property that changed.
	Property Property
}

PropertyChange records that a property of a node changed between two snapshots.

type Range

type Range struct {
	// Value is the current value of the range.
	Value float64
	// Min and Max are the ends of the range.
	Min, Max    float64
	SmallChange float64 // the step of an arrow key
	LargeChange float64 // the step of Page Up and Page Down
}

Range is the number a slider or spin box holds, with the bounds and the steps it moves by. A node with a Range exposes the RangeValue pattern.

func (*Range) Equal

func (r *Range) Equal(o *Range) bool

Equal reports whether two ranges are the same. Nil equals nil only.

type Rect

type Rect struct {
	// X, Y, W and H are the position and the size of the rectangle, in physical pixels.
	X, Y, W, H float32
}

Rect is a rectangle in physical pixels, relative to the top-left corner of the window's client area. Adapters convert it to screen coordinates.

func (Rect) Contains

func (r Rect) Contains(x, y float32) bool

Contains reports whether the point (x, y) lies inside the rectangle.

func (Rect) Empty

func (r Rect) Empty() bool

Empty reports whether the rectangle has no area.

type Request

type Request struct {
	// Action is the action that the request asks the tree to perform.
	Action Action
	// Value is the new text for ActionSetValue.
	Value string
	// X and Y are the position or the amount that the action takes, as described above.
	X, Y          float64
	Anchor, Caret int // the selection for ActionSetTextSelection, as byte offsets of the text
}

Request is an action with its argument, which the bridge passes to the runtime. Value is the new text for ActionSetValue. X and Y are the position for ActionSetScrollPercent, in percent of each axis's scrollable range, where a negative value leaves that axis alone. For ActionScroll they are the fraction of the view to move, positive down and right. For ActionSetRangeValue X is the new value of the range.

type Role

type Role uint8

Role says what kind of control a node is. The values follow the roles that UI Automation and WAI-ARIA name, so that each adapter maps them directly.

const (
	RoleUnknown       Role = iota // no role; the node is not exposed as a control
	RoleWindow                    // the window, the root of the tree
	RoleGroup                     // a container with a name or a role of its own
	RoleButton                    // a push button, including icon-only buttons
	RoleCheckBox                  // a check box with checked, mixed or unchecked state
	RoleSwitch                    // an on/off switch
	RoleRadioButton               // one choice in a group of radio buttons
	RoleTextField                 // a single-line text field
	RoleTextArea                  // a multi-line text field
	RoleStaticText                // text that is not part of a named control
	RoleImage                     // an image with alternative text
	RoleLink                      // a link: a clickable run of text
	RoleList                      // a list of items, such as a UniformList or ListOf
	RoleListItem                  // one row of a list, with its position in the set
	RoleMenuBar                   // the application's menu bar
	RoleMenu                      // a menu, or the panel of a submenu
	RoleMenuItem                  // a command in a menu
	RoleMenuItemCheck             // a checkable command in a menu (check mark)
	RoleMenuItemRadio             // a choice in a menu (radio dot)
	RoleSeparator                 // a rule between groups of menu items
	RoleDialog                    // a modal dialog, named by its title
	RoleTooltip                   // a tooltip that describes the element it hangs from
	RoleScrollArea                // a scrolling container
	RoleHeading                   // a heading; its Heading field gives the level
	RoleTabList                   // a row of tabs
	RoleTab                       // one tab of a tab list
	RoleTabPanel                  // the content of a tab
	RoleComboBox                  // a field that opens a list of choices; its Value is the chosen one
	RoleSlider                    // a value moved along a track within a range (see Node.Range)
	RoleSpinner                   // a number within a range, with an edit field (see Node.Range)
	RoleTree                      // a hierarchy of nodes that open and close, such as a file tree
	RoleTreeItem                  // one node of a tree, with its Level and its position in its siblings
	RoleProgressBar               // progress: a read-only Range when determinate, no range when busy (see Node.Range)
	RoleDataGrid                  // a grid of rows and columns, such as a DataGrid (see Node.GridRows)
	RoleDataItem                  // a cell of a data grid (see Node.GridRow and Node.GridColumn)
	RoleHeaderItem                // a column header of a data grid, with its sort state in its name
	RoleCalendar                  // a month of days, a grid with a header of weekday names (see DatePicker)
	RoleStatusBar                 // the bar along the bottom of a window that shows its status (see StatusBar)
	RoleToolBar                   // a row of controls that is one Tab stop, named by its label (see Toolbar)
	RoleAlertDialog               // a modal dialog that asks for a response to a message, named by its title (see AlertDialog)
)

func (Role) Interactive

func (r Role) Interactive() bool

Interactive reports whether a user operates a node of this role, so that it needs an accessible name (see the development warnings).

func (Role) IsDialog added in v0.4.0

func (r Role) IsDialog() bool

IsDialog reports whether the role is a dialog, RoleDialog or RoleAlertDialog: a window of its own to assistive technology. A dialog is modal unless its node has StateNonModal.

func (Role) String

func (r Role) String() string

String returns the role's name, such as "check box".

type Scroll

type Scroll struct {
	Container    bool    // the node is a scroll container
	CanX, CanY   bool    // the content is larger than the view on that axis
	X, Y         float64 // the position on each axis, in percent of the scrollable range
	ViewX, ViewY float64 // the visible part of the content on each axis, in percent
}

Scroll describes a scroll container. A node with Container set exposes the scroll pattern; the other fields are read by the adapter.

type State

type State uint32

State is a set of flags that describe a node's condition.

const (
	StateFocusable          State = 1 << iota // the node can take keyboard focus
	StateFocused                              // the node has keyboard focus
	StateDisabled                             // the node is shown but cannot be operated
	StateChecked                              // a check box, switch or radio button is on; a menu item is checked
	StateMixed                                // a check box is in the indeterminate state
	StateExpanded                             // the node is open (a menu, a tree item)
	StateSelected                             // the node is selected (a list item, a tab)
	StateReadOnly                             // a text field can be read but not edited
	StateRequired                             // a field must be filled in
	StateInvalid                              // a field's value is not valid
	StateOffscreen                            // the node is clipped out of view by a scroll container
	StateMultiLine                            // a text field takes several lines
	StateExpandable                           // the node opens and closes; StateExpanded says whether it is open
	StateSelectable                           // the node is one item of a selection; StateSelected says whether it is chosen
	StateSelectionContainer                   // the node holds selection items, such as the chips of a filter
	StateToggle                               // the node has an on or off state; StateChecked says whether it is on
	StatePassword                             // a password field: its text is hidden (UI Automation IsPassword), as in a masked OTPInput
	StateMultiSelectable                      // the selection container takes more than one item (see StateSelectionContainer)
	StateNonModal                             // a dialog that leaves the window behind it usable, so it is not a modal window
)

func (State) Has

func (s State) Has(f State) bool

Has reports whether all the flags in f are set.

func (State) String

func (s State) String() string

String lists the flags that are set, such as "focusable focused".

type TextContent

type TextContent struct {
	Text   string     // the text, UTF-8, as the editor holds it
	Points []int      // the byte offset of each point, from 0 to len(Text)
	X      []float32  // for each point, the x of the caret in layout units, on the line the point belongs to
	Lines  []TextLine // the visual lines, in order; there is always one
	Paras  []int      // the first point of each paragraph, in order
	Words  []int      // the first point of each word unit, in order, by the Windows word rule
}

TextContent is the text of one editor, with the geometry of its layout. The ui runtime builds it on the UI thread when the text or the layout changes, and shares it between the snapshots that show that text. It is never changed after it is built, so any goroutine may read it. It implements TextModel.

func (*TextContent) ByteOf

func (c *TextContent) ByteOf(p int) int

ByteOf returns the byte offset of point p, clamped to the text.

func (*TextContent) CaretX

func (c *TextContent) CaretX(p int) float32

CaretX returns the x of point p in layout units.

func (*TextContent) Len

func (c *TextContent) Len() int

Len returns the number of grapheme clusters in the text. The last point is Len(), the end of the text, so there are Len()+1 points.

func (*TextContent) Line

func (c *TextContent) Line(p int) (TextLine, int)

Line returns the visual line that holds point p, and the point where it ends.

func (*TextContent) Nearest

func (c *TextContent) Nearest(x, y float32) int

Nearest returns the point nearest to the position (x, y) in layout units. Above the text it is the first point of the first line; below it, the end of the last line.

func (*TextContent) Next

func (c *TextContent) Next(u TextUnit, p int) int

Next returns the point one unit after p, or the end of the text when there is none. A word unit moves to the start of the next word unit, as Ctrl+Right does on Windows.

func (*TextContent) PointOf

func (c *TextContent) PointOf(b int) int

PointOf returns the point at byte offset b. An offset inside a grapheme cluster rounds down to the start of the cluster.

func (*TextContent) Prev

func (c *TextContent) Prev(u TextUnit, p int) int

Prev returns the point one unit before p, or 0 when there is none. A word unit follows the editor's Ctrl+Left: it moves to the start of the word before p, past any separator.

func (*TextContent) Read

func (c *TextContent) Read(from, to, max int) string

Read returns the text of the points [from, to), cut to at most max UTF-16 code units. A negative max means no limit.

func (*TextContent) SameText

func (c *TextContent) SameText(o TextModel) bool

SameText reports whether o holds the same text as c. Another model is compared by reading its whole text, which only a model of another kind needs.

func (*TextContent) Span

func (c *TextContent) Span(u TextUnit, p int) (int, int)

Span returns the points [a, b) of the unit u that holds point p, with 0 <= p < Len().

type TextInfo

type TextInfo struct {
	// Content is the text of the field, as the Text pattern reads it.
	Content TextModel
	Anchor  int // the selection is the points between Anchor and Caret; a degenerate one is a caret
	Caret   int // the end of the selection that moves
	// OriginX and OriginY are the window position of the layout's top-left
	// corner, in physical pixels, and Scale is the number of physical pixels per
	// layout unit. Clip is the visible part of the field, in physical pixels.
	OriginX, OriginY float32
	// Scale is the number of physical pixels per layout unit.
	Scale float32
	// Clip is the visible part of the field, in physical pixels.
	Clip Rect
	// FontName, FontSize and FontWeight describe the text's font. FontSize is in
	// points, and FontWeight is the CSS-style weight (400 is normal).
	FontName string
	// FontSize is the font size, in points.
	FontSize float64
	// FontWeight is the CSS-style weight of the font.
	FontWeight int
	// Italic reports whether the text is set in italic.
	Italic   bool
	ReadOnly bool // the text can be read but not edited
}

TextInfo is the state of a text field or text area in one snapshot: its content, its selection, and where the content is drawn in the window.

func (*TextInfo) CaretRange

func (t *TextInfo) CaretRange() TextRange

CaretRange returns the degenerate range at the caret of t.

func (*TextInfo) Equal

func (t *TextInfo) Equal(o *TextInfo) bool

Equal reports whether two infos describe the same text state. Their contents are compared by identity, since a content is shared by the snapshots that show it; Diff reports a text change separately (see Update.TextChanged).

func (*TextInfo) PointAt

func (t *TextInfo) PointAt(x, y float32) int

PointAt returns the point nearest to the position (x, y), in physical pixels in the window, as a click or hover would find it. Above the text it is the first point of the first line; below it, the end of the last line.

func (*TextInfo) Selection

func (t *TextInfo) Selection() TextRange

Selection returns the selected range of t: the points between Anchor and Caret.

func (*TextInfo) Whole

func (t *TextInfo) Whole() TextRange

Whole returns the range of the whole text of t.

type TextLine

type TextLine struct {
	// Start is the first point of the line.
	Start int
	// Top and Height are the vertical position and the height of the line, in layout units.
	Top, Height float32
	// Right is the end of the line's text, without its trailing spaces, in layout units.
	Right float32
}

TextLine is one visual line of a laid-out text. The line covers the points from Start up to the Start of the next line, so a line break belongs to the line it ends. Top, Height and Right are in layout units, from the top-left of the layout: Right is the end of the line's text, without its trailing spaces.

type TextModel

type TextModel interface {
	// Len returns the last point, the end of the text.
	Len() int
	// PointOf returns the point at byte offset b, rounded down to a point.
	PointOf(b int) int
	// ByteOf returns the byte offset of point p, clamped to the text.
	ByteOf(p int) int
	// Span returns the points [a, b) of the unit u that holds point p, with
	// 0 <= p < Len().
	Span(u TextUnit, p int) (int, int)
	// Next returns the point one unit after p, or Len() when there is none.
	Next(u TextUnit, p int) int
	// Prev returns the point one unit before p, or 0 when there is none.
	Prev(u TextUnit, p int) int
	// Line returns the visual line that holds point p, and the point where the
	// line ends: the first point of the next line, or Len() on the last line.
	Line(p int) (TextLine, int)
	// CaretX returns the x of point p in layout units, on the line it belongs to.
	CaretX(p int) float32
	// Nearest returns the point nearest to the position (x, y) in layout units.
	Nearest(x, y float32) int
	// Read returns the text of the points [from, to), cut to at most max UTF-16
	// code units (see UTF16Prefix). A negative max means no limit.
	Read(from, to, max int) string
	// SameText reports whether o holds the same text as the model. A change of
	// text is reported separately from a change of selection (see Diff).
	SameText(o TextModel) bool
}

TextModel is the text of a text field or text area, as the Text pattern reads it. The pattern works in points (see TextContent). A model is never changed after it is published, so any goroutine may read it. Implementations are pointers, since TextInfo.Equal compares the models by identity.

The pattern asks the model for the units around a point, and for a range's text with a limit, rather than for the whole text, so that a large text need not be copied for a query. TextContent is the model of a text that is held in memory; the codeedit package has one over a rope. Methods may be added to TextModel in later versions.

type TextRange

type TextRange struct {
	// Info is the text that the range lies in.
	Info *TextInfo
	// Start and End are the points where the range begins and ends.
	Start, End int
}

TextRange is a span of a text: the points from Start to End, with Start <= End. A range with Start == End is degenerate, a position, which is where the insertion point of a text field is. A range keeps the TextInfo of the snapshot it was made from, so its text and geometry are the ones the client was told about, even after the field has changed. Actions on a range (Select, ScrollIntoView) act on the current text, and their points are clamped to it.

func (TextRange) CompareEndpoints

func (r TextRange) CompareEndpoints(start bool, target TextRange, targetStart bool) int

CompareEndpoints compares an endpoint of r with an endpoint of target. It returns -1, 0 or 1 as the first point is before, at, or after the second. The ranges must be of the same text; the magnitude is not defined.

func (TextRange) Content

func (r TextRange) Content() TextModel

Content returns the content of the range's text.

func (TextRange) Degenerate

func (r TextRange) Degenerate() bool

Degenerate reports whether the range is a position.

func (TextRange) Expand

func (r TextRange) Expand(u TextUnit) TextRange

Expand returns the range expanded to whole units of u, as ExpandToEnclosingUnit does: the start moves back to the start of the unit it is in, and the end moves forward to the end of the unit that holds its last grapheme. A range that is already whole units is unchanged. A degenerate range expands to the unit at its position is the unit that holds the grapheme there, or the last grapheme of the text at its end. An empty text has no units and expands to nothing.

func (TextRange) Find

func (r TextRange) Find(needle string, backward, ignoreCase bool) (TextRange, bool)

Find returns the first range (or the last, when backward is set) within r whose text is needle. Matches start on grapheme boundaries, and end on one. Case is ignored when ignoreCase is set, by simple Unicode case folding. An empty needle matches nothing.

func (TextRange) GetText

func (r TextRange) GetText(max int) string

GetText returns the text between the endpoints, cut to at most max UTF-16 code units, as UI Automation's GetText asks for it. A negative max means no limit. A model reads only the requested range.

func (TextRange) Move

func (r TextRange) Move(u TextUnit, count int) (TextRange, int)

Move moves the range by count units of u, and returns the moved range and the number of units moved. A positive count moves forward, a negative one back, and zero does nothing. Following Microsoft's rules for ITextRangeProvider::Move:

  • A degenerate range moves its position, and stays degenerate.
  • Any other range first moves its start back to the start of its unit, then moves that position by count units, and ends one unit after it, so the result is a whole unit.
  • A move that cannot happen at all leaves the range unchanged.

A word unit moves like a line: a degenerate range moves to the start of the nth unit after it, which is where Ctrl+Right stops; a backward move goes to the start of the unit before it, which is where Ctrl+Left stops. A non-degenerate range starts at the start of its unit and moves from there. The count is the number of units actually moved, which is less than requested at the ends of the text. A backward move returns a negative count.

func (TextRange) MoveEndpoint

func (r TextRange) MoveEndpoint(start bool, u TextUnit, count int) (TextRange, int)

MoveEndpoint moves one endpoint of the range by count units of u, and returns the range and the number of units moved, with the sign convention of Move. The endpoint moves to the next unit boundary in that direction. If it passes the other endpoint, the other endpoint moves with it, so the range stays ordered and becomes degenerate, as ITextRangeProvider::MoveEndpointByUnit describes. start selects the start endpoint; otherwise the end endpoint moves.

func (TextRange) MoveEndpointByRange

func (r TextRange) MoveEndpointByRange(start bool, target TextRange, targetStart bool) TextRange

MoveEndpointByRange sets one endpoint of the range to an endpoint of target, and keeps the range ordered as MoveEndpoint does.

func (TextRange) Rects

func (r TextRange) Rects() []Rect

Rects returns the bounding rectangles of the range, in physical pixels in the window: one per visual line it touches, clipped to the visible part of the field. A degenerate range, or one that is not visible, has none.

func (TextRange) Same

func (r TextRange) Same(o TextRange) bool

Same reports whether two ranges have the same text and the same endpoints. The text is compared by its TextInfo, since a snapshot's text is one object.

func (TextRange) Text

func (r TextRange) Text() string

Text returns the text between the endpoints.

type TextUnit

type TextUnit uint8

TextUnit is a unit of text that a range is expanded or moved by. The values follow the TextUnit enumeration of UI Automation.

const (
	UnitCharacter TextUnit = iota // a grapheme cluster
	UnitFormat                    // a run of text with the same formatting; a plain text has one
	UnitWord                      // a word unit: a word, or punctuation, with the spaces after it, by the Windows word rule
	UnitLine                      // a visual line, with the line break that ends it
	UnitParagraph                 // a paragraph, with the line break that ends it
	UnitPage                      // a page; a text field's one page is its whole text
	UnitDocument                  // the whole text
)

type Tree

type Tree struct {
	Root  ID // the window's node, RootID
	Focus ID // the node with keyboard focus, or zero
	// contains filtered or unexported fields
}

Tree is an immutable snapshot of the access tree. The ui runtime publishes a new Tree when the UI changed; readers keep the one they loaded, so no lock is needed to read a snapshot from another thread.

func NewTree

func NewTree(focus ID, nodes []*Node) *Tree

NewTree builds a snapshot from nodes. The root is the node whose ID is RootID; the nodes it lists as children, directly or through other nodes, are the tree. Nodes that are not reachable from the root are dropped. Ownership of the nodes passes to the tree.

func (*Tree) Dump

func (t *Tree) Dump() string

Dump returns the tree as indented text, one node per line, for tests and the development tools:

window "Demo" (1)
  button "New project" [focusable] @12,40 120x34 (4096)

Bounds are physical pixels. The ID is in parentheses.

func (*Tree) Find

func (t *Tree) Find(role Role, name string) *Node

Find returns the first node, in reading order, that has the role and the name, or nil.

func (*Tree) Len

func (t *Tree) Len() int

Len returns the number of nodes in the tree.

func (*Tree) Node

func (t *Tree) Node(id ID) *Node

Node returns the node with the given ID, or nil if the tree has none. A nil tree has no nodes.

func (*Tree) Walk

func (t *Tree) Walk(fn func(*Node) bool)

Walk calls fn for each node in reading order, depth first, until fn returns false.

type Update

type Update struct {
	Focus        ID   // the focused node in the new snapshot
	FocusChanged bool // the focused node differs from the previous snapshot
	Added        []ID // nodes in the new snapshot that were not in the previous one
	Removed      []ID // nodes in the previous snapshot that are gone
	Changed      []ID // nodes present in both whose content differs
	// Structure is set when nodes were added, removed or re-parented.
	Structure bool
	// Properties are the properties of nodes present in both snapshots that
	// changed. Adapters raise a property-changed event for each.
	Properties []PropertyChange
	// Opened are the dialogs and menus that were added, and Closed the ones that
	// were removed (taken from the previous snapshot).
	Opened []Popup
	// Closed are the dialogs and menus that were removed, as Opened describes.
	Closed []Popup
	// TextChanged are the text fields and text areas whose text changed, and
	// TextSelection those whose selection or caret moved. Adapters raise the
	// text events for them.
	TextChanged []ID
	// TextSelection are the text fields and text areas whose selection or caret moved; see TextChanged.
	TextSelection []ID
	// Announcements are the status messages queued since the last snapshot.
	Announcements []Announcement
}

Update describes what changed between two snapshots. Adapters use it to raise events and to decide which of their cached objects to refresh.

func Diff

func Diff(prev, next *Tree) Update

Diff compares two snapshots. prev may be nil, in which case every node is Added. The ID lists are sorted, so the result is deterministic.

Directories

Path Synopsis
Package accesstest has helpers for tests that check an access tree: find a node by its role and name, and assert its role, name and states.
Package accesstest has helpers for tests that check an access tree: find a node by its role and name, and assert its role, name and states.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL