OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // TODO(kochi): Generalize the notification as a component and put it | 5 // TODO(kochi): Generalize the notification as a component and put it |
6 // in js/cr/ui/notification.js . | 6 // in js/cr/ui/notification.js . |
7 | 7 |
8 cr.define('options', function() { | 8 cr.define('options', function() { |
9 /** @const */ var OptionsPage = options.OptionsPage; | 9 /** @const */ var OptionsPage = options.OptionsPage; |
10 /** @const */ var LanguageList = options.LanguageList; | 10 /** @const */ var LanguageList = options.LanguageList; |
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
419 if (!cr.isMac) | 419 if (!cr.isMac) |
420 this.updateSpellCheckLanguageButton_(languageCode); | 420 this.updateSpellCheckLanguageButton_(languageCode); |
421 | 421 |
422 if (cr.isChromeOS) | 422 if (cr.isChromeOS) |
423 this.updateInputMethodList_(languageCode); | 423 this.updateInputMethodList_(languageCode); |
424 | 424 |
425 this.updateLanguageListInAddLanguageOverlay_(); | 425 this.updateLanguageListInAddLanguageOverlay_(); |
426 }, | 426 }, |
427 | 427 |
428 /** | 428 /** |
429 * Happens when a user changes back to the language they're currently using. | |
430 */ | |
431 currentLocaleWasReselected: function() { | |
432 this.updateUiLanguageButton_( | |
433 loadTimeData.getString('currentUiLanguageCode')); | |
434 }, | |
435 | |
436 /** | |
437 * Handles languageOptionsList's save event. | 429 * Handles languageOptionsList's save event. |
438 * @param {Event} e Save event. | 430 * @param {Event} e Save event. |
439 * @private | 431 * @private |
440 */ | 432 */ |
441 handleLanguageOptionsListSave_: function(e) { | 433 handleLanguageOptionsListSave_: function(e) { |
442 if (cr.isChromeOS) { | 434 if (cr.isChromeOS) { |
443 // Sort the preload engines per the saved languages before save. | 435 // Sort the preload engines per the saved languages before save. |
444 this.preloadEngines_ = this.sortPreloadEngines_(this.preloadEngines_); | 436 this.preloadEngines_ = this.sortPreloadEngines_(this.preloadEngines_); |
445 this.savePreloadEnginesPref_(); | 437 this.savePreloadEnginesPref_(); |
446 } | 438 } |
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
846 if (checkbox.checked) { | 838 if (checkbox.checked) { |
847 chrome.send('inputMethodEnable', [checkbox.inputMethodId]); | 839 chrome.send('inputMethodEnable', [checkbox.inputMethodId]); |
848 } else { | 840 } else { |
849 chrome.send('inputMethodDisable', [checkbox.inputMethodId]); | 841 chrome.send('inputMethodDisable', [checkbox.inputMethodId]); |
850 } | 842 } |
851 this.updatePreloadEnginesFromCheckboxes_(); | 843 this.updatePreloadEnginesFromCheckboxes_(); |
852 this.preloadEngines_ = this.sortPreloadEngines_(this.preloadEngines_); | 844 this.preloadEngines_ = this.sortPreloadEngines_(this.preloadEngines_); |
853 this.savePreloadEnginesPref_(); | 845 this.savePreloadEnginesPref_(); |
854 }, | 846 }, |
855 | 847 |
856 handleAddLanguageOkButtonClick_: function() { | 848 /** |
| 849 * Handles clicks on the "OK" button of the "Add language" dialog. |
| 850 * @param {Event} e Click event. |
| 851 * @private |
| 852 */ |
| 853 handleAddLanguageOkButtonClick_: function(e) { |
857 var languagesSelect = $('add-language-overlay-language-list'); | 854 var languagesSelect = $('add-language-overlay-language-list'); |
858 var selectedIndex = languagesSelect.selectedIndex; | 855 var selectedIndex = languagesSelect.selectedIndex; |
859 if (selectedIndex >= 0) { | 856 if (selectedIndex >= 0) { |
860 var selection = languagesSelect.options[selectedIndex]; | 857 var selection = languagesSelect.options[selectedIndex]; |
861 var langCode = String(selection.value); | 858 var langCode = String(selection.value); |
862 $('language-options-list').addLanguage(langCode); | 859 $('language-options-list').addLanguage(langCode); |
863 this.addBlockedLanguage_(langCode); | 860 this.addBlockedLanguage_(langCode); |
864 OptionsPage.closeOverlay(); | 861 OptionsPage.closeOverlay(); |
865 } | 862 } |
866 }, | 863 }, |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1185 notificationElement.onmouseout = delayedHide; | 1182 notificationElement.onmouseout = delayedHide; |
1186 actionLink.onfocus = show; | 1183 actionLink.onfocus = show; |
1187 actionLink.onblur = delayedHide; | 1184 actionLink.onblur = delayedHide; |
1188 // Enable tabbing to the link now that it is shown. | 1185 // Enable tabbing to the link now that it is shown. |
1189 actionLink.tabIndex = 0; | 1186 actionLink.tabIndex = 0; |
1190 | 1187 |
1191 show(); | 1188 show(); |
1192 delayedHide(); | 1189 delayedHide(); |
1193 }, | 1190 }, |
1194 | 1191 |
| 1192 /** |
| 1193 * Chrome callback for when the UI language preference is saved. |
| 1194 * @param {string} languageCode The newly selected language to use. |
| 1195 * @private |
| 1196 */ |
| 1197 uiLanguageSaved_: function(languageCode) { |
| 1198 this.prospectiveUiLanguageCode_ = languageCode; |
| 1199 |
| 1200 // If the user is no longer on the same language code, ignore. |
| 1201 if ($('language-options-list').getSelectedLanguageCode() != languageCode) |
| 1202 return; |
| 1203 |
| 1204 // Special case for when a user changes to a different language, and |
| 1205 // changes back to the same language without having restarted Chrome or |
| 1206 // logged in/out of ChromeOS. |
| 1207 if (languageCode == loadTimeData.getString('currentUiLanguageCode')) { |
| 1208 this.updateUiLanguageButton_(languageCode); |
| 1209 return; |
| 1210 } |
| 1211 |
| 1212 // Otherwise, show a notification telling the user that their changes will |
| 1213 // only take effect after restart. |
| 1214 showMutuallyExclusiveNodes([$('language-options-ui-language-button'), |
| 1215 $('language-options-ui-notification-bar')], |
| 1216 1); |
| 1217 }, |
| 1218 |
| 1219 /** |
| 1220 * A handler for when dictionary for |languageCode| begins downloading. |
| 1221 * @param {string} languageCode The language of the dictionary that just |
| 1222 * began downloading. |
| 1223 * @private |
| 1224 */ |
1195 onDictionaryDownloadBegin_: function(languageCode) { | 1225 onDictionaryDownloadBegin_: function(languageCode) { |
1196 this.spellcheckDictionaryDownloadStatus_[languageCode] = | 1226 this.spellcheckDictionaryDownloadStatus_[languageCode] = |
1197 DOWNLOAD_STATUS.IN_PROGRESS; | 1227 DOWNLOAD_STATUS.IN_PROGRESS; |
1198 if (!cr.isMac && | 1228 if (!cr.isMac && |
1199 languageCode == | 1229 languageCode == |
1200 $('language-options-list').getSelectedLanguageCode()) { | 1230 $('language-options-list').getSelectedLanguageCode()) { |
1201 this.updateSpellCheckLanguageButton_(languageCode); | 1231 this.updateSpellCheckLanguageButton_(languageCode); |
1202 } | 1232 } |
1203 }, | 1233 }, |
1204 | 1234 |
| 1235 /** |
| 1236 * A handler for when dictionary for |languageCode| successfully downloaded. |
| 1237 * @param {string} languageCode The language of the dictionary that |
| 1238 * succeeded downloading. |
| 1239 * @private |
| 1240 */ |
1205 onDictionaryDownloadSuccess_: function(languageCode) { | 1241 onDictionaryDownloadSuccess_: function(languageCode) { |
1206 delete this.spellcheckDictionaryDownloadStatus_[languageCode]; | 1242 delete this.spellcheckDictionaryDownloadStatus_[languageCode]; |
1207 this.spellcheckDictionaryDownloadFailures_ = 0; | 1243 this.spellcheckDictionaryDownloadFailures_ = 0; |
1208 if (!cr.isMac && | 1244 if (!cr.isMac && |
1209 languageCode == | 1245 languageCode == |
1210 $('language-options-list').getSelectedLanguageCode()) { | 1246 $('language-options-list').getSelectedLanguageCode()) { |
1211 this.updateSpellCheckLanguageButton_(languageCode); | 1247 this.updateSpellCheckLanguageButton_(languageCode); |
1212 } | 1248 } |
1213 }, | 1249 }, |
1214 | 1250 |
| 1251 /** |
| 1252 * A handler for when dictionary for |languageCode| fails to download. |
| 1253 * @param {string} languageCode The language of the dictionary that failed |
| 1254 * to download. |
| 1255 * @private |
| 1256 */ |
1215 onDictionaryDownloadFailure_: function(languageCode) { | 1257 onDictionaryDownloadFailure_: function(languageCode) { |
1216 this.spellcheckDictionaryDownloadStatus_[languageCode] = | 1258 this.spellcheckDictionaryDownloadStatus_[languageCode] = |
1217 DOWNLOAD_STATUS.FAILED; | 1259 DOWNLOAD_STATUS.FAILED; |
1218 this.spellcheckDictionaryDownloadFailures_++; | 1260 this.spellcheckDictionaryDownloadFailures_++; |
1219 if (!cr.isMac && | 1261 if (!cr.isMac && |
1220 languageCode == | 1262 languageCode == |
1221 $('language-options-list').getSelectedLanguageCode()) { | 1263 $('language-options-list').getSelectedLanguageCode()) { |
1222 this.updateSpellCheckLanguageButton_(languageCode); | 1264 this.updateSpellCheckLanguageButton_(languageCode); |
1223 } | 1265 } |
1224 }, | 1266 }, |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1260 * @param {number} index The index of |nodes| to show. | 1302 * @param {number} index The index of |nodes| to show. |
1261 */ | 1303 */ |
1262 function showMutuallyExclusiveNodes(nodes, index) { | 1304 function showMutuallyExclusiveNodes(nodes, index) { |
1263 assert(index >= 0 && index < nodes.length); | 1305 assert(index >= 0 && index < nodes.length); |
1264 for (var i = 0; i < nodes.length; ++i) { | 1306 for (var i = 0; i < nodes.length; ++i) { |
1265 assert(nodes[i] instanceof HTMLElement); // TODO(dbeam): Ignore null? | 1307 assert(nodes[i] instanceof HTMLElement); // TODO(dbeam): Ignore null? |
1266 nodes[i].hidden = i != index; | 1308 nodes[i].hidden = i != index; |
1267 } | 1309 } |
1268 } | 1310 } |
1269 | 1311 |
1270 /** | |
1271 * Chrome callback for when the UI language preference is saved. | |
1272 * @param {string} languageCode The newly selected language to use. | |
1273 */ | |
1274 LanguageOptions.uiLanguageSaved = function(languageCode) { | 1312 LanguageOptions.uiLanguageSaved = function(languageCode) { |
1275 this.getInstance().prospectiveUiLanguageCode_ = languageCode; | 1313 LanguageOptions.getInstance().uiLanguageSaved_(languageCode); |
1276 | |
1277 // If the user is no longer on the same language code, ignore. | |
1278 if ($('language-options-list').getSelectedLanguageCode() != languageCode) | |
1279 return; | |
1280 | |
1281 // Special case for when a user changes to a different language, and changes | |
1282 // back to the same language without having restarted Chrome or logged | |
1283 // in/out of ChromeOS. | |
1284 if (languageCode == loadTimeData.getString('currentUiLanguageCode')) { | |
1285 LanguageOptions.getInstance().currentLocaleWasReselected(); | |
1286 return; | |
1287 } | |
1288 | |
1289 // Otherwise, show a notification telling the user that their changes will | |
1290 // only take effect after restart. | |
1291 showMutuallyExclusiveNodes([$('language-options-ui-language-button'), | |
1292 $('language-options-ui-notification-bar')], 1); | |
1293 }; | 1314 }; |
1294 | 1315 |
1295 LanguageOptions.onDictionaryDownloadBegin = function(languageCode) { | 1316 LanguageOptions.onDictionaryDownloadBegin = function(languageCode) { |
1296 LanguageOptions.getInstance().onDictionaryDownloadBegin_(languageCode); | 1317 LanguageOptions.getInstance().onDictionaryDownloadBegin_(languageCode); |
1297 }; | 1318 }; |
1298 | 1319 |
1299 LanguageOptions.onDictionaryDownloadSuccess = function(languageCode) { | 1320 LanguageOptions.onDictionaryDownloadSuccess = function(languageCode) { |
1300 LanguageOptions.getInstance().onDictionaryDownloadSuccess_(languageCode); | 1321 LanguageOptions.getInstance().onDictionaryDownloadSuccess_(languageCode); |
1301 }; | 1322 }; |
1302 | 1323 |
1303 LanguageOptions.onDictionaryDownloadFailure = function(languageCode) { | 1324 LanguageOptions.onDictionaryDownloadFailure = function(languageCode) { |
1304 LanguageOptions.getInstance().onDictionaryDownloadFailure_(languageCode); | 1325 LanguageOptions.getInstance().onDictionaryDownloadFailure_(languageCode); |
1305 }; | 1326 }; |
1306 | 1327 |
1307 LanguageOptions.onComponentManagerInitialized = function(componentImes) { | 1328 LanguageOptions.onComponentManagerInitialized = function(componentImes) { |
1308 LanguageOptions.getInstance().appendComponentExtensionIme_(componentImes); | 1329 LanguageOptions.getInstance().appendComponentExtensionIme_(componentImes); |
1309 }; | 1330 }; |
1310 | 1331 |
1311 // Export | 1332 // Export |
1312 return { | 1333 return { |
1313 LanguageOptions: LanguageOptions | 1334 LanguageOptions: LanguageOptions |
1314 }; | 1335 }; |
1315 }); | 1336 }); |
OLD | NEW |