Chromium Code Reviews| 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..f328f0f30fd3d66ce452c7b9303b22222eea531d 100644 |
| --- a/chrome/browser/resources/chromeos/chromevox/braille/braille_display_manager.js |
| +++ b/chrome/browser/resources/chromeos/chromevox/braille/braille_display_manager.js |
| @@ -40,30 +40,20 @@ cvox.BrailleDisplayManager = function(translatorManager) { |
| this.expansionType_ = |
| cvox.ExpandingBrailleTranslator.ExpansionType.SELECTION; |
| /** |
| - * @type {!ArrayBuffer} |
| - * @private |
| - */ |
| - this.translatedContent_ = new ArrayBuffer(0); |
| - /** |
| - * @type {!ArrayBuffer} |
| - * @private |
| - */ |
| - this.displayedContent_ = this.translatedContent_; |
| - /** |
| * @type {cvox.PanStrategy} |
| * @private |
| */ |
| - this.panStrategy_ = new cvox.WrappingPanStrategy(); |
| + this.panStrategy_ = new cvox.PanStrategy(); |
| /** |
| * @type {function(!cvox.BrailleKeyEvent, !cvox.NavBraille)} |
| * @private |
| */ |
| this.commandListener_ = function() {}; |
| /** |
| - * Current display state used for width calculations. This is different from |
| - * realDisplayState_ if the braille captions feature is enabled and there is |
| - * no hardware display connected. Otherwise, it is the same object |
| - * as realDisplayState_. |
| + * Current display state to show in the Virtual Braille Captions display. |
| + * This is different from realDisplayState_ if the braille captions feature |
| + * is enabled and there is no hardware display connected. Otherwise, it is |
| + * the same object as realDisplayState_. |
| * @type {!cvox.BrailleDisplayState} |
| * @private |
| */ |
| @@ -76,16 +66,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_); |
| @@ -158,19 +138,22 @@ cvox.BrailleDisplayManager.prototype.setCommandListener = function(func) { |
| */ |
| cvox.BrailleDisplayManager.prototype.refreshDisplayState_ = function( |
| newState) { |
| - var oldSize = this.displayState_.textColumnCount * |
| - this.displayState_.textRowCount || 0; |
| + var oldColumnCount = this.displayState_.textColumnCount || 0; |
| + var oldRowCount = this.displayState_.textRowCount || 0; |
| this.realDisplayState_ = newState; |
| if (newState.available) { |
| this.displayState_ = newState; |
| + // Update the dimensions of the virtual braille captions display to those |
| + // of a real physical display when one is plugged in. |
| } else { |
| this.displayState_ = |
| cvox.BrailleCaptionsBackground.getVirtualDisplayState(); |
| } |
| - var newSize = this.displayState_.textColumnCount * |
| - this.displayState_.textRowCount || 0; |
| - if (oldSize != newSize) { |
| - this.panStrategy_.setDisplaySize(newSize); |
| + var newColumnCount = this.displayState_.textColumnCount || 0; |
| + var newRowCount = this.displayState_.textRowCount || 0; |
| + |
| + if (oldColumnCount != newColumnCount || oldRowCount != newRowCount) { |
| + this.panStrategy_.setDisplaySize(newRowCount, newColumnCount); |
| } |
| this.refresh_(); |
| }; |
| @@ -188,26 +171,27 @@ cvox.BrailleDisplayManager.prototype.onCaptionsStateChanged_ = function() { |
| }; |
| -/** @private */ |
| +/** |
| + * Refreshes what is shown on the physical braille display and the virtual |
| + * braille captions display. |
| + * @private */ |
|
David Tseng
2016/11/30 22:11:54
nit: move */ to a new line
ultimatedbz
2016/12/01 05:12:14
Done.
|
| 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_.getCurrentBrailleViewportContents(); |
| + var textBuf = this.panStrategy_.getCurrentTextSlice(); |
|
David Tseng
2016/11/30 22:11:54
Maybe make this getCurrentTextViewPortContents
ultimatedbz
2016/12/01 05:12:15
Done.
|
| 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, |
| + this.displayState_.textRowCount, this.displayState_.textColumnCount); |
| } |
| }; |
| - |
| /** |
| * @param {!cvox.NavBraille} newContent New display content. |
| * @param {cvox.ExpandingBrailleTranslator.ExpansionType} newExpansionType |
| @@ -220,8 +204,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; |
| @@ -247,19 +229,15 @@ cvox.BrailleDisplayManager.prototype.translateContent_ = function( |
| } else { |
| translatedEndIndex = textToBraille[endIndex]; |
| } |
| - this.translatedContent_ = cells; |
| - // 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)); |
| - this.writeCursor_(this.displayedContent_, |
| - translatedStartIndex, translatedEndIndex); |
| + // Add the cursor to cells. |
| + this.writeCursor_(cells, translatedStartIndex, translatedEndIndex); |
| targetPosition = translatedStartIndex; |
| } else { |
| - this.translatedContent_ = this.displayedContent_ = cells; |
| targetPosition = 0; |
| } |
| - this.panStrategy_.setContent(this.translatedContent_, targetPosition); |
| + this.panStrategy_.setContent(this.content_.text.toString(), |
| + cells, brailleToText, targetPosition); |
|
David Tseng
2016/11/30 22:11:54
Optional: to help the reviewer and any future read
ultimatedbz
2016/12/01 05:12:15
Acknowledged.
|
| + |
| this.refresh_(); |
| }.bind(this); |
| @@ -289,7 +267,8 @@ cvox.BrailleDisplayManager.prototype.onKeyEvent_ = function(event) { |
| break; |
| case cvox.BrailleKeyCommand.ROUTING: |
| event.displayPosition = this.brailleToTextPosition_( |
| - event.displayPosition + this.panStrategy_.viewPort.start); |
| + event.displayPosition + this.panStrategy_.viewPort.firstRow * |
| + this.panStrategy_.displaySize.columns); |
| // fall through |
| default: |
| this.commandListener_(event, this.content_); |
| @@ -331,7 +310,6 @@ cvox.BrailleDisplayManager.prototype.panRight_ = function() { |
| } |
| }; |
| - |
| /** |
| * Writes a cursor in the specified range into translated content. |
| * @param {ArrayBuffer} buffer Buffer to add cursor to. |
| @@ -357,7 +335,6 @@ cvox.BrailleDisplayManager.prototype.writeCursor_ = function( |
| } |
| }; |
| - |
| /** |
| * Returns the text position corresponding to an absolute braille position, |
| * that is not accounting for the current pan position. |
| @@ -368,10 +345,9 @@ cvox.BrailleDisplayManager.prototype.writeCursor_ = function( |
| */ |
| cvox.BrailleDisplayManager.prototype.brailleToTextPosition_ = |
| function(braillePosition) { |
| - var mapping = this.brailleToText_; |
| + var mapping = this.panStrategy_.brailleToText; |
| if (braillePosition < 0) { |
| // This shouldn't happen. |
| - console.error('WARNING: Braille position < 0: ' + braillePosition); |
|
David Tseng
2016/11/30 22:11:54
Doesn't seem like this should be removed.
ultimatedbz
2016/12/01 05:12:15
Thanks for catching this!
|
| return 0; |
| } else if (braillePosition >= mapping.length) { |
| // This happens when the user clicks on the right part of the display |
| @@ -383,17 +359,11 @@ cvox.BrailleDisplayManager.prototype.brailleToTextPosition_ = |
| } |
| }; |
| - |
| /** |
| * @param {boolean} wordWrap |
| * @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_(); |
| }; |