| 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..33a2a9110d5b5245ac77d22753bb1003f4ea3db4 100644
|
| --- a/chrome/browser/resources/chromeos/chromevox/braille/braille_display_manager.js
|
| +++ b/chrome/browser/resources/chromeos/chromevox/braille/braille_display_manager.js
|
| @@ -87,6 +87,8 @@ cvox.BrailleDisplayManager = function(translatorManager) {
|
| */
|
| this.brailleToText_ = [];
|
|
|
| + this.displayingImage_ = false;
|
| +
|
| translatorManager.addChangeListener(function() {
|
| this.translateContent_(this.content_, this.expansionType_);
|
| }.bind(this));
|
| @@ -134,11 +136,80 @@ cvox.BrailleDisplayManager.CURSOR_DOTS_ = 1 << 6 | 1 << 7;
|
| */
|
| cvox.BrailleDisplayManager.prototype.setContent = function(
|
| content, expansionType) {
|
| + this.displayingImage_ = false;
|
| this.translateContent_(content, expansionType);
|
| };
|
|
|
|
|
| /**
|
| + * Takes an image, in the form of a data url, and displays it in braille
|
| + * onto the physical braille display and the virtual braille captions display.
|
| + * @param {string} imageUrl The image, in the form of a data url.
|
| + */
|
| +cvox.BrailleDisplayManager.prototype.setImageContent = function(imageUrl) {
|
| + // TODO(dmazzoni) We are only supporting this for multiline displays for now.
|
| + // We'd like to support single line displays with panning.
|
| + if (this.displayState_.textRowCount <= 1) {
|
| + return;
|
| + }
|
| + this.displayingImage_ = true;
|
| + if (!this.displayState_.available) {
|
| + return;
|
| + }
|
| +
|
| + var rows = this.displayState_.textRowCount;
|
| + var columns = this.displayState_.textColumnCount;
|
| + var imageDataUrl = imageUrl;
|
| + var imgElement = document.createElement('img');
|
| + imgElement.src = imageDataUrl;
|
| + var canvas = document.createElement('canvas');
|
| + var context = canvas.getContext('2d');
|
| + canvas.width = columns * 2;
|
| + canvas.height = rows * 4;
|
| + context.drawImage(imgElement, 0, 0, canvas.width, canvas.height);
|
| + var imageData = context.getImageData(0, 0, canvas.width, canvas.height);
|
| + var data = imageData.data;
|
| + var outputData = [];
|
| +
|
| + // Convert image to black and white.
|
| + for (var i = 0; i < data.length; i += 4) {
|
| + // Show if the alpha value is visible (above 20) and the pixel is not
|
| + // white (under 600).
|
| + var show = (data[i] +
|
| + data[i + 1] +
|
| + data[i + 2] <= 200 * 3) &&
|
| + (data[i + 3]) == 255;
|
| + outputData.push(show);
|
| + }
|
| +
|
| + // Convert to Braille.
|
| + var buf = new ArrayBuffer(rows * columns);
|
| + var view = new Uint8Array(buf);
|
| + var coordsToBrailleDot = [0x1, 0x2, 0x4, 0x40, 0x8, 0x10, 0x20, 0x80];
|
| + for (var i = 0; i < rows; i++) {
|
| + for (var j = 0; j < columns; j++) {
|
| + // Index in braille array.
|
| + var index = i * columns + j;
|
| + view[index] = 0;
|
| + for (var x = 0; x < 2; x++) {
|
| + for (var y = 0; y < 4; y++) {
|
| + if (outputData[((i * columns * 4 + j + y * columns) * 2 + x)])
|
| + view[index] += coordsToBrailleDot[x * 4 + y];
|
| + }
|
| + }
|
| + }
|
| + }
|
| +
|
| + if (this.realDisplayState_.available) {
|
| + chrome.brailleDisplayPrivate.writeDots(buf, buf.byteLength, 1);
|
| + }
|
| + if (cvox.BrailleCaptionsBackground.isEnabled()) {
|
| + cvox.BrailleCaptionsBackground.setImageContent(buf, rows, columns);
|
| + }
|
| +};
|
| +
|
| +
|
| +/**
|
| * Sets the command listener. When a command is invoked, the listener will be
|
| * called with the BrailleKeyEvent corresponding to the command and the content
|
| * that was present on the display when the command was invoked. The content
|
| @@ -190,7 +261,9 @@ cvox.BrailleDisplayManager.prototype.onCaptionsStateChanged_ = function() {
|
|
|
| /** @private */
|
| cvox.BrailleDisplayManager.prototype.refresh_ = function() {
|
| - if (!this.displayState_.available) {
|
| + // TODO(dmazzoni) Implement Panning support for images so refresh works with
|
| + // images as well.
|
| + if (!this.displayState_.available || this.displayingImage_) {
|
| return;
|
| }
|
| var viewPort = this.panStrategy_.viewPort;
|
|
|