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 Provides output services for ChromeVox. | 6 * @fileoverview Provides output services for ChromeVox. |
7 */ | 7 */ |
8 | 8 |
9 goog.provide('Output'); | 9 goog.provide('Output'); |
10 goog.provide('Output.EventType'); | 10 goog.provide('Output.EventType'); |
(...skipping 977 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
988 options.annotation.push(new Output.NodeSpan(node)); | 988 options.annotation.push(new Output.NodeSpan(node)); |
989 | 989 |
990 // Process token based on prefix. | 990 // Process token based on prefix. |
991 var prefix = token[0]; | 991 var prefix = token[0]; |
992 token = token.slice(1); | 992 token = token.slice(1); |
993 | 993 |
994 // All possible tokens based on prefix. | 994 // All possible tokens based on prefix. |
995 if (prefix == '$') { | 995 if (prefix == '$') { |
996 if (token == 'value') { | 996 if (token == 'value') { |
997 var text = node.value; | 997 var text = node.value; |
| 998 if (!node.state.editable && node.name == text) |
| 999 return; |
998 if (text !== undefined) { | 1000 if (text !== undefined) { |
999 if (node.textSelStart !== undefined) { | 1001 if (node.textSelStart !== undefined) { |
1000 options.annotation.push(new Output.SelectionSpan( | 1002 options.annotation.push(new Output.SelectionSpan( |
1001 node.textSelStart, | 1003 node.textSelStart, |
1002 node.textSelEnd)); | 1004 node.textSelEnd)); |
1003 } | 1005 } |
1004 } | 1006 } |
1005 options.annotation.push(token); | 1007 options.annotation.push(token); |
1006 this.append_(buff, text, options); | 1008 this.append_(buff, text, options); |
1007 } else if (token == 'name') { | 1009 } else if (token == 'name') { |
1008 options.annotation.push(token); | 1010 options.annotation.push(token); |
1009 var earcon = node ? this.findEarcon_(node, opt_prevNode) : null; | 1011 var earcon = node ? this.findEarcon_(node, opt_prevNode) : null; |
1010 if (earcon) | 1012 if (earcon) |
1011 options.annotation.push(earcon); | 1013 options.annotation.push(earcon); |
1012 this.append_(buff, node.name, options); | 1014 this.append_(buff, node.name, options); |
1013 } else if (token == 'nameFromNode') { | 1015 } else if (token == 'nameFromNode') { |
1014 if (chrome.automation.NameFromType[node.nameFrom] == | 1016 if (chrome.automation.NameFromType[node.nameFrom] == |
1015 'nameFromContents') | 1017 'nameFromContents') |
1016 return; | 1018 return; |
1017 | 1019 |
1018 options.annotation.push('name'); | 1020 options.annotation.push('name'); |
1019 this.append_(buff, node.name, options); | 1021 this.append_(buff, node.name, options); |
1020 } else if (token == 'nameOrDescendants') { | 1022 } else if (token == 'nameOrDescendants') { |
1021 options.annotation.push(token); | 1023 options.annotation.push(token); |
1022 if (node.name) | 1024 if (node.name) |
1023 this.append_(buff, node.name, options); | 1025 this.append_(buff, node.name, options); |
1024 else | 1026 else |
1025 this.format_(node, '$descendants', buff); | 1027 this.format_(node, '$descendants', buff); |
| 1028 } else if (token == 'description') { |
| 1029 if (node.name == node.description || node.value == node.description) |
| 1030 return; |
| 1031 options.annotation.push(token); |
| 1032 this.append_(buff, node.description, options); |
1026 } else if (token == 'indexInParent') { | 1033 } else if (token == 'indexInParent') { |
1027 options.annotation.push(token); | 1034 options.annotation.push(token); |
1028 this.append_(buff, String(node.indexInParent + 1)); | 1035 this.append_(buff, String(node.indexInParent + 1)); |
1029 } else if (token == 'parentChildCount') { | 1036 } else if (token == 'parentChildCount') { |
1030 options.annotation.push(token); | 1037 options.annotation.push(token); |
1031 if (node.parent) | 1038 if (node.parent) |
1032 this.append_(buff, String(node.parent.children.length)); | 1039 this.append_(buff, String(node.parent.children.length)); |
1033 } else if (token == 'state') { | 1040 } else if (token == 'state') { |
1034 options.annotation.push(token); | 1041 options.annotation.push(token); |
1035 Object.getOwnPropertyNames(node.state).forEach(function(s) { | 1042 Object.getOwnPropertyNames(node.state).forEach(function(s) { |
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1427 /** | 1434 /** |
1428 * Appends output to the |buff|. | 1435 * Appends output to the |buff|. |
1429 * @param {!Array<Spannable>} buff | 1436 * @param {!Array<Spannable>} buff |
1430 * @param {string|!Spannable} value | 1437 * @param {string|!Spannable} value |
1431 * @param {{isUnique: (boolean|undefined), | 1438 * @param {{isUnique: (boolean|undefined), |
1432 * annotation: !Array<*>}=} opt_options | 1439 * annotation: !Array<*>}=} opt_options |
1433 */ | 1440 */ |
1434 append_: function(buff, value, opt_options) { | 1441 append_: function(buff, value, opt_options) { |
1435 opt_options = opt_options || {isUnique: false, annotation: []}; | 1442 opt_options = opt_options || {isUnique: false, annotation: []}; |
1436 | 1443 |
1437 // Reject empty values without annotations. | 1444 // Reject empty values without meaningful annotations. |
1438 if ((!value || value.length == 0) && opt_options.annotation.length == 0) | 1445 if ((!value || value.length == 0) && opt_options.annotation.every( |
| 1446 function(a) { |
| 1447 return !(a instanceof Output.Action) && |
| 1448 !(a instanceof Output.SelectionSpan); |
| 1449 |
| 1450 })) |
1439 return; | 1451 return; |
1440 | 1452 |
1441 var spannableToAdd = new Spannable(value); | 1453 var spannableToAdd = new Spannable(value); |
1442 opt_options.annotation.forEach(function(a) { | 1454 opt_options.annotation.forEach(function(a) { |
1443 spannableToAdd.setSpan(a, 0, spannableToAdd.length); | 1455 spannableToAdd.setSpan(a, 0, spannableToAdd.length); |
1444 }); | 1456 }); |
1445 | 1457 |
1446 // |isUnique| specifies an annotation that cannot be duplicated. | 1458 // |isUnique| specifies an annotation that cannot be duplicated. |
1447 if (opt_options.isUnique) { | 1459 if (opt_options.isUnique) { |
1448 var annotationSansNodes = opt_options.annotation.filter( | 1460 var annotationSansNodes = opt_options.annotation.filter( |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1597 break; | 1609 break; |
1598 } | 1610 } |
1599 earconFinder = earconFinder.parent; | 1611 earconFinder = earconFinder.parent; |
1600 } | 1612 } |
1601 } | 1613 } |
1602 return null; | 1614 return null; |
1603 } | 1615 } |
1604 }; | 1616 }; |
1605 | 1617 |
1606 }); // goog.scope | 1618 }); // goog.scope |
OLD | NEW |