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..23365adac00392b25bb82d6dcb8c1ff8e93ab2db 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_); |
| @@ -158,19 +148,23 @@ 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 those |
| + // of a real physical display when one is plugged in. |
| + localStorage['virtualBrailleRows'] = newState.textRowCount; |
| + localStorage['virtualBrailleColumns'] = newState.textColumnCount; |
| } 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); |
|
David Tseng
2016/11/15 17:54:59
Make the display size a pair i.e.
@type {{rows: nu
ultimatedbz
2016/11/19 03:11:58
Done. The parameters are still the same, but the i
|
| } |
| this.refresh_(); |
| }; |
| @@ -188,26 +182,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(); |
|
David Tseng
2016/11/15 17:54:59
Slice seems wrong in terms of multiline; maybe cal
ultimatedbz
2016/11/19 03:11:58
Done.
|
| + 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 +214,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 +224,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 +243,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 +251,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 +282,11 @@ cvox.BrailleDisplayManager.prototype.onKeyEvent_ = function(event) { |
| this.panRight_(); |
| break; |
| case cvox.BrailleKeyCommand.ROUTING: |
| + /* TODO |
|
David Tseng
2016/11/15 17:54:59
The goal is to get this cl checked in, so please r
ultimatedbz
2016/11/15 19:31:57
I do intend to complete this block, but for the ti
David Tseng
2016/11/15 21:36:38
I would not accept this cl without this working as
ultimatedbz
2016/11/15 21:58:09
I think you are assuming that I want to commit the
ultimatedbz
2016/11/19 03:11:58
As per our offline conversation, I will leave the
ultimatedbz
2016/11/19 03:11:58
I just implemented a solution to your problem. I'm
|
| event.displayPosition = this.brailleToTextPosition_( |
| event.displayPosition + this.panStrategy_.viewPort.start); |
| // fall through |
| + // */ |
| default: |
| this.commandListener_(event, this.content_); |
| break; |
| @@ -368,7 +364,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 +386,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_(); |
| }; |