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

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: Fix GN build 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('Msgs');
13 goog.require('PanelCommand');
14
15 function $(id) {
16 return document.getElementById(id);
17 }
18
19 /**
20 * Class to manage the panel.
21 * @constructor
22 */
23 Panel = function() {
24 };
25
26 /**
27 * Initialize the panel.
28 */
29 Panel.init = function() {
30 /** @type {Element} @private */
31 this.speechContainer_ = $('speech-container');
32
33 /** @type {Element} @private */
34 this.speechElement_ = $('speech');
35
36 /** @type {Element} @private */
37 this.brailleContainer_ = $('braille-container');
38
39 /** @type {Element} @private */
40 this.brailleTextElement_ = $('braille-text');
41
42 /** @type {Element} @private */
43 this.brailleCellsElement_ = $('braille-cells');
44
45 Panel.updateFromPrefs();
46 window.addEventListener('storage', function(event) {
47 if (event.key == 'brailleCaptions') {
48 Panel.updateFromPrefs();
49 }
50 }, false);
51
52 window.addEventListener('message', function(message) {
53 var command = JSON.parse(message.data);
54 Panel.exec(/** @type {PanelCommand} */(command));
55 }, false);
56
57 $('menu').addEventListener('click', Panel.onMenu, false);
58 $('options').addEventListener('click', Panel.onOptions, false);
59 $('close').addEventListener('click', Panel.onClose, false);
60
61 Msgs.addTranslatedMessagesToDom(document);
62 };
63
64 /**
65 * Update the display based on prefs.
66 */
67 Panel.updateFromPrefs = function() {
68 if (localStorage['brailleCaptions'] === String(true)) {
69 this.speechContainer_.style.visibility = 'hidden';
70 this.brailleContainer_.style.visibility = 'visible';
71 } else {
72 this.speechContainer_.style.visibility = 'visible';
73 this.brailleContainer_.style.visibility = 'hidden';
74 }
75 };
76
77 /**
78 * Execute a command to update the panel.
79 *
80 * @param {PanelCommand} command The command to execute.
81 */
82 Panel.exec = function(command) {
83 /**
84 * Escape text so it can be safely added to HTML.
85 * @param {*} str Text to be added to HTML, will be cast to string.
86 * @return {string} The escaped string.
87 */
88 function escapeForHtml(str) {
89 return String(str)
90 .replace(/&/g, '&')
91 .replace(/</g, '&lt;')
92 .replace(/\>/g, '&gt;')
93 .replace(/"/g, '&quot;')
94 .replace(/'/g, '&#039;')
95 .replace(/\//g, '&#x2F;');
96 }
97
98 switch (command.type) {
99 case PanelCommandType.CLEAR_SPEECH:
100 this.speechElement_.innerHTML = '';
101 break;
102 case PanelCommandType.ADD_NORMAL_SPEECH:
103 if (this.speechElement_.innerHTML != '') {
104 this.speechElement_.innerHTML += '&nbsp;&nbsp;';
105 }
106 this.speechElement_.innerHTML += '<span class="usertext">' +
107 escapeForHtml(command.data) +
108 '</span>';
109 break;
110 case PanelCommandType.ADD_ANNOTATION_SPEECH:
111 if (this.speechElement_.innerHTML != '') {
112 this.speechElement_.innerHTML += '&nbsp;&nbsp;';
113 }
114 this.speechElement_.innerHTML += escapeForHtml(command.data);
115 break;
116 case PanelCommandType.UPDATE_BRAILLE:
117 this.brailleTextElement_.textContent = command.data.text;
118 this.brailleCellsElement_.textContent = command.data.braille;
119 break;
120 }
121 };
122
123 /**
124 * Open the ChromeVox Menu.
125 */
126 Panel.onMenu = function() {
127 window.location = '#fullscreen';
128 // TODO(dmazzoni): implement the menu UI here.
129 };
130
131 /**
132 * Open the ChromeVox Options.
133 */
134 Panel.onOptions = function() {
135 var bkgnd =
136 chrome.extension.getBackgroundPage()['global']['backgroundObj'];
137 bkgnd['showOptionsPage']();
138 window.location = '#';
139 };
140
141 /**
142 * Exit ChromeVox.
143 */
144 Panel.onClose = function() {
145 window.location = '#close';
146 };
147
148 window.addEventListener('load', function() {
149 Panel.init();
150 }, false);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698