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

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

Issue 2362673004: Aligns text to braille in chromevox. (Closed)
Patch Set: Addressed all presubmit issues. Created 4 years, 3 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 unified diff | Download patch
OLDNEW
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 /** @fileoverview If the braille captions feature is enabled, sends 5 /** @fileoverview If the braille captions feature is enabled, sends
6 * braille content to the Panel on Chrome OS, or a content script on 6 * braille content to the Panel on Chrome OS, or a content script on
7 * other platforms. 7 * other platforms.
8 */ 8 */
9 9
10 goog.provide('cvox.BrailleCaptionsBackground'); 10 goog.provide('cvox.BrailleCaptionsBackground');
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 */ 50 */
51 cvox.BrailleCaptionsBackground.isEnabled = function() { 51 cvox.BrailleCaptionsBackground.isEnabled = function() {
52 var self = cvox.BrailleCaptionsBackground; 52 var self = cvox.BrailleCaptionsBackground;
53 return localStorage[self.PREF_KEY] === String(true); 53 return localStorage[self.PREF_KEY] === String(true);
54 }; 54 };
55 55
56 56
57 /** 57 /**
58 * @param {string} text Text of the shown braille. 58 * @param {string} text Text of the shown braille.
59 * @param {ArrayBuffer} cells Braille cells shown on the display. 59 * @param {ArrayBuffer} cells Braille cells shown on the display.
60 * @param {Array} brailleToText Map of Braille letters to the first
dmazzoni 2016/09/26 04:53:49 How about {Array<number>} - it's always good to be
ultimatedbz 2016/09/27 22:56:24 Done.
61 * index of
62 * corresponding text letter.
dmazzoni 2016/09/26 04:53:48 nit: wrap this
ultimatedbz 2016/09/27 22:56:24 Done.
60 */ 63 */
61 cvox.BrailleCaptionsBackground.setContent = function(text, cells) { 64 cvox.BrailleCaptionsBackground.setContent = function(text, cells,
65 brailleToText) {
62 var self = cvox.BrailleCaptionsBackground; 66 var self = cvox.BrailleCaptionsBackground;
63 // Convert the cells to Unicode braille pattern characters. 67 // Convert the cells to Unicode braille pattern characters.
64 var byteBuf = new Uint8Array(cells); 68 var byteBuf = new Uint8Array(cells);
65 var brailleChars = ''; 69 var brailleChars = '';
66 for (var i = 0; i < byteBuf.length; ++i) { 70 var brailleBuf = '';
71 var textIndex = 0;
72 var groups = [];
73
74 for (var i = 0; i < byteBuf.length - 1; ++i) {
dmazzoni 2016/09/26 04:53:48 Abstract this concept of breaking into groups into
ultimatedbz 2016/09/27 22:56:24 Done.
67 brailleChars += String.fromCharCode( 75 brailleChars += String.fromCharCode(
dmazzoni 2016/09/26 04:53:49 We're not using brailleChars anymore, so you can j
ultimatedbz 2016/09/27 21:15:49 Isn't brailleChars used below in line 100 though?
dmazzoni 2016/09/27 21:54:50 You're right, I missed that. That's for a way to d
ultimatedbz 2016/09/27 22:56:24 Done.
68 self.BRAILLE_UNICODE_BLOCK_START | byteBuf[i]); 76 self.BRAILLE_UNICODE_BLOCK_START | byteBuf[i]);
77 if ((i != 0) && ((brailleToText[i] != textIndex))) {
78 groups.push([text.substr(textIndex, brailleToText[i] - textIndex),
dmazzoni 2016/09/26 04:53:49 Instead of each group being an array [text, braill
79 brailleBuf]);
80 brailleBuf = '';
81 textIndex = brailleToText[i];
82 }
83 brailleBuf += String.fromCharCode(
84 self.BRAILLE_UNICODE_BLOCK_START | byteBuf[i]);
85 }
86 // Puts the rest of the text into the last group.
87 if (byteBuf.length > 0) {
88 brailleChars += String.fromCharCode(
89 self.BRAILLE_UNICODE_BLOCK_START | byteBuf[byteBuf.length - 1]);
90 groups.push([text.substr(textIndex), brailleBuf]);
69 } 91 }
70 92
71 if (cvox.ChromeVox.isChromeOS) { 93 if (cvox.ChromeVox.isChromeOS) {
72 var data = {text: text, braille: brailleChars}; 94 var data = {groups: groups};
73 (new PanelCommand(PanelCommandType.UPDATE_BRAILLE, data)).send(); 95 (new PanelCommand(PanelCommandType.UPDATE_BRAILLE, data)).send();
74 } else { 96 } else {
75 cvox.ExtensionBridge.send({ 97 cvox.ExtensionBridge.send({
76 message: 'BRAILLE_CAPTION', 98 message: 'BRAILLE_CAPTION',
77 text: text, 99 text: text,
78 brailleChars: brailleChars 100 brailleChars: brailleChars
79 }); 101 });
80 } 102 }
81 }; 103 };
82 104
(...skipping 25 matching lines...) Expand all
108 * @return {cvox.BrailleDisplayState} 130 * @return {cvox.BrailleDisplayState}
109 */ 131 */
110 cvox.BrailleCaptionsBackground.getVirtualDisplayState = function() { 132 cvox.BrailleCaptionsBackground.getVirtualDisplayState = function() {
111 var self = cvox.BrailleCaptionsBackground; 133 var self = cvox.BrailleCaptionsBackground;
112 if (self.isEnabled()) { 134 if (self.isEnabled()) {
113 return {available: true, textCellCount: 40}; // 40, why not? 135 return {available: true, textCellCount: 40}; // 40, why not?
114 } else { 136 } else {
115 return {available: false}; 137 return {available: false};
116 } 138 }
117 }; 139 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698