Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(87)

Side by Side Diff: chrome/browser/resources/chromeos/chromevox/common/braille_util.js

Issue 1362223003: Improve braille related message descriptions and clean up message handling in Chromevox. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@inputtypeexception
Patch Set: Move another braille message to Msgs.Untranslated Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 general braille functionality. 6 * @fileoverview A utility class for general braille functionality.
7 */ 7 */
8 8
9 9
10 goog.provide('cvox.BrailleUtil'); 10 goog.provide('cvox.BrailleUtil');
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 * n: replaced with braille name. 51 * n: replaced with braille name.
52 * r: replaced with braille role. 52 * r: replaced with braille role.
53 * s: replaced with braille state. 53 * s: replaced with braille state.
54 * c: replaced with braille container role; this potentially returns whitespace, 54 * c: replaced with braille container role; this potentially returns whitespace,
55 * so place at the beginning or end of templates for trimming. 55 * so place at the beginning or end of templates for trimming.
56 * v: replaced with braille value. 56 * v: replaced with braille value.
57 * @type {Object<string>} 57 * @type {Object<string>}
58 */ 58 */
59 cvox.BrailleUtil.TEMPLATE = { 59 cvox.BrailleUtil.TEMPLATE = {
60 'base': 'c n v r s', 60 'base': 'c n v r s',
61 'aria_role_alert': 'r: n', 61 'role_alert': 'r: n',
62 'aria_role_button': 'n r s', 62 'role_button': 'n r s',
63 'aria_role_checkbox': 'n r s', 63 'role_checkbox': 'n r s',
64 'aria_role_menuitemcheckbox': 'n r s', 64 'role_menuitemcheckbox': 'n r s',
65 'aria_role_menuitemradio': 'n r s', 65 'role_menuitemradio': 'n r s',
66 'aria_role_radio': 'n r s', 66 'role_radio': 'n r s',
67 'aria_role_textbox': 'n: v r s', 67 'role_textbox': 'n: v r s',
68 'input_type_button': 'n r s',
69 'input_type_checkbox': 'n r s',
70 'input_type_email': 'n: v r s', 68 'input_type_email': 'n: v r s',
71 'input_type_number': 'n: v r s', 69 'input_type_number': 'n: v r s',
72 'input_type_password': 'n: v r s', 70 'input_type_password': 'n: v r s',
73 'input_type_radio': 'n r s',
74 'input_type_search': 'n: v r s', 71 'input_type_search': 'n: v r s',
75 'input_type_submit': 'n r s',
76 'input_type_text': 'n: v r s', 72 'input_type_text': 'n: v r s',
77 'input_type_tel': 'n: v r s',
78 'input_type_url': 'n: v r s', 73 'input_type_url': 'n: v r s',
79 'tag_button': 'n r s',
80 'tag_textarea': 'n: v r s' 74 'tag_textarea': 'n: v r s'
81 }; 75 };
82 76
83 77
84 /** 78 /**
85 * Gets the braille name for a node. 79 * Gets the braille name for a node.
86 * See DomUtil for a more precise definition of 'name'. 80 * See DomUtil for a more precise definition of 'name'.
87 * Additionally, whitespace is trimmed. 81 * Additionally, whitespace is trimmed.
88 * @param {Node} node The node. 82 * @param {Node} node The node.
89 * @return {string} The string representation. 83 * @return {string} The string representation.
(...skipping 14 matching lines...) Expand all
104 */ 98 */
105 cvox.BrailleUtil.getRoleMsg = function(node) { 99 cvox.BrailleUtil.getRoleMsg = function(node) {
106 if (!node) { 100 if (!node) {
107 return ''; 101 return '';
108 } 102 }
109 var roleMsg = cvox.DomUtil.getRoleMsg(node, cvox.VERBOSITY_VERBOSE); 103 var roleMsg = cvox.DomUtil.getRoleMsg(node, cvox.VERBOSITY_VERBOSE);
110 if (roleMsg) { 104 if (roleMsg) {
111 roleMsg = cvox.DomUtil.collapseWhitespace(roleMsg); 105 roleMsg = cvox.DomUtil.collapseWhitespace(roleMsg);
112 } 106 }
113 if (roleMsg && (roleMsg.length > 0)) { 107 if (roleMsg && (roleMsg.length > 0)) {
114 if (cvox.ChromeVox.msgs.getMsg(roleMsg + '_brl')) { 108 if (Msgs.getMsg(roleMsg + '_brl')) {
115 roleMsg += '_brl'; 109 roleMsg += '_brl';
116 } 110 }
117 } 111 }
118 return roleMsg; 112 return roleMsg;
119 }; 113 };
120 114
121 115
122 /** 116 /**
123 * Transforms a {@code cvox.NodeState} list of state messages to the 117 * Transforms a {@code cvox.NodeState} list of state messages to the
124 * corresponding messages for braille and expands them into a localized 118 * corresponding messages for braille and expands them into a localized
125 * string suitable for output on a braille display. 119 * string suitable for output on a braille display.
126 * @param {cvox.NodeState} stateMsgs The states to expand. The content of this 120 * @param {cvox.NodeState} stateMsgs The states to expand. The content of this
127 * array is modified. 121 * array is modified.
128 * @return {string} The string representation. 122 * @return {string} The string representation.
129 * @private 123 * @private
130 */ 124 */
131 cvox.BrailleUtil.expandStateMsgs_ = function(stateMsgs) { 125 cvox.BrailleUtil.expandStateMsgs_ = function(stateMsgs) {
132 stateMsgs.forEach(function(state) { 126 stateMsgs.forEach(function(state) {
133 // Check to see if a variant of the message with '_brl' exists, 127 // Check to see if a variant of the message with '_brl' exists,
134 // and use it if so. 128 // and use it if so.
135 // 129 //
136 // Note: many messages are templatized, and if we don't pass any 130 // Note: many messages are templatized, and if we don't pass any
137 // argument to substitute, getMsg might throw an error if the 131 // argument to substitute, getMsg might throw an error if the
138 // resulting string is empty. To avoid this, we pass a dummy 132 // resulting string is empty. To avoid this, we pass a dummy
139 // substitution string array here. 133 // substitution string array here.
140 var dummySubs = ['dummy', 'dummy', 'dummy']; 134 var dummySubs = ['dummy', 'dummy', 'dummy'];
141 if (cvox.ChromeVox.msgs.getMsg(state[0] + '_brl', dummySubs)) { 135 if (Msgs.getMsg(state[0] + '_brl', dummySubs)) {
142 state[0] += '_brl'; 136 state[0] += '_brl';
143 } 137 }
144 }); 138 });
145 return cvox.NodeStateUtil.expand(stateMsgs); 139 return cvox.NodeStateUtil.expand(stateMsgs);
146 }; 140 };
147 141
148 142
149 /** 143 /**
150 * Gets the braille container role of a node. 144 * Gets the braille container role of a node.
151 * @param {Node} prev The previous node in navigation. 145 * @param {Node} prev The previous node in navigation.
152 * @param {Node} node The node. 146 * @param {Node} node The node.
153 * @return {string} The string representation. 147 * @return {string} The string representation.
154 */ 148 */
155 cvox.BrailleUtil.getContainer = function(prev, node) { 149 cvox.BrailleUtil.getContainer = function(prev, node) {
156 if (!prev || !node) { 150 if (!prev || !node) {
157 return ''; 151 return '';
158 } 152 }
159 var ancestors = cvox.DomUtil.getUniqueAncestors(prev, node); 153 var ancestors = cvox.DomUtil.getUniqueAncestors(prev, node);
160 for (var i = 0, container; container = ancestors[i]; i++) { 154 for (var i = 0, container; container = ancestors[i]; i++) {
161 var msg = cvox.BrailleUtil.getRoleMsg(container); 155 var msg = cvox.BrailleUtil.getRoleMsg(container);
162 if (msg && cvox.BrailleUtil.CONTAINER.indexOf(msg) != -1) { 156 if (msg && cvox.BrailleUtil.CONTAINER.indexOf(msg) != -1) {
163 return cvox.ChromeVox.msgs.getMsg(msg); 157 return Msgs.getMsg(msg);
164 } 158 }
165 } 159 }
166 return ''; 160 return '';
167 }; 161 };
168 162
169 163
170 /** 164 /**
171 * Gets the braille value of a node. A {@code cvox.ValueSpan} will be 165 * Gets the braille value of a node. A {@code cvox.ValueSpan} will be
172 * attached, along with (possibly) a {@code cvox.ValueSelectionSpan}. 166 * attached, along with (possibly) a {@code cvox.ValueSelectionSpan}.
173 * @param {Node} node The node. 167 * @param {Node} node The node.
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 if (!state) { 237 if (!state) {
244 if (node) { 238 if (node) {
245 state = cvox.BrailleUtil.expandStateMsgs_( 239 state = cvox.BrailleUtil.expandStateMsgs_(
246 cvox.DomUtil.getStateMsgs(node, true)); 240 cvox.DomUtil.getStateMsgs(node, true));
247 } else { 241 } else {
248 state = ''; 242 state = '';
249 } 243 }
250 } 244 }
251 var role = opt_override.role || ''; 245 var role = opt_override.role || '';
252 if (!role && roleMsg) { 246 if (!role && roleMsg) {
253 role = cvox.ChromeVox.msgs.getMsg(roleMsg + '_brl') || 247 role = Msgs.getMsg(roleMsg + '_brl') ||
254 cvox.ChromeVox.msgs.getMsg(roleMsg); 248 Msgs.getMsg(roleMsg);
255 } 249 }
256 250
257 var templated = new cvox.Spannable(); 251 var templated = new cvox.Spannable();
258 var mapChar = function(c) { 252 var mapChar = function(c) {
259 switch (c) { 253 switch (c) {
260 case 'n': 254 case 'n':
261 return opt_override.name || cvox.BrailleUtil.getName(node); 255 return opt_override.name || cvox.BrailleUtil.getName(node);
262 case 'r': 256 case 'r':
263 return role; 257 return role;
264 case 's': 258 case 's':
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 * @param {number} number The number to clamp. 365 * @param {number} number The number to clamp.
372 * @param {number} min The minimum value to return. 366 * @param {number} min The minimum value to return.
373 * @param {number} max The maximum value to return. 367 * @param {number} max The maximum value to return.
374 * @return {number} {@code number} if it is within the bounds, or the nearest 368 * @return {number} {@code number} if it is within the bounds, or the nearest
375 * number within the bounds otherwise. 369 * number within the bounds otherwise.
376 * @private 370 * @private
377 */ 371 */
378 cvox.BrailleUtil.clamp_ = function(number, min, max) { 372 cvox.BrailleUtil.clamp_ = function(number, min, max) {
379 return Math.min(Math.max(number, min), max); 373 return Math.min(Math.max(number, min), max);
380 }; 374 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698