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 A utility class for building NavDescriptions from the dom. | 6 * @fileoverview A utility class for building NavDescriptions from the dom. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 goog.provide('cvox.DescriptionUtil'); | 10 goog.provide('cvox.DescriptionUtil'); |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 // Now, generate a description for all other elements. | 209 // Now, generate a description for all other elements. |
210 var ancestors = cvox.DomUtil.getUniqueAncestors(prevNode, node, true); | 210 var ancestors = cvox.DomUtil.getUniqueAncestors(prevNode, node, true); |
211 var desc = cvox.DescriptionUtil.getDescriptionFromAncestors( | 211 var desc = cvox.DescriptionUtil.getDescriptionFromAncestors( |
212 ancestors, recursive, verbosity); | 212 ancestors, recursive, verbosity); |
213 var prevAncestors = cvox.DomUtil.getUniqueAncestors(node, prevNode); | 213 var prevAncestors = cvox.DomUtil.getUniqueAncestors(node, prevNode); |
214 if (cvox.DescriptionUtil.shouldDescribeExit_(prevAncestors)) { | 214 if (cvox.DescriptionUtil.shouldDescribeExit_(prevAncestors)) { |
215 var prevDesc = cvox.DescriptionUtil.getDescriptionFromAncestors( | 215 var prevDesc = cvox.DescriptionUtil.getDescriptionFromAncestors( |
216 prevAncestors, recursive, verbosity); | 216 prevAncestors, recursive, verbosity); |
217 if (prevDesc.context && !desc.context) { | 217 if (prevDesc.context && !desc.context) { |
218 desc.context = | 218 desc.context = |
219 cvox.ChromeVox.msgs.getMsg('exited_container', [prevDesc.context]); | 219 Msgs.getMsg('exited_container', [prevDesc.context]); |
220 } | 220 } |
221 } | 221 } |
222 return [desc]; | 222 return [desc]; |
223 }; | 223 }; |
224 | 224 |
225 | 225 |
226 /** | 226 /** |
227 * Returns an array of NavDescriptions that includes everything that would be | 227 * Returns an array of NavDescriptions that includes everything that would be |
228 * spoken by an object walker while traversing from prevSel to sel. | 228 * spoken by an object walker while traversing from prevSel to sel. |
229 * It also includes any necessary annotations and context about the set of | 229 * It also includes any necessary annotations and context about the set of |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 var commonAnnotation = annotations[0]; | 369 var commonAnnotation = annotations[0]; |
370 var firstContext = descriptions[0].context; | 370 var firstContext = descriptions[0].context; |
371 descriptions[0].context = ''; | 371 descriptions[0].context = ''; |
372 for (var i = 0; i < descriptions.length; i++) { | 372 for (var i = 0; i < descriptions.length; i++) { |
373 descriptions[i].annotation = ''; | 373 descriptions[i].annotation = ''; |
374 } | 374 } |
375 | 375 |
376 descriptions.splice(0, 0, new cvox.NavDescription({ | 376 descriptions.splice(0, 0, new cvox.NavDescription({ |
377 context: firstContext, | 377 context: firstContext, |
378 text: '', | 378 text: '', |
379 annotation: cvox.ChromeVox.msgs.getMsg( | 379 annotation: Msgs.getMsg( |
380 'collection', | 380 'collection', |
381 [commonAnnotation, | 381 [commonAnnotation, |
382 cvox.ChromeVox.msgs.getNumber(descriptions.length)]) | 382 Msgs.getNumber(descriptions.length)]) |
383 })); | 383 })); |
384 } | 384 } |
385 }; | 385 }; |
386 | 386 |
387 | 387 |
388 /** | 388 /** |
389 * Pulls the annotations from a description array. | 389 * Pulls the annotations from a description array. |
390 * @param {Array<cvox.NavDescription>} descriptions The descriptions. | 390 * @param {Array<cvox.NavDescription>} descriptions The descriptions. |
391 * @return {Array<string>} The annotations. | 391 * @return {Array<string>} The annotations. |
392 * @private | 392 * @private |
393 */ | 393 */ |
394 cvox.DescriptionUtil.getAnnotations_ = function(descriptions) { | 394 cvox.DescriptionUtil.getAnnotations_ = function(descriptions) { |
395 var annotations = []; | 395 var annotations = []; |
396 for (var i = 0; i < descriptions.length; ++i) { | 396 for (var i = 0; i < descriptions.length; ++i) { |
397 var description = descriptions[i]; | 397 var description = descriptions[i]; |
398 if (annotations.indexOf(description.annotation) == -1) { | 398 if (annotations.indexOf(description.annotation) == -1) { |
399 // If we have an Internal link collection, call it Link collection. | 399 // If we have an Internal link collection, call it Link collection. |
400 // NOTE(deboer): The message comparison is a symptom of a bad design. | 400 // NOTE(deboer): The message comparison is a symptom of a bad design. |
401 // I suspect this code belongs elsewhere but I don't know where, yet. | 401 // I suspect this code belongs elsewhere but I don't know where, yet. |
402 var linkMsg = cvox.ChromeVox.msgs.getMsg('tag_link'); | 402 var linkMsg = Msgs.getMsg('role_link'); |
403 if (description.annotation.toLowerCase().indexOf(linkMsg.toLowerCase()) != | 403 if (description.annotation.toLowerCase().indexOf(linkMsg.toLowerCase()) != |
404 -1) { | 404 -1) { |
405 if (annotations.indexOf(linkMsg) == -1) { | 405 if (annotations.indexOf(linkMsg) == -1) { |
406 annotations.push(linkMsg); | 406 annotations.push(linkMsg); |
407 } | 407 } |
408 } else { | 408 } else { |
409 annotations.push(description.annotation); | 409 annotations.push(description.annotation); |
410 } | 410 } |
411 } | 411 } |
412 } | 412 } |
413 return annotations; | 413 return annotations; |
414 }; | 414 }; |
415 | 415 |
416 | 416 |
417 /** | 417 /** |
418 * Returns true if this annotation should be grouped as a collection, | 418 * Returns true if this annotation should be grouped as a collection, |
419 * meaning that instead of repeating the annotation for each item, we | 419 * meaning that instead of repeating the annotation for each item, we |
420 * just announce <annotation> collection with <n> items at the front. | 420 * just announce <annotation> collection with <n> items at the front. |
421 * | 421 * |
422 * Currently enabled for links, but could be extended to support other | 422 * Currently enabled for links, but could be extended to support other |
423 * roles that make sense. | 423 * roles that make sense. |
424 * | 424 * |
425 * @param {string} annotation The annotation text. | 425 * @param {string} annotation The annotation text. |
426 * @return {boolean} If this annotation should be a collection. | 426 * @return {boolean} If this annotation should be a collection. |
427 * @private | 427 * @private |
428 */ | 428 */ |
429 cvox.DescriptionUtil.isAnnotationCollection_ = function(annotation) { | 429 cvox.DescriptionUtil.isAnnotationCollection_ = function(annotation) { |
430 return (annotation == cvox.ChromeVox.msgs.getMsg('tag_link')); | 430 return (annotation == Msgs.getMsg('role_link')); |
431 }; | 431 }; |
432 | 432 |
433 /** | 433 /** |
434 * Determines whether to describe the exit of an ancestor chain. | 434 * Determines whether to describe the exit of an ancestor chain. |
435 * @param {Array<Node>} ancestors The ancestors exited during navigation. | 435 * @param {Array<Node>} ancestors The ancestors exited during navigation. |
436 * @return {boolean} The result. | 436 * @return {boolean} The result. |
437 * @private | 437 * @private |
438 */ | 438 */ |
439 cvox.DescriptionUtil.shouldDescribeExit_ = function(ancestors) { | 439 cvox.DescriptionUtil.shouldDescribeExit_ = function(ancestors) { |
440 return ancestors.some(function(node) { | 440 return ancestors.some(function(node) { |
(...skipping 24 matching lines...) Expand all Loading... |
465 var ret = speechEngine.evaluateNode(traverse.activeNode); | 465 var ret = speechEngine.evaluateNode(traverse.activeNode); |
466 if (ret == []) { | 466 if (ret == []) { |
467 return [new cvox.NavDescription({'text': 'empty math'})]; | 467 return [new cvox.NavDescription({'text': 'empty math'})]; |
468 } | 468 } |
469 if (cvox.ChromeVox.verbosity == cvox.VERBOSITY_VERBOSE) { | 469 if (cvox.ChromeVox.verbosity == cvox.VERBOSITY_VERBOSE) { |
470 ret[ret.length - 1].annotation = 'math'; | 470 ret[ret.length - 1].annotation = 'math'; |
471 } | 471 } |
472 ret[0].pushEarcon(cvox.Earcon.MATH); | 472 ret[0].pushEarcon(cvox.Earcon.MATH); |
473 return ret; | 473 return ret; |
474 }; | 474 }; |
OLD | NEW |