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

Side by Side Diff: chrome/browser/resources/chromeos/chromevox/braille/braille_translator_manager.js

Issue 2813743002: Switch to selected 8-dot braille table in email and url text fields (Closed)
Patch Set: Address feedback. Created 3 years, 8 months 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
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 Keeps track of the current braille translators. 6 * @fileoverview Keeps track of the current braille translators.
7 */ 7 */
8 8
9 goog.provide('cvox.BrailleTranslatorManager'); 9 goog.provide('cvox.BrailleTranslatorManager');
10 10
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 * @param {function()} listener The listener. 75 * @param {function()} listener The listener.
76 */ 76 */
77 addChangeListener: function(listener) { 77 addChangeListener: function(listener) {
78 this.changeListeners_.push(listener); 78 this.changeListeners_.push(listener);
79 }, 79 },
80 80
81 /** 81 /**
82 * Refreshes the braille translator(s) used for input and output. This 82 * Refreshes the braille translator(s) used for input and output. This
83 * should be called when something has changed (such as a preference) to 83 * should be called when something has changed (such as a preference) to
84 * make sure that the correct translator is used. 84 * make sure that the correct translator is used.
85 * @param {string} brailleTable The table for this translator to use.
86 * @param {string=} opt_brailleTable8 Optionally specify an uncontracted
87 * table.
85 */ 88 */
86 refresh: function() { 89 refresh: function(brailleTable, opt_brailleTable8) {
87 var tables = this.tables_; 90 var tables = this.tables_;
88 if (tables.length == 0) 91 if (tables.length == 0)
89 return; 92 return;
90 93
91 // First, see if we have a braille table set previously. 94 // Look for the table requested.
92 var table = cvox.BrailleTable.forId(tables, localStorage['brailleTable']); 95 var table = cvox.BrailleTable.forId(tables, brailleTable);
93 if (!table) { 96 if (!table) {
94 // Match table against current locale. 97 // Match table against current locale.
95 var currentLocale = chrome.i18n.getMessage('@@ui_locale').split(/[_-]/); 98 var currentLocale = chrome.i18n.getMessage('@@ui_locale').split(/[_-]/);
96 var major = currentLocale[0]; 99 var major = currentLocale[0];
97 var minor = currentLocale[1]; 100 var minor = currentLocale[1];
98 var firstPass = tables.filter(function(table) { 101 var firstPass = tables.filter(function(table) {
99 return table.locale.split(/[_-]/)[0] == major; 102 return table.locale.split(/[_-]/)[0] == major;
100 }); 103 });
101 if (firstPass.length > 0) { 104 if (firstPass.length > 0) {
102 table = firstPass[0]; 105 table = firstPass[0];
103 if (minor) { 106 if (minor) {
104 var secondPass = firstPass.filter(function(table) { 107 var secondPass = firstPass.filter(function(table) {
105 return table.locale.split(/[_-]/)[1] == minor; 108 return table.locale.split(/[_-]/)[1] == minor;
106 }); 109 });
107 if (secondPass.length > 0) 110 if (secondPass.length > 0)
108 table = secondPass[0]; 111 table = secondPass[0];
109 } 112 }
110 } 113 }
111 } 114 }
112 if (!table) 115 if (!table)
113 table = cvox.BrailleTable.forId(tables, 'en-US-comp8'); 116 table = cvox.BrailleTable.forId(tables, 'en-US-comp8');
114 117
115 // TODO(plundblad): Only update when user explicitly selects a table
116 // so that switching locales changes table by default. crbug.com/441206.
117 localStorage['brailleTable'] = table.id;
118 if (!localStorage['brailleTable6'])
119 localStorage['brailleTable6'] = 'en-US-g1';
120 if (!localStorage['brailleTable8'])
121 localStorage['brailleTable8'] = 'en-US-comp8';
122
123 if (table.dots == '6') {
124 localStorage['brailleTableType'] = 'brailleTable6';
125 localStorage['brailleTable6'] = table.id;
126 } else {
127 localStorage['brailleTableType'] = 'brailleTable8';
128 localStorage['brailleTable8'] = table.id;
129 }
130
131 // If the user explicitly set an 8 dot table, use that when looking 118 // If the user explicitly set an 8 dot table, use that when looking
132 // for an uncontracted table. Otherwise, use the current table and let 119 // for an uncontracted table. Otherwise, use the current table and let
133 // getUncontracted find an appropriate corresponding table. 120 // getUncontracted find an appropriate corresponding table.
134 var table8Dot = cvox.BrailleTable.forId(tables, 121 var table8Dot = opt_brailleTable8 ?
135 localStorage['brailleTable8']); 122 cvox.BrailleTable.forId(tables, opt_brailleTable8) : null;
136 var uncontractedTable = cvox.BrailleTable.getUncontracted( 123 var uncontractedTable = cvox.BrailleTable.getUncontracted(
137 tables, table8Dot || table); 124 tables, table8Dot || table);
138 125
139 var newDefaultTableId = table.id; 126 var newDefaultTableId = table.id;
140 var newUncontractedTableId = table.id === uncontractedTable.id ? 127 var newUncontractedTableId = table.id === uncontractedTable.id ?
141 null : uncontractedTable.id; 128 null : uncontractedTable.id;
142 if (newDefaultTableId === this.defaultTableId_ && 129 if (newDefaultTableId === this.defaultTableId_ &&
143 newUncontractedTableId === this.uncontractedTableId_) { 130 newUncontractedTableId === this.uncontractedTableId_) {
144 return; 131 return;
145 } 132 }
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 }, 180 },
194 181
195 /** 182 /**
196 * Asynchronously fetches the list of braille tables and refreshes the 183 * Asynchronously fetches the list of braille tables and refreshes the
197 * translators when done. 184 * translators when done.
198 * @private 185 * @private
199 */ 186 */
200 fetchTables_: function() { 187 fetchTables_: function() {
201 cvox.BrailleTable.getAll(function(tables) { 188 cvox.BrailleTable.getAll(function(tables) {
202 this.tables_ = tables; 189 this.tables_ = tables;
203 this.refresh(); 190
191 // Initial refresh; set options from user preferences.
192 this.refresh(localStorage['brailleTable'], localStorage['brailleTable8']);
204 }.bind(this)); 193 }.bind(this));
205 }, 194 },
206 195
207 /** 196 /**
208 * Loads the liblouis instance by attaching it to the document. 197 * Loads the liblouis instance by attaching it to the document.
209 * @private 198 * @private
210 */ 199 */
211 loadLiblouis_: function() { 200 loadLiblouis_: function() {
212 // Cast away nullability. When the document is loaded, it will always 201 // Cast away nullability. When the document is loaded, it will always
213 // have a body. 202 // have a body.
(...skipping 10 matching lines...) Expand all
224 }, 213 },
225 214
226 /** 215 /**
227 * @return {!Array<cvox.BrailleTable.Table>} The currently loaded braille 216 * @return {!Array<cvox.BrailleTable.Table>} The currently loaded braille
228 * tables, or an empty array if they are not yet loaded. 217 * tables, or an empty array if they are not yet loaded.
229 */ 218 */
230 getTablesForTest: function() { 219 getTablesForTest: function() {
231 return this.tables_; 220 return this.tables_;
232 } 221 }
233 }; 222 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698