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

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

Issue 10907196: Add the ability to filter out extension IMEs from the language settings page. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix mock input manager Created 8 years, 3 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 | Annotate | Revision Log
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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 var addLanguageCode = match[1]; 86 var addLanguageCode = match[1];
87 $('language-options-list').addLanguage(addLanguageCode); 87 $('language-options-list').addLanguage(addLanguageCode);
88 } else { 88 } else {
89 OptionsPage.navigateToPage('addLanguage'); 89 OptionsPage.navigateToPage('addLanguage');
90 } 90 }
91 }; 91 };
92 92
93 if (cr.isChromeOS) { 93 if (cr.isChromeOS) {
94 // Listen to user clicks on the add language list. 94 // Listen to user clicks on the add language list.
95 var addLanguageList = $('add-language-overlay-language-list'); 95 var addLanguageList = $('add-language-overlay-language-list');
96 addLanguageList.addEventListener('click', 96 addLanguageList.addEventListener(
97 'click',
97 this.handleAddLanguageListClick_.bind(this)); 98 this.handleAddLanguageListClick_.bind(this));
99 $('language-options-extension-ime-button').addEventListener(
100 'click',
101 this.handleExtensionImeButtonClick_.bind(this));
98 } else { 102 } else {
99 // Listen to add language dialog ok button. 103 // Listen to add language dialog ok button.
100 var addLanguageOkButton = $('add-language-overlay-ok-button'); 104 var addLanguageOkButton = $('add-language-overlay-ok-button');
101 addLanguageOkButton.addEventListener('click', 105 addLanguageOkButton.addEventListener(
106 'click',
102 this.handleAddLanguageOkButtonClick_.bind(this)); 107 this.handleAddLanguageOkButtonClick_.bind(this));
103 108
104 // Show experimental features if enabled. 109 // Show experimental features if enabled.
105 if (loadTimeData.getBoolean('experimentalSpellCheckFeatures')) 110 if (loadTimeData.getBoolean('experimentalSpellCheckFeatures'))
106 $('auto-spell-correction-option').hidden = false; 111 $('auto-spell-correction-option').hidden = false;
107 112
108 // Handle spell check enable/disable. 113 // Handle spell check enable/disable.
109 if (!cr.isMac) { 114 if (!cr.isMac) {
110 Preferences.getInstance().addEventListener( 115 Preferences.getInstance().addEventListener(
111 this.enableSpellCheckPref, 116 this.enableSpellCheckPref,
(...skipping 17 matching lines...) Expand all
129 OptionsPage.closeOverlay.bind(OptionsPage); 134 OptionsPage.closeOverlay.bind(OptionsPage);
130 }, 135 },
131 136
132 // The preference is a boolean that enables/disables spell checking. 137 // The preference is a boolean that enables/disables spell checking.
133 enableSpellCheckPref: 'browser.enable_spellchecking', 138 enableSpellCheckPref: 'browser.enable_spellchecking',
134 // The preference is a CSV string that describes preload engines 139 // The preference is a CSV string that describes preload engines
135 // (i.e. active input methods). 140 // (i.e. active input methods).
136 preloadEnginesPref: 'settings.language.preload_engines', 141 preloadEnginesPref: 'settings.language.preload_engines',
137 // The list of preload engines, like ['mozc', 'pinyin']. 142 // The list of preload engines, like ['mozc', 'pinyin'].
138 preloadEngines_: [], 143 preloadEngines_: [],
144 // The preference that lists the extension IMEs that are filtered out of
145 // the language menu.
146 filteredExtensionImesPref: 'settings.language.filtered_extension_imes',
147 // The list of extension IMEs that are filtered out of the language menu.
148 filteredExtensionImes_: [],
139 // The preference is a string that describes the spell check 149 // The preference is a string that describes the spell check
140 // dictionary language, like "en-US". 150 // dictionary language, like "en-US".
141 spellCheckDictionaryPref: 'spellcheck.dictionary', 151 spellCheckDictionaryPref: 'spellcheck.dictionary',
142 spellCheckDictionary_: '', 152 spellCheckDictionary_: '',
143 // The map of language code to input method IDs, like: 153 // The map of language code to input method IDs, like:
144 // {'ja': ['mozc', 'mozc-jp'], 'zh-CN': ['pinyin'], ...} 154 // {'ja': ['mozc', 'mozc-jp'], 'zh-CN': ['pinyin'], ...}
145 languageCodeToInputMethodIdsMap_: {}, 155 languageCodeToInputMethodIdsMap_: {},
146 156
147 /** 157 /**
148 * Initializes the input method list. 158 * Initializes the input method list.
(...skipping 24 matching lines...) Expand all
173 // Add the configure button if the config page is present for this 183 // Add the configure button if the config page is present for this
174 // input method. 184 // input method.
175 if (inputMethod.id in INPUT_METHOD_ID_TO_CONFIG_PAGE_NAME) { 185 if (inputMethod.id in INPUT_METHOD_ID_TO_CONFIG_PAGE_NAME) {
176 var pageName = INPUT_METHOD_ID_TO_CONFIG_PAGE_NAME[inputMethod.id]; 186 var pageName = INPUT_METHOD_ID_TO_CONFIG_PAGE_NAME[inputMethod.id];
177 var button = this.createConfigureInputMethodButton_(inputMethod.id, 187 var button = this.createConfigureInputMethodButton_(inputMethod.id,
178 pageName); 188 pageName);
179 element.appendChild(button); 189 element.appendChild(button);
180 } 190 }
181 inputMethodList.appendChild(element); 191 inputMethodList.appendChild(element);
182 } 192 }
193
194 var extensionImeList = loadTimeData.getValue('extensionImeList');
195 for (var i = 0; i < extensionImeList.length; i++) {
196 var inputMethod = extensionImeList[i];
197 var element = inputMethodPrototype.cloneNode(true);
198 element.id = '';
199 element.languageCodeSet = {};
200 var input = element.querySelectorAll('input')[0];
201 input.inputMethodId = inputMethod.id;
202 var span = element.querySelectorAll('span')[0];
203 span.textContent = inputMethod.displayName;
204
205 input.addEventListener('click',
206 this.handleExtensionCheckboxClick_.bind(this));
207
208 inputMethodList.appendChild(element);
209 }
210
183 // Listen to pref change once the input method list is initialized. 211 // Listen to pref change once the input method list is initialized.
184 Preferences.getInstance().addEventListener(this.preloadEnginesPref, 212 Preferences.getInstance().addEventListener(
213 this.preloadEnginesPref,
185 this.handlePreloadEnginesPrefChange_.bind(this)); 214 this.handlePreloadEnginesPrefChange_.bind(this));
215 Preferences.getInstance().addEventListener(
216 this.filteredExtensionImesPref,
217 this.handleFilteredExtensionsPrefChange_.bind(this));
186 }, 218 },
187 219
188 /** 220 /**
189 * Creates a configure button for the given input method ID. 221 * Creates a configure button for the given input method ID.
190 * @param {string} inputMethodId Input method ID (ex. "pinyin"). 222 * @param {string} inputMethodId Input method ID (ex. "pinyin").
191 * @param {string} pageName Name of the config page (ex. "languagePinyin"). 223 * @param {string} pageName Name of the config page (ex. "languagePinyin").
192 * @private 224 * @private
193 */ 225 */
194 createConfigureInputMethodButton_: function(inputMethodId, pageName) { 226 createConfigureInputMethodButton_: function(inputMethodId, pageName) {
195 var button = document.createElement('button'); 227 var button = document.createElement('button');
(...skipping 23 matching lines...) Expand all
219 251
220 /** 252 /**
221 * Handles languageOptionsList's change event. 253 * Handles languageOptionsList's change event.
222 * @param {Event} e Change event. 254 * @param {Event} e Change event.
223 * @private 255 * @private
224 */ 256 */
225 handleLanguageOptionsListChange_: function(e) { 257 handleLanguageOptionsListChange_: function(e) {
226 var languageOptionsList = $('language-options-list'); 258 var languageOptionsList = $('language-options-list');
227 var languageCode = languageOptionsList.getSelectedLanguageCode(); 259 var languageCode = languageOptionsList.getSelectedLanguageCode();
228 260
261 // If there's no selection, just return.
262 if (!languageCode)
263 return;
264
229 // Select the language if it's specified in the URL hash (ex. lang=ja). 265 // Select the language if it's specified in the URL hash (ex. lang=ja).
230 // Used for automated testing. 266 // Used for automated testing.
231 var match = document.location.hash.match(/\blang=([\w-]+)/); 267 var match = document.location.hash.match(/\blang=([\w-]+)/);
232 if (match) { 268 if (match) {
233 var specifiedLanguageCode = match[1]; 269 var specifiedLanguageCode = match[1];
234 if (languageOptionsList.selectLanguageByCode(specifiedLanguageCode)) { 270 if (languageOptionsList.selectLanguageByCode(specifiedLanguageCode)) {
235 languageCode = specifiedLanguageCode; 271 languageCode = specifiedLanguageCode;
236 } 272 }
237 } 273 }
238 274
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 * @private 547 * @private
512 */ 548 */
513 handlePreloadEnginesPrefChange_: function(e) { 549 handlePreloadEnginesPrefChange_: function(e) {
514 var value = e.value.value; 550 var value = e.value.value;
515 this.preloadEngines_ = this.filterBadPreloadEngines_(value.split(',')); 551 this.preloadEngines_ = this.filterBadPreloadEngines_(value.split(','));
516 this.updateCheckboxesFromPreloadEngines_(); 552 this.updateCheckboxesFromPreloadEngines_();
517 $('language-options-list').updateDeletable(); 553 $('language-options-list').updateDeletable();
518 }, 554 },
519 555
520 /** 556 /**
557 * Handles filteredExtensionImesPref change.
558 * @param {Event} e Change event.
559 * @private
560 */
561 handleFilteredExtensionsPrefChange_: function(e) {
562 var value = e.value.value;
563 this.filteredExtensionImes_ = value.split(',');
564 this.updateCheckboxesFromFilteredExtensions_();
565 },
566
567 /**
521 * Handles input method checkbox's click event. 568 * Handles input method checkbox's click event.
522 * @param {Event} e Click event. 569 * @param {Event} e Click event.
523 * @private 570 * @private
524 */ 571 */
525 handleCheckboxClick_: function(e) { 572 handleCheckboxClick_: function(e) {
526 var checkbox = e.target; 573 var checkbox = e.target;
527 if (this.preloadEngines_.length == 1 && !checkbox.checked) { 574 if (this.preloadEngines_.length == 1 && !checkbox.checked) {
528 // Don't allow disabling the last input method. 575 // Don't allow disabling the last input method.
529 this.showNotification_( 576 this.showNotification_(
530 loadTimeData.getString('please_add_another_input_method'), 577 loadTimeData.getString('please_add_another_input_method'),
531 loadTimeData.getString('ok_button')); 578 loadTimeData.getString('ok_button'));
532 checkbox.checked = true; 579 checkbox.checked = true;
533 return; 580 return;
534 } 581 }
535 if (checkbox.checked) { 582 if (checkbox.checked) {
536 chrome.send('inputMethodEnable', [checkbox.inputMethodId]); 583 chrome.send('inputMethodEnable', [checkbox.inputMethodId]);
537 } else { 584 } else {
538 chrome.send('inputMethodDisable', [checkbox.inputMethodId]); 585 chrome.send('inputMethodDisable', [checkbox.inputMethodId]);
539 } 586 }
540 this.updatePreloadEnginesFromCheckboxes_(); 587 this.updatePreloadEnginesFromCheckboxes_();
541 this.preloadEngines_ = this.sortPreloadEngines_(this.preloadEngines_); 588 this.preloadEngines_ = this.sortPreloadEngines_(this.preloadEngines_);
542 this.savePreloadEnginesPref_(); 589 this.savePreloadEnginesPref_();
543 }, 590 },
544 591
545 /** 592 /**
593 * Handles extension input method checkbox's click event.
594 * @param {Event} e Click event.
595 * @private
596 */
597 handleExtensionCheckboxClick_: function(e) {
598 var checkbox = e.target;
599 this.updateFilteredExtensionsFromCheckboxes_();
600 this.saveFilteredExtensionPref_();
601 },
602
603 /**
546 * Handles add language list's click event. 604 * Handles add language list's click event.
547 * @param {Event} e Click event. 605 * @param {Event} e Click event.
548 */ 606 */
549 handleAddLanguageListClick_: function(e) { 607 handleAddLanguageListClick_: function(e) {
550 var languageOptionsList = $('language-options-list'); 608 var languageOptionsList = $('language-options-list');
551 var languageCode = e.target.languageCode; 609 var languageCode = e.target.languageCode;
552 // languageCode can be undefined, if click was made on some random 610 // languageCode can be undefined, if click was made on some random
553 // place in the overlay, rather than a button. Ignore it. 611 // place in the overlay, rather than a button. Ignore it.
554 if (!languageCode) { 612 if (!languageCode) {
555 return; 613 return;
556 } 614 }
557 languageOptionsList.addLanguage(languageCode); 615 languageOptionsList.addLanguage(languageCode);
558 var inputMethodIds = this.languageCodeToInputMethodIdsMap_[languageCode]; 616 var inputMethodIds = this.languageCodeToInputMethodIdsMap_[languageCode];
559 // Enable the first input method for the language added. 617 // Enable the first input method for the language added.
560 if (inputMethodIds && inputMethodIds[0] && 618 if (inputMethodIds && inputMethodIds[0] &&
561 // Don't add the input method it's already present. This can 619 // Don't add the input method it's already present. This can
562 // happen if the same input method is shared among multiple 620 // happen if the same input method is shared among multiple
563 // languages (ex. English US keyboard is used for English US and 621 // languages (ex. English US keyboard is used for English US and
564 // Filipino). 622 // Filipino).
565 this.preloadEngines_.indexOf(inputMethodIds[0]) == -1) { 623 this.preloadEngines_.indexOf(inputMethodIds[0]) == -1) {
566 this.preloadEngines_.push(inputMethodIds[0]); 624 this.preloadEngines_.push(inputMethodIds[0]);
567 this.updateCheckboxesFromPreloadEngines_(); 625 this.updateCheckboxesFromPreloadEngines_();
568 this.savePreloadEnginesPref_(); 626 this.savePreloadEnginesPref_();
569 } 627 }
570 OptionsPage.closeOverlay(); 628 OptionsPage.closeOverlay();
571 }, 629 },
572 630
573 /** 631 /**
574 * Handles add language dialog ok button. 632 * Handles extension IME button.
575 */ 633 */
634 handleExtensionImeButtonClick_: function() {
635 $('language-options-list').clearSelection();
636
637 var languageName = $('language-options-language-name');
638 languageName.textContent = loadTimeData.getString('extension_ime_label');
639
640 var uiLanguageMessage = $('language-options-ui-language-message');
641 uiLanguageMessage.textContent =
642 loadTimeData.getString('extension_ime_description');
643
644 var uiLanguageButton = $('language-options-ui-language-button');
645 uiLanguageButton.onclick = null;
646 uiLanguageButton.hidden = true;
647
648 this.updateSpellCheckLanguageButton_();
649
650 // Hide all input method checkboxes that aren't extension IMEs.
651 var inputMethodList = $('language-options-input-method-list');
652 var methods = inputMethodList.querySelectorAll('.input-method');
653 for (var i = 0; i < methods.length; i++) {
654 var method = methods[i];
655 var input = method.querySelectorAll('input')[0];
656 // Give it focus if the ID matches.
657 if (input.inputMethodId.match(/^_ext_ime_/))
658 method.hidden = false;
659 else
660 method.hidden = true;
661 }
662 },
663
664
576 handleAddLanguageOkButtonClick_: function() { 665 handleAddLanguageOkButtonClick_: function() {
577 var languagesSelect = $('add-language-overlay-language-list'); 666 var languagesSelect = $('add-language-overlay-language-list');
578 var selectedIndex = languagesSelect.selectedIndex; 667 var selectedIndex = languagesSelect.selectedIndex;
579 if (selectedIndex >= 0) { 668 if (selectedIndex >= 0) {
580 var selection = languagesSelect.options[selectedIndex]; 669 var selection = languagesSelect.options[selectedIndex];
581 $('language-options-list').addLanguage(String(selection.value)); 670 $('language-options-list').addLanguage(String(selection.value));
582 OptionsPage.closeOverlay(); 671 OptionsPage.closeOverlay();
583 } 672 }
584 }, 673 },
585 674
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
678 if (!(this.preloadEngines_[i] in enginesToBeRemovedSet)) { 767 if (!(this.preloadEngines_[i] in enginesToBeRemovedSet)) {
679 newPreloadEngines.push(this.preloadEngines_[i]); 768 newPreloadEngines.push(this.preloadEngines_[i]);
680 } 769 }
681 } 770 }
682 // Don't allow this operation if it causes the number of preload 771 // Don't allow this operation if it causes the number of preload
683 // engines to be zero. 772 // engines to be zero.
684 return (newPreloadEngines.length > 0); 773 return (newPreloadEngines.length > 0);
685 }, 774 },
686 775
687 /** 776 /**
777 * Saves the filtered extension preference.
778 * @private
779 */
780 saveFilteredExtensionPref_: function() {
781 Preferences.setStringPref(this.filteredExtensionImesPref,
782 this.filteredExtensionImes_.join(','), true);
783 },
784
785 /**
786 * Updates the checkboxes in the input method list from the filtered
787 * extensions preference.
788 * @private
789 */
790 updateCheckboxesFromFilteredExtensions_: function() {
791 // Convert the list into a dictonary for simpler lookup.
792 var dictionary = {};
793 for (var i = 0; i < this.filteredExtensionImes_.length; i++)
794 dictionary[this.filteredExtensionImes_[i]] = true;
795
796 var inputMethodList = $('language-options-input-method-list');
797 var checkboxes = inputMethodList.querySelectorAll('input');
798 for (var i = 0; i < checkboxes.length; i++) {
799 if (checkboxes[i].inputMethodId.match(/^_ext_ime_/))
800 checkboxes[i].checked = !(checkboxes[i].inputMethodId in dictionary);
801 }
802 },
803
804 /**
805 * Updates the filtered extensions preference from the checkboxes in the
806 * input method list.
807 * @private
808 */
809 updateFilteredExtensionsFromCheckboxes_: function() {
810 this.filteredExtensionImes_ = [];
811 var inputMethodList = $('language-options-input-method-list');
812 var checkboxes = inputMethodList.querySelectorAll('input');
813 for (var i = 0; i < checkboxes.length; i++) {
814 if (checkboxes[i].inputMethodId.match(/^_ext_ime_/)) {
815 if (!checkboxes[i].checked)
816 this.filteredExtensionImes_.push(checkboxes[i].inputMethodId);
817 }
818 }
819 },
820
821 /**
688 * Saves the preload engines preference. 822 * Saves the preload engines preference.
689 * @private 823 * @private
690 */ 824 */
691 savePreloadEnginesPref_: function() { 825 savePreloadEnginesPref_: function() {
692 Preferences.setStringPref(this.preloadEnginesPref, 826 Preferences.setStringPref(this.preloadEnginesPref,
693 this.preloadEngines_.join(','), true); 827 this.preloadEngines_.join(','), true);
694 }, 828 },
695 829
696 /** 830 /**
697 * Updates the checkboxes in the input method list from the preload 831 * Updates the checkboxes in the input method list from the preload
698 * engines preference. 832 * engines preference.
699 * @private 833 * @private
700 */ 834 */
701 updateCheckboxesFromPreloadEngines_: function() { 835 updateCheckboxesFromPreloadEngines_: function() {
702 // Convert the list into a dictonary for simpler lookup. 836 // Convert the list into a dictonary for simpler lookup.
703 var dictionary = {}; 837 var dictionary = {};
704 for (var i = 0; i < this.preloadEngines_.length; i++) { 838 for (var i = 0; i < this.preloadEngines_.length; i++) {
705 dictionary[this.preloadEngines_[i]] = true; 839 dictionary[this.preloadEngines_[i]] = true;
706 } 840 }
707 841
708 var inputMethodList = $('language-options-input-method-list'); 842 var inputMethodList = $('language-options-input-method-list');
709 var checkboxes = inputMethodList.querySelectorAll('input'); 843 var checkboxes = inputMethodList.querySelectorAll('input');
710 for (var i = 0; i < checkboxes.length; i++) { 844 for (var i = 0; i < checkboxes.length; i++) {
711 checkboxes[i].checked = (checkboxes[i].inputMethodId in dictionary); 845 if (!checkboxes[i].inputMethodId.match(/^_ext_ime_/))
846 checkboxes[i].checked = (checkboxes[i].inputMethodId in dictionary);
712 } 847 }
713 }, 848 },
714 849
715 /** 850 /**
716 * Updates the preload engines preference from the checkboxes in the 851 * Updates the preload engines preference from the checkboxes in the
717 * input method list. 852 * input method list.
718 * @private 853 * @private
719 */ 854 */
720 updatePreloadEnginesFromCheckboxes_: function() { 855 updatePreloadEnginesFromCheckboxes_: function() {
721 this.preloadEngines_ = []; 856 this.preloadEngines_ = [];
722 var inputMethodList = $('language-options-input-method-list'); 857 var inputMethodList = $('language-options-input-method-list');
723 var checkboxes = inputMethodList.querySelectorAll('input'); 858 var checkboxes = inputMethodList.querySelectorAll('input');
724 for (var i = 0; i < checkboxes.length; i++) { 859 for (var i = 0; i < checkboxes.length; i++) {
725 if (checkboxes[i].checked) { 860 if (!checkboxes[i].inputMethodId.match(/^_ext_ime_/)) {
726 this.preloadEngines_.push(checkboxes[i].inputMethodId); 861 if (checkboxes[i].checked)
862 this.preloadEngines_.push(checkboxes[i].inputMethodId);
727 } 863 }
728 } 864 }
729 var languageOptionsList = $('language-options-list'); 865 var languageOptionsList = $('language-options-list');
730 languageOptionsList.updateDeletable(); 866 languageOptionsList.updateDeletable();
731 }, 867 },
732 868
733 /** 869 /**
734 * Filters bad preload engines in case bad preload engines are 870 * Filters bad preload engines in case bad preload engines are
735 * stored in the preference. Removes duplicates as well. 871 * stored in the preference. Removes duplicates as well.
736 * @param {Array} preloadEngines List of preload engines. 872 * @param {Array} preloadEngines List of preload engines.
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
851 // only take effect after restart. 987 // only take effect after restart.
852 showMutuallyExclusiveNodes([$('language-options-ui-language-button'), 988 showMutuallyExclusiveNodes([$('language-options-ui-language-button'),
853 $('language-options-ui-notification-bar')], 1); 989 $('language-options-ui-notification-bar')], 1);
854 }; 990 };
855 991
856 // Export 992 // Export
857 return { 993 return {
858 LanguageOptions: LanguageOptions 994 LanguageOptions: LanguageOptions
859 }; 995 };
860 }); 996 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698