Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * @fileoverview ChromeVox options page. | 6 * @fileoverview ChromeVox options page. |
| 7 * | 7 * |
| 8 */ | 8 */ |
| 9 | 9 |
| 10 goog.provide('cvox.OptionsPage'); | 10 goog.provide('cvox.OptionsPage'); |
| 11 | 11 |
| 12 goog.require('Msgs'); | 12 goog.require('Msgs'); |
| 13 goog.require('PanelCommand'); | |
| 13 goog.require('cvox.BrailleTable'); | 14 goog.require('cvox.BrailleTable'); |
| 14 goog.require('cvox.BrailleTranslatorManager'); | 15 goog.require('cvox.BrailleTranslatorManager'); |
| 15 goog.require('cvox.ChromeEarcons'); | 16 goog.require('cvox.ChromeEarcons'); |
| 16 goog.require('cvox.ChromeTts'); | 17 goog.require('cvox.ChromeTts'); |
| 17 goog.require('cvox.ChromeVox'); | 18 goog.require('cvox.ChromeVox'); |
| 18 goog.require('cvox.ChromeVoxPrefs'); | 19 goog.require('cvox.ChromeVoxPrefs'); |
| 19 goog.require('cvox.CommandStore'); | 20 goog.require('cvox.CommandStore'); |
| 20 goog.require('cvox.ExtensionBridge'); | 21 goog.require('cvox.ExtensionBridge'); |
| 21 goog.require('cvox.KeyMap'); | 22 goog.require('cvox.KeyMap'); |
| 22 goog.require('cvox.KeySequence'); | 23 goog.require('cvox.KeySequence'); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 64 cvox.OptionsPage.populateVoicesSelect(); | 65 cvox.OptionsPage.populateVoicesSelect(); |
| 65 cvox.BrailleTable.getAll(function(tables) { | 66 cvox.BrailleTable.getAll(function(tables) { |
| 66 /** @type {!Array<cvox.BrailleTable.Table>} */ | 67 /** @type {!Array<cvox.BrailleTable.Table>} */ |
| 67 cvox.OptionsPage.brailleTables = tables; | 68 cvox.OptionsPage.brailleTables = tables; |
| 68 cvox.OptionsPage.populateBrailleTablesSelect(); | 69 cvox.OptionsPage.populateBrailleTablesSelect(); |
| 69 }); | 70 }); |
| 70 chrome.storage.local.get({'brailleWordWrap': true}, function(items) { | 71 chrome.storage.local.get({'brailleWordWrap': true}, function(items) { |
| 71 $('brailleWordWrap').checked = items.brailleWordWrap; | 72 $('brailleWordWrap').checked = items.brailleWordWrap; |
| 72 }); | 73 }); |
| 73 | 74 |
| 75 $('virtual_braille_display_rows_input').value = | |
| 76 localStorage['virtualBrailleRows']; | |
| 77 $('virtual_braille_display_columns_input').value = | |
| 78 localStorage['virtualBrailleColumns']; | |
| 79 var changeToInterleave = | |
| 80 Msgs.getMsg('options_change_current_display_style_interleave'); | |
| 81 var changeToSideBySide = | |
| 82 Msgs.getMsg('options_change_current_display_style_side_by_side'); | |
| 83 var currentlyDisplayingInterleave = | |
| 84 Msgs.getMsg('options_current_display_style_interleave'); | |
| 85 var currentlyDisplayingSideBySide = | |
| 86 Msgs.getMsg('options_current_display_style_side_by_side'); | |
| 87 $('changeDisplayStyle').textContent = | |
| 88 localStorage['brailleSideBySide'] === 'true' ? | |
| 89 changeToInterleave : changeToSideBySide; | |
| 90 $('currentDisplayStyle').textContent = | |
| 91 localStorage['brailleSideBySide'] === 'true' ? | |
| 92 currentlyDisplayingSideBySide : currentlyDisplayingInterleave; | |
| 93 | |
| 94 | |
| 74 Msgs.addTranslatedMessagesToDom(document); | 95 Msgs.addTranslatedMessagesToDom(document); |
| 75 cvox.OptionsPage.hidePlatformSpecifics(); | 96 cvox.OptionsPage.hidePlatformSpecifics(); |
| 76 | 97 |
| 77 cvox.OptionsPage.update(); | 98 cvox.OptionsPage.update(); |
| 78 | 99 |
| 79 document.addEventListener('change', cvox.OptionsPage.eventListener, false); | 100 document.addEventListener('change', cvox.OptionsPage.eventListener, false); |
| 80 document.addEventListener('click', cvox.OptionsPage.eventListener, false); | 101 document.addEventListener('click', cvox.OptionsPage.eventListener, false); |
| 81 document.addEventListener('keydown', cvox.OptionsPage.eventListener, false); | 102 document.addEventListener('keydown', cvox.OptionsPage.eventListener, false); |
| 82 | 103 |
| 83 cvox.ExtensionBridge.addMessageListener(function(message) { | 104 cvox.ExtensionBridge.addMessageListener(function(message) { |
| 84 if (message['keyBindings'] || message['prefs']) { | 105 if (message['keyBindings'] || message['prefs']) { |
| 85 cvox.OptionsPage.update(); | 106 cvox.OptionsPage.update(); |
| 86 } | 107 } |
| 87 }); | 108 }); |
| 88 | 109 |
| 89 $('selectKeys').addEventListener( | 110 $('selectKeys').addEventListener( |
| 90 'click', cvox.OptionsPage.reset, false); | 111 'click', cvox.OptionsPage.reset, false); |
| 91 | 112 |
| 92 if (cvox.PlatformUtil.matchesPlatform(cvox.PlatformFilter.WML)) { | 113 if (cvox.PlatformUtil.matchesPlatform(cvox.PlatformFilter.WML)) { |
| 93 $('version').textContent = | 114 $('version').textContent = |
| 94 chrome.app.getDetails().version; | 115 chrome.app.getDetails().version; |
| 95 } | 116 } |
| 117 | |
| 118 var clearVirtualDisplay = function() { | |
| 119 var groups = []; | |
| 120 var sizeOfDisplay = parseInt(localStorage['virtualBrailleRows'], 10) * | |
| 121 parseInt(localStorage['virtualBrailleColumns'], 10); | |
| 122 for (var i = 0; i < sizeOfDisplay; i++) { | |
| 123 groups.push(['X', 'X']); | |
| 124 } | |
| 125 (new PanelCommand(PanelCommandType.UPDATE_BRAILLE, | |
| 126 {groups: groups})).send(); | |
| 127 }; | |
| 128 | |
| 129 $('changeDisplayStyle').addEventListener('click', function(evt) { | |
| 130 var sideBySide = localStorage['brailleSideBySide'] !== 'true'; | |
| 131 localStorage['brailleSideBySide'] = sideBySide; | |
| 132 $('changeDisplayStyle').textContent = | |
| 133 sideBySide ? changeToInterleave : changeToSideBySide; | |
| 134 $('currentDisplayStyle').textContent = | |
| 135 sideBySide ? currentlyDisplayingSideBySide : | |
| 136 currentlyDisplayingInterleave; | |
| 137 clearVirtualDisplay(); | |
| 138 }, true); | |
| 139 | |
| 140 handleNumbericalInputPref('virtual_braille_display_rows_input', | |
| 141 'virtualBrailleRows'); | |
| 142 handleNumbericalInputPref('virtual_braille_display_columns_input', | |
| 143 'virtualBrailleColumns'); | |
| 96 }; | 144 }; |
| 97 | 145 |
| 98 /** | 146 /** |
| 99 * Update the value of controls to match the current preferences. | 147 * Update the value of controls to match the current preferences. |
| 100 * This happens if the user presses a key in a tab that changes a | 148 * This happens if the user presses a key in a tab that changes a |
| 101 * pref. | 149 * pref. |
| 102 */ | 150 */ |
| 103 cvox.OptionsPage.update = function() { | 151 cvox.OptionsPage.update = function() { |
| 104 var prefs = cvox.OptionsPage.prefs.getPrefs(); | 152 var prefs = cvox.OptionsPage.prefs.getPrefs(); |
| 105 for (var key in prefs) { | 153 for (var key in prefs) { |
| 106 // TODO(rshearer): 'active' is a pref, but there's no place in the | 154 // TODO(rshearer): 'active' is a pref, but there's no place in the |
| 107 // options page to specify whether you want ChromeVox active. | 155 // options page to specify whether you want ChromeVox active. |
| 108 var elements = document.querySelectorAll('*[name="' + key + '"]'); | 156 var elements = document.querySelectorAll('*[name="' + key + '"]'); |
| 109 for (var i = 0; i < elements.length; i++) { | 157 for (var i = 0; i < elements.length; i++) { |
| 110 cvox.OptionsPage.setValue(elements[i], prefs[key]); | 158 cvox.OptionsPage.setValue(elements[i], prefs[key]); |
| 111 } | 159 } |
| 112 } | 160 } |
| 113 }; | 161 }; |
| 162 /** | |
| 163 * Adds event listeners to input boxes to update local storage values and | |
| 164 * make sure that the input is a positive nonempty number between 1 and 99. | |
| 165 * @param {string} id Id of the input box. | |
| 166 * @param {string} pref Preference key in localStorage to access and modify. | |
| 167 */ | |
| 168 var handleNumbericalInputPref = function(id, pref) { | |
| 169 $(id).addEventListener('input', function(evt) { | |
| 170 if ($(id).value === '') | |
| 171 return; | |
|
dmazzoni
2016/10/31 20:03:44
nit: Need braces throughout this if/else
ultimatedbz
2016/10/31 20:05:57
What if I bring line 173 up to line 172 so the who
dmazzoni
2016/10/31 20:55:41
If it fits, that's fine. If anything wraps then us
ultimatedbz
2016/10/31 20:57:15
Gotcha!
| |
| 172 else if (parseInt($(id).value, 10) < 1 || | |
| 173 parseInt($(id).value, 10) > 99) | |
| 174 $(id).value = localStorage[pref]; | |
| 175 else | |
| 176 localStorage[pref] = $(id).value; | |
| 177 }, true); | |
| 178 | |
| 179 $(id).addEventListener('focusout', function(evt) { | |
| 180 if ($(id).value === '') | |
| 181 $(id).value = localStorage[pref]; | |
| 182 }, true); | |
| 183 }; | |
| 114 | 184 |
| 115 /** | 185 /** |
| 116 * Populate the keymap select element with stored keymaps | 186 * Populate the keymap select element with stored keymaps |
| 117 */ | 187 */ |
| 118 cvox.OptionsPage.populateKeyMapSelect = function() { | 188 cvox.OptionsPage.populateKeyMapSelect = function() { |
| 119 var select = $('cvox_keymaps'); | 189 var select = $('cvox_keymaps'); |
| 120 for (var id in cvox.KeyMap.AVAILABLE_MAP_INFO) { | 190 for (var id in cvox.KeyMap.AVAILABLE_MAP_INFO) { |
| 121 var info = cvox.KeyMap.AVAILABLE_MAP_INFO[id]; | 191 var info = cvox.KeyMap.AVAILABLE_MAP_INFO[id]; |
| 122 var option = document.createElement('option'); | 192 var option = document.createElement('option'); |
| 123 option.id = id; | 193 option.id = id; |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 367 /** | 437 /** |
| 368 * @return {cvox.BrailleTranslatorManager} | 438 * @return {cvox.BrailleTranslatorManager} |
| 369 */ | 439 */ |
| 370 cvox.OptionsPage.getBrailleTranslatorManager = function() { | 440 cvox.OptionsPage.getBrailleTranslatorManager = function() { |
| 371 return chrome.extension.getBackgroundPage()['braille_translator_manager']; | 441 return chrome.extension.getBackgroundPage()['braille_translator_manager']; |
| 372 }; | 442 }; |
| 373 | 443 |
| 374 document.addEventListener('DOMContentLoaded', function() { | 444 document.addEventListener('DOMContentLoaded', function() { |
| 375 cvox.OptionsPage.init(); | 445 cvox.OptionsPage.init(); |
| 376 }, false); | 446 }, false); |
| OLD | NEW |