Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(468)

Side by Side Diff: chrome/browser/resources/chromeos/switch_access/automation_predicate.js

Issue 2863613003: Implemented scanning by group (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 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.
4
5 /**
6 * Class containing predicates for the chrome automation API. Each predicate
7 * can be run on one or more AutomationNodes and returns a boolean value.
8 *
9 * @constructor
10 */
11 function AutomationPredicate() {};
12
13 /**
14 * Returns true if |node| is a subtreeLeaf, meaning that |node| is either
15 * interesting or a group (both defined below).
16 *
17 * @param {!chrome.automation.AutomationNode} node
18 * @param {!chrome.automation.AutomationNode} scope
19 * @return {boolean}
20 */
21 AutomationPredicate.isSubtreeLeaf = function(node, scope) {
22 return AutomationPredicate.isInteresting(node)
23 || AutomationPredicate.isGroup(node, scope);
24 };
25
26 /**
27 * Returns true if |node| is a group, meaning that the node has more than one
28 * interesting descendant, and that its interesting descendants exist in more
29 * than one subtree of its immediate children.
30 *
31 * Additionally, for |node| to be a group, it cannot have the same location as
32 * its outer group, |scope|.
dmazzoni 2017/05/05 18:23:19 How about "it cannot have the same bounding box as
elichtenberg 2017/05/06 00:13:53 Done.
33 *
34 * @param {!chrome.automation.AutomationNode} node
35 * @param {!chrome.automation.AutomationNode} scope
36 * @return {boolean}
37 */
38 AutomationPredicate.isGroup = function(node, scope) {
39 if (node !== scope && AutomationPredicate.hasSameLocation_(node, scope))
40 return false;
41
42 // Work around for client nested in client. No need to have user select both
43 // clients for a window. Once locations for outer client updates correctly,
44 // this won't be needed.
45 if (node.role === chrome.automation.RoleType.CLIENT
46 && node.role === scope.role && node !== scope)
47 return false;
48
49 let interestingBranches = 0;
50 for (let child of node.children) {
51 if (AutomationPredicate.isInterestingSubtree(child))
52 interestingBranches += 1;
53 if (interestingBranches > 1)
54 return true;
55 }
56 return false;
57 };
58
59 /**
60 * Returns true if the two nodes have the same location.
61 *
62 * @param {!chrome.automation.AutomationNode} node1
63 * @param {!chrome.automation.AutomationNode} node2
64 * @return {boolean}
65 */
66 AutomationPredicate.hasSameLocation_ = function(node1, node2) {
dmazzoni 2017/05/05 18:23:19 Don't have to do anything now, but I wonder if thi
elichtenberg 2017/05/06 00:13:53 Good idea. That's probably something we should loo
67 let l1 = node1.location;
68 let l2 = node2.location;
69 return l1.left === l2.left && l1.top === l2.top && l1.width === l2.width
70 && l1.height === l2.height;
71 };
72
73 /**
74 * Returns true if there is an interesting node in the subtree containing
75 * |node| as its root (including |node| itself).
76 *
77 * @param {!chrome.automation.AutomationNode} node
78 * @return {boolean}
79 */
80 AutomationPredicate.isInterestingSubtree = function(node) {
81 let children = node.children || [];
82 return AutomationPredicate.isInteresting(node)
83 || children.some(AutomationPredicate.isInterestingSubtree);
84 };
85
86 /**
87 * Returns true if |node| is interesting, meaning that a user can perform some
88 * type of action on it.
89 *
90 * @param {!chrome.automation.AutomationNode} node
91 * @return {boolean}
92 */
93 AutomationPredicate.isInteresting = function(node) {
94 let loc = node.location;
95 let parent = node.parent;
96 let root = node.root;
97 let role = node.role;
98 let state = node.state;
99
100 // Skip things that are offscreen
101 if (state[chrome.automation.StateType.OFFSCREEN]
dmazzoni 2017/05/05 18:23:19 Consider defining shorthand for chrome.automation.
elichtenberg 2017/05/06 00:13:53 Adding a TODO for this. Hopefully I can find an ea
102 || loc.top < 0 || loc.left < 0)
103 return false;
104
105 // Should just leave these as groups
106 if (role === chrome.automation.RoleType.WEB_VIEW
107 || role === chrome.automation.RoleType.ROOT_WEB_AREA)
108 return false;
109
110 if (parent) {
111 // crbug.com/710559
112 // Work around for browser tabs
113 if (role === chrome.automation.RoleType.TAB
114 && parent.role === chrome.automation.RoleType.TAB_LIST
115 && root.role === chrome.automation.RoleType.DESKTOP)
116 return true;
117 }
118
119 // The general rule that applies to everything.
120 return state[chrome.automation.StateType.FOCUSABLE] === true;
121 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698