| Index: chrome/browser/resources/chromeos/chromevox/chromevox/background/braille_captions_background.js
|
| diff --git a/chrome/browser/resources/chromeos/chromevox/chromevox/background/braille_captions_background.js b/chrome/browser/resources/chromeos/chromevox/chromevox/background/braille_captions_background.js
|
| index 47fdd0e6188fbcf8dd084a40458f9f63cb398c53..506e24644fd056c9a84088ee7a68b57ba4223161 100644
|
| --- a/chrome/browser/resources/chromeos/chromevox/chromevox/background/braille_captions_background.js
|
| +++ b/chrome/browser/resources/chromeos/chromevox/chromevox/background/braille_captions_background.js
|
| @@ -58,9 +58,11 @@ cvox.BrailleCaptionsBackground.isEnabled = function() {
|
| * @param {ArrayBuffer} cells Braille cells shown on the display.
|
| * @param {Array<number>} brailleToText Map of Braille letters to the first
|
| * index of corresponding text letter.
|
| + * @param {Array<number>} offsetsForSlices Offsets to use for caculating
|
| + * indices. The element is the braille offset, the second is the text offset.
|
| */
|
| cvox.BrailleCaptionsBackground.setContent = function(text, cells,
|
| - brailleToText) {
|
| + brailleToText, offsetsForSlices) {
|
| var self = cvox.BrailleCaptionsBackground;
|
| // Convert the cells to Unicode braille pattern characters.
|
| var byteBuf = new Uint8Array(cells);
|
| @@ -70,9 +72,8 @@ cvox.BrailleCaptionsBackground.setContent = function(text, cells,
|
| brailleChars += String.fromCharCode(
|
| self.BRAILLE_UNICODE_BLOCK_START | byteBuf[i]);
|
| }
|
| -
|
| - var groups = this.groupBrailleAndText(brailleChars, text, brailleToText);
|
| -
|
| + var groups = this.groupBrailleAndText(brailleChars, text, brailleToText,
|
| + offsetsForSlices);
|
| if (cvox.ChromeVox.isChromeOS) {
|
| var data = {groups: groups};
|
| (new PanelCommand(PanelCommandType.UPDATE_BRAILLE, data)).send();
|
| @@ -88,26 +89,36 @@ cvox.BrailleCaptionsBackground.setContent = function(text, cells,
|
| /**
|
| * @param {string} brailleChars Braille characters shown on the display.
|
| * @param {string} text Text of the shown braille.
|
| - * @param {Array<number>} brailleToText Map of Braille letters to the first
|
| + * @param {Array<number>} brailleToText Map of Braille cells to the first
|
| * index of corresponding text letter.
|
| - * @return {Array}
|
| + * @param {Array<number>} offsets Offsets to use for caculating indices. The
|
| + * element is the braille offset, the second is the text offset.
|
| + * @return {Array} The groups of braille and texts to be displayed.
|
| */
|
| cvox.BrailleCaptionsBackground.groupBrailleAndText = function(brailleChars,
|
| - text, brailleToText) {
|
| + text, brailleToText, offsets) {
|
| var brailleBuf = '';
|
| var groups = [];
|
| var textIndex = 0;
|
| + var brailleOffset = offsets[0];
|
| + var textOffset = offsets[1];
|
| + var calculateTextIndex = function(index) {
|
| + return brailleToText[index + brailleOffset] - textOffset;
|
| + };
|
| +
|
| for (var i = 0; i < brailleChars.length; ++i) {
|
| - if ((i != 0) && ((brailleToText[i] != textIndex))) {
|
| - groups.push([text.substr(textIndex, brailleToText[i] - textIndex),
|
| + var textSliceIndex = calculateTextIndex(i);
|
| + if (i != 0 && textSliceIndex != textIndex) {
|
| + groups.push([text.substr(textIndex,
|
| + textSliceIndex - textIndex),
|
| brailleBuf]);
|
| brailleBuf = '';
|
| - textIndex = brailleToText[i];
|
| + textIndex = textSliceIndex;
|
| }
|
| brailleBuf += brailleChars.charAt(i);
|
| }
|
| // Puts the rest of the text into the last group.
|
| - if (brailleBuf.length > 0) {
|
| + if (brailleBuf.length > 0 && text.charAt(textIndex) != ' ') {
|
| groups.push([text.substr(textIndex), brailleBuf]);
|
| }
|
| return groups;
|
|
|