Chromium Code Reviews| 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 a38d3b75dcfd09be1fc67631602dadf25149c574..f1109e7c89084ab43d90089cd87f2f2ed979ec54 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 |
| @@ -53,23 +53,28 @@ cvox.BrailleCaptionsBackground.isEnabled = function() { |
| return localStorage[self.PREF_KEY] === String(true); |
| }; |
| - |
| /** |
| * @param {string} text Text of the shown braille. |
| * @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. |
|
dmazzoni
2016/09/29 16:13:12
nit: indent this comment by 4 spaces since it's a
ultimatedbz
2016/09/29 21:00:55
Done.
|
| */ |
| -cvox.BrailleCaptionsBackground.setContent = function(text, cells) { |
| +cvox.BrailleCaptionsBackground.setContent = function(text, cells, |
| + brailleToText) { |
| var self = cvox.BrailleCaptionsBackground; |
| // Convert the cells to Unicode braille pattern characters. |
| var byteBuf = new Uint8Array(cells); |
| var brailleChars = ''; |
| + |
| for (var i = 0; i < byteBuf.length; ++i) { |
| brailleChars += String.fromCharCode( |
| self.BRAILLE_UNICODE_BLOCK_START | byteBuf[i]); |
| } |
| + var groups = this.groupBrailleAndText(brailleChars, text, brailleToText); |
| + |
| if (cvox.ChromeVox.isChromeOS) { |
| - var data = {text: text, braille: brailleChars}; |
| + var data = {groups: groups}; |
| (new PanelCommand(PanelCommandType.UPDATE_BRAILLE, data)).send(); |
| } else { |
| cvox.ExtensionBridge.send({ |
| @@ -80,6 +85,33 @@ 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 |
| + * index of corresponding text letter. |
|
dmazzoni
2016/09/29 16:13:13
nit: indent this comment by 4 spaces since it's a
ultimatedbz
2016/09/29 21:00:55
Done.
|
| + * @return {Array} |
| + */ |
| +cvox.BrailleCaptionsBackground.groupBrailleAndText = function(brailleChars, |
| + text, brailleToText) { |
| + var brailleBuf = ''; |
| + var groups = []; |
| + var textIndex = 0; |
| + for (var i = 0; i < brailleChars.length - 1; ++i) { |
| + if ((i != 0) && ((brailleToText[i] != textIndex))) { |
| + groups.push([text.substr(textIndex, brailleToText[i] - textIndex), |
| + brailleBuf]); |
| + brailleBuf = ''; |
| + textIndex = brailleToText[i]; |
| + } |
| + brailleBuf += brailleChars.charAt(i); |
| + } |
| + // Puts the rest of the text into the last group. |
| + if (brailleBuf.length > 0) { |
| + groups.push([text.substr(textIndex), brailleBuf]); |
| + } |
| + return groups; |
| +}; |
| /** |
| * Sets whether the overlay should be active. |
| @@ -101,7 +133,6 @@ cvox.BrailleCaptionsBackground.setActive = function(newValue) { |
| } |
| }; |
| - |
| /** |
| * Returns a display state representing the state of the captions feature. |
| * This is used when no actual hardware display is connected. |