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

Side by Side Diff: chrome/browser/resources/options/language_options.js

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

Powered by Google App Engine
This is Rietveld 408576698