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 Page = cr.ui.pageManager.Page; | 9 /** @const */ var Page = cr.ui.pageManager.Page; |
10 /** @const */ var PageManager = cr.ui.pageManager.PageManager; | 10 /** @const */ var PageManager = cr.ui.pageManager.PageManager; |
11 /** @const */ var LanguageList = options.LanguageList; | 11 /** @const */ var LanguageList = options.LanguageList; |
12 /** @const */ var ThirdPartyImeConfirmOverlay = | 12 /** @const */ var ThirdPartyImeConfirmOverlay = |
13 options.ThirdPartyImeConfirmOverlay; | 13 options.ThirdPartyImeConfirmOverlay; |
14 | 14 |
15 /** | 15 /** |
16 * Spell check dictionary download status. | 16 * Spell check dictionary download status. |
17 * @type {Enum} | 17 * @type {Enum} |
18 */ | 18 */ |
19 /** @const*/ var DOWNLOAD_STATUS = { | 19 /** @const*/ var DOWNLOAD_STATUS = {IN_PROGRESS: 1, FAILED: 2}; |
20 IN_PROGRESS: 1, | |
21 FAILED: 2 | |
22 }; | |
23 | 20 |
24 /** | 21 /** |
25 * The preference is a boolean that enables/disables spell checking. | 22 * The preference is a boolean that enables/disables spell checking. |
26 * @type {string} | 23 * @type {string} |
27 * @const | 24 * @const |
28 */ | 25 */ |
29 var ENABLE_SPELL_CHECK_PREF = 'browser.enable_spellchecking'; | 26 var ENABLE_SPELL_CHECK_PREF = 'browser.enable_spellchecking'; |
30 | 27 |
31 /** | 28 /** |
32 * The preference is a CSV string that describes preload engines | 29 * The preference is a CSV string that describes preload engines |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 | 72 |
76 ///////////////////////////////////////////////////////////////////////////// | 73 ///////////////////////////////////////////////////////////////////////////// |
77 // LanguageOptions class: | 74 // LanguageOptions class: |
78 | 75 |
79 /** | 76 /** |
80 * Encapsulated handling of ChromeOS language options page. | 77 * Encapsulated handling of ChromeOS language options page. |
81 * @constructor | 78 * @constructor |
82 * @extends {cr.ui.pageManager.Page} | 79 * @extends {cr.ui.pageManager.Page} |
83 */ | 80 */ |
84 function LanguageOptions(model) { | 81 function LanguageOptions(model) { |
85 Page.call(this, 'languages', | 82 Page.call( |
86 loadTimeData.getString('languagePageTabTitle'), 'languagePage'); | 83 this, 'languages', loadTimeData.getString('languagePageTabTitle'), |
| 84 'languagePage'); |
87 } | 85 } |
88 | 86 |
89 cr.addSingletonGetter(LanguageOptions); | 87 cr.addSingletonGetter(LanguageOptions); |
90 | 88 |
91 // Inherit LanguageOptions from Page. | 89 // Inherit LanguageOptions from Page. |
92 LanguageOptions.prototype = { | 90 LanguageOptions.prototype = { |
93 __proto__: Page.prototype, | 91 __proto__: Page.prototype, |
94 | 92 |
95 /** | 93 /** |
96 * For recording the prospective language (the next locale after relaunch). | 94 * For recording the prospective language (the next locale after relaunch). |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 */ | 163 */ |
166 enableTranslate_: false, | 164 enableTranslate_: false, |
167 | 165 |
168 /** @override */ | 166 /** @override */ |
169 initializePage: function() { | 167 initializePage: function() { |
170 Page.prototype.initializePage.call(this); | 168 Page.prototype.initializePage.call(this); |
171 | 169 |
172 var languageOptionsList = $('language-options-list'); | 170 var languageOptionsList = $('language-options-list'); |
173 LanguageList.decorate(languageOptionsList); | 171 LanguageList.decorate(languageOptionsList); |
174 | 172 |
175 languageOptionsList.addEventListener('change', | 173 languageOptionsList.addEventListener( |
176 this.handleLanguageOptionsListChange_.bind(this)); | 174 'change', this.handleLanguageOptionsListChange_.bind(this)); |
177 languageOptionsList.addEventListener('save', | 175 languageOptionsList.addEventListener( |
178 this.handleLanguageOptionsListSave_.bind(this)); | 176 'save', this.handleLanguageOptionsListSave_.bind(this)); |
179 | 177 |
180 this.prospectiveUiLanguageCode_ = | 178 this.prospectiveUiLanguageCode_ = |
181 loadTimeData.getString('prospectiveUiLanguageCode'); | 179 loadTimeData.getString('prospectiveUiLanguageCode'); |
182 this.addEventListener('visibleChange', | 180 this.addEventListener( |
183 this.handleVisibleChange_.bind(this)); | 181 'visibleChange', this.handleVisibleChange_.bind(this)); |
184 | 182 |
185 if (cr.isChromeOS) { | 183 if (cr.isChromeOS) { |
186 this.initializeInputMethodList_(); | 184 this.initializeInputMethodList_(); |
187 this.initializeLanguageCodeToInputMethodIdsMap_(); | 185 this.initializeLanguageCodeToInputMethodIdsMap_(); |
188 } | 186 } |
189 | 187 |
190 var checkbox = $('offer-to-translate-in-this-language'); | 188 var checkbox = $('offer-to-translate-in-this-language'); |
191 checkbox.addEventListener('click', | 189 checkbox.addEventListener( |
192 this.handleOfferToTranslateCheckboxClick_.bind(this)); | 190 'click', this.handleOfferToTranslateCheckboxClick_.bind(this)); |
193 | 191 |
194 Preferences.getInstance().addEventListener( | 192 Preferences.getInstance().addEventListener( |
195 TRANSLATE_BLOCKED_LANGUAGES_PREF, | 193 TRANSLATE_BLOCKED_LANGUAGES_PREF, |
196 this.handleTranslateBlockedLanguagesPrefChange_.bind(this)); | 194 this.handleTranslateBlockedLanguagesPrefChange_.bind(this)); |
197 Preferences.getInstance().addEventListener(SPELL_CHECK_DICTIONARIES_PREF, | 195 Preferences.getInstance().addEventListener( |
| 196 SPELL_CHECK_DICTIONARIES_PREF, |
198 this.handleSpellCheckDictionariesPrefChange_.bind(this)); | 197 this.handleSpellCheckDictionariesPrefChange_.bind(this)); |
199 Preferences.getInstance().addEventListener(ENABLE_TRANSLATE, | 198 Preferences.getInstance().addEventListener( |
200 this.handleEnableTranslatePrefChange_.bind(this)); | 199 ENABLE_TRANSLATE, this.handleEnableTranslatePrefChange_.bind(this)); |
201 this.translateSupportedLanguages_ = /** @type {Array} */( | 200 this.translateSupportedLanguages_ = /** @type {Array} */ ( |
202 loadTimeData.getValue('translateSupportedLanguages')); | 201 loadTimeData.getValue('translateSupportedLanguages')); |
203 | 202 |
204 // Set up add button. | 203 // Set up add button. |
205 var onclick = function(e) { | 204 var onclick = function(e) { |
206 // Add the language without showing the overlay if it's specified in | 205 // Add the language without showing the overlay if it's specified in |
207 // the URL hash (ex. lang_add=ja). Used for automated testing. | 206 // the URL hash (ex. lang_add=ja). Used for automated testing. |
208 var match = document.location.hash.match(/\blang_add=([\w-]+)/); | 207 var match = document.location.hash.match(/\blang_add=([\w-]+)/); |
209 if (match) { | 208 if (match) { |
210 var addLanguageCode = match[1]; | 209 var addLanguageCode = match[1]; |
211 $('language-options-list').addLanguage(addLanguageCode); | 210 $('language-options-list').addLanguage(addLanguageCode); |
212 this.addBlockedLanguage_(addLanguageCode); | 211 this.addBlockedLanguage_(addLanguageCode); |
213 } else { | 212 } else { |
214 PageManager.showPageByName('addLanguage'); | 213 PageManager.showPageByName('addLanguage'); |
215 chrome.send('coreOptionsUserMetricsAction', | 214 chrome.send( |
216 ['Options_Languages_Add']); | 215 'coreOptionsUserMetricsAction', ['Options_Languages_Add']); |
217 } | 216 } |
218 }; | 217 }; |
219 $('language-options-add-button').onclick = onclick.bind(this); | 218 $('language-options-add-button').onclick = onclick.bind(this); |
220 | 219 |
221 if (!cr.isMac) { | 220 if (!cr.isMac) { |
222 // Set up the button for editing custom spelling dictionary. | 221 // Set up the button for editing custom spelling dictionary. |
223 $('edit-custom-dictionary-button').onclick = function(e) { | 222 $('edit-custom-dictionary-button').onclick = function(e) { |
224 PageManager.showPageByName('editDictionary'); | 223 PageManager.showPageByName('editDictionary'); |
225 }; | 224 }; |
226 $('dictionary-download-retry-button').onclick = function(e) { | 225 $('dictionary-download-retry-button').onclick = function(e) { |
227 chrome.send('retryDictionaryDownload', | 226 chrome.send( |
228 [e.currentTarget.languageCode]); | 227 'retryDictionaryDownload', [e.currentTarget.languageCode]); |
229 }; | 228 }; |
230 } | 229 } |
231 | 230 |
232 // Listen to add language dialog ok button. | 231 // Listen to add language dialog ok button. |
233 $('add-language-overlay-ok-button').addEventListener( | 232 $('add-language-overlay-ok-button') |
234 'click', this.handleAddLanguageOkButtonClick_.bind(this)); | 233 .addEventListener( |
| 234 'click', this.handleAddLanguageOkButtonClick_.bind(this)); |
235 | 235 |
236 if (!(cr.isMac || cr.isChromeOS)) { | 236 if (!(cr.isMac || cr.isChromeOS)) { |
237 // Handle spell check enable/disable. | 237 // Handle spell check enable/disable. |
238 Preferences.getInstance().addEventListener( | 238 Preferences.getInstance().addEventListener( |
239 ENABLE_SPELL_CHECK_PREF, this.updateEnableSpellCheck_.bind(this)); | 239 ENABLE_SPELL_CHECK_PREF, this.updateEnableSpellCheck_.bind(this)); |
240 } | 240 } |
241 | 241 |
242 // Handle clicks on "Use this language for spell checking" button. | 242 // Handle clicks on "Use this language for spell checking" button. |
243 if (!cr.isMac) { | 243 if (!cr.isMac) { |
244 $('spellcheck-language-checkbox').addEventListener( | 244 $('spellcheck-language-checkbox') |
245 'change', | 245 .addEventListener( |
246 this.handleSpellCheckLanguageCheckboxClick_.bind(this)); | 246 'change', |
| 247 this.handleSpellCheckLanguageCheckboxClick_.bind(this)); |
247 } | 248 } |
248 | 249 |
249 if (cr.isChromeOS) { | 250 if (cr.isChromeOS) { |
250 $('language-options-ui-restart-button').onclick = function() { | 251 $('language-options-ui-restart-button').onclick = function() { |
251 chrome.send('uiLanguageRestart'); | 252 chrome.send('uiLanguageRestart'); |
252 }; | 253 }; |
253 } | 254 } |
254 | 255 |
255 $('language-confirm').onclick = | 256 $('language-confirm').onclick = |
256 PageManager.closeOverlay.bind(PageManager); | 257 PageManager.closeOverlay.bind(PageManager); |
257 | 258 |
258 // Public session users cannot change the locale. | 259 // Public session users cannot change the locale. |
259 if (cr.isChromeOS && UIAccountTweaks.loggedInAsPublicAccount()) | 260 if (cr.isChromeOS && UIAccountTweaks.loggedInAsPublicAccount()) |
260 $('language-options-ui-language-section').hidden = true; | 261 $('language-options-ui-language-section').hidden = true; |
261 | 262 |
262 // IME menu (CrOS only). | 263 // IME menu (CrOS only). |
263 if (cr.isChromeOS) { | 264 if (cr.isChromeOS) { |
264 // Show the 'activate-ime-menu' checkbox if the flag is tured on. | 265 // Show the 'activate-ime-menu' checkbox if the flag is tured on. |
265 if (loadTimeData.getBoolean('enableLanguageOptionsImeMenu')) | 266 if (loadTimeData.getBoolean('enableLanguageOptionsImeMenu')) |
266 $('language-options-ime-menu-template').hidden = false; | 267 $('language-options-ime-menu-template').hidden = false; |
267 | 268 |
268 // Updates the initial checked state of the check box. | 269 // Updates the initial checked state of the check box. |
269 Preferences.getInstance().addEventListener( | 270 Preferences.getInstance().addEventListener( |
270 ACTIVATE_IME_MENU_PREF, this.updateImeMenuCheckbox_.bind(this)); | 271 ACTIVATE_IME_MENU_PREF, this.updateImeMenuCheckbox_.bind(this)); |
271 | 272 |
272 // Listen to check on 'activate-ime-menu' checkbox. | 273 // Listen to check on 'activate-ime-menu' checkbox. |
273 var checkboxImeMenu = $('activate-ime-menu'); | 274 var checkboxImeMenu = $('activate-ime-menu'); |
274 checkboxImeMenu.addEventListener('click', | 275 checkboxImeMenu.addEventListener( |
275 this.handleActivateImeMenuCheckboxClick_.bind(this)); | 276 'click', this.handleActivateImeMenuCheckboxClick_.bind(this)); |
276 } | 277 } |
277 }, | 278 }, |
278 | 279 |
279 /** | 280 /** |
280 * Initializes the input method list. | 281 * Initializes the input method list. |
281 */ | 282 */ |
282 initializeInputMethodList_: function() { | 283 initializeInputMethodList_: function() { |
283 var inputMethodList = $('language-options-input-method-list'); | 284 var inputMethodList = $('language-options-input-method-list'); |
284 var inputMethodPrototype = $('language-options-input-method-template'); | 285 var inputMethodPrototype = $('language-options-input-method-template'); |
285 | 286 |
286 // Add all input methods, but make all of them invisible here. We'll | 287 // Add all input methods, but make all of them invisible here. We'll |
287 // change the visibility in handleLanguageOptionsListChange_() based | 288 // change the visibility in handleLanguageOptionsListChange_() based |
288 // on the selected language. Note that we only have less than 100 | 289 // on the selected language. Note that we only have less than 100 |
289 // input methods, so creating DOM nodes at once here should be ok. | 290 // input methods, so creating DOM nodes at once here should be ok. |
290 this.appendInputMethodElement_(/** @type {!Array} */( | 291 this.appendInputMethodElement_( |
291 loadTimeData.getValue('inputMethodList'))); | 292 /** @type {!Array} */ (loadTimeData.getValue('inputMethodList'))); |
292 this.appendComponentExtensionIme_(/** @type {!Array} */( | 293 this.appendComponentExtensionIme_(/** @type {!Array} */ ( |
293 loadTimeData.getValue('componentExtensionImeList'))); | 294 loadTimeData.getValue('componentExtensionImeList'))); |
294 this.appendInputMethodElement_(/** @type {!Array} */( | 295 this.appendInputMethodElement_( |
295 loadTimeData.getValue('extensionImeList'))); | 296 /** @type {!Array} */ (loadTimeData.getValue('extensionImeList'))); |
296 | 297 |
297 // Listen to pref change once the input method list is initialized. | 298 // Listen to pref change once the input method list is initialized. |
298 Preferences.getInstance().addEventListener( | 299 Preferences.getInstance().addEventListener( |
299 PRELOAD_ENGINES_PREF, | 300 PRELOAD_ENGINES_PREF, |
300 this.handlePreloadEnginesPrefChange_.bind(this)); | 301 this.handlePreloadEnginesPrefChange_.bind(this)); |
301 Preferences.getInstance().addEventListener( | 302 Preferences.getInstance().addEventListener( |
302 ENABLED_EXTENSION_IME_PREF, | 303 ENABLED_EXTENSION_IME_PREF, |
303 this.handleEnabledExtensionsPrefChange_.bind(this)); | 304 this.handleEnabledExtensionsPrefChange_.bind(this)); |
304 }, | 305 }, |
305 | 306 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 var button = document.createElement('button'); | 352 var button = document.createElement('button'); |
352 button.textContent = loadTimeData.getString('configure'); | 353 button.textContent = loadTimeData.getString('configure'); |
353 button.inputMethodId = inputMethod.id; | 354 button.inputMethodId = inputMethod.id; |
354 button.onclick = function(inputMethodId, e) { | 355 button.onclick = function(inputMethodId, e) { |
355 chrome.send('inputMethodOptionsOpen', [inputMethodId]); | 356 chrome.send('inputMethodOptionsOpen', [inputMethodId]); |
356 }.bind(this, inputMethod.id); | 357 }.bind(this, inputMethod.id); |
357 element.appendChild(button); | 358 element.appendChild(button); |
358 } | 359 } |
359 | 360 |
360 // Listen to user clicks. | 361 // Listen to user clicks. |
361 input.addEventListener('click', | 362 input.addEventListener('click', this.handleCheckboxClick_.bind(this)); |
362 this.handleCheckboxClick_.bind(this)); | |
363 inputMethodList.appendChild(element); | 363 inputMethodList.appendChild(element); |
364 } | 364 } |
365 }, | 365 }, |
366 | 366 |
367 /** | 367 /** |
368 * Adds a language to the preference 'translate_blocked_languages'. If | 368 * Adds a language to the preference 'translate_blocked_languages'. If |
369 * |langCode| is already added, nothing happens. |langCode| is converted | 369 * |langCode| is already added, nothing happens. |langCode| is converted |
370 * to a Translate language synonym before added. | 370 * to a Translate language synonym before added. |
371 * @param {string} langCode A language code like 'en' | 371 * @param {string} langCode A language code like 'en' |
372 * @private | 372 * @private |
373 */ | 373 */ |
374 addBlockedLanguage_: function(langCode) { | 374 addBlockedLanguage_: function(langCode) { |
375 langCode = this.convertLangCodeForTranslation_(langCode); | 375 langCode = this.convertLangCodeForTranslation_(langCode); |
376 if (this.translateBlockedLanguages_.indexOf(langCode) == -1) { | 376 if (this.translateBlockedLanguages_.indexOf(langCode) == -1) { |
377 this.translateBlockedLanguages_.push(langCode); | 377 this.translateBlockedLanguages_.push(langCode); |
378 Preferences.setListPref(TRANSLATE_BLOCKED_LANGUAGES_PREF, | 378 Preferences.setListPref( |
379 this.translateBlockedLanguages_, true); | 379 TRANSLATE_BLOCKED_LANGUAGES_PREF, this.translateBlockedLanguages_, |
| 380 true); |
380 } | 381 } |
381 }, | 382 }, |
382 | 383 |
383 /** | 384 /** |
384 * Removes a language from the preference 'translate_blocked_languages'. | 385 * Removes a language from the preference 'translate_blocked_languages'. |
385 * If |langCode| doesn't exist in the preference, nothing happens. | 386 * If |langCode| doesn't exist in the preference, nothing happens. |
386 * |langCode| is converted to a Translate language synonym before removed. | 387 * |langCode| is converted to a Translate language synonym before removed. |
387 * @param {string} langCode A language code like 'en' | 388 * @param {string} langCode A language code like 'en' |
388 * @private | 389 * @private |
389 */ | 390 */ |
390 removeBlockedLanguage_: function(langCode) { | 391 removeBlockedLanguage_: function(langCode) { |
391 langCode = this.convertLangCodeForTranslation_(langCode); | 392 langCode = this.convertLangCodeForTranslation_(langCode); |
392 if (this.translateBlockedLanguages_.indexOf(langCode) != -1) { | 393 if (this.translateBlockedLanguages_.indexOf(langCode) != -1) { |
393 this.translateBlockedLanguages_ = | 394 this.translateBlockedLanguages_ = |
394 this.translateBlockedLanguages_.filter( | 395 this.translateBlockedLanguages_.filter(function( |
395 function(langCodeNotTranslated) { | 396 langCodeNotTranslated) { |
396 return langCodeNotTranslated != langCode; | 397 return langCodeNotTranslated != langCode; |
397 }); | 398 }); |
398 Preferences.setListPref(TRANSLATE_BLOCKED_LANGUAGES_PREF, | 399 Preferences.setListPref( |
399 this.translateBlockedLanguages_, true); | 400 TRANSLATE_BLOCKED_LANGUAGES_PREF, this.translateBlockedLanguages_, |
| 401 true); |
400 } | 402 } |
401 }, | 403 }, |
402 | 404 |
403 /** | 405 /** |
404 * Handles Page's visible property change event. | 406 * Handles Page's visible property change event. |
405 * @param {Event} e Property change event. | 407 * @param {Event} e Property change event. |
406 * @private | 408 * @private |
407 */ | 409 */ |
408 handleVisibleChange_: function(e) { | 410 handleVisibleChange_: function(e) { |
409 if (this.visible) { | 411 if (this.visible) { |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
486 // Convert the list into a dictonary for simpler lookup. | 488 // Convert the list into a dictonary for simpler lookup. |
487 var preloadEngineSet = {}; | 489 var preloadEngineSet = {}; |
488 for (var i = 0; i < preloadEngines.length; i++) { | 490 for (var i = 0; i < preloadEngines.length; i++) { |
489 preloadEngineSet[preloadEngines[i]] = true; | 491 preloadEngineSet[preloadEngines[i]] = true; |
490 } | 492 } |
491 | 493 |
492 // Create the new preload engine list per the language codes. | 494 // Create the new preload engine list per the language codes. |
493 var newPreloadEngines = []; | 495 var newPreloadEngines = []; |
494 for (var i = 0; i < languageCodes.length; i++) { | 496 for (var i = 0; i < languageCodes.length; i++) { |
495 var languageCode = languageCodes[i]; | 497 var languageCode = languageCodes[i]; |
496 var inputMethodIds = this.languageCodeToInputMethodIdsMap_[ | 498 var inputMethodIds = |
497 languageCode]; | 499 this.languageCodeToInputMethodIdsMap_[languageCode]; |
498 if (!inputMethodIds) | 500 if (!inputMethodIds) |
499 continue; | 501 continue; |
500 | 502 |
501 // Check if we have active input methods associated with the language. | 503 // Check if we have active input methods associated with the language. |
502 for (var j = 0; j < inputMethodIds.length; j++) { | 504 for (var j = 0; j < inputMethodIds.length; j++) { |
503 var inputMethodId = inputMethodIds[j]; | 505 var inputMethodId = inputMethodIds[j]; |
504 if (inputMethodId in preloadEngineSet) { | 506 if (inputMethodId in preloadEngineSet) { |
505 // If we have, add it to the new engine list. | 507 // If we have, add it to the new engine list. |
506 newPreloadEngines.push(inputMethodId); | 508 newPreloadEngines.push(inputMethodId); |
507 // And delete it from the set. This is necessary as one input | 509 // And delete it from the set. This is necessary as one input |
(...skipping 26 matching lines...) Expand all Loading... |
534 } | 536 } |
535 } | 537 } |
536 }, | 538 }, |
537 | 539 |
538 /** | 540 /** |
539 * Updates the currently selected language name. | 541 * Updates the currently selected language name. |
540 * @param {string} languageCode Language code (ex. "fr"). | 542 * @param {string} languageCode Language code (ex. "fr"). |
541 * @private | 543 * @private |
542 */ | 544 */ |
543 updateSelectedLanguageName_: function(languageCode) { | 545 updateSelectedLanguageName_: function(languageCode) { |
544 var languageInfo = LanguageList.getLanguageInfoFromLanguageCode( | 546 var languageInfo = |
545 languageCode); | 547 LanguageList.getLanguageInfoFromLanguageCode(languageCode); |
546 var languageDisplayName = languageInfo.displayName; | 548 var languageDisplayName = languageInfo.displayName; |
547 var languageNativeDisplayName = languageInfo.nativeDisplayName; | 549 var languageNativeDisplayName = languageInfo.nativeDisplayName; |
548 var textDirection = languageInfo.textDirection; | 550 var textDirection = languageInfo.textDirection; |
549 | 551 |
550 // If the native name is different, add it. | 552 // If the native name is different, add it. |
551 if (languageDisplayName != languageNativeDisplayName) { | 553 if (languageDisplayName != languageNativeDisplayName) { |
552 languageDisplayName += ' - ' + languageNativeDisplayName; | 554 languageDisplayName += ' - ' + languageNativeDisplayName; |
553 } | 555 } |
554 | 556 |
555 // Update the currently selected language name. | 557 // Update the currently selected language name. |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
668 [spellCheckLanguageSection, dictionaryDownloadFailed], 1); | 670 [spellCheckLanguageSection, dictionaryDownloadFailed], 1); |
669 if (this.spellcheckDictionaryDownloadFailures_ > 1) | 671 if (this.spellcheckDictionaryDownloadFailures_ > 1) |
670 dictionaryDownloadFailHelp.hidden = false; | 672 dictionaryDownloadFailHelp.hidden = false; |
671 $('dictionary-download-retry-button').languageCode = languageCode; | 673 $('dictionary-download-retry-button').languageCode = languageCode; |
672 break; | 674 break; |
673 } | 675 } |
674 | 676 |
675 var areNoLanguagesSelected = | 677 var areNoLanguagesSelected = |
676 Object.keys(this.spellCheckLanguages_).length == 0; | 678 Object.keys(this.spellCheckLanguages_).length == 0; |
677 var usesSystemSpellchecker = !$('enable-spellcheck-container'); | 679 var usesSystemSpellchecker = !$('enable-spellcheck-container'); |
678 var isSpellcheckingEnabled = usesSystemSpellchecker || | 680 var isSpellcheckingEnabled = |
679 $('enable-spellcheck').checked; | 681 usesSystemSpellchecker || $('enable-spellcheck').checked; |
680 $('edit-custom-dictionary-button').hidden = | 682 $('edit-custom-dictionary-button').hidden = |
681 areNoLanguagesSelected || !isSpellcheckingEnabled; | 683 areNoLanguagesSelected || !isSpellcheckingEnabled; |
682 }, | 684 }, |
683 | 685 |
684 /** | 686 /** |
685 * Updates the checkbox for stopping translation. | 687 * Updates the checkbox for stopping translation. |
686 * @param {string} languageCode Language code (ex. "fr"). | 688 * @param {string} languageCode Language code (ex. "fr"). |
687 * @private | 689 * @private |
688 */ | 690 */ |
689 updateOfferToTranslateCheckbox_: function(languageCode) { | 691 updateOfferToTranslateCheckbox_: function(languageCode) { |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
852 * Handles input method checkbox's click event. | 854 * Handles input method checkbox's click event. |
853 * @param {Event} e Click event. | 855 * @param {Event} e Click event. |
854 * @private | 856 * @private |
855 */ | 857 */ |
856 handleCheckboxClick_: function(e) { | 858 handleCheckboxClick_: function(e) { |
857 var checkbox = assertInstanceof(e.target, Element); | 859 var checkbox = assertInstanceof(e.target, Element); |
858 | 860 |
859 // Third party IMEs require additional confirmation prior to enabling due | 861 // Third party IMEs require additional confirmation prior to enabling due |
860 // to privacy risk. | 862 // to privacy risk. |
861 if (/^_ext_ime_/.test(checkbox.inputMethodId) && checkbox.checked) { | 863 if (/^_ext_ime_/.test(checkbox.inputMethodId) && checkbox.checked) { |
862 var confirmationCallback = this.handleCheckboxUpdate_.bind(this, | 864 var confirmationCallback = |
863 checkbox); | 865 this.handleCheckboxUpdate_.bind(this, checkbox); |
864 var cancellationCallback = function() { | 866 var cancellationCallback = function() { |
865 checkbox.checked = false; | 867 checkbox.checked = false; |
866 }; | 868 }; |
867 ThirdPartyImeConfirmOverlay.showConfirmationDialog({ | 869 ThirdPartyImeConfirmOverlay.showConfirmationDialog({ |
868 extension: checkbox.imeProvider, | 870 extension: checkbox.imeProvider, |
869 confirm: confirmationCallback, | 871 confirm: confirmationCallback, |
870 cancel: cancellationCallback | 872 cancel: cancellationCallback |
871 }); | 873 }); |
872 } else { | 874 } else { |
873 this.handleCheckboxUpdate_(checkbox); | 875 this.handleCheckboxUpdate_(checkbox); |
874 } | 876 } |
875 | 877 |
876 chrome.send('coreOptionsUserMetricsAction', | 878 chrome.send( |
877 ['Options_Languages_InputMethodCheckbox' + | 879 'coreOptionsUserMetricsAction', |
878 (checkbox.checked ? '_Enable' : '_Disable')]); | 880 ['Options_Languages_InputMethodCheckbox' + |
| 881 (checkbox.checked ? '_Enable' : '_Disable')]); |
879 }, | 882 }, |
880 | 883 |
881 /** | 884 /** |
882 * Updates active IMEs based on change in state of a checkbox for an input | 885 * Updates active IMEs based on change in state of a checkbox for an input |
883 * method. | 886 * method. |
884 * @param {!Element} checkbox Updated checkbox element. | 887 * @param {!Element} checkbox Updated checkbox element. |
885 * @private | 888 * @private |
886 */ | 889 */ |
887 handleCheckboxUpdate_: function(checkbox) { | 890 handleCheckboxUpdate_: function(checkbox) { |
888 if (checkbox.inputMethodId.match(/^_ext_ime_/)) { | 891 if (checkbox.inputMethodId.match(/^_ext_ime_/)) { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
926 }, | 929 }, |
927 | 930 |
928 /** | 931 /** |
929 * Checks if languageCode is deletable or not. | 932 * Checks if languageCode is deletable or not. |
930 * @param {string} languageCode the languageCode to check for deletability. | 933 * @param {string} languageCode the languageCode to check for deletability. |
931 */ | 934 */ |
932 languageIsDeletable: function(languageCode) { | 935 languageIsDeletable: function(languageCode) { |
933 // Don't allow removing the language if it's a UI language. | 936 // Don't allow removing the language if it's a UI language. |
934 if (languageCode == this.prospectiveUiLanguageCode_) | 937 if (languageCode == this.prospectiveUiLanguageCode_) |
935 return false; | 938 return false; |
936 return (!cr.isChromeOS || | 939 return (!cr.isChromeOS || this.canDeleteLanguage_(languageCode)); |
937 this.canDeleteLanguage_(languageCode)); | |
938 }, | 940 }, |
939 | 941 |
940 /** | 942 /** |
941 * Handles browser.enable_spellchecking change. | 943 * Handles browser.enable_spellchecking change. |
942 * @param {Event} e Change event. | 944 * @param {Event} e Change event. |
943 * @private | 945 * @private |
944 */ | 946 */ |
945 updateEnableSpellCheck_: function(e) { | 947 updateEnableSpellCheck_: function(e) { |
946 var value = !$('enable-spellcheck').checked; | 948 var value = !$('enable-spellcheck').checked; |
947 var languageControl = $('spellcheck-language-checkbox'); | 949 var languageControl = $('spellcheck-language-checkbox'); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1002 */ | 1004 */ |
1003 handleSpellCheckLanguageCheckboxClick_: function(e) { | 1005 handleSpellCheckLanguageCheckboxClick_: function(e) { |
1004 var languageCode = e.currentTarget.languageCode; | 1006 var languageCode = e.currentTarget.languageCode; |
1005 | 1007 |
1006 if (e.currentTarget.checked) | 1008 if (e.currentTarget.checked) |
1007 this.spellCheckLanguages_[languageCode] = true; | 1009 this.spellCheckLanguages_[languageCode] = true; |
1008 else | 1010 else |
1009 delete this.spellCheckLanguages_[languageCode]; | 1011 delete this.spellCheckLanguages_[languageCode]; |
1010 | 1012 |
1011 var languageCodes = Object.keys(this.spellCheckLanguages_); | 1013 var languageCodes = Object.keys(this.spellCheckLanguages_); |
1012 Preferences.setListPref(SPELL_CHECK_DICTIONARIES_PREF, | 1014 Preferences.setListPref( |
1013 languageCodes, true); | 1015 SPELL_CHECK_DICTIONARIES_PREF, languageCodes, true); |
1014 | 1016 |
1015 // The spellCheckLanguageChange argument is only used for logging. | 1017 // The spellCheckLanguageChange argument is only used for logging. |
1016 chrome.send('spellCheckLanguageChange', [languageCodes.join(',')]); | 1018 chrome.send('spellCheckLanguageChange', [languageCodes.join(',')]); |
1017 chrome.send('coreOptionsUserMetricsAction', | 1019 chrome.send( |
1018 ['Options_Languages_SpellCheck']); | 1020 'coreOptionsUserMetricsAction', ['Options_Languages_SpellCheck']); |
1019 }, | 1021 }, |
1020 | 1022 |
1021 /** | 1023 /** |
1022 * Checks whether it's possible to remove the language specified by | 1024 * Checks whether it's possible to remove the language specified by |
1023 * languageCode and returns true if possible. This function returns false | 1025 * languageCode and returns true if possible. This function returns false |
1024 * if the removal causes the number of preload engines to be zero. | 1026 * if the removal causes the number of preload engines to be zero. |
1025 * | 1027 * |
1026 * @param {string} languageCode Language code (ex. "fr"). | 1028 * @param {string} languageCode Language code (ex. "fr"). |
1027 * @return {boolean} Returns true on success. | 1029 * @return {boolean} Returns true on success. |
1028 * @private | 1030 * @private |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1075 // Don't allow this operation if it causes the number of preload | 1077 // Don't allow this operation if it causes the number of preload |
1076 // engines to be zero. | 1078 // engines to be zero. |
1077 return (newPreloadEngines.length > 0); | 1079 return (newPreloadEngines.length > 0); |
1078 }, | 1080 }, |
1079 | 1081 |
1080 /** | 1082 /** |
1081 * Saves the enabled extension preference. | 1083 * Saves the enabled extension preference. |
1082 * @private | 1084 * @private |
1083 */ | 1085 */ |
1084 saveEnabledExtensionPref_: function() { | 1086 saveEnabledExtensionPref_: function() { |
1085 Preferences.setStringPref(ENABLED_EXTENSION_IME_PREF, | 1087 Preferences.setStringPref( |
1086 this.enabledExtensionImes_.join(','), true); | 1088 ENABLED_EXTENSION_IME_PREF, this.enabledExtensionImes_.join(','), |
| 1089 true); |
1087 }, | 1090 }, |
1088 | 1091 |
1089 /** | 1092 /** |
1090 * Updates the checkboxes in the input method list from the enabled | 1093 * Updates the checkboxes in the input method list from the enabled |
1091 * extensions preference. | 1094 * extensions preference. |
1092 * @private | 1095 * @private |
1093 */ | 1096 */ |
1094 updateCheckboxesFromEnabledExtensions_: function() { | 1097 updateCheckboxesFromEnabledExtensions_: function() { |
1095 // Convert the list into a dictonary for simpler lookup. | 1098 // Convert the list into a dictonary for simpler lookup. |
1096 var dictionary = {}; | 1099 var dictionary = {}; |
(...skipping 30 matching lines...) Expand all Loading... |
1127 this.enabledExtensionImes_.push(checkboxes[i].inputMethodId); | 1130 this.enabledExtensionImes_.push(checkboxes[i].inputMethodId); |
1128 } | 1131 } |
1129 } | 1132 } |
1130 }, | 1133 }, |
1131 | 1134 |
1132 /** | 1135 /** |
1133 * Saves the preload engines preference. | 1136 * Saves the preload engines preference. |
1134 * @private | 1137 * @private |
1135 */ | 1138 */ |
1136 savePreloadEnginesPref_: function() { | 1139 savePreloadEnginesPref_: function() { |
1137 Preferences.setStringPref(PRELOAD_ENGINES_PREF, | 1140 Preferences.setStringPref( |
1138 this.preloadEngines_.join(','), true); | 1141 PRELOAD_ENGINES_PREF, this.preloadEngines_.join(','), true); |
1139 }, | 1142 }, |
1140 | 1143 |
1141 /** | 1144 /** |
1142 * Updates the checkboxes in the input method list from the preload | 1145 * Updates the checkboxes in the input method list from the preload |
1143 * engines preference. | 1146 * engines preference. |
1144 * @private | 1147 * @private |
1145 */ | 1148 */ |
1146 updateCheckboxesFromPreloadEngines_: function() { | 1149 updateCheckboxesFromPreloadEngines_: function() { |
1147 // Convert the list into a dictonary for simpler lookup. | 1150 // Convert the list into a dictonary for simpler lookup. |
1148 var dictionary = {}; | 1151 var dictionary = {}; |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1293 // Special case for when a user changes to a different language, and | 1296 // Special case for when a user changes to a different language, and |
1294 // changes back to the same language without having restarted Chrome or | 1297 // changes back to the same language without having restarted Chrome or |
1295 // logged in/out of ChromeOS. | 1298 // logged in/out of ChromeOS. |
1296 if (languageCode == loadTimeData.getString('currentUiLanguageCode')) { | 1299 if (languageCode == loadTimeData.getString('currentUiLanguageCode')) { |
1297 this.updateUiLanguageButton_(languageCode); | 1300 this.updateUiLanguageButton_(languageCode); |
1298 return; | 1301 return; |
1299 } | 1302 } |
1300 | 1303 |
1301 // Otherwise, show a notification telling the user that their changes will | 1304 // Otherwise, show a notification telling the user that their changes will |
1302 // only take effect after restart. | 1305 // only take effect after restart. |
1303 showMutuallyExclusiveNodes([$('language-options-ui-language-button'), | 1306 showMutuallyExclusiveNodes( |
1304 $('language-options-ui-notification-bar')], | 1307 [ |
1305 1); | 1308 $('language-options-ui-language-button'), |
| 1309 $('language-options-ui-notification-bar') |
| 1310 ], |
| 1311 1); |
1306 }, | 1312 }, |
1307 | 1313 |
1308 /** | 1314 /** |
1309 * A handler for when dictionary for |languageCode| begins downloading. | 1315 * A handler for when dictionary for |languageCode| begins downloading. |
1310 * @param {string} languageCode The language of the dictionary that just | 1316 * @param {string} languageCode The language of the dictionary that just |
1311 * began downloading. | 1317 * began downloading. |
1312 * @private | 1318 * @private |
1313 */ | 1319 */ |
1314 onDictionaryDownloadBegin_: function(languageCode) { | 1320 onDictionaryDownloadBegin_: function(languageCode) { |
1315 this.spellcheckDictionaryDownloadStatus_[languageCode] = | 1321 this.spellcheckDictionaryDownloadStatus_[languageCode] = |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1388 }, | 1394 }, |
1389 | 1395 |
1390 /** | 1396 /** |
1391 * Handles activate-ime-menu checkbox's click event. | 1397 * Handles activate-ime-menu checkbox's click event. |
1392 * @param {Event} e Click event. | 1398 * @param {Event} e Click event. |
1393 * @private | 1399 * @private |
1394 */ | 1400 */ |
1395 handleActivateImeMenuCheckboxClick_: function(e) { | 1401 handleActivateImeMenuCheckboxClick_: function(e) { |
1396 if (cr.isChromeOS) { | 1402 if (cr.isChromeOS) { |
1397 var checkbox = e.target; | 1403 var checkbox = e.target; |
1398 Preferences.setBooleanPref(ACTIVATE_IME_MENU_PREF, | 1404 Preferences.setBooleanPref( |
1399 checkbox.checked, true); | 1405 ACTIVATE_IME_MENU_PREF, checkbox.checked, true); |
1400 } | 1406 } |
1401 }, | 1407 }, |
1402 | 1408 |
1403 /** | 1409 /** |
1404 * Updates the activate-ime-menu check box's checked state. | 1410 * Updates the activate-ime-menu check box's checked state. |
1405 * @param {Event} e Change event. | 1411 * @param {Event} e Change event. |
1406 * @private | 1412 * @private |
1407 */ | 1413 */ |
1408 updateImeMenuCheckbox_: function(e) { | 1414 updateImeMenuCheckbox_: function(e) { |
1409 $('activate-ime-menu').checked = e.value.value; | 1415 $('activate-ime-menu').checked = e.value.value; |
(...skipping 23 matching lines...) Expand all Loading... |
1433 | 1439 |
1434 LanguageOptions.onDictionaryDownloadSuccess = function(languageCode) { | 1440 LanguageOptions.onDictionaryDownloadSuccess = function(languageCode) { |
1435 LanguageOptions.getInstance().onDictionaryDownloadSuccess_(languageCode); | 1441 LanguageOptions.getInstance().onDictionaryDownloadSuccess_(languageCode); |
1436 }; | 1442 }; |
1437 | 1443 |
1438 LanguageOptions.onDictionaryDownloadFailure = function(languageCode) { | 1444 LanguageOptions.onDictionaryDownloadFailure = function(languageCode) { |
1439 LanguageOptions.getInstance().onDictionaryDownloadFailure_(languageCode); | 1445 LanguageOptions.getInstance().onDictionaryDownloadFailure_(languageCode); |
1440 }; | 1446 }; |
1441 | 1447 |
1442 // Export | 1448 // Export |
1443 return { | 1449 return {LanguageOptions: LanguageOptions}; |
1444 LanguageOptions: LanguageOptions | |
1445 }; | |
1446 }); | 1450 }); |
OLD | NEW |