Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(84)

Side by Side Diff: chrome/browser/resources/options/language_options.js

Issue 1523593002: Add an option in language settings for activating the IME menu. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add enable-ime-menu flag Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 */ 59 */
60 var SPELL_CHECK_DICTIONARIES_PREF = 'spellcheck.dictionaries'; 60 var SPELL_CHECK_DICTIONARIES_PREF = 'spellcheck.dictionaries';
61 61
62 /** 62 /**
63 * The preference that indicates if the Translate feature is enabled. 63 * The preference that indicates if the Translate feature is enabled.
64 * @type {string} 64 * @type {string}
65 * @const 65 * @const
66 */ 66 */
67 var ENABLE_TRANSLATE = 'translate.enabled'; 67 var ENABLE_TRANSLATE = 'translate.enabled';
68 68
69 /**
70 * The preference is a boolean indicates whether the 'enable-ime-menu' flag is
71 * enabled or disabled
72 * @type {string}
73 * @const
74 */
75 var ENABLE_IME_MENU_FLAG_PREF = 'settings.language.ime_menu_flag_enabled';
michaelpg 2016/01/04 16:37:36 i think we usually set flag info via loadTimeData
stevenjb 2016/01/04 17:58:10 Correct, e.g. see enableTimeZoneTrackingOption
Azure Wei 2016/01/05 06:48:03 Done.
Azure Wei 2016/01/05 06:48:03 Done.
76
77 /**
78 * The preference is a boolean that activates/deactivates IME menu on shelf.
79 * @type {string}
80 * @const
81 */
82 var ACTIVATE_IME_MENU_PREF = 'settings.language.ime_menu_activated';
83
69 ///////////////////////////////////////////////////////////////////////////// 84 /////////////////////////////////////////////////////////////////////////////
70 // LanguageOptions class: 85 // LanguageOptions class:
71 86
72 /** 87 /**
73 * Encapsulated handling of ChromeOS language options page. 88 * Encapsulated handling of ChromeOS language options page.
74 * @constructor 89 * @constructor
75 * @extends {cr.ui.pageManager.Page} 90 * @extends {cr.ui.pageManager.Page}
76 */ 91 */
77 function LanguageOptions(model) { 92 function LanguageOptions(model) {
78 Page.call(this, 'languages', 93 Page.call(this, 'languages',
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 210
196 Preferences.getInstance().addEventListener( 211 Preferences.getInstance().addEventListener(
197 TRANSLATE_BLOCKED_LANGUAGES_PREF, 212 TRANSLATE_BLOCKED_LANGUAGES_PREF,
198 this.handleTranslateBlockedLanguagesPrefChange_.bind(this)); 213 this.handleTranslateBlockedLanguagesPrefChange_.bind(this));
199 Preferences.getInstance().addEventListener(SPELL_CHECK_DICTIONARIES_PREF, 214 Preferences.getInstance().addEventListener(SPELL_CHECK_DICTIONARIES_PREF,
200 this.handleSpellCheckDictionariesPrefChange_.bind(this)); 215 this.handleSpellCheckDictionariesPrefChange_.bind(this));
201 Preferences.getInstance().addEventListener(ENABLE_TRANSLATE, 216 Preferences.getInstance().addEventListener(ENABLE_TRANSLATE,
202 this.handleEnableTranslatePrefChange_.bind(this)); 217 this.handleEnableTranslatePrefChange_.bind(this));
203 this.translateSupportedLanguages_ = 218 this.translateSupportedLanguages_ =
204 loadTimeData.getValue('translateSupportedLanguages'); 219 loadTimeData.getValue('translateSupportedLanguages');
220 Preferences.getInstance().addEventListener(ENABLE_IME_MENU_FLAG_PREF,
221 this.handleEnableImeMenuFlagPrefChange_.bind(this));
stevenjb 2016/01/04 17:58:10 Flags can not be changed at runtime so this is unn
Azure Wei 2016/01/05 06:48:03 It was replaced with loadTimeData.
205 222
206 // Set up add button. 223 // Set up add button.
207 var onclick = function(e) { 224 var onclick = function(e) {
208 // Add the language without showing the overlay if it's specified in 225 // Add the language without showing the overlay if it's specified in
209 // the URL hash (ex. lang_add=ja). Used for automated testing. 226 // the URL hash (ex. lang_add=ja). Used for automated testing.
210 var match = document.location.hash.match(/\blang_add=([\w-]+)/); 227 var match = document.location.hash.match(/\blang_add=([\w-]+)/);
211 if (match) { 228 if (match) {
212 var addLanguageCode = match[1]; 229 var addLanguageCode = match[1];
213 $('language-options-list').addLanguage(addLanguageCode); 230 $('language-options-list').addLanguage(addLanguageCode);
214 this.addBlockedLanguage_(addLanguageCode); 231 this.addBlockedLanguage_(addLanguageCode);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 chrome.send('uiLanguageRestart'); 280 chrome.send('uiLanguageRestart');
264 }; 281 };
265 } 282 }
266 283
267 $('language-confirm').onclick = 284 $('language-confirm').onclick =
268 PageManager.closeOverlay.bind(PageManager); 285 PageManager.closeOverlay.bind(PageManager);
269 286
270 // Public session users cannot change the locale. 287 // Public session users cannot change the locale.
271 if (cr.isChromeOS && UIAccountTweaks.loggedInAsPublicAccount()) 288 if (cr.isChromeOS && UIAccountTweaks.loggedInAsPublicAccount())
272 $('language-options-ui-language-section').hidden = true; 289 $('language-options-ui-language-section').hidden = true;
290
291 // Listen to check on 'activate-ime-menu' checkbox
292 var checkboxImeMenu = $('activate-ime-menu');
293 checkboxImeMenu.addEventListener('click',
294 this.handleActivateImeMenuCheckboxClick_.bind(this));
273 }, 295 },
274 296
275 /** 297 /**
276 * Initializes the input method list. 298 * Initializes the input method list.
277 */ 299 */
278 initializeInputMethodList_: function() { 300 initializeInputMethodList_: function() {
279 var inputMethodList = $('language-options-input-method-list'); 301 var inputMethodList = $('language-options-input-method-list');
280 var inputMethodPrototype = $('language-options-input-method-template'); 302 var inputMethodPrototype = $('language-options-input-method-template');
281 303
282 // Add all input methods, but make all of them invisible here. We'll 304 // Add all input methods, but make all of them invisible here. We'll
(...skipping 717 matching lines...) Expand 10 before | Expand all | Expand 10 after
1000 * @private 1022 * @private
1001 */ 1023 */
1002 handleEnableTranslatePrefChange_: function(e) { 1024 handleEnableTranslatePrefChange_: function(e) {
1003 var enabled = e.value.value; 1025 var enabled = e.value.value;
1004 this.enableTranslate_ = enabled; 1026 this.enableTranslate_ = enabled;
1005 this.updateOfferToTranslateCheckbox_( 1027 this.updateOfferToTranslateCheckbox_(
1006 $('language-options-list').getSelectedLanguageCode()); 1028 $('language-options-list').getSelectedLanguageCode());
1007 }, 1029 },
1008 1030
1009 /** 1031 /**
1032 * Handles enable-ime-menu change.
1033 * @param {Event} e Change event.
1034 * @private
1035 */
1036 handleEnableImeMenuFlagPrefChange_: function(e) {
1037 $('language-options-ime-menu-template').hidden = !e.value.value;
1038 },
1039
1040
michaelpg 2016/01/04 16:37:36 remove extra newline
Azure Wei 2016/01/05 06:48:03 Done.
1041 /**
1010 * Handles spellCheckLanguageButton click. 1042 * Handles spellCheckLanguageButton click.
1011 * @param {Event} e Click event. 1043 * @param {Event} e Click event.
1012 * @private 1044 * @private
1013 */ 1045 */
1014 handleSpellCheckLanguageButtonClick_: function(e) { 1046 handleSpellCheckLanguageButtonClick_: function(e) {
1015 var languageCode = e.currentTarget.languageCode; 1047 var languageCode = e.currentTarget.languageCode;
1016 // Save the preference. 1048 // Save the preference.
1017 Preferences.setListPref(SPELL_CHECK_DICTIONARIES_PREF, 1049 Preferences.setListPref(SPELL_CHECK_DICTIONARIES_PREF,
1018 [languageCode], true); 1050 [languageCode], true);
1019 1051
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after
1409 if (main in synonyms) { 1441 if (main in synonyms) {
1410 return synonyms[main]; 1442 return synonyms[main];
1411 } else if (main == 'zh') { 1443 } else if (main == 'zh') {
1412 // In Translation, general Chinese is not used, and the sub code is 1444 // In Translation, general Chinese is not used, and the sub code is
1413 // necessary as a language code for Translate server. 1445 // necessary as a language code for Translate server.
1414 return languageCode; 1446 return languageCode;
1415 } 1447 }
1416 1448
1417 return main; 1449 return main;
1418 }, 1450 },
1451
1452 /**
1453 * Handles activate-ime-menu checkbox's click event.
1454 * @param {Event} e Click event.
1455 * @private
1456 */
1457 handleActivateImeMenuCheckboxClick_: function(e) {
1458 var checkbox = e.target;
1459 Preferences.setBooleanPref(ACTIVATE_IME_MENU_PREF,
1460 checkbox.checked, true);
michaelpg 2016/01/04 16:37:36 indent off by 1
Azure Wei 2016/01/05 06:48:03 Done.
1461 },
1419 }; 1462 };
1420 1463
1421 /** 1464 /**
1422 * Shows the node at |index| in |nodes|, hides all others. 1465 * Shows the node at |index| in |nodes|, hides all others.
1423 * @param {Array<HTMLElement>} nodes The nodes to be shown or hidden. 1466 * @param {Array<HTMLElement>} nodes The nodes to be shown or hidden.
1424 * @param {number} index The index of |nodes| to show. 1467 * @param {number} index The index of |nodes| to show.
1425 */ 1468 */
1426 function showMutuallyExclusiveNodes(nodes, index) { 1469 function showMutuallyExclusiveNodes(nodes, index) {
1427 assert(index >= 0 && index < nodes.length); 1470 assert(index >= 0 && index < nodes.length);
1428 for (var i = 0; i < nodes.length; ++i) { 1471 for (var i = 0; i < nodes.length; ++i) {
(...skipping 16 matching lines...) Expand all
1445 1488
1446 LanguageOptions.onDictionaryDownloadFailure = function(languageCode) { 1489 LanguageOptions.onDictionaryDownloadFailure = function(languageCode) {
1447 LanguageOptions.getInstance().onDictionaryDownloadFailure_(languageCode); 1490 LanguageOptions.getInstance().onDictionaryDownloadFailure_(languageCode);
1448 }; 1491 };
1449 1492
1450 // Export 1493 // Export
1451 return { 1494 return {
1452 LanguageOptions: LanguageOptions 1495 LanguageOptions: LanguageOptions
1453 }; 1496 };
1454 }); 1497 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698