Chromium Code Reviews| 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 22 matching lines...) Expand all Loading... | |
| 33 loadTimeData.getString('languagePageTabTitle'), | 33 loadTimeData.getString('languagePageTabTitle'), |
| 34 'languagePage'); | 34 'languagePage'); |
| 35 } | 35 } |
| 36 | 36 |
| 37 cr.addSingletonGetter(LanguageOptions); | 37 cr.addSingletonGetter(LanguageOptions); |
| 38 | 38 |
| 39 // Inherit LanguageOptions from OptionsPage. | 39 // Inherit LanguageOptions from OptionsPage. |
| 40 LanguageOptions.prototype = { | 40 LanguageOptions.prototype = { |
| 41 __proto__: OptionsPage.prototype, | 41 __proto__: OptionsPage.prototype, |
| 42 | 42 |
| 43 /* For recording the prospective language (the next locale after relaunch). | |
| 44 * @type {?string} | |
| 45 * @private | |
| 46 */ | |
| 47 prospectiveUiLanguageCode_: null, | |
| 48 | |
| 43 /** | 49 /** |
| 44 * Initializes LanguageOptions page. | 50 * Initializes LanguageOptions page. |
| 45 * Calls base class implementation to starts preference initialization. | 51 * Calls base class implementation to start preference initialization. |
| 46 */ | 52 */ |
| 47 initializePage: function() { | 53 initializePage: function() { |
| 48 OptionsPage.prototype.initializePage.call(this); | 54 OptionsPage.prototype.initializePage.call(this); |
| 49 | 55 |
| 50 var languageOptionsList = $('language-options-list'); | 56 var languageOptionsList = $('language-options-list'); |
| 51 LanguageList.decorate(languageOptionsList); | 57 LanguageList.decorate(languageOptionsList); |
| 52 | 58 |
| 53 languageOptionsList.addEventListener('change', | 59 languageOptionsList.addEventListener('change', |
| 54 this.handleLanguageOptionsListChange_.bind(this)); | 60 this.handleLanguageOptionsListChange_.bind(this)); |
| 55 languageOptionsList.addEventListener('save', | 61 languageOptionsList.addEventListener('save', |
| 56 this.handleLanguageOptionsListSave_.bind(this)); | 62 this.handleLanguageOptionsListSave_.bind(this)); |
| 57 | 63 |
| 64 this.prospectiveUiLanguageCode_ = | |
| 65 loadTimeData.getString('prospectiveUiLanguageCode'); | |
| 58 this.addEventListener('visibleChange', | 66 this.addEventListener('visibleChange', |
| 59 this.handleVisibleChange_.bind(this)); | 67 this.handleVisibleChange_.bind(this)); |
| 60 | 68 |
| 61 if (cr.isChromeOS) { | 69 if (cr.isChromeOS) { |
| 62 $('chewing-confirm').onclick = $('hangul-confirm').onclick = | 70 $('chewing-confirm').onclick = $('hangul-confirm').onclick = |
| 63 $('mozc-confirm').onclick = $('pinyin-confirm').onclick = | 71 $('mozc-confirm').onclick = $('pinyin-confirm').onclick = |
| 64 OptionsPage.closeOverlay.bind(OptionsPage); | 72 OptionsPage.closeOverlay.bind(OptionsPage); |
| 65 | 73 |
| 66 this.initializeInputMethodList_(); | 74 this.initializeInputMethodList_(); |
| 67 this.initializeLanguageCodeToInputMethodIdsMap_(); | 75 this.initializeLanguageCodeToInputMethodIdsMap_(); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 106 var spellCheckLanguageButton = getRequiredElement( | 114 var spellCheckLanguageButton = getRequiredElement( |
| 107 'language-options-spell-check-language-button'); | 115 'language-options-spell-check-language-button'); |
| 108 spellCheckLanguageButton.addEventListener( | 116 spellCheckLanguageButton.addEventListener( |
| 109 'click', | 117 'click', |
| 110 this.handleSpellCheckLanguageButtonClick_.bind(this)); | 118 this.handleSpellCheckLanguageButtonClick_.bind(this)); |
| 111 } | 119 } |
| 112 } | 120 } |
| 113 | 121 |
| 114 if (cr.isChromeOS) { | 122 if (cr.isChromeOS) { |
| 115 $('language-options-ui-restart-button').onclick = | 123 $('language-options-ui-restart-button').onclick = |
| 116 chrome.send.bind(chrome, 'uiLanguageRestart'); | 124 chrome.send('uiLanguageRestart'); |
|
Dan Beam
2012/06/12 01:28:28
this calls the function, doesn't return a referenc
kochi
2012/06/12 06:02:25
Oh, I hope I understand you this time:)
When I tr
| |
| 117 } | 125 } |
| 118 | 126 |
| 119 $('language-confirm').onclick = | 127 $('language-confirm').onclick = |
| 120 OptionsPage.closeOverlay.bind(OptionsPage); | 128 OptionsPage.closeOverlay.bind(OptionsPage); |
| 121 }, | 129 }, |
| 122 | 130 |
| 123 // The preference is a boolean that enables/disables spell checking. | 131 // The preference is a boolean that enables/disables spell checking. |
| 124 enableSpellCheckPref: 'browser.enable_spellchecking', | 132 enableSpellCheckPref: 'browser.enable_spellchecking', |
| 125 // The preference is a CSV string that describes preload engines | 133 // The preference is a CSV string that describes preload engines |
| 126 // (i.e. active input methods). | 134 // (i.e. active input methods). |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 363 var uiLanguageMessage = $('language-options-ui-language-message'); | 371 var uiLanguageMessage = $('language-options-ui-language-message'); |
| 364 var uiLanguageNotification = $('language-options-ui-notification-bar'); | 372 var uiLanguageNotification = $('language-options-ui-notification-bar'); |
| 365 | 373 |
| 366 // Remove the event listener and add it back if useful. | 374 // Remove the event listener and add it back if useful. |
| 367 uiLanguageButton.onclick = null; | 375 uiLanguageButton.onclick = null; |
| 368 | 376 |
| 369 // Unhide the language button every time, as it could've been previously | 377 // Unhide the language button every time, as it could've been previously |
| 370 // hidden by a language change. | 378 // hidden by a language change. |
| 371 uiLanguageButton.hidden = false; | 379 uiLanguageButton.hidden = false; |
| 372 | 380 |
| 373 if (languageCode == loadTimeData.getString('prospectiveUiLanguageCode')) { | 381 if (languageCode == this.prospectiveUiLanguageCode_) { |
| 374 uiLanguageMessage.textContent = | 382 uiLanguageMessage.textContent = |
| 375 loadTimeData.getString('is_displayed_in_this_language'); | 383 loadTimeData.getString('is_displayed_in_this_language'); |
| 376 showMutuallyExclusiveNodes( | 384 showMutuallyExclusiveNodes( |
| 377 [uiLanguageButton, uiLanguageMessage, uiLanguageNotification], 1); | 385 [uiLanguageButton, uiLanguageMessage, uiLanguageNotification], 1); |
| 378 } else if (languageCode in loadTimeData.getValue('uiLanguageCodeSet')) { | 386 } else if (languageCode in loadTimeData.getValue('uiLanguageCodeSet')) { |
| 379 if (cr.isChromeOS && UIAccountTweaks.loggedInAsGuest()) { | 387 if (cr.isChromeOS && UIAccountTweaks.loggedInAsGuest()) { |
| 380 // In the guest mode for ChromeOS, changing UI language does not make | 388 // In the guest mode for ChromeOS, changing UI language does not make |
| 381 // sense because it does not take effect after browser restart. | 389 // sense because it does not take effect after browser restart. |
| 382 uiLanguageButton.hidden = true; | 390 uiLanguageButton.hidden = true; |
| 383 uiLanguageMessage.hidden = true; | 391 uiLanguageMessage.hidden = true; |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 573 OptionsPage.closeOverlay(); | 581 OptionsPage.closeOverlay(); |
| 574 } | 582 } |
| 575 }, | 583 }, |
| 576 | 584 |
| 577 /** | 585 /** |
| 578 * Checks if languageCode is deletable or not. | 586 * Checks if languageCode is deletable or not. |
| 579 * @param {String} languageCode the languageCode to check for deletability. | 587 * @param {String} languageCode the languageCode to check for deletability. |
| 580 */ | 588 */ |
| 581 languageIsDeletable: function(languageCode) { | 589 languageIsDeletable: function(languageCode) { |
| 582 // Don't allow removing the language if it's a UI language. | 590 // Don't allow removing the language if it's a UI language. |
| 583 if (languageCode == loadTimeData.getString('prospectiveUiLanguageCode')) | 591 if (languageCode == this.prospectiveUiLanguageCode_) |
| 584 return false; | 592 return false; |
| 585 return (!cr.isChromeOS || | 593 return (!cr.isChromeOS || |
| 586 this.canDeleteLanguage_(languageCode)); | 594 this.canDeleteLanguage_(languageCode)); |
| 587 }, | 595 }, |
| 588 | 596 |
| 589 /** | 597 /** |
| 590 * Handles browse.enable_spellchecking change. | 598 * Handles browse.enable_spellchecking change. |
| 591 * @param {Event} e Change event. | 599 * @param {Event} e Change event. |
| 592 * @private | 600 * @private |
| 593 */ | 601 */ |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 817 assert(nodes[i] instanceof HTMLElement); // TODO(dbeam): Ignore null? | 825 assert(nodes[i] instanceof HTMLElement); // TODO(dbeam): Ignore null? |
| 818 nodes[i].hidden = i != index; | 826 nodes[i].hidden = i != index; |
| 819 } | 827 } |
| 820 } | 828 } |
| 821 | 829 |
| 822 /** | 830 /** |
| 823 * Chrome callback for when the UI language preference is saved. | 831 * Chrome callback for when the UI language preference is saved. |
| 824 * @param {string} languageCode The newly selected language to use. | 832 * @param {string} languageCode The newly selected language to use. |
| 825 */ | 833 */ |
| 826 LanguageOptions.uiLanguageSaved = function(languageCode) { | 834 LanguageOptions.uiLanguageSaved = function(languageCode) { |
| 827 loadTimeData.getString('prospectiveUiLanguageCode') = languageCode; | 835 this.prospectiveUiLanguageCode_ = languageCode; |
| 828 | 836 |
| 829 // If the user is no longer on the same language code, ignore. | 837 // If the user is no longer on the same language code, ignore. |
| 830 if ($('language-options-list').getSelectedLanguageCode() != languageCode) | 838 if ($('language-options-list').getSelectedLanguageCode() != languageCode) |
| 831 return; | 839 return; |
| 832 | 840 |
| 833 // Special case for when a user changes to a different language, and changes | 841 // Special case for when a user changes to a different language, and changes |
| 834 // back to the same language without having restarted Chrome or logged | 842 // back to the same language without having restarted Chrome or logged |
| 835 // in/out of ChromeOS. | 843 // in/out of ChromeOS. |
| 836 if (languageCode == loadTimeData.getString('currentUiLanguageCode')) { | 844 if (languageCode == loadTimeData.getString('currentUiLanguageCode')) { |
| 837 LanguageOptions.getInstance().currentLocaleWasReselected(); | 845 LanguageOptions.getInstance().currentLocaleWasReselected(); |
| 838 return; | 846 return; |
| 839 } | 847 } |
| 840 | 848 |
| 841 // Otherwise, show a notification telling the user that their changes will | 849 // Otherwise, show a notification telling the user that their changes will |
| 842 // only take effect after restart. | 850 // only take effect after restart. |
| 843 showMutuallyExclusiveNodes([$('language-options-ui-language-button'), | 851 showMutuallyExclusiveNodes([$('language-options-ui-language-button'), |
| 844 $('language-options-ui-notification-bar')], 1); | 852 $('language-options-ui-notification-bar')], 1); |
| 845 }; | 853 }; |
| 846 | 854 |
| 847 // Export | 855 // Export |
| 848 return { | 856 return { |
| 849 LanguageOptions: LanguageOptions | 857 LanguageOptions: LanguageOptions |
| 850 }; | 858 }; |
| 851 }); | 859 }); |
| OLD | NEW |