| 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 Page = cr.ui.pageManager.Page; |
| 10 /** @const */ var PageManager = cr.ui.pageManager.PageManager; |
| 10 /** @const */ var LanguageList = options.LanguageList; | 11 /** @const */ var LanguageList = options.LanguageList; |
| 11 /** @const */ var ThirdPartyImeConfirmOverlay = | 12 /** @const */ var ThirdPartyImeConfirmOverlay = |
| 12 options.ThirdPartyImeConfirmOverlay; | 13 options.ThirdPartyImeConfirmOverlay; |
| 13 | 14 |
| 14 /** | 15 /** |
| 15 * Spell check dictionary download status. | 16 * Spell check dictionary download status. |
| 16 * @type {Enum} | 17 * @type {Enum} |
| 17 */ | 18 */ |
| 18 /** @const*/ var DOWNLOAD_STATUS = { | 19 /** @const*/ var DOWNLOAD_STATUS = { |
| 19 IN_PROGRESS: 1, | 20 IN_PROGRESS: 1, |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 var ENABLE_TRANSLATE = 'translate.enabled'; | 67 var ENABLE_TRANSLATE = 'translate.enabled'; |
| 67 | 68 |
| 68 ///////////////////////////////////////////////////////////////////////////// | 69 ///////////////////////////////////////////////////////////////////////////// |
| 69 // LanguageOptions class: | 70 // LanguageOptions class: |
| 70 | 71 |
| 71 /** | 72 /** |
| 72 * Encapsulated handling of ChromeOS language options page. | 73 * Encapsulated handling of ChromeOS language options page. |
| 73 * @constructor | 74 * @constructor |
| 74 */ | 75 */ |
| 75 function LanguageOptions(model) { | 76 function LanguageOptions(model) { |
| 76 OptionsPage.call(this, 'languages', | 77 Page.call(this, 'languages', |
| 77 loadTimeData.getString('languagePageTabTitle'), | 78 loadTimeData.getString('languagePageTabTitle'), 'languagePage'); |
| 78 'languagePage'); | |
| 79 } | 79 } |
| 80 | 80 |
| 81 cr.addSingletonGetter(LanguageOptions); | 81 cr.addSingletonGetter(LanguageOptions); |
| 82 | 82 |
| 83 // Inherit LanguageOptions from OptionsPage. | 83 // Inherit LanguageOptions from Page. |
| 84 LanguageOptions.prototype = { | 84 LanguageOptions.prototype = { |
| 85 __proto__: OptionsPage.prototype, | 85 __proto__: Page.prototype, |
| 86 | 86 |
| 87 /* For recording the prospective language (the next locale after relaunch). | 87 /* For recording the prospective language (the next locale after relaunch). |
| 88 * @type {?string} | 88 * @type {?string} |
| 89 * @private | 89 * @private |
| 90 */ | 90 */ |
| 91 prospectiveUiLanguageCode_: null, | 91 prospectiveUiLanguageCode_: null, |
| 92 | 92 |
| 93 /* | 93 /* |
| 94 * Map from language code to spell check dictionary download status for that | 94 * Map from language code to spell check dictionary download status for that |
| 95 * language. | 95 * language. |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 | 151 |
| 152 /** | 152 /** |
| 153 * The value that indicates if Translate feature is enabled or not. | 153 * The value that indicates if Translate feature is enabled or not. |
| 154 * @type {boolean} | 154 * @type {boolean} |
| 155 * @private | 155 * @private |
| 156 */ | 156 */ |
| 157 enableTranslate_: false, | 157 enableTranslate_: false, |
| 158 | 158 |
| 159 /** | 159 /** |
| 160 * Initializes LanguageOptions page. | 160 * Initializes LanguageOptions page. |
| 161 * Calls base class implementation to start preference initialization. | |
| 162 */ | 161 */ |
| 163 initializePage: function() { | 162 initializePage: function() { |
| 164 OptionsPage.prototype.initializePage.call(this); | 163 Page.prototype.initializePage.call(this); |
| 165 | 164 |
| 166 var languageOptionsList = $('language-options-list'); | 165 var languageOptionsList = $('language-options-list'); |
| 167 LanguageList.decorate(languageOptionsList); | 166 LanguageList.decorate(languageOptionsList); |
| 168 | 167 |
| 169 languageOptionsList.addEventListener('change', | 168 languageOptionsList.addEventListener('change', |
| 170 this.handleLanguageOptionsListChange_.bind(this)); | 169 this.handleLanguageOptionsListChange_.bind(this)); |
| 171 languageOptionsList.addEventListener('save', | 170 languageOptionsList.addEventListener('save', |
| 172 this.handleLanguageOptionsListSave_.bind(this)); | 171 this.handleLanguageOptionsListSave_.bind(this)); |
| 173 | 172 |
| 174 this.prospectiveUiLanguageCode_ = | 173 this.prospectiveUiLanguageCode_ = |
| (...skipping 23 matching lines...) Expand all Loading... |
| 198 // Set up add button. | 197 // Set up add button. |
| 199 $('language-options-add-button').onclick = function(e) { | 198 $('language-options-add-button').onclick = function(e) { |
| 200 // Add the language without showing the overlay if it's specified in | 199 // Add the language without showing the overlay if it's specified in |
| 201 // the URL hash (ex. lang_add=ja). Used for automated testing. | 200 // the URL hash (ex. lang_add=ja). Used for automated testing. |
| 202 var match = document.location.hash.match(/\blang_add=([\w-]+)/); | 201 var match = document.location.hash.match(/\blang_add=([\w-]+)/); |
| 203 if (match) { | 202 if (match) { |
| 204 var addLanguageCode = match[1]; | 203 var addLanguageCode = match[1]; |
| 205 $('language-options-list').addLanguage(addLanguageCode); | 204 $('language-options-list').addLanguage(addLanguageCode); |
| 206 this.addBlockedLanguage_(addLanguageCode); | 205 this.addBlockedLanguage_(addLanguageCode); |
| 207 } else { | 206 } else { |
| 208 OptionsPage.navigateToPage('addLanguage'); | 207 PageManager.navigateToPage('addLanguage'); |
| 209 } | 208 } |
| 210 }.bind(this); | 209 }.bind(this); |
| 211 | 210 |
| 212 if (!cr.isMac) { | 211 if (!cr.isMac) { |
| 213 // Set up the button for editing custom spelling dictionary. | 212 // Set up the button for editing custom spelling dictionary. |
| 214 $('edit-dictionary-button').onclick = function(e) { | 213 $('edit-dictionary-button').onclick = function(e) { |
| 215 OptionsPage.navigateToPage('editDictionary'); | 214 PageManager.navigateToPage('editDictionary'); |
| 216 }; | 215 }; |
| 217 $('dictionary-download-retry-button').onclick = function(e) { | 216 $('dictionary-download-retry-button').onclick = function(e) { |
| 218 chrome.send('retryDictionaryDownload'); | 217 chrome.send('retryDictionaryDownload'); |
| 219 }; | 218 }; |
| 220 } | 219 } |
| 221 | 220 |
| 222 // Listen to add language dialog ok button. | 221 // Listen to add language dialog ok button. |
| 223 $('add-language-overlay-ok-button').addEventListener( | 222 $('add-language-overlay-ok-button').addEventListener( |
| 224 'click', this.handleAddLanguageOkButtonClick_.bind(this)); | 223 'click', this.handleAddLanguageOkButtonClick_.bind(this)); |
| 225 | 224 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 245 this.handleSpellCheckLanguageButtonClick_.bind(this)); | 244 this.handleSpellCheckLanguageButtonClick_.bind(this)); |
| 246 } | 245 } |
| 247 | 246 |
| 248 if (cr.isChromeOS) { | 247 if (cr.isChromeOS) { |
| 249 $('language-options-ui-restart-button').onclick = function() { | 248 $('language-options-ui-restart-button').onclick = function() { |
| 250 chrome.send('uiLanguageRestart'); | 249 chrome.send('uiLanguageRestart'); |
| 251 }; | 250 }; |
| 252 } | 251 } |
| 253 | 252 |
| 254 $('language-confirm').onclick = | 253 $('language-confirm').onclick = |
| 255 OptionsPage.closeOverlay.bind(OptionsPage); | 254 PageManager.closeOverlay.bind(PageManager); |
| 256 | 255 |
| 257 // Public session users cannot change the locale. | 256 // Public session users cannot change the locale. |
| 258 if (cr.isChromeOS && UIAccountTweaks.loggedInAsPublicAccount()) | 257 if (cr.isChromeOS && UIAccountTweaks.loggedInAsPublicAccount()) |
| 259 $('language-options-ui-language-section').hidden = true; | 258 $('language-options-ui-language-section').hidden = true; |
| 259 PageManager.closeOverlay.bind(PageManager); |
| 260 }, | 260 }, |
| 261 | 261 |
| 262 /** | 262 /** |
| 263 * Initializes the input method list. | 263 * Initializes the input method list. |
| 264 */ | 264 */ |
| 265 initializeInputMethodList_: function() { | 265 initializeInputMethodList_: function() { |
| 266 var inputMethodList = $('language-options-input-method-list'); | 266 var inputMethodList = $('language-options-input-method-list'); |
| 267 var inputMethodPrototype = $('language-options-input-method-template'); | 267 var inputMethodPrototype = $('language-options-input-method-template'); |
| 268 | 268 |
| 269 // Add all input methods, but make all of them invisible here. We'll | 269 // Add all input methods, but make all of them invisible here. We'll |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 375 this.translateBlockedLanguages_.filter( | 375 this.translateBlockedLanguages_.filter( |
| 376 function(langCodeNotTranslated) { | 376 function(langCodeNotTranslated) { |
| 377 return langCodeNotTranslated != langCode; | 377 return langCodeNotTranslated != langCode; |
| 378 }); | 378 }); |
| 379 Preferences.setListPref(TRANSLATE_BLOCKED_LANGUAGES_PREF, | 379 Preferences.setListPref(TRANSLATE_BLOCKED_LANGUAGES_PREF, |
| 380 this.translateBlockedLanguages_, true); | 380 this.translateBlockedLanguages_, true); |
| 381 } | 381 } |
| 382 }, | 382 }, |
| 383 | 383 |
| 384 /** | 384 /** |
| 385 * Handles OptionsPage's visible property change event. | 385 * Handles Page's visible property change event. |
| 386 * @param {Event} e Property change event. | 386 * @param {Event} e Property change event. |
| 387 * @private | 387 * @private |
| 388 */ | 388 */ |
| 389 handleVisibleChange_: function(e) { | 389 handleVisibleChange_: function(e) { |
| 390 if (this.visible) { | 390 if (this.visible) { |
| 391 $('language-options-list').redraw(); | 391 $('language-options-list').redraw(); |
| 392 chrome.send('languageOptionsOpen'); | 392 chrome.send('languageOptionsOpen'); |
| 393 } | 393 } |
| 394 }, | 394 }, |
| 395 | 395 |
| (...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 884 * @private | 884 * @private |
| 885 */ | 885 */ |
| 886 handleAddLanguageOkButtonClick_: function(e) { | 886 handleAddLanguageOkButtonClick_: function(e) { |
| 887 var languagesSelect = $('add-language-overlay-language-list'); | 887 var languagesSelect = $('add-language-overlay-language-list'); |
| 888 var selectedIndex = languagesSelect.selectedIndex; | 888 var selectedIndex = languagesSelect.selectedIndex; |
| 889 if (selectedIndex >= 0) { | 889 if (selectedIndex >= 0) { |
| 890 var selection = languagesSelect.options[selectedIndex]; | 890 var selection = languagesSelect.options[selectedIndex]; |
| 891 var langCode = String(selection.value); | 891 var langCode = String(selection.value); |
| 892 $('language-options-list').addLanguage(langCode); | 892 $('language-options-list').addLanguage(langCode); |
| 893 this.addBlockedLanguage_(langCode); | 893 this.addBlockedLanguage_(langCode); |
| 894 OptionsPage.closeOverlay(); | 894 PageManager.closeOverlay(); |
| 895 } | 895 } |
| 896 }, | 896 }, |
| 897 | 897 |
| 898 /** | 898 /** |
| 899 * Checks if languageCode is deletable or not. | 899 * Checks if languageCode is deletable or not. |
| 900 * @param {string} languageCode the languageCode to check for deletability. | 900 * @param {string} languageCode the languageCode to check for deletability. |
| 901 */ | 901 */ |
| 902 languageIsDeletable: function(languageCode) { | 902 languageIsDeletable: function(languageCode) { |
| 903 // Don't allow removing the language if it's a UI language. | 903 // Don't allow removing the language if it's a UI language. |
| 904 if (languageCode == this.prospectiveUiLanguageCode_) | 904 if (languageCode == this.prospectiveUiLanguageCode_) |
| (...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1360 | 1360 |
| 1361 LanguageOptions.onComponentManagerInitialized = function(componentImes) { | 1361 LanguageOptions.onComponentManagerInitialized = function(componentImes) { |
| 1362 LanguageOptions.getInstance().appendComponentExtensionIme_(componentImes); | 1362 LanguageOptions.getInstance().appendComponentExtensionIme_(componentImes); |
| 1363 }; | 1363 }; |
| 1364 | 1364 |
| 1365 // Export | 1365 // Export |
| 1366 return { | 1366 return { |
| 1367 LanguageOptions: LanguageOptions | 1367 LanguageOptions: LanguageOptions |
| 1368 }; | 1368 }; |
| 1369 }); | 1369 }); |
| OLD | NEW |