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.
6 * @fileoverview ChromeVox predicates for the automation extension API.
9 goog.provide('AutomationPredicate');
10 goog.provide('AutomationPredicate.Binary');
11 goog.provide('AutomationPredicate.Unary');
16 AutomationPredicate = function() {};
19 * @typedef {function(chrome.automation.AutomationNode) : boolean}
21 AutomationPredicate.Unary;
24 * @typedef {function(chrome.automation.AutomationNode,
25 * chrome.automation.AutomationNode) : boolean}
27 AutomationPredicate.Binary;
30 * Constructs a predicate given a role.
31 * @param {chrome.automation.RoleType} role
32 * @return {AutomationPredicate.Unary}
34 AutomationPredicate.makeRolePredicate = function(role) {
35 return function(node) {
36 return node.role == role;
40 /** @type {AutomationPredicate.Unary} */
41 AutomationPredicate.heading =
42 AutomationPredicate.makeRolePredicate(
43 chrome.automation.RoleType.heading);
44 /** @type {AutomationPredicate.Unary} */
45 AutomationPredicate.inlineTextBox =
46 AutomationPredicate.makeRolePredicate(
47 chrome.automation.RoleType.inlineTextBox);
48 /** @type {AutomationPredicate.Unary} */
49 AutomationPredicate.link =
50 AutomationPredicate.makeRolePredicate(
51 chrome.automation.RoleType.link);
54 * @param {chrome.automation.AutomationNode} node
57 AutomationPredicate.leaf = function(node) {
58 return !node.firstChild ||
59 node.role == chrome.automation.RoleType.button ||
60 node.children.every(function(n) {
61 return n.state.invisible;
66 * @param {chrome.automation.AutomationNode} node
69 AutomationPredicate.leafWithText = function(node) {
70 return AutomationPredicate.leaf(node) &&
71 !!(node.attributes.name || node.attributes.value);
75 * @param {chrome.automation.AutomationNode} first
76 * @param {chrome.automation.AutomationNode} second
79 AutomationPredicate.linebreak = function(first, second) {
80 // TODO(dtseng): Use next/previousOnLin once available.
81 var fl = first.location;
82 var sl = second.location;
83 return fl.top != sl.top ||
84 (fl.top + fl.height != sl.top + sl.height);