| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 | 9 |
| 10 const OptionsPage = options.OptionsPage; | 10 const OptionsPage = options.OptionsPage; |
| 11 const AddLanguageOverlay = options.language.AddLanguageOverlay; | 11 const AddLanguageOverlay = options.language.AddLanguageOverlay; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 LanguageList.decorate(languageOptionsList); | 51 LanguageList.decorate(languageOptionsList); |
| 52 | 52 |
| 53 languageOptionsList.addEventListener('change', | 53 languageOptionsList.addEventListener('change', |
| 54 this.handleLanguageOptionsListChange_.bind(this)); | 54 this.handleLanguageOptionsListChange_.bind(this)); |
| 55 languageOptionsList.addEventListener('save', | 55 languageOptionsList.addEventListener('save', |
| 56 this.handleLanguageOptionsListSave_.bind(this)); | 56 this.handleLanguageOptionsListSave_.bind(this)); |
| 57 | 57 |
| 58 this.addEventListener('visibleChange', | 58 this.addEventListener('visibleChange', |
| 59 this.handleVisibleChange_.bind(this)); | 59 this.handleVisibleChange_.bind(this)); |
| 60 | 60 |
| 61 this.initializeInputMethodList_(); | 61 if (cr.isChromeOS) { |
| 62 this.initializeLanguageCodeToInputMehotdIdsMap_(); | 62 this.initializeInputMethodList_(); |
| 63 this.initializeLanguageCodeToInputMehotdIdsMap_(); |
| 64 } |
| 65 Preferences.getInstance().addEventListener(this.spellCheckDictionaryPref, |
| 66 this.handleSpellCheckDictionaryPrefChange_.bind(this)); |
| 63 | 67 |
| 64 // Set up add button. | 68 // Set up add button. |
| 65 $('language-options-add-button').onclick = function(e) { | 69 $('language-options-add-button').onclick = function(e) { |
| 66 // Add the language without showing the overlay if it's specified in | 70 // Add the language without showing the overlay if it's specified in |
| 67 // the URL hash (ex. lang_add=ja). Used for automated testing. | 71 // the URL hash (ex. lang_add=ja). Used for automated testing. |
| 68 var match = document.location.hash.match(/\blang_add=([\w-]+)/); | 72 var match = document.location.hash.match(/\blang_add=([\w-]+)/); |
| 69 if (match) { | 73 if (match) { |
| 70 var addLanguageCode = match[1]; | 74 var addLanguageCode = match[1]; |
| 71 $('language-options-list').addLanguage(addLanguageCode); | 75 $('language-options-list').addLanguage(addLanguageCode); |
| 72 } else { | 76 } else { |
| 73 OptionsPage.showOverlay('addLanguageOverlay'); | 77 OptionsPage.showOverlay('addLanguageOverlay'); |
| 74 } | 78 } |
| 75 }; | 79 }; |
| 76 // Set up remove button. | 80 // Set up remove button. |
| 77 $('language-options-remove-button').addEventListener('click', | 81 $('language-options-remove-button').addEventListener('click', |
| 78 this.handleRemoveButtonClick_.bind(this)); | 82 this.handleRemoveButtonClick_.bind(this)); |
| 79 | 83 |
| 80 // Setup add language overlay page. | 84 // Setup add language overlay page. |
| 81 OptionsPage.registerOverlay(AddLanguageOverlay.getInstance()); | 85 OptionsPage.registerOverlay(AddLanguageOverlay.getInstance()); |
| 82 | 86 |
| 83 // Listen to user clicks on the add language list. | 87 if (cr.isChromeOS) { |
| 84 var addLanguageList = $('add-language-overlay-language-list'); | 88 // Listen to user clicks on the add language list. |
| 85 addLanguageList.addEventListener('click', | 89 var addLanguageList = $('add-language-overlay-language-list'); |
| 86 this.handleAddLanguageListClick_.bind(this)); | 90 addLanguageList.addEventListener('click', |
| 91 this.handleAddLanguageListClick_.bind(this)); |
| 92 } else { |
| 93 // Listen to add language dialog ok button. |
| 94 var addLanguageOkButton = $('add-language-overlay-ok-button'); |
| 95 addLanguageOkButton.addEventListener('click', |
| 96 this.handleAddLanguageOkButtonClick_.bind(this)); |
| 97 |
| 98 // Show experimental features if enabled. |
| 99 if (templateData.experimentalSpellCheckFeatures == 'true') { |
| 100 $('auto-spell-correction-option').classList.remove('hidden'); |
| 101 } |
| 102 } |
| 87 }, | 103 }, |
| 88 | 104 |
| 89 // The preference is a CSV string that describes preload engines | 105 // The preference is a CSV string that describes preload engines |
| 90 // (i.e. active input methods). | 106 // (i.e. active input methods). |
| 91 preloadEnginesPref: 'settings.language.preload_engines', | 107 preloadEnginesPref: 'settings.language.preload_engines', |
| 92 // The list of preload engines, like ['mozc', 'pinyin']. | 108 // The list of preload engines, like ['mozc', 'pinyin']. |
| 93 preloadEngines_: [], | 109 preloadEngines_: [], |
| 94 // The preference is a string that describes the spell check | 110 // The preference is a string that describes the spell check |
| 95 // dictionary language, like "en-US". | 111 // dictionary language, like "en-US". |
| 96 spellCheckDictionaryPref: 'spellcheck.dictionary', | 112 spellCheckDictionaryPref: 'spellcheck.dictionary', |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 var button = this.createConfigureInputMethodButton_(inputMethod.id, | 146 var button = this.createConfigureInputMethodButton_(inputMethod.id, |
| 131 pageName); | 147 pageName); |
| 132 label.appendChild(button); | 148 label.appendChild(button); |
| 133 } | 149 } |
| 134 | 150 |
| 135 inputMethodList.appendChild(label); | 151 inputMethodList.appendChild(label); |
| 136 } | 152 } |
| 137 // Listen to pref change once the input method list is initialized. | 153 // Listen to pref change once the input method list is initialized. |
| 138 Preferences.getInstance().addEventListener(this.preloadEnginesPref, | 154 Preferences.getInstance().addEventListener(this.preloadEnginesPref, |
| 139 this.handlePreloadEnginesPrefChange_.bind(this)); | 155 this.handlePreloadEnginesPrefChange_.bind(this)); |
| 140 Preferences.getInstance().addEventListener(this.spellCheckDictionaryPref, | |
| 141 this.handleSpellCheckDictionaryPrefChange_.bind(this)); | |
| 142 }, | 156 }, |
| 143 | 157 |
| 144 /** | 158 /** |
| 145 * Creates a configure button for the given input method ID. | 159 * Creates a configure button for the given input method ID. |
| 146 * @param {string} inputMethodId Input method ID (ex. "pinyin"). | 160 * @param {string} inputMethodId Input method ID (ex. "pinyin"). |
| 147 * @param {string} pageName Name of the config page (ex. "languagePinyin"). | 161 * @param {string} pageName Name of the config page (ex. "languagePinyin"). |
| 148 * @private | 162 * @private |
| 149 */ | 163 */ |
| 150 createConfigureInputMethodButton_: function(inputMethodId, pageName) { | 164 createConfigureInputMethodButton_: function(inputMethodId, pageName) { |
| 151 var button = document.createElement('button'); | 165 var button = document.createElement('button'); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 // Select the language if it's specified in the URL hash (ex. lang=ja). | 198 // Select the language if it's specified in the URL hash (ex. lang=ja). |
| 185 // Used for automated testing. | 199 // Used for automated testing. |
| 186 var match = document.location.hash.match(/\blang=([\w-]+)/); | 200 var match = document.location.hash.match(/\blang=([\w-]+)/); |
| 187 if (match) { | 201 if (match) { |
| 188 var specifiedLanguageCode = match[1]; | 202 var specifiedLanguageCode = match[1]; |
| 189 if (languageOptionsList.selectLanguageByCode(specifiedLanguageCode)) { | 203 if (languageOptionsList.selectLanguageByCode(specifiedLanguageCode)) { |
| 190 languageCode = specifiedLanguageCode; | 204 languageCode = specifiedLanguageCode; |
| 191 } | 205 } |
| 192 } | 206 } |
| 193 this.updateSelectedLanguageName_(languageCode); | 207 this.updateSelectedLanguageName_(languageCode); |
| 194 this.updateUiLanguageButton_(languageCode); | 208 if (!cr.isMac) |
| 209 this.updateUiLanguageButton_(languageCode); |
| 195 this.updateSpellCheckLanguageButton_(languageCode); | 210 this.updateSpellCheckLanguageButton_(languageCode); |
| 196 this.updateInputMethodList_(languageCode); | 211 if (cr.isChromeOS) |
| 212 this.updateInputMethodList_(languageCode); |
| 197 this.updateLanguageListInAddLanguageOverlay_(); | 213 this.updateLanguageListInAddLanguageOverlay_(); |
| 198 }, | 214 }, |
| 199 | 215 |
| 200 /** | 216 /** |
| 201 * Handles languageOptionsList's save event. | 217 * Handles languageOptionsList's save event. |
| 202 * @param {Event} e Save event. | 218 * @param {Event} e Save event. |
| 203 * @private | 219 * @private |
| 204 */ | 220 */ |
| 205 handleLanguageOptionsListSave_: function(e) { | 221 handleLanguageOptionsListSave_: function(e) { |
| 206 // Sort the preload engines per the saved languages before save. | 222 if (cr.isChromeOS) { |
| 207 this.preloadEngines_ = this.sortPreloadEngines_(this.preloadEngines_); | 223 // Sort the preload engines per the saved languages before save. |
| 208 this.savePreloadEnginesPref_(); | 224 this.preloadEngines_ = this.sortPreloadEngines_(this.preloadEngines_); |
| 225 this.savePreloadEnginesPref_(); |
| 226 } |
| 209 }, | 227 }, |
| 210 | 228 |
| 211 /** | 229 /** |
| 212 * Sorts preloadEngines_ by languageOptionsList's order. | 230 * Sorts preloadEngines_ by languageOptionsList's order. |
| 213 * @param {Array} preloadEngines List of preload engines. | 231 * @param {Array} preloadEngines List of preload engines. |
| 214 * @return {Array} Returns sorted preloadEngines. | 232 * @return {Array} Returns sorted preloadEngines. |
| 215 * @private | 233 * @private |
| 216 */ | 234 */ |
| 217 sortPreloadEngines_: function(preloadEngines) { | 235 sortPreloadEngines_: function(preloadEngines) { |
| 218 // For instance, suppose we have two languages and associated input | 236 // For instance, suppose we have two languages and associated input |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 } else if (languageCode in templateData.uiLanguageCodeSet) { | 332 } else if (languageCode in templateData.uiLanguageCodeSet) { |
| 315 // If the language is supported as UI language, users can click on | 333 // If the language is supported as UI language, users can click on |
| 316 // the button to change the UI language. | 334 // the button to change the UI language. |
| 317 uiLanguageButton.textContent = | 335 uiLanguageButton.textContent = |
| 318 localStrings.getString('display_in_this_language'); | 336 localStrings.getString('display_in_this_language'); |
| 319 uiLanguageButton.className = ''; | 337 uiLanguageButton.className = ''; |
| 320 // Send the change request to Chrome. | 338 // Send the change request to Chrome. |
| 321 uiLanguageButton.onclick = function(e) { | 339 uiLanguageButton.onclick = function(e) { |
| 322 chrome.send('uiLanguageChange', [languageCode]); | 340 chrome.send('uiLanguageChange', [languageCode]); |
| 323 } | 341 } |
| 324 $('language-options-ui-sign-out-button').onclick = function(e) { | 342 $('language-options-ui-restart-button').onclick = function(e) { |
| 325 chrome.send('uiLanguageSignOut'); | 343 chrome.send('uiLanguageRestart'); |
| 326 } | 344 } |
| 327 } else { | 345 } else { |
| 328 // If the language is not supported as UI language, the button | 346 // If the language is not supported as UI language, the button |
| 329 // just says that Chromium OS cannot be displayed in this language. | 347 // just says that Chromium OS cannot be displayed in this language. |
| 330 uiLanguageButton.textContent = | 348 uiLanguageButton.textContent = |
| 331 localStrings.getString('cannot_be_displayed_in_this_language'); | 349 localStrings.getString('cannot_be_displayed_in_this_language'); |
| 332 uiLanguageButton.className = 'text-button'; | 350 uiLanguageButton.className = 'text-button'; |
| 333 uiLanguageButton.onclick = undefined; | 351 uiLanguageButton.onclick = undefined; |
| 334 } | 352 } |
| 335 uiLanguageButton.style.display = 'block'; | 353 uiLanguageButton.style.display = 'block'; |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 500 // Filipino). | 518 // Filipino). |
| 501 this.preloadEngines_.indexOf(inputMethodIds[0]) == -1) { | 519 this.preloadEngines_.indexOf(inputMethodIds[0]) == -1) { |
| 502 this.preloadEngines_.push(inputMethodIds[0]); | 520 this.preloadEngines_.push(inputMethodIds[0]); |
| 503 this.updateCheckboxesFromPreloadEngines_(); | 521 this.updateCheckboxesFromPreloadEngines_(); |
| 504 this.savePreloadEnginesPref_(); | 522 this.savePreloadEnginesPref_(); |
| 505 } | 523 } |
| 506 OptionsPage.clearOverlays(); | 524 OptionsPage.clearOverlays(); |
| 507 }, | 525 }, |
| 508 | 526 |
| 509 /** | 527 /** |
| 528 * Handles add language dialog ok button. |
| 529 */ |
| 530 handleAddLanguageOkButtonClick_ : function() { |
| 531 var languagesSelect = $('add-language-overlay-language-list'); |
| 532 var selectedIndex = languagesSelect.selectedIndex; |
| 533 if (selectedIndex >= 0) { |
| 534 var selection = languagesSelect.options[selectedIndex]; |
| 535 $('language-options-list').addLanguage(String(selection.value)); |
| 536 OptionsPage.clearOverlays(); |
| 537 } |
| 538 }, |
| 539 |
| 540 /** |
| 510 * Handles remove button's click event. | 541 * Handles remove button's click event. |
| 511 * @param {Event} e Click event. | 542 * @param {Event} e Click event. |
| 512 */ | 543 */ |
| 513 handleRemoveButtonClick_: function(e) { | 544 handleRemoveButtonClick_: function(e) { |
| 514 var languageOptionsList = $('language-options-list'); | 545 var languageOptionsList = $('language-options-list'); |
| 515 var languageCode = languageOptionsList.getSelectedLanguageCode(); | 546 var languageCode = languageOptionsList.getSelectedLanguageCode(); |
| 516 // Don't allow removing the language if it's as UI language. | 547 // Don't allow removing the language if it's as UI language. |
| 517 if (languageCode == templateData.currentUiLanguageCode) { | 548 if (languageCode == templateData.currentUiLanguageCode) { |
| 518 this.showNotification_( | 549 this.showNotification_( |
| 519 localStrings.getString('this_language_is_currently_in_use'), | 550 localStrings.getString('this_language_is_currently_in_use'), |
| 520 localStrings.getString('ok_button')); | 551 localStrings.getString('ok_button')); |
| 521 return; | 552 return; |
| 522 } | 553 } |
| 523 // Disable input methods associated with |languageCode|. | 554 if (cr.isChromeOS) { |
| 524 // Don't allow removing the language if cerntain conditions are met. | 555 // Disable input methods associated with |languageCode|. |
| 525 // See removePreloadEnginesByLanguageCode_() for details. | 556 // Don't allow removing the language if cerntain conditions are met. |
| 526 if (!this.removePreloadEnginesByLanguageCode_(languageCode)) { | 557 // See removePreloadEnginesByLanguageCode_() for details. |
| 527 this.showNotification_( | 558 if (!this.removePreloadEnginesByLanguageCode_(languageCode)) { |
| 528 localStrings.getString('please_add_another_language'), | 559 this.showNotification_( |
| 529 localStrings.getString('ok_button')); | 560 localStrings.getString('please_add_another_language'), |
| 530 return; | 561 localStrings.getString('ok_button')); |
| 562 return; |
| 563 } |
| 531 } | 564 } |
| 532 languageOptionsList.removeSelectedLanguage(); | 565 languageOptionsList.removeSelectedLanguage(); |
| 533 }, | 566 }, |
| 534 | 567 |
| 535 /** | 568 /** |
| 536 * Handles spellCheckDictionaryPref change. | 569 * Handles spellCheckDictionaryPref change. |
| 537 * @param {Event} e Change event. | 570 * @param {Event} e Change event. |
| 538 * @private | 571 * @private |
| 539 */ | 572 */ |
| 540 handleSpellCheckDictionaryPrefChange_: function(e) { | 573 handleSpellCheckDictionaryPrefChange_: function(e) { |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 752 $('language-options-ui-language-button').style.display = 'none'; | 785 $('language-options-ui-language-button').style.display = 'none'; |
| 753 $('language-options-ui-notification-bar').style.display = 'block'; | 786 $('language-options-ui-notification-bar').style.display = 'block'; |
| 754 }; | 787 }; |
| 755 | 788 |
| 756 // Export | 789 // Export |
| 757 return { | 790 return { |
| 758 LanguageOptions: LanguageOptions | 791 LanguageOptions: LanguageOptions |
| 759 }; | 792 }; |
| 760 | 793 |
| 761 }); | 794 }); |
| OLD | NEW |