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

Side by Side Diff: chrome/browser/resources/chromeos/chromevox/braille/expanding_braille_translator.js

Issue 924083004: Shorten Closure template notation from Array.<*> to Array<*> in cvox. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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 Translates text to braille, optionally with some parts 6 * @fileoverview Translates text to braille, optionally with some parts
7 * uncontracted. 7 * uncontracted.
8 */ 8 */
9 9
10 goog.provide('cvox.ExpandingBrailleTranslator'); 10 goog.provide('cvox.ExpandingBrailleTranslator');
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 ALL: 2 74 ALL: 2
75 }; 75 };
76 76
77 77
78 /** 78 /**
79 * Translates text to braille using the translator(s) provided to the 79 * Translates text to braille using the translator(s) provided to the
80 * constructor. See {@code cvox.LibLouis.Translator} for further details. 80 * constructor. See {@code cvox.LibLouis.Translator} for further details.
81 * @param {!cvox.Spannable} text Text to translate. 81 * @param {!cvox.Spannable} text Text to translate.
82 * @param {cvox.ExpandingBrailleTranslator.ExpansionType} expansionType 82 * @param {cvox.ExpandingBrailleTranslator.ExpansionType} expansionType
83 * Indicates how the text marked by a value span, if any, is expanded. 83 * Indicates how the text marked by a value span, if any, is expanded.
84 * @param {function(!ArrayBuffer, !Array.<number>, !Array.<number>)} 84 * @param {function(!ArrayBuffer, !Array<number>, !Array<number>)}
85 * callback Called when the translation is done. It takes resulting 85 * callback Called when the translation is done. It takes resulting
86 * braille cells and positional mappings as parameters. 86 * braille cells and positional mappings as parameters.
87 */ 87 */
88 cvox.ExpandingBrailleTranslator.prototype.translate = 88 cvox.ExpandingBrailleTranslator.prototype.translate =
89 function(text, expansionType, callback) { 89 function(text, expansionType, callback) {
90 var expandRanges = this.findExpandRanges_(text, expansionType); 90 var expandRanges = this.findExpandRanges_(text, expansionType);
91 if (expandRanges.length == 0) { 91 if (expandRanges.length == 0) {
92 this.defaultTranslator_.translate( 92 this.defaultTranslator_.translate(
93 text.toString(), 93 text.toString(),
94 cvox.ExpandingBrailleTranslator.nullParamsToEmptyAdapter_( 94 cvox.ExpandingBrailleTranslator.nullParamsToEmptyAdapter_(
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 var end = pos + /^(\s+|\S+)/.exec(str.substring(pos, end))[0].length; 185 var end = pos + /^(\s+|\S+)/.exec(str.substring(pos, end))[0].length;
186 return {start: start, end: end}; 186 return {start: start, end: end};
187 }; 187 };
188 188
189 189
190 /** 190 /**
191 * Finds the ranges in which contracted braille should not be used. 191 * Finds the ranges in which contracted braille should not be used.
192 * @param {!cvox.Spannable} text Text to find expansion ranges in. 192 * @param {!cvox.Spannable} text Text to find expansion ranges in.
193 * @param {cvox.ExpandingBrailleTranslator.ExpansionType} expansionType 193 * @param {cvox.ExpandingBrailleTranslator.ExpansionType} expansionType
194 * Indicates how the text marked up as the value is expanded. 194 * Indicates how the text marked up as the value is expanded.
195 * @return {!Array.<cvox.ExpandingBrailleTranslator.Range_>} The calculated 195 * @return {!Array<cvox.ExpandingBrailleTranslator.Range_>} The calculated
196 * ranges. 196 * ranges.
197 * @private 197 * @private
198 */ 198 */
199 cvox.ExpandingBrailleTranslator.prototype.findExpandRanges_ = function( 199 cvox.ExpandingBrailleTranslator.prototype.findExpandRanges_ = function(
200 text, expansionType) { 200 text, expansionType) {
201 var result = []; 201 var result = [];
202 if (this.uncontractedTranslator_ && 202 if (this.uncontractedTranslator_ &&
203 expansionType != cvox.ExpandingBrailleTranslator.ExpansionType.NONE) { 203 expansionType != cvox.ExpandingBrailleTranslator.ExpansionType.NONE) {
204 var value = text.getSpanInstanceOf(cvox.ValueSpan); 204 var value = text.getSpanInstanceOf(cvox.ValueSpan);
205 if (value) { 205 if (value) {
(...skipping 15 matching lines...) Expand all
221 return result; 221 return result;
222 }; 222 };
223 223
224 224
225 /** 225 /**
226 * Finds ranges to expand around selection end points inside the value of 226 * Finds ranges to expand around selection end points inside the value of
227 * a string. If any ranges are found, adds them to {@code outRanges}. 227 * a string. If any ranges are found, adds them to {@code outRanges}.
228 * @param {cvox.Spannable} text Text to find ranges in. 228 * @param {cvox.Spannable} text Text to find ranges in.
229 * @param {number} valueStart Start of the value in {@code text}. 229 * @param {number} valueStart Start of the value in {@code text}.
230 * @param {number} valueEnd End of the value in {@code text}. 230 * @param {number} valueEnd End of the value in {@code text}.
231 * @param {Array.<cvox.ExpandingBrailleTranslator.Range_>} outRanges 231 * @param {Array<cvox.ExpandingBrailleTranslator.Range_>} outRanges
232 * Destination for the expansion ranges. Untouched if no ranges 232 * Destination for the expansion ranges. Untouched if no ranges
233 * are found. Note that ranges may be coalesced. 233 * are found. Note that ranges may be coalesced.
234 * @private 234 * @private
235 */ 235 */
236 cvox.ExpandingBrailleTranslator.prototype.addRangesForSelection_ = function( 236 cvox.ExpandingBrailleTranslator.prototype.addRangesForSelection_ = function(
237 text, valueStart, valueEnd, outRanges) { 237 text, valueStart, valueEnd, outRanges) {
238 var selection = text.getSpanInstanceOf(cvox.ValueSelectionSpan); 238 var selection = text.getSpanInstanceOf(cvox.ValueSelectionSpan);
239 if (!selection) { 239 if (!selection) {
240 return; 240 return;
241 } 241 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 } 275 }
276 } 276 }
277 }; 277 };
278 278
279 279
280 /** 280 /**
281 * Adapts {@code callback} to accept null arguments and treat them as if the 281 * Adapts {@code callback} to accept null arguments and treat them as if the
282 * translation result is empty. 282 * translation result is empty.
283 * @param {number} inputLength Length of the input to the translation. 283 * @param {number} inputLength Length of the input to the translation.
284 * Used for populating {@code textToBraille} if null. 284 * Used for populating {@code textToBraille} if null.
285 * @param {function(!ArrayBuffer, !Array.<number>, !Array.<number>)} callback 285 * @param {function(!ArrayBuffer, !Array<number>, !Array<number>)} callback
286 * The callback to adapt. 286 * The callback to adapt.
287 * @return {function(ArrayBuffer, Array.<number>, Array.<number>)} 287 * @return {function(ArrayBuffer, Array<number>, Array<number>)}
288 * An adapted version of the callback. 288 * An adapted version of the callback.
289 * @private 289 * @private
290 */ 290 */
291 cvox.ExpandingBrailleTranslator.nullParamsToEmptyAdapter_ = 291 cvox.ExpandingBrailleTranslator.nullParamsToEmptyAdapter_ =
292 function(inputLength, callback) { 292 function(inputLength, callback) {
293 return function(cells, textToBraille, brailleToText) { 293 return function(cells, textToBraille, brailleToText) {
294 if (!textToBraille) { 294 if (!textToBraille) {
295 textToBraille = new Array(inputLength); 295 textToBraille = new Array(inputLength);
296 for (var i = 0; i < inputLength; ++i) { 296 for (var i = 0; i < inputLength; ++i) {
297 textToBraille[i] = 0; 297 textToBraille[i] = 0;
298 } 298 }
299 } 299 }
300 callback(cells || new ArrayBuffer(0), 300 callback(cells || new ArrayBuffer(0),
301 textToBraille, 301 textToBraille,
302 brailleToText || []); 302 brailleToText || []);
303 }; 303 };
304 }; 304 };
305 305
306 306
307 /** 307 /**
308 * A character range with inclusive start and exclusive end positions. 308 * A character range with inclusive start and exclusive end positions.
309 * @typedef {{start: number, end: number}} 309 * @typedef {{start: number, end: number}}
310 * @private 310 * @private
311 */ 311 */
312 cvox.ExpandingBrailleTranslator.Range_; 312 cvox.ExpandingBrailleTranslator.Range_;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698