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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 | 113 |
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 = function() { |
116 chrome.send.bind(chrome, 'uiLanguageRestart'); | 124 chrome.send('uiLanguageRestart'); |
| 125 }; |
117 } | 126 } |
118 | 127 |
119 $('language-confirm').onclick = | 128 $('language-confirm').onclick = |
120 OptionsPage.closeOverlay.bind(OptionsPage); | 129 OptionsPage.closeOverlay.bind(OptionsPage); |
121 }, | 130 }, |
122 | 131 |
123 // The preference is a boolean that enables/disables spell checking. | 132 // The preference is a boolean that enables/disables spell checking. |
124 enableSpellCheckPref: 'browser.enable_spellchecking', | 133 enableSpellCheckPref: 'browser.enable_spellchecking', |
125 // The preference is a CSV string that describes preload engines | 134 // The preference is a CSV string that describes preload engines |
126 // (i.e. active input methods). | 135 // (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'); | 372 var uiLanguageMessage = $('language-options-ui-language-message'); |
364 var uiLanguageNotification = $('language-options-ui-notification-bar'); | 373 var uiLanguageNotification = $('language-options-ui-notification-bar'); |
365 | 374 |
366 // Remove the event listener and add it back if useful. | 375 // Remove the event listener and add it back if useful. |
367 uiLanguageButton.onclick = null; | 376 uiLanguageButton.onclick = null; |
368 | 377 |
369 // Unhide the language button every time, as it could've been previously | 378 // Unhide the language button every time, as it could've been previously |
370 // hidden by a language change. | 379 // hidden by a language change. |
371 uiLanguageButton.hidden = false; | 380 uiLanguageButton.hidden = false; |
372 | 381 |
373 if (languageCode == loadTimeData.getString('prospectiveUiLanguageCode')) { | 382 if (languageCode == this.prospectiveUiLanguageCode_) { |
374 uiLanguageMessage.textContent = | 383 uiLanguageMessage.textContent = |
375 loadTimeData.getString('is_displayed_in_this_language'); | 384 loadTimeData.getString('is_displayed_in_this_language'); |
376 showMutuallyExclusiveNodes( | 385 showMutuallyExclusiveNodes( |
377 [uiLanguageButton, uiLanguageMessage, uiLanguageNotification], 1); | 386 [uiLanguageButton, uiLanguageMessage, uiLanguageNotification], 1); |
378 } else if (languageCode in loadTimeData.getValue('uiLanguageCodeSet')) { | 387 } else if (languageCode in loadTimeData.getValue('uiLanguageCodeSet')) { |
379 if (cr.isChromeOS && UIAccountTweaks.loggedInAsGuest()) { | 388 if (cr.isChromeOS && UIAccountTweaks.loggedInAsGuest()) { |
380 // In the guest mode for ChromeOS, changing UI language does not make | 389 // In the guest mode for ChromeOS, changing UI language does not make |
381 // sense because it does not take effect after browser restart. | 390 // sense because it does not take effect after browser restart. |
382 uiLanguageButton.hidden = true; | 391 uiLanguageButton.hidden = true; |
383 uiLanguageMessage.hidden = true; | 392 uiLanguageMessage.hidden = true; |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
573 OptionsPage.closeOverlay(); | 582 OptionsPage.closeOverlay(); |
574 } | 583 } |
575 }, | 584 }, |
576 | 585 |
577 /** | 586 /** |
578 * Checks if languageCode is deletable or not. | 587 * Checks if languageCode is deletable or not. |
579 * @param {String} languageCode the languageCode to check for deletability. | 588 * @param {String} languageCode the languageCode to check for deletability. |
580 */ | 589 */ |
581 languageIsDeletable: function(languageCode) { | 590 languageIsDeletable: function(languageCode) { |
582 // Don't allow removing the language if it's a UI language. | 591 // Don't allow removing the language if it's a UI language. |
583 if (languageCode == loadTimeData.getString('prospectiveUiLanguageCode')) | 592 if (languageCode == this.prospectiveUiLanguageCode_) |
584 return false; | 593 return false; |
585 return (!cr.isChromeOS || | 594 return (!cr.isChromeOS || |
586 this.canDeleteLanguage_(languageCode)); | 595 this.canDeleteLanguage_(languageCode)); |
587 }, | 596 }, |
588 | 597 |
589 /** | 598 /** |
590 * Handles browse.enable_spellchecking change. | 599 * Handles browse.enable_spellchecking change. |
591 * @param {Event} e Change event. | 600 * @param {Event} e Change event. |
592 * @private | 601 * @private |
593 */ | 602 */ |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
817 assert(nodes[i] instanceof HTMLElement); // TODO(dbeam): Ignore null? | 826 assert(nodes[i] instanceof HTMLElement); // TODO(dbeam): Ignore null? |
818 nodes[i].hidden = i != index; | 827 nodes[i].hidden = i != index; |
819 } | 828 } |
820 } | 829 } |
821 | 830 |
822 /** | 831 /** |
823 * Chrome callback for when the UI language preference is saved. | 832 * Chrome callback for when the UI language preference is saved. |
824 * @param {string} languageCode The newly selected language to use. | 833 * @param {string} languageCode The newly selected language to use. |
825 */ | 834 */ |
826 LanguageOptions.uiLanguageSaved = function(languageCode) { | 835 LanguageOptions.uiLanguageSaved = function(languageCode) { |
827 loadTimeData.getString('prospectiveUiLanguageCode') = languageCode; | 836 this.prospectiveUiLanguageCode_ = languageCode; |
828 | 837 |
829 // If the user is no longer on the same language code, ignore. | 838 // If the user is no longer on the same language code, ignore. |
830 if ($('language-options-list').getSelectedLanguageCode() != languageCode) | 839 if ($('language-options-list').getSelectedLanguageCode() != languageCode) |
831 return; | 840 return; |
832 | 841 |
833 // Special case for when a user changes to a different language, and changes | 842 // 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 | 843 // back to the same language without having restarted Chrome or logged |
835 // in/out of ChromeOS. | 844 // in/out of ChromeOS. |
836 if (languageCode == loadTimeData.getString('currentUiLanguageCode')) { | 845 if (languageCode == loadTimeData.getString('currentUiLanguageCode')) { |
837 LanguageOptions.getInstance().currentLocaleWasReselected(); | 846 LanguageOptions.getInstance().currentLocaleWasReselected(); |
838 return; | 847 return; |
839 } | 848 } |
840 | 849 |
841 // Otherwise, show a notification telling the user that their changes will | 850 // Otherwise, show a notification telling the user that their changes will |
842 // only take effect after restart. | 851 // only take effect after restart. |
843 showMutuallyExclusiveNodes([$('language-options-ui-language-button'), | 852 showMutuallyExclusiveNodes([$('language-options-ui-language-button'), |
844 $('language-options-ui-notification-bar')], 1); | 853 $('language-options-ui-notification-bar')], 1); |
845 }; | 854 }; |
846 | 855 |
847 // Export | 856 // Export |
848 return { | 857 return { |
849 LanguageOptions: LanguageOptions | 858 LanguageOptions: LanguageOptions |
850 }; | 859 }; |
851 }); | 860 }); |
OLD | NEW |