| 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 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'); |
| 11 | 11 |
| 12 goog.require('cvox.BrailleUtil'); | |
| 13 goog.require('cvox.LibLouis'); | 12 goog.require('cvox.LibLouis'); |
| 14 goog.require('cvox.Spannable'); | 13 goog.require('cvox.Spannable'); |
| 14 goog.require('cvox.ValueSelectionSpan'); |
| 15 goog.require('cvox.ValueSpan'); |
| 15 | 16 |
| 16 | 17 |
| 17 /** | 18 /** |
| 18 * A wrapper around one or two braille translators that uses contracted | 19 * A wrapper around one or two braille translators that uses contracted |
| 19 * braille or not based on the selection start- and end-points (if any) in the | 20 * braille or not based on the selection start- and end-points (if any) in the |
| 20 * translated text. If only one translator is provided, then that translator | 21 * translated text. If only one translator is provided, then that translator |
| 21 * is used for all text regardless of selection. If two translators | 22 * is used for all text regardless of selection. If two translators |
| 22 * are provided, then the uncontracted translator is used for some text | 23 * are provided, then the uncontracted translator is used for some text |
| 23 * around the selection end-points and the contracted translator is used | 24 * around the selection end-points and the contracted translator is used |
| 24 * for all other text. When determining what text to use uncontracted | 25 * for all other text. When determining what text to use uncontracted |
| (...skipping 16 matching lines...) Expand all Loading... |
| 41 /** | 42 /** |
| 42 * @type {cvox.LibLouis.Translator} | 43 * @type {cvox.LibLouis.Translator} |
| 43 * @private | 44 * @private |
| 44 */ | 45 */ |
| 45 this.uncontractedTranslator_ = opt_uncontractedTranslator || null; | 46 this.uncontractedTranslator_ = opt_uncontractedTranslator || null; |
| 46 }; | 47 }; |
| 47 | 48 |
| 48 | 49 |
| 49 /** | 50 /** |
| 50 * What expansion to apply to the part of the translated string marked by the | 51 * What expansion to apply to the part of the translated string marked by the |
| 51 * {@code cvox.BrailleUtil.ValueSpan} spannable. | 52 * {@code cvox.ValueSpan} spannable. |
| 52 * @enum {number} | 53 * @enum {number} |
| 53 */ | 54 */ |
| 54 cvox.ExpandingBrailleTranslator.ExpansionType = { | 55 cvox.ExpandingBrailleTranslator.ExpansionType = { |
| 55 /** | 56 /** |
| 56 * Use the default translator all of the value, regardless of any selection. | 57 * Use the default translator all of the value, regardless of any selection. |
| 57 * This is typically used when the user is in the middle of typing and the | 58 * This is typically used when the user is in the middle of typing and the |
| 58 * typing started outside of a word. | 59 * typing started outside of a word. |
| 59 */ | 60 */ |
| 60 NONE: 0, | 61 NONE: 0, |
| 61 /** | 62 /** |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 * Indicates how the text marked up as the value is expanded. | 194 * Indicates how the text marked up as the value is expanded. |
| 194 * @return {!Array.<cvox.ExpandingBrailleTranslator.Range_>} The calculated | 195 * @return {!Array.<cvox.ExpandingBrailleTranslator.Range_>} The calculated |
| 195 * ranges. | 196 * ranges. |
| 196 * @private | 197 * @private |
| 197 */ | 198 */ |
| 198 cvox.ExpandingBrailleTranslator.prototype.findExpandRanges_ = function( | 199 cvox.ExpandingBrailleTranslator.prototype.findExpandRanges_ = function( |
| 199 text, expansionType) { | 200 text, expansionType) { |
| 200 var result = []; | 201 var result = []; |
| 201 if (this.uncontractedTranslator_ && | 202 if (this.uncontractedTranslator_ && |
| 202 expansionType != cvox.ExpandingBrailleTranslator.ExpansionType.NONE) { | 203 expansionType != cvox.ExpandingBrailleTranslator.ExpansionType.NONE) { |
| 203 var value = text.getSpanInstanceOf(cvox.BrailleUtil.ValueSpan); | 204 var value = text.getSpanInstanceOf(cvox.ValueSpan); |
| 204 if (value) { | 205 if (value) { |
| 205 // The below type casts are valid because the ranges must be valid when | 206 // The below type casts are valid because the ranges must be valid when |
| 206 // the span is known to exist. | 207 // the span is known to exist. |
| 207 var valueStart = /** @type {number} */ (text.getSpanStart(value)); | 208 var valueStart = /** @type {number} */ (text.getSpanStart(value)); |
| 208 var valueEnd = /** @type {number} */ (text.getSpanEnd(value)); | 209 var valueEnd = /** @type {number} */ (text.getSpanEnd(value)); |
| 209 switch (expansionType) { | 210 switch (expansionType) { |
| 210 case cvox.ExpandingBrailleTranslator.ExpansionType.SELECTION: | 211 case cvox.ExpandingBrailleTranslator.ExpansionType.SELECTION: |
| 211 this.addRangesForSelection_(text, valueStart, valueEnd, result); | 212 this.addRangesForSelection_(text, valueStart, valueEnd, result); |
| 212 break; | 213 break; |
| 213 case cvox.ExpandingBrailleTranslator.ExpansionType.ALL: | 214 case cvox.ExpandingBrailleTranslator.ExpansionType.ALL: |
| (...skipping 13 matching lines...) Expand all Loading... |
| 227 * @param {cvox.Spannable} text Text to find ranges in. | 228 * @param {cvox.Spannable} text Text to find ranges in. |
| 228 * @param {number} valueStart Start of the value in {@code text}. | 229 * @param {number} valueStart Start of the value in {@code text}. |
| 229 * @param {number} valueEnd End of the value in {@code text}. | 230 * @param {number} valueEnd End of the value in {@code text}. |
| 230 * @param {Array.<cvox.ExpandingBrailleTranslator.Range_>} outRanges | 231 * @param {Array.<cvox.ExpandingBrailleTranslator.Range_>} outRanges |
| 231 * Destination for the expansion ranges. Untouched if no ranges | 232 * Destination for the expansion ranges. Untouched if no ranges |
| 232 * are found. Note that ranges may be coalesced. | 233 * are found. Note that ranges may be coalesced. |
| 233 * @private | 234 * @private |
| 234 */ | 235 */ |
| 235 cvox.ExpandingBrailleTranslator.prototype.addRangesForSelection_ = function( | 236 cvox.ExpandingBrailleTranslator.prototype.addRangesForSelection_ = function( |
| 236 text, valueStart, valueEnd, outRanges) { | 237 text, valueStart, valueEnd, outRanges) { |
| 237 var selection = text.getSpanInstanceOf( | 238 var selection = text.getSpanInstanceOf(cvox.ValueSelectionSpan); |
| 238 cvox.BrailleUtil.ValueSelectionSpan); | |
| 239 if (!selection) { | 239 if (!selection) { |
| 240 return; | 240 return; |
| 241 } | 241 } |
| 242 var selectionStart = text.getSpanStart(selection); | 242 var selectionStart = text.getSpanStart(selection); |
| 243 var selectionEnd = text.getSpanEnd(selection); | 243 var selectionEnd = text.getSpanEnd(selection); |
| 244 if (selectionStart < valueStart || selectionEnd > valueEnd) { | 244 if (selectionStart < valueStart || selectionEnd > valueEnd) { |
| 245 return; | 245 return; |
| 246 } | 246 } |
| 247 var expandPositions = []; | 247 var expandPositions = []; |
| 248 if (selectionStart == valueEnd) { | 248 if (selectionStart == valueEnd) { |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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_; |
| OLD | NEW |