1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // The <code>chrome.automation</code> API allows developers to access the
6 // automation (accessibility) tree for the browser. The tree resembles the DOM
7 // tree, but only exposes the <em>semantic</em> structure of a page. It can be
8 // used to programmatically interact with a page by examining names, roles, and
9 // states, listening for events, and performing actions on nodes.
10 [nocompile
] namespace automation
{
11 // Keep the following enums in sync with 'ui/accessibility/ax_enums.idl'.
12 // They are kept here purely for extension docs generation.
14 // Possible events fired on an $(ref:automation.AutomationNode).
16 activedescendantchanged
,
19 autocorrectionOccured
,
40 scrollPositionChanged
,
42 selectedChildrenChanged
,
53 // Describes the purpose of an $(ref:automation.AutomationNode).
79 descriptionListDetail
,
160 tableHeaderContainer
,
179 // Describes characteristics of an $(ref:automation.AutomationNode).
185 disabled
, // ui/views only
186 editable
, // ui/views only
187 enabled
, // content only
216 // Arguments for the find() and findAll() methods.
217 [nocompile
, noinline_doc
] dictionary FindParams
{
218 automation.RoleType? role
;
220 // A map of $(ref:automation.StateType) to boolean, indicating for each
221 // state whether it should be set or not. For example:
222 // <code>{ StateType.enabled: false }</code> would only match if
223 // <code>StateType.enabled</code> was <em>not</em> present in the node's
224 // <code>state</code> object.
227 // A map of attribute name to expected value, for example
228 // <code>{ name: 'Root directory', button_mixed: true }</code>.
229 // String attribute values may be specified as a regex, for example
230 // <code>{ name: /stralia$/</code> }</code>.
231 // Unless specifying a regex, the expected value must be an exact match
232 // in type and value for the actual value. Thus, the type of expected value
243 // Called when the result for a <code>query</code> is available.
244 callback QueryCallback
= void(AutomationNode node
);
246 // An event in the Automation tree.
247 [nocompile
, noinline_doc
] dictionary AutomationEvent
{
248 // The $(ref:automation.AutomationNode) to which the event was targeted.
249 AutomationNode target
;
251 // The type of the event.
254 // Stops this event from further processing except for any remaining
255 // listeners on $(ref:AutomationEvent.target).
256 static
void stopPropagation
();
259 // A listener for events on an <code>AutomationNode</code>.
260 callback AutomationListener
= void(AutomationEvent event
);
262 // A single node in an Automation tree.
263 [nocompile
, noinline_doc
] dictionary AutomationNode
{
264 // The root node of the tree containing this AutomationNode.
267 // Whether this AutomationNode is root node.
270 // The role of this node.
271 automation.RoleType role
;
273 // TODO(aboxhall): expose states as mixins instead
275 // The $(ref:automation.StateType)s describing this node.
278 // The rendered location (as a bounding box) of this node within the frame.
279 automation.Rect location
;
281 // The purpose of the node, other than the role, if any.
282 DOMString description
;
284 // The help text for the node, if any.
287 // The accessible name for this node, via the
288 // <a href="http://www.w3.org/TR/wai-aria/roles#namecalculation">
289 // Accessible Name Calculation</a> process.
292 // The value for this node: for example the <code>value</code> attribute of
293 // an <code><input> element.
296 // The nodes, if any, which this node is specified to control via
297 // <a href="http://www.w3.org/TR/wai-aria/states_and_properties#aria-controls">
298 // <code>aria-controls</code></a>.
299 AutomationNode
[] controls
;
301 // The nodes, if any, which form a description for this node.
302 AutomationNode
[] describedBy
;
304 // The nodes, if any, which may optionally be navigated to after this
306 // <a href="http://www.w3.org/TR/wai-aria/states_and_properties#aria-flowto">
307 // <code>aria-flowto</code></a>.
308 AutomationNode
[] flowTo
;
310 // The nodes, if any, which form a label for this element. Generally, the
311 // text from these elements will also be exposed as the element's accessible
312 // name, via the $(ref:automation.AutomationNode.name) attribute.
313 AutomationNode
[] labelledBy
;
315 // The nodes, if any, which are to be considered children of this node but
316 // are not children in the DOM tree.
317 AutomationNode
[] owns
;
319 // TODO(aboxhall): Make this private?
321 // A collection of this node's other attributes.
324 // The index of this node in its parent node's list of children. If this is
325 // the root node, this will be undefined.
328 AutomationNode
[] children
;
329 AutomationNode parent
;
330 AutomationNode firstChild
;
331 AutomationNode lastChild
;
332 AutomationNode previousSibling
;
333 AutomationNode nextSibling
;
335 // Does the default action based on this node's role. This is generally
336 // the same action that would result from clicking the node such as
337 // expanding a treeitem, toggling a checkbox, selecting a radiobutton,
338 // or activating a button.
339 static
void doDefault
();
341 // Places focus on this node.
344 // Scrolls this node to make it visible.
345 static
void makeVisible
();
347 // Sets selection within a text field.
348 static
void setSelection
(long startIndex
, long endIndex
);
350 // Adds a listener for the given event type and event phase.
351 static
void addEventListener
(
352 EventType eventType
, AutomationListener listener
, boolean capture
);
354 // Removes a listener for the given event type and event phase.
355 static
void removeEventListener
(
356 EventType eventType
, AutomationListener listener
, boolean capture
);
358 // Gets the first node in this node's subtree which matches the given CSS
359 // selector and is within the same DOM context.
361 // If this node doesn't correspond directly with an HTML node in the DOM,
362 // querySelector will be run on this node's nearest HTML node ancestor. Note
363 // that this may result in the query returning a node which is not a
364 // descendant of this node.
366 // If the selector matches a node which doesn't directly correspond to an
367 // automation node (for example an element within an ARIA widget, where the
368 // ARIA widget forms one node of the automation tree, or an element which
369 // is hidden from accessibility via hiding it using CSS or using
370 // aria-hidden), this will return the nearest ancestor which does correspond
371 // to an automation node.
372 static
void domQuerySelector
(DOMString selector
, QueryCallback
callback);
374 // Finds the first AutomationNode in this node's subtree which matches the
375 // given search parameters.
376 static AutomationNode find
(FindParams params
);
378 // Finds all the AutomationNodes in this node's subtree which matches the
379 // given search parameters.
380 static AutomationNode
[] findAll
(FindParams params
);
382 // Returns whether this node matches the given $(ref:automation.FindParams).
383 static
boolean matches
(FindParams params
);
386 dictionary ActiveDescendantMixin
{
387 // The node referred to by <code>aria-activedescendant</code>, where
389 AutomationNode activedescendant
;
392 // Attributes which are mixed in to an AutomationNode if it is a link.
393 dictionary LinkMixins
{
394 // TODO(aboxhall): Add visited state
396 // The URL that this link will navigate to.
400 // Attributes which are mixed in to an AutomationNode if it is a document.
401 dictionary DocumentMixins
{
402 // The URL of this document.
405 // The title of this document.
408 // Whether this document has finished loading.
411 // The proportion (out of 1.0) that this doc has completed loading.
412 double docLoadingProgress
;
415 // TODO(aboxhall): document ScrollableMixins (e.g. what is scrollXMin? is it
418 // Attributes which are mixed in to an AutomationNode if it is scrollable.
419 dictionary ScrollableMixins
{
428 // Attributes which are mixed in to an AutomationNode if it is editable text.
429 dictionary EditableTextMixins
{
430 // The character index of the start of the selection within this editable
431 // text element; -1 if no selection.
434 // The character index of the end of the selection within this editable
435 // text element; -1 if no selection.
439 // Attributes which are mixed in to an AutomationNode if it is a range.
440 dictionary RangeMixins
{
441 // The current value for this range.
442 double valueForRange
;
444 // The minimum possible value for this range.
445 double minValueForRange
;
447 // The maximum possible value for this range.
448 double maxValueForRange
;
451 // TODO(aboxhall): live region mixins.
453 // Attributes which are mixed in to an AutomationNode if it is a table.
454 dictionary TableMixins
{
455 // The number of rows in this table.
458 // The number of columns in this table.
459 long tableColumnCount
;
462 // Attributes which are mixed in to an AutomationNode if it is a table cell.
463 dictionary TableCellMixins
{
464 // The zero-based index of the column that this cell is in.
465 long tableCellColumnIndex
;
467 // The number of columns that this cell spans (default is 1).
468 long tableCellColumnSpan
;
470 // The zero-based index of the row that this cell is in.
471 long tableCellRowIndex
;
473 // The number of rows that this cell spans (default is 1).
474 long tableCellRowSpan
;
477 // Called when the <code>AutomationNode</code> for the page is available.
478 callback RootCallback
= void(AutomationNode rootNode
);
480 interface Functions
{
481 // Get the automation tree for the tab with the given tabId, or the current
482 // tab if no tabID is given, enabling automation if necessary. Returns a
483 // tree with a placeholder root node; listen for the "loadComplete" event to
484 // get a notification that the tree has fully loaded (the previous root node
485 // reference will stop working at or before this point).
486 [nocompile
] static
void getTree
(optional long tabId
, RootCallback
callback);
488 // Get the automation tree for the whole desktop which consists of all on
489 // screen views. Note this API is currently only supported on Chrome OS.
490 [nocompile
] static
void getDesktop
(RootCallback
callback);