OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * @fileoverview ChromeVox predicates for the automation extension API. | 6 * @fileoverview ChromeVox predicates for the automation extension API. |
7 */ | 7 */ |
8 | 8 |
9 goog.provide('AutomationPredicate'); | 9 goog.provide('AutomationPredicate'); |
10 goog.provide('AutomationPredicate.Binary'); | 10 goog.provide('AutomationPredicate.Binary'); |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 /** | 170 /** |
171 * Non-inline textbox nodes which have an equivalent in the DOM. | 171 * Non-inline textbox nodes which have an equivalent in the DOM. |
172 * @param {!AutomationNode} node | 172 * @param {!AutomationNode} node |
173 * @return {boolean} | 173 * @return {boolean} |
174 */ | 174 */ |
175 AutomationPredicate.leafDomNode = function(node) { | 175 AutomationPredicate.leafDomNode = function(node) { |
176 return AutomationPredicate.leaf(node) || | 176 return AutomationPredicate.leaf(node) || |
177 node.role == RoleType.staticText; | 177 node.role == RoleType.staticText; |
178 }; | 178 }; |
179 | 179 |
180 | |
181 /** | 180 /** |
182 * Matches nodes that are containers that should be ignored during | 181 * Matches against nodes visited during object navigation. An object as |
183 * element navigation. | |
184 * @param {!AutomationNode} node | |
185 * @return {boolean} | |
186 */ | |
187 AutomationPredicate.ignoredContainer = function(node) { | |
188 return (node.role == RoleType.rootWebArea || | |
189 node.role == RoleType.embeddedObject || | |
190 node.role == RoleType.iframe || | |
191 node.role == RoleType.iframePresentational || | |
192 node.role == RoleType.embeddedObject); | |
193 }; | |
194 | |
195 /** | |
196 * Matches against nodes visited during element navigation. An element as | |
197 * defined below, are all nodes that are focusable or static text. When used in | 182 * defined below, are all nodes that are focusable or static text. When used in |
198 * tree walking, it should visit all nodes that tab traversal would as well as | 183 * tree walking, it should visit all nodes that tab traversal would as well as |
199 * non-focusable static text. | 184 * non-focusable static text. |
200 * @param {!AutomationNode} node | 185 * @param {!AutomationNode} node |
201 * @return {boolean} | 186 * @return {boolean} |
202 */ | 187 */ |
203 AutomationPredicate.element = function(node) { | 188 AutomationPredicate.object = function(node) { |
204 if (AutomationPredicate.ignoredContainer(node)) | |
205 return false; | |
206 | |
207 return node.state.focusable || | 189 return node.state.focusable || |
208 (AutomationPredicate.leafDomNode(node) && | 190 (AutomationPredicate.leafDomNode(node) && |
209 (/\S+/.test(node.name) || | 191 (/\S+/.test(node.name) || |
210 (node.role != RoleType.lineBreak && | 192 (node.role != RoleType.lineBreak && |
211 node.role != RoleType.staticText && | 193 node.role != RoleType.staticText && |
212 node.role != RoleType.inlineTextBox))); | 194 node.role != RoleType.inlineTextBox))); |
213 }; | 195 }; |
214 | 196 |
215 /** | 197 /** |
216 * @param {!AutomationNode} first | 198 * @param {!AutomationNode} first |
217 * @param {!AutomationNode} second | 199 * @param {!AutomationNode} second |
218 * @return {boolean} | 200 * @return {boolean} |
219 */ | 201 */ |
220 AutomationPredicate.linebreak = function(first, second) { | 202 AutomationPredicate.linebreak = function(first, second) { |
221 // TODO(dtseng): Use next/previousOnLin once available. | 203 // TODO(dtseng): Use next/previousOnLin once available. |
222 var fl = first.location; | 204 var fl = first.location; |
223 var sl = second.location; | 205 var sl = second.location; |
224 return fl.top != sl.top || | 206 return fl.top != sl.top || |
225 (fl.top + fl.height != sl.top + sl.height); | 207 (fl.top + fl.height != sl.top + sl.height); |
226 }; | 208 }; |
227 | 209 |
228 /** | 210 /** |
229 * Matches against a node that should be visited but not considered a leaf. | 211 * Matches against a node that contains other interesting nodes. |
| 212 * These nodes should always have their subtrees scanned when navigating. |
230 * @param {!AutomationNode} node | 213 * @param {!AutomationNode} node |
231 * @return {boolean} | 214 * @return {boolean} |
232 */ | 215 */ |
233 AutomationPredicate.container = function(node) { | 216 AutomationPredicate.container = function(node) { |
234 if (node.role == RoleType.rootWebArea) | 217 return AutomationPredicate.structuralContainer(node) || |
235 return !node.parent || node.parent.root.role != RoleType.rootWebArea; | 218 node.role == RoleType.div || |
236 | 219 node.role == RoleType.document || |
237 return node.role == RoleType.document || | 220 node.role == RoleType.group || |
| 221 node.role == RoleType.listItem || |
238 node.role == RoleType.toolbar || | 222 node.role == RoleType.toolbar || |
239 node.role == RoleType.window; | 223 node.role == RoleType.window; |
240 }; | 224 }; |
241 | 225 |
242 /** | 226 /** |
243 * Leaf nodes that should be ignored while traversing the automation tree. For | 227 * Matches against nodes that contain interesting nodes, but should never be |
244 * example, apply this predicate when moving to the next element. | 228 * visited. |
245 * @param {!AutomationNode} node | 229 * @param {!AutomationNode} node |
246 * @return {boolean} | 230 * @return {boolean} |
247 */ | 231 */ |
248 AutomationPredicate.shouldIgnoreLeaf = function(node) { | 232 AutomationPredicate.structuralContainer = function(node) { |
| 233 return node.role == RoleType.rootWebArea || |
| 234 node.role == RoleType.embeddedObject || |
| 235 node.role == RoleType.iframe || |
| 236 node.role == RoleType.iframePresentational; |
| 237 }; |
| 238 |
| 239 /** |
| 240 * Returns whether the given node should not be crossed when performing |
| 241 * traversals up the ancestry chain. |
| 242 * @param {AutomationNode} node |
| 243 * @return {boolean} |
| 244 */ |
| 245 AutomationPredicate.root = function(node) { |
| 246 switch (node.role) { |
| 247 case RoleType.dialog: |
| 248 case RoleType.window: |
| 249 return true; |
| 250 case RoleType.toolbar: |
| 251 return node.root.role == RoleType.desktop; |
| 252 case RoleType.rootWebArea: |
| 253 return !node.parent || node.parent.root.role == RoleType.desktop; |
| 254 default: |
| 255 return false; |
| 256 } |
| 257 }; |
| 258 |
| 259 /** |
| 260 * Nodes that should be ignored while traversing the automation tree. For |
| 261 * example, apply this predicate when moving to the next object. |
| 262 * @param {!AutomationNode} node |
| 263 * @return {boolean} |
| 264 */ |
| 265 AutomationPredicate.shouldIgnoreNode = function(node) { |
| 266 // Ignore invisible nodes. |
249 if (node.state.invisible || | 267 if (node.state.invisible || |
250 (node.location.height == 0 && node.location.width == 0)) | 268 (node.location.height == 0 && node.location.width == 0)) |
251 return true; | 269 return true; |
252 | 270 |
253 if (node.name || node.value) | 271 // Ignore structural containres. |
| 272 if (AutomationPredicate.structuralContainer(node)) |
| 273 return true; |
| 274 |
| 275 // Don't ignore nodes with names. |
| 276 if (node.name || node.value || node.description) |
254 return false; | 277 return false; |
255 | 278 |
| 279 // Ignore some roles. |
256 return AutomationPredicate.leaf(node) && | 280 return AutomationPredicate.leaf(node) && |
257 (node.role == RoleType.client || | 281 (node.role == RoleType.client || |
258 node.role == RoleType.div || | 282 node.role == RoleType.div || |
259 node.role == RoleType.group || | 283 node.role == RoleType.group || |
260 node.role == RoleType.image || | 284 node.role == RoleType.image || |
261 node.role == RoleType.staticText); | 285 node.role == RoleType.staticText); |
262 }; | 286 }; |
263 | 287 |
264 }); // goog.scope | 288 }); // goog.scope |
OLD | NEW |