| 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 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 prevNode = node; | 294 prevNode = node; |
| 295 node = curSel.start.node; | 295 node = curSel.start.node; |
| 296 } | 296 } |
| 297 | 297 |
| 298 return descriptions; | 298 return descriptions; |
| 299 }; | 299 }; |
| 300 | 300 |
| 301 /** | 301 /** |
| 302 * Returns the full descriptions of the child nodes that would be gotten by an | 302 * Returns the full descriptions of the child nodes that would be gotten by an |
| 303 * object walker. | 303 * object walker. |
| 304 * @param {?Element} prevnode The previous element if there is one. | 304 * @param {?Node} prevnode The previous element if there is one. |
| 305 * @param {!Element} node The target element. | 305 * @param {!Node} node The target element. |
| 306 * @return {!Array<!cvox.NavDescription>} The descriptions. | 306 * @return {!Array<!cvox.NavDescription>} The descriptions. |
| 307 */ | 307 */ |
| 308 cvox.DescriptionUtil.getFullDescriptionsFromChildren = | 308 cvox.DescriptionUtil.getFullDescriptionsFromChildren = |
| 309 function(prevnode, node) { | 309 function(prevnode, node) { |
| 310 var descriptions = []; | 310 var descriptions = []; |
| 311 if (!node) { | 311 if (!node) { |
| 312 return descriptions; | 312 return descriptions; |
| 313 } | 313 } |
| 314 var desc; | 314 var desc; |
| 315 if (cvox.DomUtil.isLeafNode(node)) { | 315 if (cvox.DomUtil.isLeafNode(node)) { |
| 316 var ancestors; | 316 var ancestors; |
| 317 if (prevnode) { | 317 if (prevnode) { |
| 318 ancestors = cvox.DomUtil.getUniqueAncestors(prevnode, node); | 318 ancestors = cvox.DomUtil.getUniqueAncestors(prevnode, node); |
| 319 } else { | 319 } else { |
| 320 ancestors = new Array(); | 320 ancestors = new Array(); |
| 321 ancestors.push(node); | 321 ancestors.push(node); |
| 322 } | 322 } |
| 323 desc = cvox.DescriptionUtil.getDescriptionFromAncestors( | 323 desc = cvox.DescriptionUtil.getDescriptionFromAncestors( |
| 324 ancestors, true, cvox.ChromeVox.verbosity); | 324 ancestors, true, cvox.ChromeVox.verbosity); |
| 325 descriptions.push(desc); | 325 descriptions.push(desc); |
| 326 return descriptions; | 326 return descriptions; |
| 327 } | 327 } |
| 328 var originalNode = node; | 328 var originalNode = node; |
| 329 var curSel = cvox.CursorSelection.fromNode(node); | 329 var curSel = cvox.CursorSelection.fromNode(node); |
| 330 if (!curSel) { | 330 if (!curSel) { |
| 331 return descriptions; | 331 return descriptions; |
| 332 } | 332 } |
| 333 node = cvox.DescriptionUtil.subWalker_.sync(curSel).start.node; | 333 var newNode = cvox.DescriptionUtil.subWalker_.sync(curSel).start.node; |
| 334 curSel = cvox.CursorSelection.fromNode(node); | 334 curSel = cvox.CursorSelection.fromNode(newNode); |
| 335 if (!curSel) { | 335 if (!curSel) { |
| 336 return descriptions; | 336 return descriptions; |
| 337 } | 337 } |
| 338 while (cvox.DomUtil.isDescendantOfNode(node, originalNode)) { | 338 while (newNode && cvox.DomUtil.isDescendantOfNode(newNode, originalNode)) { |
| 339 descriptions = descriptions.concat( | 339 descriptions = descriptions.concat( |
| 340 cvox.DescriptionUtil.getFullDescriptionsFromChildren(prevnode, node)); | 340 cvox.DescriptionUtil.getFullDescriptionsFromChildren( |
| 341 prevnode, newNode)); |
| 341 curSel = cvox.DescriptionUtil.subWalker_.next(curSel); | 342 curSel = cvox.DescriptionUtil.subWalker_.next(curSel); |
| 342 if (!curSel) { | 343 if (!curSel) { |
| 343 break; | 344 break; |
| 344 } | 345 } |
| 345 curSel = /** @type {!cvox.CursorSelection} */ (curSel); | 346 curSel = /** @type {!cvox.CursorSelection} */ (curSel); |
| 346 prevnode = node; | 347 prevnode = newNode; |
| 347 node = curSel.start.node; | 348 newNode = curSel.start.node; |
| 348 } | 349 } |
| 349 return descriptions; | 350 return descriptions; |
| 350 }; | 351 }; |
| 351 | 352 |
| 352 | 353 |
| 353 /** | 354 /** |
| 354 * Modify the descriptions to say that it is a collection. | 355 * Modify the descriptions to say that it is a collection. |
| 355 * @param {Array<cvox.NavDescription>} descriptions The descriptions. | 356 * @param {Array<cvox.NavDescription>} descriptions The descriptions. |
| 356 * @private | 357 * @private |
| 357 */ | 358 */ |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 444 return true; | 445 return true; |
| 445 } | 446 } |
| 446 return cvox.AriaUtil.isLandmark(node); | 447 return cvox.AriaUtil.isLandmark(node); |
| 447 }); | 448 }); |
| 448 }; | 449 }; |
| 449 | 450 |
| 450 | 451 |
| 451 // TODO(sorge): Bad naming...this thing returns *multiple* descriptions. | 452 // TODO(sorge): Bad naming...this thing returns *multiple* descriptions. |
| 452 /** | 453 /** |
| 453 * Generates a description for a math node. | 454 * Generates a description for a math node. |
| 454 * @param {!Node} node The given node. | 455 * @param {Node} node The given node. |
| 455 * @return {!Array<cvox.NavDescription>} A list of Navigation descriptions. | 456 * @return {!Array<cvox.NavDescription>} A list of Navigation descriptions. |
| 456 */ | 457 */ |
| 457 cvox.DescriptionUtil.getMathDescription = function(node) { | 458 cvox.DescriptionUtil.getMathDescription = function(node) { |
| 459 if (!node) { |
| 460 return []; |
| 461 } |
| 458 // TODO (sorge) This function should evantually be removed. Descriptions | 462 // TODO (sorge) This function should evantually be removed. Descriptions |
| 459 // should come directly from the speech rule engine, taking information on | 463 // should come directly from the speech rule engine, taking information on |
| 460 // verbosity etc. into account. | 464 // verbosity etc. into account. |
| 461 var speechEngine = cvox.SpeechRuleEngine.getInstance(); | 465 var speechEngine = cvox.SpeechRuleEngine.getInstance(); |
| 462 var traverse = cvox.TraverseMath.getInstance(); | 466 var traverse = cvox.TraverseMath.getInstance(); |
| 463 speechEngine.parameterize(cvox.MathmlStore.getInstance()); | 467 speechEngine.parameterize(cvox.MathmlStore.getInstance()); |
| 464 traverse.initialize(node); | 468 traverse.initialize(node); |
| 465 var ret = speechEngine.evaluateNode(traverse.activeNode); | 469 var ret = speechEngine.evaluateNode(traverse.activeNode); |
| 466 if (ret == []) { | 470 if (ret == []) { |
| 467 return [new cvox.NavDescription({'text': 'empty math'})]; | 471 return [new cvox.NavDescription({'text': 'empty math'})]; |
| 468 } | 472 } |
| 469 if (cvox.ChromeVox.verbosity == cvox.VERBOSITY_VERBOSE) { | 473 if (cvox.ChromeVox.verbosity == cvox.VERBOSITY_VERBOSE) { |
| 470 ret[ret.length - 1].annotation = 'math'; | 474 ret[ret.length - 1].annotation = 'math'; |
| 471 } | 475 } |
| 472 ret[0].pushEarcon(cvox.Earcon.MATH); | 476 ret[0].pushEarcon(cvox.Earcon.MATH); |
| 473 return ret; | 477 return ret; |
| 474 }; | 478 }; |
| OLD | NEW |