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 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
378 for (var i = 0; i < preloadEngines.length; i++) { | 378 for (var i = 0; i < preloadEngines.length; i++) { |
379 preloadEngineSet[preloadEngines[i]] = true; | 379 preloadEngineSet[preloadEngines[i]] = true; |
380 } | 380 } |
381 | 381 |
382 // Create the new preload engine list per the language codes. | 382 // Create the new preload engine list per the language codes. |
383 var newPreloadEngines = []; | 383 var newPreloadEngines = []; |
384 for (var i = 0; i < languageCodes.length; i++) { | 384 for (var i = 0; i < languageCodes.length; i++) { |
385 var languageCode = languageCodes[i]; | 385 var languageCode = languageCodes[i]; |
386 var inputMethodIds = this.languageCodeToInputMethodIdsMap_[ | 386 var inputMethodIds = this.languageCodeToInputMethodIdsMap_[ |
387 languageCode]; | 387 languageCode]; |
388 if (!inputMethodIds) | |
389 continue; | |
James Hawkins
2013/04/05 18:41:50
Optional nit: Add a blank line below this to incre
Zachary Kuznia
2013/04/09 06:45:52
Done.
| |
388 // Check if we have active input methods associated with the language. | 390 // Check if we have active input methods associated with the language. |
389 for (var j = 0; j < inputMethodIds.length; j++) { | 391 for (var j = 0; j < inputMethodIds.length; j++) { |
390 var inputMethodId = inputMethodIds[j]; | 392 var inputMethodId = inputMethodIds[j]; |
391 if (inputMethodId in preloadEngineSet) { | 393 if (inputMethodId in preloadEngineSet) { |
392 // If we have, add it to the new engine list. | 394 // If we have, add it to the new engine list. |
393 newPreloadEngines.push(inputMethodId); | 395 newPreloadEngines.push(inputMethodId); |
394 // And delete it from the set. This is necessary as one input | 396 // And delete it from the set. This is necessary as one input |
395 // method can be associated with more than one language thus | 397 // method can be associated with more than one language thus |
396 // we should avoid having duplicates in the new list. | 398 // we should avoid having duplicates in the new list. |
397 delete preloadEngineSet[inputMethodId]; | 399 delete preloadEngineSet[inputMethodId]; |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
572 var input = method.querySelector('input'); | 574 var input = method.querySelector('input'); |
573 // Give it focus if the ID matches. | 575 // Give it focus if the ID matches. |
574 if (input.inputMethodId == focusInputMethodId) { | 576 if (input.inputMethodId == focusInputMethodId) { |
575 input.focus(); | 577 input.focus(); |
576 } | 578 } |
577 } else { | 579 } else { |
578 method.hidden = true; | 580 method.hidden = true; |
579 } | 581 } |
580 } | 582 } |
581 | 583 |
584 $('language-options-input-method-none').hidden = | |
585 (languageCode in this.languageCodeToInputMethodIdsMap_); | |
586 | |
582 if (focusInputMethodId == 'add') { | 587 if (focusInputMethodId == 'add') { |
583 $('language-options-add-button').focus(); | 588 $('language-options-add-button').focus(); |
584 } | 589 } |
585 }, | 590 }, |
586 | 591 |
587 /** | 592 /** |
588 * Updates the language list in the add language overlay. | 593 * Updates the language list in the add language overlay. |
589 * @param {string} languageCode Language code (ex. "fr"). | 594 * @param {string} languageCode Language code (ex. "fr"). |
590 * @private | 595 * @private |
591 */ | 596 */ |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
791 * | 796 * |
792 * @param {string} languageCode Language code (ex. "fr"). | 797 * @param {string} languageCode Language code (ex. "fr"). |
793 * @return {boolean} Returns true on success. | 798 * @return {boolean} Returns true on success. |
794 * @private | 799 * @private |
795 */ | 800 */ |
796 canDeleteLanguage_: function(languageCode) { | 801 canDeleteLanguage_: function(languageCode) { |
797 // First create the set of engines to be removed from input methods | 802 // First create the set of engines to be removed from input methods |
798 // associated with the language code. | 803 // associated with the language code. |
799 var enginesToBeRemovedSet = {}; | 804 var enginesToBeRemovedSet = {}; |
800 var inputMethodIds = this.languageCodeToInputMethodIdsMap_[languageCode]; | 805 var inputMethodIds = this.languageCodeToInputMethodIdsMap_[languageCode]; |
806 | |
807 // If this language doesn't have any input methods, it can be deleted. | |
808 if (!inputMethodIds) | |
809 return true; | |
810 | |
801 for (var i = 0; i < inputMethodIds.length; i++) { | 811 for (var i = 0; i < inputMethodIds.length; i++) { |
802 enginesToBeRemovedSet[inputMethodIds[i]] = true; | 812 enginesToBeRemovedSet[inputMethodIds[i]] = true; |
803 } | 813 } |
804 | 814 |
805 // Then eliminate engines that are also used for other active languages. | 815 // Then eliminate engines that are also used for other active languages. |
806 // For instance, if "xkb:us::eng" is used for both English and Filipino. | 816 // For instance, if "xkb:us::eng" is used for both English and Filipino. |
807 var languageCodes = $('language-options-list').getLanguageCodes(); | 817 var languageCodes = $('language-options-list').getLanguageCodes(); |
808 for (var i = 0; i < languageCodes.length; i++) { | 818 for (var i = 0; i < languageCodes.length; i++) { |
809 // Skip the target language code. | 819 // Skip the target language code. |
810 if (languageCodes[i] == languageCode) { | 820 if (languageCodes[i] == languageCode) { |
811 continue; | 821 continue; |
812 } | 822 } |
813 // Check if input methods used in this language are included in | 823 // Check if input methods used in this language are included in |
814 // enginesToBeRemovedSet. If so, eliminate these from the set, so | 824 // enginesToBeRemovedSet. If so, eliminate these from the set, so |
815 // we don't remove this time. | 825 // we don't remove this time. |
816 var inputMethodIdsForAnotherLanguage = | 826 var inputMethodIdsForAnotherLanguage = |
817 this.languageCodeToInputMethodIdsMap_[languageCodes[i]]; | 827 this.languageCodeToInputMethodIdsMap_[languageCodes[i]]; |
828 if (!inputMethodIdsForAnotherLanguage) | |
829 continue; | |
James Hawkins
2013/04/05 18:41:50
Optional nit: Add a blank line below this to incre
Zachary Kuznia
2013/04/09 06:45:52
Done.
| |
818 for (var j = 0; j < inputMethodIdsForAnotherLanguage.length; j++) { | 830 for (var j = 0; j < inputMethodIdsForAnotherLanguage.length; j++) { |
819 var inputMethodId = inputMethodIdsForAnotherLanguage[j]; | 831 var inputMethodId = inputMethodIdsForAnotherLanguage[j]; |
820 if (inputMethodId in enginesToBeRemovedSet) { | 832 if (inputMethodId in enginesToBeRemovedSet) { |
821 delete enginesToBeRemovedSet[inputMethodId]; | 833 delete enginesToBeRemovedSet[inputMethodId]; |
822 } | 834 } |
823 } | 835 } |
824 } | 836 } |
825 | 837 |
826 // Update the preload engine list with the to-be-removed set. | 838 // Update the preload engine list with the to-be-removed set. |
827 var newPreloadEngines = []; | 839 var newPreloadEngines = []; |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1092 | 1104 |
1093 LanguageOptions.onDictionaryDownloadFailure = function(languageCode) { | 1105 LanguageOptions.onDictionaryDownloadFailure = function(languageCode) { |
1094 LanguageOptions.getInstance().onDictionaryDownloadFailure_(languageCode); | 1106 LanguageOptions.getInstance().onDictionaryDownloadFailure_(languageCode); |
1095 }; | 1107 }; |
1096 | 1108 |
1097 // Export | 1109 // Export |
1098 return { | 1110 return { |
1099 LanguageOptions: LanguageOptions | 1111 LanguageOptions: LanguageOptions |
1100 }; | 1112 }; |
1101 }); | 1113 }); |
OLD | NEW |