Chromium Code Reviews| Index: chrome/browser/resources/chromeos/chromevox/cvox2/background/panel.js |
| diff --git a/chrome/browser/resources/chromeos/chromevox/cvox2/background/panel.js b/chrome/browser/resources/chromeos/chromevox/cvox2/background/panel.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..ea9d8a2135eedaf29da4ffa3aa6711af0c28c430 |
| --- /dev/null |
| +++ b/chrome/browser/resources/chromeos/chromevox/cvox2/background/panel.js |
| @@ -0,0 +1,121 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +/** |
| + * @fileoverview ChromeVox panel. |
| + * |
| + */ |
| + |
| +goog.provide('cvox.Panel'); |
| + |
| +goog.require('cvox.ChromeVox'); |
| +goog.require('cvox.ExtensionBridge'); |
| +goog.require('cvox.Msgs'); |
| +goog.require('cvox.PanelCommand'); |
| + |
| +/** |
| + * Class to manage the options page. |
|
David Tseng
2015/08/07 21:43:03
nit: panel
dmazzoni
2015/11/05 23:59:40
Done.
|
| + * @constructor |
| + */ |
| +cvox.Panel = function() { |
|
David Tseng
2015/08/07 21:43:03
Do we still want cvox namespaces in next code?
dmazzoni
2015/11/05 23:59:40
Done.
|
| +}; |
| + |
| +/** |
| + * Initialize the panel. |
| + */ |
| +cvox.Panel.init = function() { |
| + cvox.ChromeVox.msgs = new cvox.Msgs(); |
| + |
| + /** @type {Element} */ |
|
David Tseng
2015/08/07 21:43:03
nit: @private and !Element
dmazzoni
2015/11/05 23:59:40
Done.
|
| + this.speechContainer_ = $('speech-container'); |
| + |
| + /** @type {Element} */ |
|
David Tseng
2015/08/07 21:43:03
ditto
dmazzoni
2015/11/05 23:59:40
Done.
|
| + this.speechElement_ = $('speech'); |
| + |
| + /** @type {Element} */ |
|
David Tseng
2015/08/07 21:43:03
ditto
dmazzoni
2015/11/05 23:59:40
Done.
|
| + this.brailleContainer_ = $('braille-container'); |
| + |
| + /** @type {Element} */ |
| + this.brailleTextElement_ = $('braille-text'); |
| + |
| + /** @type {Element} */ |
| + this.brailleCellsElement_ = $('braille-cells'); |
| + |
| + cvox.Panel.updateFromPrefs(); |
| + window.addEventListener('storage', function(event) { |
| + if (event.key == 'brailleCaptions') { |
| + cvox.Panel.updateFromPrefs(); |
| + } |
| + }, false); |
| + |
| + window.addEventListener('message', function(message) { |
| + var command = JSON.parse(message.data); |
| + cvox.Panel.exec(/** @type {cvox.PanelCommand} */(command)); |
| + }, false); |
| + |
| + $('options').addEventListener('click', cvox.Panel.onOptions, false); |
| + $('close').addEventListener('click', cvox.Panel.onClose, false); |
| +}; |
| + |
| +/** |
| + * Update the display based on prefs. |
| + */ |
| +cvox.Panel.updateFromPrefs = function() { |
|
David Tseng
2015/08/07 21:43:03
It would be nice if this class had a prototype so
dmazzoni
2015/11/05 23:59:40
My thinking at this point is that there will be on
|
| + if (localStorage['brailleCaptions'] === String(true)) { |
| + this.speechContainer_.style.visibility = 'hidden'; |
| + this.brailleContainer_.style.visibility = 'visible'; |
| + } else { |
| + this.speechContainer_.style.visibility = 'visible'; |
| + this.brailleContainer_.style.visibility = 'hidden'; |
| + } |
| +}; |
| + |
| +/** |
| + * Execute a command to update the panel. |
| + * |
| + * @param {cvox.PanelCommand} command The command to execute. |
| + */ |
| +cvox.Panel.exec = function(command) { |
| + switch (command.type) { |
| + case cvox.PanelCommandType.CLEAR_SPEECH: |
| + this.speechElement_.innerHTML = ''; |
| + break; |
| + case cvox.PanelCommandType.ADD_NORMAL_SPEECH: |
| + if (this.speechElement_.innerHTML != '') { |
| + this.speechElement_.innerHTML += ' '; |
| + } |
| + this.speechElement_.innerHTML += '<span class="usertext">' + |
| + command.data + |
| + '</span>'; |
| + break; |
| + case cvox.PanelCommandType.ADD_ANNOTATION_SPEECH: |
| + if (this.speechElement_.innerHTML != '') { |
| + this.speechElement_.innerHTML += ' '; |
| + } |
| + this.speechElement_.innerHTML += command.data; |
| + break; |
| + case cvox.PanelCommandType.UPDATE_BRAILLE_TEXT: |
| + this.brailleTextElement_.textContent = command.data; |
| + break; |
| + case cvox.PanelCommandType.UPDATE_BRAILLE_CELLS: |
| + this.brailleCellsElement_.textContent = command.data; |
| + break; |
| + } |
| +}; |
| + |
| +/** |
| + * Open the ChromeVox Options. |
| + */ |
| +cvox.Panel.onOptions = function() { |
| +}; |
|
David Tseng
2015/08/07 21:43:03
TODO?
dmazzoni
2015/11/05 23:59:40
Implemented now.
|
| + |
| +/** |
| + * Exit ChromeVox. |
| + */ |
| +cvox.Panel.onClose = function() { |
| +}; |
|
David Tseng
2015/08/07 21:43:02
TODO?
dmazzoni
2015/11/05 23:59:40
Implemented now.
|
| + |
| +window.addEventListener('load', function() { |
| + cvox.Panel.init(); |
| +}, false); |