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 /** @override */ | 159 /** @override */ |
160 initializePage: function() { | 160 initializePage: function() { |
161 OptionsPage.prototype.initializePage.call(this); | 161 Page.prototype.initializePage.call(this); |
162 | 162 |
163 var languageOptionsList = $('language-options-list'); | 163 var languageOptionsList = $('language-options-list'); |
164 LanguageList.decorate(languageOptionsList); | 164 LanguageList.decorate(languageOptionsList); |
165 | 165 |
166 languageOptionsList.addEventListener('change', | 166 languageOptionsList.addEventListener('change', |
167 this.handleLanguageOptionsListChange_.bind(this)); | 167 this.handleLanguageOptionsListChange_.bind(this)); |
168 languageOptionsList.addEventListener('save', | 168 languageOptionsList.addEventListener('save', |
169 this.handleLanguageOptionsListSave_.bind(this)); | 169 this.handleLanguageOptionsListSave_.bind(this)); |
170 | 170 |
171 this.prospectiveUiLanguageCode_ = | 171 this.prospectiveUiLanguageCode_ = |
(...skipping 23 matching lines...) Expand all Loading... |
195 // Set up add button. | 195 // Set up add button. |
196 var onclick = function(e) { | 196 var onclick = function(e) { |
197 // Add the language without showing the overlay if it's specified in | 197 // Add the language without showing the overlay if it's specified in |
198 // the URL hash (ex. lang_add=ja). Used for automated testing. | 198 // the URL hash (ex. lang_add=ja). Used for automated testing. |
199 var match = document.location.hash.match(/\blang_add=([\w-]+)/); | 199 var match = document.location.hash.match(/\blang_add=([\w-]+)/); |
200 if (match) { | 200 if (match) { |
201 var addLanguageCode = match[1]; | 201 var addLanguageCode = match[1]; |
202 $('language-options-list').addLanguage(addLanguageCode); | 202 $('language-options-list').addLanguage(addLanguageCode); |
203 this.addBlockedLanguage_(addLanguageCode); | 203 this.addBlockedLanguage_(addLanguageCode); |
204 } else { | 204 } else { |
205 OptionsPage.navigateToPage('addLanguage'); | 205 PageManager.showPageByName('addLanguage'); |
206 } | 206 } |
207 }; | 207 }; |
208 $('language-options-add-button').onclick = onclick.bind(this); | 208 $('language-options-add-button').onclick = onclick.bind(this); |
209 | 209 |
210 if (!cr.isMac) { | 210 if (!cr.isMac) { |
211 // Set up the button for editing custom spelling dictionary. | 211 // Set up the button for editing custom spelling dictionary. |
212 $('edit-dictionary-button').onclick = function(e) { | 212 $('edit-dictionary-button').onclick = function(e) { |
213 OptionsPage.navigateToPage('editDictionary'); | 213 PageManager.showPageByName('editDictionary'); |
214 }; | 214 }; |
215 $('dictionary-download-retry-button').onclick = function(e) { | 215 $('dictionary-download-retry-button').onclick = function(e) { |
216 chrome.send('retryDictionaryDownload'); | 216 chrome.send('retryDictionaryDownload'); |
217 }; | 217 }; |
218 } | 218 } |
219 | 219 |
220 // Listen to add language dialog ok button. | 220 // Listen to add language dialog ok button. |
221 $('add-language-overlay-ok-button').addEventListener( | 221 $('add-language-overlay-ok-button').addEventListener( |
222 'click', this.handleAddLanguageOkButtonClick_.bind(this)); | 222 'click', this.handleAddLanguageOkButtonClick_.bind(this)); |
223 | 223 |
(...skipping 19 matching lines...) Expand all Loading... |
243 this.handleSpellCheckLanguageButtonClick_.bind(this)); | 243 this.handleSpellCheckLanguageButtonClick_.bind(this)); |
244 } | 244 } |
245 | 245 |
246 if (cr.isChromeOS) { | 246 if (cr.isChromeOS) { |
247 $('language-options-ui-restart-button').onclick = function() { | 247 $('language-options-ui-restart-button').onclick = function() { |
248 chrome.send('uiLanguageRestart'); | 248 chrome.send('uiLanguageRestart'); |
249 }; | 249 }; |
250 } | 250 } |
251 | 251 |
252 $('language-confirm').onclick = | 252 $('language-confirm').onclick = |
253 OptionsPage.closeOverlay.bind(OptionsPage); | 253 PageManager.closeOverlay.bind(PageManager); |
254 | 254 |
255 // Public session users cannot change the locale. | 255 // Public session users cannot change the locale. |
256 if (cr.isChromeOS && UIAccountTweaks.loggedInAsPublicAccount()) | 256 if (cr.isChromeOS && UIAccountTweaks.loggedInAsPublicAccount()) |
257 $('language-options-ui-language-section').hidden = true; | 257 $('language-options-ui-language-section').hidden = true; |
| 258 PageManager.closeOverlay.bind(PageManager); |
258 }, | 259 }, |
259 | 260 |
260 /** | 261 /** |
261 * Initializes the input method list. | 262 * Initializes the input method list. |
262 */ | 263 */ |
263 initializeInputMethodList_: function() { | 264 initializeInputMethodList_: function() { |
264 var inputMethodList = $('language-options-input-method-list'); | 265 var inputMethodList = $('language-options-input-method-list'); |
265 var inputMethodPrototype = $('language-options-input-method-template'); | 266 var inputMethodPrototype = $('language-options-input-method-template'); |
266 | 267 |
267 // Add all input methods, but make all of them invisible here. We'll | 268 // Add all input methods, but make all of them invisible here. We'll |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
374 this.translateBlockedLanguages_.filter( | 375 this.translateBlockedLanguages_.filter( |
375 function(langCodeNotTranslated) { | 376 function(langCodeNotTranslated) { |
376 return langCodeNotTranslated != langCode; | 377 return langCodeNotTranslated != langCode; |
377 }); | 378 }); |
378 Preferences.setListPref(TRANSLATE_BLOCKED_LANGUAGES_PREF, | 379 Preferences.setListPref(TRANSLATE_BLOCKED_LANGUAGES_PREF, |
379 this.translateBlockedLanguages_, true); | 380 this.translateBlockedLanguages_, true); |
380 } | 381 } |
381 }, | 382 }, |
382 | 383 |
383 /** | 384 /** |
384 * Handles OptionsPage's visible property change event. | 385 * Handles Page's visible property change event. |
385 * @param {Event} e Property change event. | 386 * @param {Event} e Property change event. |
386 * @private | 387 * @private |
387 */ | 388 */ |
388 handleVisibleChange_: function(e) { | 389 handleVisibleChange_: function(e) { |
389 if (this.visible) { | 390 if (this.visible) { |
390 $('language-options-list').redraw(); | 391 $('language-options-list').redraw(); |
391 chrome.send('languageOptionsOpen'); | 392 chrome.send('languageOptionsOpen'); |
392 } | 393 } |
393 }, | 394 }, |
394 | 395 |
(...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
883 * @private | 884 * @private |
884 */ | 885 */ |
885 handleAddLanguageOkButtonClick_: function(e) { | 886 handleAddLanguageOkButtonClick_: function(e) { |
886 var languagesSelect = $('add-language-overlay-language-list'); | 887 var languagesSelect = $('add-language-overlay-language-list'); |
887 var selectedIndex = languagesSelect.selectedIndex; | 888 var selectedIndex = languagesSelect.selectedIndex; |
888 if (selectedIndex >= 0) { | 889 if (selectedIndex >= 0) { |
889 var selection = languagesSelect.options[selectedIndex]; | 890 var selection = languagesSelect.options[selectedIndex]; |
890 var langCode = String(selection.value); | 891 var langCode = String(selection.value); |
891 $('language-options-list').addLanguage(langCode); | 892 $('language-options-list').addLanguage(langCode); |
892 this.addBlockedLanguage_(langCode); | 893 this.addBlockedLanguage_(langCode); |
893 OptionsPage.closeOverlay(); | 894 PageManager.closeOverlay(); |
894 } | 895 } |
895 }, | 896 }, |
896 | 897 |
897 /** | 898 /** |
898 * Checks if languageCode is deletable or not. | 899 * Checks if languageCode is deletable or not. |
899 * @param {string} languageCode the languageCode to check for deletability. | 900 * @param {string} languageCode the languageCode to check for deletability. |
900 */ | 901 */ |
901 languageIsDeletable: function(languageCode) { | 902 languageIsDeletable: function(languageCode) { |
902 // 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. |
903 if (languageCode == this.prospectiveUiLanguageCode_) | 904 if (languageCode == this.prospectiveUiLanguageCode_) |
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1355 | 1356 |
1356 LanguageOptions.onDictionaryDownloadFailure = function(languageCode) { | 1357 LanguageOptions.onDictionaryDownloadFailure = function(languageCode) { |
1357 LanguageOptions.getInstance().onDictionaryDownloadFailure_(languageCode); | 1358 LanguageOptions.getInstance().onDictionaryDownloadFailure_(languageCode); |
1358 }; | 1359 }; |
1359 | 1360 |
1360 // Export | 1361 // Export |
1361 return { | 1362 return { |
1362 LanguageOptions: LanguageOptions | 1363 LanguageOptions: LanguageOptions |
1363 }; | 1364 }; |
1364 }); | 1365 }); |
OLD | NEW |