| 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 705 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 716 /** | 716 /** |
| 717 * Calling this will make the next speech utterance use |mode| even if it would | 717 * Calling this will make the next speech utterance use |mode| even if it would |
| 718 * normally queue or do a category flush. This differs from the |withQueueMode| | 718 * normally queue or do a category flush. This differs from the |withQueueMode| |
| 719 * instance method as it can apply to future output. | 719 * instance method as it can apply to future output. |
| 720 * @param {cvox.QueueMode} mode | 720 * @param {cvox.QueueMode} mode |
| 721 */ | 721 */ |
| 722 Output.forceModeForNextSpeechUtterance = function(mode) { | 722 Output.forceModeForNextSpeechUtterance = function(mode) { |
| 723 Output.forceModeForNextSpeechUtterance_ = mode; | 723 Output.forceModeForNextSpeechUtterance_ = mode; |
| 724 }; | 724 }; |
| 725 | 725 |
| 726 /** |
| 727 * For a given automation property, return true if the the value |
| 728 * represents something 'truthy', e.g.: for checked: |
| 729 * 'true'|'mixed' -> true |
| 730 * 'false'|undefined -> false |
| 731 */ |
| 732 Output.isTruthy = function(node, attrib) { |
| 733 switch(attrib) { |
| 734 case 'checked': |
| 735 return node.checked && node.checked !== 'false'; |
| 736 default: |
| 737 return node[attrib] !== undefined || node.state[attrib]; |
| 738 } |
| 739 }; |
| 740 |
| 726 Output.prototype = { | 741 Output.prototype = { |
| 727 /** | 742 /** |
| 728 * @return {boolean} True if there's any speech that will be output. | 743 * @return {boolean} True if there's any speech that will be output. |
| 729 */ | 744 */ |
| 730 get hasSpeech() { | 745 get hasSpeech() { |
| 731 for (var i = 0; i < this.speechBuffer_.length; i++) { | 746 for (var i = 0; i < this.speechBuffer_.length; i++) { |
| 732 if (this.speechBuffer_[i].trim().length) | 747 if (this.speechBuffer_[i].trim().length) |
| 733 return true; | 748 return true; |
| 734 } | 749 } |
| 735 return false; | 750 return false; |
| (...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1148 } else if (token == 'parentChildCount') { | 1163 } else if (token == 'parentChildCount') { |
| 1149 if (node.parent) { | 1164 if (node.parent) { |
| 1150 options.annotation.push(token); | 1165 options.annotation.push(token); |
| 1151 var count = node.parent.children.filter(function(child) { | 1166 var count = node.parent.children.filter(function(child) { |
| 1152 return node.role == child.role; | 1167 return node.role == child.role; |
| 1153 }).length; | 1168 }).length; |
| 1154 this.append_(buff, String(count)); | 1169 this.append_(buff, String(count)); |
| 1155 } | 1170 } |
| 1156 } else if (token == 'checked') { | 1171 } else if (token == 'checked') { |
| 1157 var msg; | 1172 var msg; |
| 1158 var ariaChecked = node.htmlAttributes['aria-checked']; | 1173 switch (node.checked) { |
| 1159 switch (ariaChecked) { | |
| 1160 case 'mixed': | 1174 case 'mixed': |
| 1161 msg = 'aria_checked_mixed'; | 1175 msg = 'checked_mixed'; |
| 1162 break; | 1176 break; |
| 1163 case 'true': | 1177 case 'true': |
| 1164 msg = 'aria_checked_true'; | 1178 msg = 'checked_true'; |
| 1165 break; | |
| 1166 case 'false': | |
| 1167 msg = 'aria_checked_false'; | |
| 1168 break; | 1179 break; |
| 1169 default: | 1180 default: |
| 1170 msg = node.state[StateType.CHECKED] ? | 1181 msg = 'checked_false'; |
| 1171 'aria_checked_true' : 'aria_checked_false'; | 1182 break; |
| 1172 } | 1183 } |
| 1173 this.format_(node, '@' + msg, buff); | 1184 this.format_(node, '@' + msg, buff); |
| 1174 } else if (token == 'state') { | 1185 } else if (token == 'state') { |
| 1175 if (node.state) { | 1186 if (node.state) { |
| 1176 Object.getOwnPropertyNames(node.state).forEach(function(s) { | 1187 Object.getOwnPropertyNames(node.state).forEach(function(s) { |
| 1177 var stateInfo = Output.STATE_INFO_[s]; | 1188 var stateInfo = Output.STATE_INFO_[s]; |
| 1178 if (stateInfo && !stateInfo.isRoleSpecific && stateInfo.on) | 1189 if (stateInfo && !stateInfo.isRoleSpecific && stateInfo.on) |
| 1179 this.format_(node, '@' + stateInfo.on.msgId, buff); | 1190 this.format_(node, '@' + stateInfo.on.msgId, buff); |
| 1180 }.bind(this)); | 1191 }.bind(this)); |
| 1181 } | 1192 } |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1293 var msgId = | 1304 var msgId = |
| 1294 this.formatOptions_.braille ? resolvedInfo.msgId + '_brl' : | 1305 this.formatOptions_.braille ? resolvedInfo.msgId + '_brl' : |
| 1295 resolvedInfo.msgId; | 1306 resolvedInfo.msgId; |
| 1296 var msg = Msgs.getMsg(msgId); | 1307 var msg = Msgs.getMsg(msgId); |
| 1297 this.append_(buff, msg, options); | 1308 this.append_(buff, msg, options); |
| 1298 } else if (tree.firstChild) { | 1309 } else if (tree.firstChild) { |
| 1299 // Custom functions. | 1310 // Custom functions. |
| 1300 if (token == 'if') { | 1311 if (token == 'if') { |
| 1301 var cond = tree.firstChild; | 1312 var cond = tree.firstChild; |
| 1302 var attrib = cond.value.slice(1); | 1313 var attrib = cond.value.slice(1); |
| 1303 if (node[attrib] !== undefined || node.state[attrib]) | 1314 if (Output.isTruthy(node, attrib)) |
| 1304 this.format_(node, cond.nextSibling, buff); | 1315 this.format_(node, cond.nextSibling, buff); |
| 1305 else | 1316 else |
| 1306 this.format_(node, cond.nextSibling.nextSibling, buff); | 1317 this.format_(node, cond.nextSibling.nextSibling, buff); |
| 1307 } else if (token == 'earcon') { | 1318 } else if (token == 'earcon') { |
| 1308 // Ignore unless we're generating speech output. | 1319 // Ignore unless we're generating speech output. |
| 1309 if (!this.formatOptions_.speech) | 1320 if (!this.formatOptions_.speech) |
| 1310 return; | 1321 return; |
| 1311 | 1322 |
| 1312 options.annotation.push( | 1323 options.annotation.push( |
| 1313 new Output.EarconAction(tree.firstChild.value, | 1324 new Output.EarconAction(tree.firstChild.value, |
| (...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1876 /** | 1887 /** |
| 1877 * Gets the output buffer for braille. | 1888 * Gets the output buffer for braille. |
| 1878 * @return {!Spannable} | 1889 * @return {!Spannable} |
| 1879 */ | 1890 */ |
| 1880 get brailleOutputForTest() { | 1891 get brailleOutputForTest() { |
| 1881 return this.mergeBraille_(this.brailleBuffer_); | 1892 return this.mergeBraille_(this.brailleBuffer_); |
| 1882 } | 1893 } |
| 1883 }; | 1894 }; |
| 1884 | 1895 |
| 1885 }); // goog.scope | 1896 }); // goog.scope |
| OLD | NEW |