| 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 JavaScript shim for the liblouis Native Client wrapper. | 6 * @fileoverview JavaScript shim for the liblouis Native Client wrapper. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 goog.provide('cvox.LibLouis'); | 9 goog.provide('cvox.LibLouis'); |
| 10 | 10 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 | 37 |
| 38 /** | 38 /** |
| 39 * The state of the instance. | 39 * The state of the instance. |
| 40 * @private {cvox.LibLouis.InstanceState} | 40 * @private {cvox.LibLouis.InstanceState} |
| 41 */ | 41 */ |
| 42 this.instanceState_ = | 42 this.instanceState_ = |
| 43 cvox.LibLouis.InstanceState.NOT_LOADED; | 43 cvox.LibLouis.InstanceState.NOT_LOADED; |
| 44 | 44 |
| 45 /** | 45 /** |
| 46 * Pending requests to construct translators. | 46 * Pending requests to construct translators. |
| 47 * @private {!Array.<{tableName: string, | 47 * @private {!Array<{tableName: string, |
| 48 * callback: function(cvox.LibLouis.Translator)}>} | 48 * callback: function(cvox.LibLouis.Translator)}>} |
| 49 */ | 49 */ |
| 50 this.pendingTranslators_ = []; | 50 this.pendingTranslators_ = []; |
| 51 | 51 |
| 52 /** | 52 /** |
| 53 * Pending RPC callbacks. Maps from message IDs to callbacks. | 53 * Pending RPC callbacks. Maps from message IDs to callbacks. |
| 54 * @private {!Object.<string, function(!Object)>} | 54 * @private {!Object<string, function(!Object)>} |
| 55 */ | 55 */ |
| 56 this.pendingRpcCallbacks_ = {}; | 56 this.pendingRpcCallbacks_ = {}; |
| 57 | 57 |
| 58 /** | 58 /** |
| 59 * Next message ID to be used. Incremented with each sent message. | 59 * Next message ID to be used. Incremented with each sent message. |
| 60 * @private {number} | 60 * @private {number} |
| 61 */ | 61 */ |
| 62 this.nextMessageId_ = 1; | 62 this.nextMessageId_ = 1; |
| 63 }; | 63 }; |
| 64 | 64 |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 * The table name. | 264 * The table name. |
| 265 * @private {string} | 265 * @private {string} |
| 266 */ | 266 */ |
| 267 this.tableNames_ = tableNames; | 267 this.tableNames_ = tableNames; |
| 268 }; | 268 }; |
| 269 | 269 |
| 270 | 270 |
| 271 /** | 271 /** |
| 272 * Translates text into braille cells. | 272 * Translates text into braille cells. |
| 273 * @param {string} text Text to be translated. | 273 * @param {string} text Text to be translated. |
| 274 * @param {function(ArrayBuffer, Array.<number>, Array.<number>)} callback | 274 * @param {function(ArrayBuffer, Array<number>, Array<number>)} callback |
| 275 * Callback for result. Takes 3 parameters: the resulting cells, | 275 * Callback for result. Takes 3 parameters: the resulting cells, |
| 276 * mapping from text to braille positions and mapping from braille to | 276 * mapping from text to braille positions and mapping from braille to |
| 277 * text positions. If translation fails for any reason, all parameters are | 277 * text positions. If translation fails for any reason, all parameters are |
| 278 * {@code null}. | 278 * {@code null}. |
| 279 */ | 279 */ |
| 280 cvox.LibLouis.Translator.prototype.translate = function(text, callback) { | 280 cvox.LibLouis.Translator.prototype.translate = function(text, callback) { |
| 281 var message = { 'table_names': this.tableNames_, 'text': text }; | 281 var message = { 'table_names': this.tableNames_, 'text': text }; |
| 282 this.instance_.rpc_('Translate', message, function(reply) { | 282 this.instance_.rpc_('Translate', message, function(reply) { |
| 283 var cells = null; | 283 var cells = null; |
| 284 var textToBraille = null; | 284 var textToBraille = null; |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 */ | 355 */ |
| 356 cvox.LibLouis.Translator.encodeHexString_ = function(arrayBuffer) { | 356 cvox.LibLouis.Translator.encodeHexString_ = function(arrayBuffer) { |
| 357 var array = new Uint8Array(arrayBuffer); | 357 var array = new Uint8Array(arrayBuffer); |
| 358 var hex = ''; | 358 var hex = ''; |
| 359 for (var i = 0; i < array.length; i++) { | 359 for (var i = 0; i < array.length; i++) { |
| 360 var b = array[i]; | 360 var b = array[i]; |
| 361 hex += (b < 0x10 ? '0' : '') + b.toString(16); | 361 hex += (b < 0x10 ? '0' : '') + b.toString(16); |
| 362 } | 362 } |
| 363 return hex; | 363 return hex; |
| 364 }; | 364 }; |
| OLD | NEW |