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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 // Set up the button for editing custom spelling dictionary. | 118 // Set up the button for editing custom spelling dictionary. |
119 $('edit-dictionary-button').onclick = function(e) { | 119 $('edit-dictionary-button').onclick = function(e) { |
120 OptionsPage.navigateToPage('editDictionary'); | 120 OptionsPage.navigateToPage('editDictionary'); |
121 }; | 121 }; |
122 $('dictionary-download-retry-button').onclick = function(e) { | 122 $('dictionary-download-retry-button').onclick = function(e) { |
123 chrome.send('retryDictionaryDownload'); | 123 chrome.send('retryDictionaryDownload'); |
124 }; | 124 }; |
125 } | 125 } |
126 | 126 |
127 if (cr.isChromeOS) { | 127 if (cr.isChromeOS) { |
128 // Listen to user clicks on the add language list. | 128 // Listen to user click on the extension ime button. |
129 var addLanguageList = $('add-language-overlay-language-list'); | |
130 addLanguageList.addEventListener( | |
131 'click', | |
132 this.handleAddLanguageListClick_.bind(this)); | |
133 $('language-options-extension-ime-button').addEventListener( | 129 $('language-options-extension-ime-button').addEventListener( |
134 'click', | 130 'click', |
135 this.handleExtensionImeButtonClick_.bind(this)); | 131 this.handleExtensionImeButtonClick_.bind(this)); |
136 | 132 |
137 // Check if there is an Extension IME. | 133 // Check if there is an Extension IME. |
138 var hasExtensionIme = false; | 134 var hasExtensionIme = false; |
139 var inputMethods = ($('language-options-input-method-list') | 135 var inputMethods = ($('language-options-input-method-list') |
140 .querySelectorAll('.input-method')); | 136 .querySelectorAll('.input-method')); |
141 for (var i = 0, inputMethod; inputMethod = inputMethods[i]; ++i) { | 137 for (var i = 0, inputMethod; inputMethod = inputMethods[i]; ++i) { |
142 if (inputMethod.querySelector('input') | 138 if (inputMethod.querySelector('input') |
143 .inputMethodId.match(/^_ext_ime_/)) { | 139 .inputMethodId.match(/^_ext_ime_/)) { |
144 hasExtensionIme = true; | 140 hasExtensionIme = true; |
145 break; | 141 break; |
146 } | 142 } |
147 } | 143 } |
148 // Show the Extension IME button only if available. | 144 // Show the Extension IME button only if available. |
149 $('language-options-extension-ime-button').hidden = !hasExtensionIme; | 145 $('language-options-extension-ime-button').hidden = !hasExtensionIme; |
150 } else { | 146 } |
151 // Listen to add language dialog ok button. | |
152 var addLanguageOkButton = $('add-language-overlay-ok-button'); | |
153 addLanguageOkButton.addEventListener( | |
154 'click', | |
155 this.handleAddLanguageOkButtonClick_.bind(this)); | |
156 | 147 |
| 148 // Listen to add language dialog ok button. |
| 149 $('add-language-overlay-ok-button').addEventListener( |
| 150 'click', this.handleAddLanguageOkButtonClick_.bind(this)); |
| 151 |
| 152 if (!cr.isChromeOS) { |
157 // Show experimental features if enabled. | 153 // Show experimental features if enabled. |
158 if (loadTimeData.getBoolean('enableSpellingAutoCorrect')) | 154 if (loadTimeData.getBoolean('enableSpellingAutoCorrect')) |
159 $('auto-spell-correction-option').hidden = false; | 155 $('auto-spell-correction-option').hidden = false; |
160 | 156 |
161 // Handle spell check enable/disable. | 157 // Handle spell check enable/disable. |
162 if (!cr.isMac) { | 158 if (!cr.isMac) { |
163 Preferences.getInstance().addEventListener( | 159 Preferences.getInstance().addEventListener( |
164 this.enableSpellCheckPref, | 160 this.enableSpellCheckPref, |
165 this.updateEnableSpellCheck_.bind(this)); | 161 this.updateEnableSpellCheck_.bind(this)); |
166 } | 162 } |
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
669 * @param {Event} e Click event. | 665 * @param {Event} e Click event. |
670 * @private | 666 * @private |
671 */ | 667 */ |
672 handleExtensionCheckboxClick_: function(e) { | 668 handleExtensionCheckboxClick_: function(e) { |
673 var checkbox = e.target; | 669 var checkbox = e.target; |
674 this.updateFilteredExtensionsFromCheckboxes_(); | 670 this.updateFilteredExtensionsFromCheckboxes_(); |
675 this.saveFilteredExtensionPref_(); | 671 this.saveFilteredExtensionPref_(); |
676 }, | 672 }, |
677 | 673 |
678 /** | 674 /** |
679 * Handles add language list's click event. | |
680 * @param {Event} e Click event. | |
681 */ | |
682 handleAddLanguageListClick_: function(e) { | |
683 var languageOptionsList = $('language-options-list'); | |
684 var languageCode = e.target.languageCode; | |
685 // languageCode can be undefined, if click was made on some random | |
686 // place in the overlay, rather than a button. Ignore it. | |
687 if (!languageCode) { | |
688 return; | |
689 } | |
690 languageOptionsList.addLanguage(languageCode); | |
691 var inputMethodIds = this.languageCodeToInputMethodIdsMap_[languageCode]; | |
692 // Enable the first input method for the language added. | |
693 if (inputMethodIds && inputMethodIds[0] && | |
694 // Don't add the input method it's already present. This can | |
695 // happen if the same input method is shared among multiple | |
696 // languages (ex. English US keyboard is used for English US and | |
697 // Filipino). | |
698 this.preloadEngines_.indexOf(inputMethodIds[0]) == -1) { | |
699 this.preloadEngines_.push(inputMethodIds[0]); | |
700 this.updateCheckboxesFromPreloadEngines_(); | |
701 this.savePreloadEnginesPref_(); | |
702 } | |
703 OptionsPage.closeOverlay(); | |
704 }, | |
705 | |
706 /** | |
707 * Handles extension IME button. | 675 * Handles extension IME button. |
708 */ | 676 */ |
709 handleExtensionImeButtonClick_: function() { | 677 handleExtensionImeButtonClick_: function() { |
710 $('language-options-list').clearSelection(); | 678 $('language-options-list').clearSelection(); |
711 | 679 |
712 var languageName = $('language-options-language-name'); | 680 var languageName = $('language-options-language-name'); |
713 languageName.textContent = loadTimeData.getString('extension_ime_label'); | 681 languageName.textContent = loadTimeData.getString('extension_ime_label'); |
714 | 682 |
715 var uiLanguageMessage = $('language-options-ui-language-message'); | 683 var uiLanguageMessage = $('language-options-ui-language-message'); |
716 uiLanguageMessage.textContent = | 684 uiLanguageMessage.textContent = |
(...skipping 18 matching lines...) Expand all Loading... |
735 method.hidden = true; | 703 method.hidden = true; |
736 } | 704 } |
737 }, | 705 }, |
738 | 706 |
739 handleAddLanguageOkButtonClick_: function() { | 707 handleAddLanguageOkButtonClick_: function() { |
740 var languagesSelect = $('add-language-overlay-language-list'); | 708 var languagesSelect = $('add-language-overlay-language-list'); |
741 var selectedIndex = languagesSelect.selectedIndex; | 709 var selectedIndex = languagesSelect.selectedIndex; |
742 if (selectedIndex >= 0) { | 710 if (selectedIndex >= 0) { |
743 var selection = languagesSelect.options[selectedIndex]; | 711 var selection = languagesSelect.options[selectedIndex]; |
744 $('language-options-list').addLanguage(String(selection.value)); | 712 $('language-options-list').addLanguage(String(selection.value)); |
| 713 if (cr.isChromeOS) { |
| 714 var inputMethodIds = |
| 715 this.languageCodeToInputMethodIdsMap_[selection.value]; |
| 716 // Enable the first input method for the language added. |
| 717 if (inputMethodIds && inputMethodIds[0] && |
| 718 // Don't add the input method it's already present. This can |
| 719 // happen if the same input method is shared among multiple |
| 720 // languages (ex. English US keyboard is used for English US and |
| 721 // Filipino). |
| 722 this.preloadEngines_.indexOf(inputMethodIds[0]) == -1) { |
| 723 this.preloadEngines_.push(inputMethodIds[0]); |
| 724 this.updateCheckboxesFromPreloadEngines_(); |
| 725 this.savePreloadEnginesPref_(); |
| 726 } |
| 727 } |
745 OptionsPage.closeOverlay(); | 728 OptionsPage.closeOverlay(); |
746 } | 729 } |
747 }, | 730 }, |
748 | 731 |
749 /** | 732 /** |
750 * Checks if languageCode is deletable or not. | 733 * Checks if languageCode is deletable or not. |
751 * @param {string} languageCode the languageCode to check for deletability. | 734 * @param {string} languageCode the languageCode to check for deletability. |
752 */ | 735 */ |
753 languageIsDeletable: function(languageCode) { | 736 languageIsDeletable: function(languageCode) { |
754 // Don't allow removing the language if it's a UI language. | 737 // Don't allow removing the language if it's a UI language. |
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1105 | 1088 |
1106 LanguageOptions.onDictionaryDownloadFailure = function(languageCode) { | 1089 LanguageOptions.onDictionaryDownloadFailure = function(languageCode) { |
1107 LanguageOptions.getInstance().onDictionaryDownloadFailure_(languageCode); | 1090 LanguageOptions.getInstance().onDictionaryDownloadFailure_(languageCode); |
1108 }; | 1091 }; |
1109 | 1092 |
1110 // Export | 1093 // Export |
1111 return { | 1094 return { |
1112 LanguageOptions: LanguageOptions | 1095 LanguageOptions: LanguageOptions |
1113 }; | 1096 }; |
1114 }); | 1097 }); |
OLD | NEW |