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

Unified Diff: chrome/browser/resources/chromeos/chromevox/chromevox/background/braille_captions_background.js

Issue 2362673004: Aligns text to braille in chromevox. (Closed)
Patch Set: fixed test Created 4 years, 2 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 side-by-side diff with in-line comments
Download patch
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..47fdd0e6188fbcf8dd084a40458f9f63cb398c53 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.
*/
-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.
+ * @return {Array}
+ */
+cvox.BrailleCaptionsBackground.groupBrailleAndText = function(brailleChars,
+ text, brailleToText) {
+ var brailleBuf = '';
+ var groups = [];
+ var textIndex = 0;
+ for (var i = 0; i < brailleChars.length; ++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.

Powered by Google App Engine
This is Rietveld 408576698