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