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

Unified Diff: chrome/browser/resources/chromeos/chromevox/braille/braille_display_manager.js

Issue 2496823002: Implement word wrapping and panning in multiline Braille. (Closed)
Patch Set: removed unnecessary files Created 4 years, 1 month 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/braille/braille_display_manager.js
diff --git a/chrome/browser/resources/chromeos/chromevox/braille/braille_display_manager.js b/chrome/browser/resources/chromeos/chromevox/braille/braille_display_manager.js
index 91352693897ff7619798b5995d8ec6485060c439..16a88cb877017822199df28929e0907d77f8db46 100644
--- a/chrome/browser/resources/chromeos/chromevox/braille/braille_display_manager.js
+++ b/chrome/browser/resources/chromeos/chromevox/braille/braille_display_manager.js
@@ -53,7 +53,7 @@ cvox.BrailleDisplayManager = function(translatorManager) {
* @type {cvox.PanStrategy}
* @private
*/
- this.panStrategy_ = new cvox.WrappingPanStrategy();
+ this.panStrategy_ = new cvox.PanStrategy();
/**
* @type {function(!cvox.BrailleKeyEvent, !cvox.NavBraille)}
* @private
@@ -76,16 +76,6 @@ cvox.BrailleDisplayManager = function(translatorManager) {
* @private
*/
this.realDisplayState_ = this.displayState_;
- /**
- * @type {!Array<number>}
- * @private
- */
- this.textToBraille_ = [];
- /**
- * @type {!Array<number>}
- * @private
- */
- this.brailleToText_ = [];
translatorManager.addChangeListener(function() {
this.translateContent_(this.content_, this.expansionType_);
@@ -170,7 +160,10 @@ cvox.BrailleDisplayManager.prototype.refreshDisplayState_ = function(
var newSize = this.displayState_.textColumnCount *
this.displayState_.textRowCount || 0;
if (oldSize != newSize) {
- this.panStrategy_.setDisplaySize(newSize);
+ // TODO might need to change when display is plugged in.
David Tseng 2016/11/14 21:05:08 This is going to break for real devices. Look at t
ultimatedbz 2016/11/15 18:04:02 Right, I'm thinking that if a newState is availabl
+ this.panStrategy_.setDisplaySize(parseInt(
+ localStorage['virtualBrailleRows'], 10),
+ parseInt(localStorage['virtualBrailleColumns'], 10));
}
this.refresh_();
};
@@ -188,26 +181,26 @@ cvox.BrailleDisplayManager.prototype.onCaptionsStateChanged_ = function() {
};
-/** @private */
+/**
+ * Refreshes what is shown on the physical braille display and the virtual
+ * braille captions display.
+ * @private */
cvox.BrailleDisplayManager.prototype.refresh_ = function() {
if (!this.displayState_.available) {
return;
}
- var viewPort = this.panStrategy_.viewPort;
- var buf = this.displayedContent_.slice(viewPort.start, viewPort.end);
+ var brailleBuf = this.panStrategy_.getCurrentBrailleSlice();
+ var textBuf = this.panStrategy_.getCurrentTextSlice();
if (this.realDisplayState_.available) {
- chrome.brailleDisplayPrivate.writeDots(buf, buf.byteLength, 1);
+ chrome.brailleDisplayPrivate.writeDots(brailleBuf,
+ brailleBuf.byteLength, 1);
}
if (cvox.BrailleCaptionsBackground.isEnabled()) {
- var start = this.brailleToTextPosition_(viewPort.start);
- var end = this.brailleToTextPosition_(viewPort.end);
- cvox.BrailleCaptionsBackground.setContent(
- this.content_.text.toString().substring(start, end), buf,
- this.brailleToText_);
+ cvox.BrailleCaptionsBackground.setContent(textBuf, brailleBuf,
+ this.panStrategy_.brailleToText, this.panStrategy_.offsetsForSlices);
}
};
-
/**
* @param {!cvox.NavBraille} newContent New display content.
* @param {cvox.ExpandingBrailleTranslator.ExpansionType} newExpansionType
@@ -220,8 +213,6 @@ cvox.BrailleDisplayManager.prototype.translateContent_ = function(
var writeTranslatedContent = function(cells, textToBraille, brailleToText) {
this.content_ = newContent;
this.expansionType_ = newExpansionType;
- this.textToBraille_ = textToBraille;
- this.brailleToText_ = brailleToText;
var startIndex = this.content_.startIndex;
var endIndex = this.content_.endIndex;
var targetPosition;
@@ -232,7 +223,7 @@ cvox.BrailleDisplayManager.prototype.translateContent_ = function(
// Allow the cells to be extended with one extra cell for
// a carret after the last character.
var extCells = new ArrayBuffer(cells.byteLength + 1);
- new Uint8Array(extCells).set(new Uint8Array(cells));
+ new Uint8Array(extCells).set(cells);
// Last byte is initialized to 0.
cells = extCells;
translatedStartIndex = cells.byteLength - 1;
@@ -251,7 +242,7 @@ cvox.BrailleDisplayManager.prototype.translateContent_ = function(
// Copy the translated content to a separate buffer and add the cursor
// to it.
this.displayedContent_ = new ArrayBuffer(cells.byteLength);
- new Uint8Array(this.displayedContent_).set(new Uint8Array(cells));
+ new Uint8Array(this.displayedContent_).set(cells);
this.writeCursor_(this.displayedContent_,
translatedStartIndex, translatedEndIndex);
targetPosition = translatedStartIndex;
@@ -259,7 +250,9 @@ cvox.BrailleDisplayManager.prototype.translateContent_ = function(
this.translatedContent_ = this.displayedContent_ = cells;
targetPosition = 0;
}
- this.panStrategy_.setContent(this.translatedContent_, targetPosition);
+ this.panStrategy_.setContent(this.content_.text.toString(),
+ this.translatedContent_, brailleToText);
+
this.refresh_();
}.bind(this);
@@ -288,9 +281,11 @@ cvox.BrailleDisplayManager.prototype.onKeyEvent_ = function(event) {
this.panRight_();
break;
case cvox.BrailleKeyCommand.ROUTING:
+ /* TODO
event.displayPosition = this.brailleToTextPosition_(
event.displayPosition + this.panStrategy_.viewPort.start);
// fall through
+ // */
David Tseng 2016/11/14 21:05:08 Please don't comment out code like this with a TOD
ultimatedbz 2016/11/15 00:01:17 Hey David! Noted, my intentions weren't for this t
default:
this.commandListener_(event, this.content_);
break;
@@ -368,7 +363,8 @@ cvox.BrailleDisplayManager.prototype.writeCursor_ = function(
*/
cvox.BrailleDisplayManager.prototype.brailleToTextPosition_ =
function(braillePosition) {
- var mapping = this.brailleToText_;
+ // TODO I'll need to support this function
+ var mapping = this.panStrategy_.brailleToText;
if (braillePosition < 0) {
// This shouldn't happen.
console.error('WARNING: Braille position < 0: ' + braillePosition);
@@ -389,11 +385,6 @@ cvox.BrailleDisplayManager.prototype.brailleToTextPosition_ =
* @private
*/
cvox.BrailleDisplayManager.prototype.updatePanStrategy_ = function(wordWrap) {
- var newStrategy = wordWrap ? new cvox.WrappingPanStrategy() :
- new cvox.FixedPanStrategy();
- newStrategy.setDisplaySize(this.displayState_.textColumnCount || 0);
- newStrategy.setContent(this.translatedContent_,
- this.panStrategy_.viewPort.start);
- this.panStrategy_ = newStrategy;
+ this.panStrategy_.setPanStrategy(wordWrap);
this.refresh_();
};

Powered by Google App Engine
This is Rietveld 408576698