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

Side by Side Diff: chrome/browser/resources/chromeos/chromevox/cvox2/background/panel.js

Issue 1277183003: Add ChromeVox panel and implement caption display functionality. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Finish initial implementation for Chrome OS, address feedback Created 5 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 /**
6 * @fileoverview ChromeVox panel.
7 *
8 */
9
10 goog.provide('Panel');
11
12 goog.require('PanelCommand');
13 goog.require('cvox.ChromeVox');
14 goog.require('cvox.ExtensionBridge');
Peter Lundblad 2015/11/06 15:00:58 Do you need to pull in this and the above?
dmazzoni 2015/11/06 21:01:00 ExtensionBridge isn't needed. cvox.ChromeVox is w
15
16 /**
17 * Class to manage the panel.
18 * @constructor
19 */
20 Panel = function() {
21 };
22
23 /**
24 * Initialize the panel.
25 */
26 Panel.init = function() {
27 /** @type {Element} @private */
28 this.speechContainer_ = $('speech-container');
29
30 /** @type {Element} @private*/
Peter Lundblad 2015/11/06 15:00:58 nit: missing space after @private
dmazzoni 2015/11/06 21:01:00 Done.
31 this.speechElement_ = $('speech');
32
33 /** @type {Element} @private*/
Peter Lundblad 2015/11/06 15:00:58 nit: missing space after @private
dmazzoni 2015/11/06 21:01:01 Done.
34 this.brailleContainer_ = $('braille-container');
35
36 /** @type {Element} @private*/
37 this.brailleTextElement_ = $('braille-text');
38
39 /** @type {Element} @private*/
40 this.brailleCellsElement_ = $('braille-cells');
41
42 Panel.updateFromPrefs();
43 window.addEventListener('storage', function(event) {
44 if (event.key == 'brailleCaptions') {
45 Panel.updateFromPrefs();
46 }
47 }, false);
48
49 window.addEventListener('message', function(message) {
50 var command = JSON.parse(message.data);
51 Panel.exec(/** @type {PanelCommand} */(command));
52 }, false);
53
54 $('menu').addEventListener('click', Panel.onMenu, false);
55 $('options').addEventListener('click', Panel.onOptions, false);
56 $('close').addEventListener('click', Panel.onClose, false);
57 };
Peter Lundblad 2015/11/06 15:00:58 Do you need an Msgs.addTranslatedMessagesToDom som
dmazzoni 2015/11/06 21:01:00 Yes. Done and tested.
58
59 /**
60 * Update the display based on prefs.
61 */
62 Panel.updateFromPrefs = function() {
63 if (localStorage['brailleCaptions'] === String(true)) {
64 this.speechContainer_.style.visibility = 'hidden';
65 this.brailleContainer_.style.visibility = 'visible';
66 } else {
67 this.speechContainer_.style.visibility = 'visible';
68 this.brailleContainer_.style.visibility = 'hidden';
69 }
70 };
71
72 /**
73 * Execute a command to update the panel.
74 *
75 * @param {PanelCommand} command The command to execute.
76 */
77 Panel.exec = function(command) {
78 switch (command.type) {
79 case PanelCommandType.CLEAR_SPEECH:
80 this.speechElement_.innerHTML = '';
81 break;
82 case PanelCommandType.ADD_NORMAL_SPEECH:
83 if (this.speechElement_.innerHTML != '') {
84 this.speechElement_.innerHTML += '  ';
85 }
86 this.speechElement_.innerHTML += '<span class="usertext">' +
87 command.data +
Peter Lundblad 2015/11/06 15:00:58 Where is this & and < escaped?
dmazzoni 2015/11/06 21:01:01 Good catch.
88 '</span>';
89 break;
90 case PanelCommandType.ADD_ANNOTATION_SPEECH:
91 if (this.speechElement_.innerHTML != '') {
92 this.speechElement_.innerHTML += '&nbsp;&nbsp;';
93 }
94 this.speechElement_.innerHTML += command.data;
95 break;
96 case PanelCommandType.UPDATE_BRAILLE_TEXT:
97 this.brailleTextElement_.textContent = command.data;
Peter Lundblad 2015/11/06 15:00:58 Will this collapse whitespace? Perhaps this needs
dmazzoni 2015/11/06 21:01:00 Good idea, done.
98 break;
99 case PanelCommandType.UPDATE_BRAILLE_CELLS:
100 this.brailleCellsElement_.textContent = command.data;
101 break;
102 }
103 };
104
105 /**
106 * Open the ChromeVox Menu.
107 */
108 Panel.onMenu = function() {
109 window.location = '#fullscreen';
110 // TODO(dmazzoni): implement the menu UI here.
111 };
112
113 /**
114 * Open the ChromeVox Options.
115 */
116 Panel.onOptions = function() {
117 var bkgnd =
118 chrome.extension.getBackgroundPage()['global']['backgroundObj'];
119 bkgnd['showOptionsPage']();
120 window.location = '#';
121 };
122
123 /**
124 * Exit ChromeVox.
125 */
126 Panel.onClose = function() {
127 window.location = '#close';
128 };
129
130 window.addEventListener('load', function() {
131 Panel.init();
132 }, false);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698