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

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: Fixes corner cases (liblouis callbacks sometimes drop when called quickly). 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
« no previous file with comments | « no previous file | chrome/browser/resources/chromeos/chromevox/braille/braille_translator_manager_test.extjs » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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) {
90 if (brailleTable && brailleTable === this.defaultTableId_) {
91 return;
92 }
93
87 var tables = this.tables_; 94 var tables = this.tables_;
88 if (tables.length == 0) 95 if (tables.length == 0)
89 return; 96 return;
90 97
91 // First, see if we have a braille table set previously. 98 // Look for the table requested.
92 var table = cvox.BrailleTable.forId(tables, localStorage['brailleTable']); 99 var table = cvox.BrailleTable.forId(tables, brailleTable);
93 if (!table) { 100 if (!table) {
94 // Match table against current locale. 101 // Match table against current locale.
95 var currentLocale = chrome.i18n.getMessage('@@ui_locale').split(/[_-]/); 102 var currentLocale = chrome.i18n.getMessage('@@ui_locale').split(/[_-]/);
96 var major = currentLocale[0]; 103 var major = currentLocale[0];
97 var minor = currentLocale[1]; 104 var minor = currentLocale[1];
98 var firstPass = tables.filter(function(table) { 105 var firstPass = tables.filter(function(table) {
99 return table.locale.split(/[_-]/)[0] == major; 106 return table.locale.split(/[_-]/)[0] == major;
100 }); 107 });
101 if (firstPass.length > 0) { 108 if (firstPass.length > 0) {
102 table = firstPass[0]; 109 table = firstPass[0];
103 if (minor) { 110 if (minor) {
104 var secondPass = firstPass.filter(function(table) { 111 var secondPass = firstPass.filter(function(table) {
105 return table.locale.split(/[_-]/)[1] == minor; 112 return table.locale.split(/[_-]/)[1] == minor;
106 }); 113 });
107 if (secondPass.length > 0) 114 if (secondPass.length > 0)
108 table = secondPass[0]; 115 table = secondPass[0];
109 } 116 }
110 } 117 }
111 } 118 }
112 if (!table) 119 if (!table)
113 table = cvox.BrailleTable.forId(tables, 'en-US-comp8'); 120 table = cvox.BrailleTable.forId(tables, 'en-US-comp8');
114 121
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 122 // 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 123 // for an uncontracted table. Otherwise, use the current table and let
133 // getUncontracted find an appropriate corresponding table. 124 // getUncontracted find an appropriate corresponding table.
134 var table8Dot = cvox.BrailleTable.forId(tables, 125 var table8Dot = opt_brailleTable8 ?
135 localStorage['brailleTable8']); 126 cvox.BrailleTable.forId(tables, opt_brailleTable8) : null;
136 var uncontractedTable = cvox.BrailleTable.getUncontracted( 127 var uncontractedTable = cvox.BrailleTable.getUncontracted(
137 tables, table8Dot || table); 128 tables, table8Dot || table);
138
139 var newDefaultTableId = table.id; 129 var newDefaultTableId = table.id;
140 var newUncontractedTableId = table.id === uncontractedTable.id ? 130 var newUncontractedTableId = table.id === uncontractedTable.id ?
141 null : uncontractedTable.id; 131 null : uncontractedTable.id;
142 if (newDefaultTableId === this.defaultTableId_ && 132 if (newDefaultTableId === this.defaultTableId_ &&
143 newUncontractedTableId === this.uncontractedTableId_) { 133 newUncontractedTableId === this.uncontractedTableId_) {
144 return; 134 return;
145 } 135 }
146 136
147 var finishRefresh = function(defaultTranslator, uncontractedTranslator) { 137 var finishRefresh = function(defaultTranslator, uncontractedTranslator) {
148 this.defaultTableId_ = newDefaultTableId; 138 this.defaultTableId_ = newDefaultTableId;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 }, 183 },
194 184
195 /** 185 /**
196 * Asynchronously fetches the list of braille tables and refreshes the 186 * Asynchronously fetches the list of braille tables and refreshes the
197 * translators when done. 187 * translators when done.
198 * @private 188 * @private
199 */ 189 */
200 fetchTables_: function() { 190 fetchTables_: function() {
201 cvox.BrailleTable.getAll(function(tables) { 191 cvox.BrailleTable.getAll(function(tables) {
202 this.tables_ = tables; 192 this.tables_ = tables;
203 this.refresh(); 193
194 // Initial refresh; set options from user preferences.
195 this.refresh(localStorage['brailleTable'], localStorage['brailleTable8']);
204 }.bind(this)); 196 }.bind(this));
205 }, 197 },
206 198
207 /** 199 /**
208 * Loads the liblouis instance by attaching it to the document. 200 * Loads the liblouis instance by attaching it to the document.
209 * @private 201 * @private
210 */ 202 */
211 loadLiblouis_: function() { 203 loadLiblouis_: function() {
212 // Cast away nullability. When the document is loaded, it will always 204 // Cast away nullability. When the document is loaded, it will always
213 // have a body. 205 // have a body.
(...skipping 10 matching lines...) Expand all
224 }, 216 },
225 217
226 /** 218 /**
227 * @return {!Array<cvox.BrailleTable.Table>} The currently loaded braille 219 * @return {!Array<cvox.BrailleTable.Table>} The currently loaded braille
228 * tables, or an empty array if they are not yet loaded. 220 * tables, or an empty array if they are not yet loaded.
229 */ 221 */
230 getTablesForTest: function() { 222 getTablesForTest: function() {
231 return this.tables_; 223 return this.tables_;
232 } 224 }
233 }; 225 };
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/resources/chromeos/chromevox/braille/braille_translator_manager_test.extjs » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698