OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 cr.define('options', function() { | 5 cr.define('options', function() { |
6 const OptionsPage = options.OptionsPage; | 6 const OptionsPage = options.OptionsPage; |
7 const ArrayDataModel = cr.ui.ArrayDataModel; | 7 const ArrayDataModel = cr.ui.ArrayDataModel; |
8 const ListSelectionModel = cr.ui.ListSelectionModel; | 8 const ListSelectionModel = cr.ui.ListSelectionModel; |
9 | 9 |
10 // | 10 // |
(...skipping 23 matching lines...) Expand all Loading... |
34 }, | 34 }, |
35 | 35 |
36 /** | 36 /** |
37 * Initialize BrowserOptions page. | 37 * Initialize BrowserOptions page. |
38 */ | 38 */ |
39 initializePage: function() { | 39 initializePage: function() { |
40 // Call base class implementation to start preference initialization. | 40 // Call base class implementation to start preference initialization. |
41 OptionsPage.prototype.initializePage.call(this); | 41 OptionsPage.prototype.initializePage.call(this); |
42 | 42 |
43 // Wire up controls. | 43 // Wire up controls. |
44 $('startupAddButton').onclick = function(event) { | |
45 OptionsPage.showOverlay('addStartupPageOverlay'); | |
46 }; | |
47 $('startupRemoveButton').onclick = | |
48 this.removeSelectedStartupPages_.bind(this); | |
49 $('startupUseCurrentButton').onclick = function(event) { | 44 $('startupUseCurrentButton').onclick = function(event) { |
50 chrome.send('setStartupPagesToCurrentPages'); | 45 chrome.send('setStartupPagesToCurrentPages'); |
51 }; | 46 }; |
| 47 $('startupPageManagerButton').onclick = function(event) { |
| 48 OptionsPage.showPageByName('startupPages'); |
| 49 }; |
52 $('defaultSearchManageEnginesButton').onclick = function(event) { | 50 $('defaultSearchManageEnginesButton').onclick = function(event) { |
53 OptionsPage.showPageByName('searchEngines'); | 51 OptionsPage.showPageByName('searchEngines'); |
54 chrome.send('coreOptionsUserMetricsAction', | 52 chrome.send('coreOptionsUserMetricsAction', |
55 ['Options_ManageSearchEngines']); | 53 ['Options_ManageSearchEngines']); |
56 }; | 54 }; |
57 $('instantEnableCheckbox').onclick = function(event) { | 55 $('instantEnableCheckbox').onclick = function(event) { |
58 var alreadyConfirmed = $('instantDialogShown').checked; | 56 var alreadyConfirmed = $('instantDialogShown').checked; |
59 | 57 |
60 if (this.checked && !alreadyConfirmed) { | 58 if (this.checked && !alreadyConfirmed) { |
61 // Leave disabled for now. The PrefCheckbox handler already set it to | 59 // Leave disabled for now. The PrefCheckbox handler already set it to |
(...skipping 16 matching lines...) Expand all Loading... |
78 if (document.activeElement == homepageField) | 76 if (document.activeElement == homepageField) |
79 homepageField.blur(); | 77 homepageField.blur(); |
80 }); | 78 }); |
81 | 79 |
82 if (!cr.isChromeOS) { | 80 if (!cr.isChromeOS) { |
83 $('defaultBrowserUseAsDefaultButton').onclick = function(event) { | 81 $('defaultBrowserUseAsDefaultButton').onclick = function(event) { |
84 chrome.send('becomeDefaultBrowser'); | 82 chrome.send('becomeDefaultBrowser'); |
85 }; | 83 }; |
86 } | 84 } |
87 | 85 |
88 var list = $('startupPages'); | 86 var list = $('startupPagesShortList'); |
89 options.browser_options.StartupPageList.decorate(list); | 87 options.browser_options.StartupPageList.decorate(list); |
90 list.autoExpands = true; | 88 list.autoExpands = true; |
91 list.selectionModel = new ListSelectionModel; | 89 list.selectionModel = new ListSelectionModel; |
92 | 90 |
93 list.selectionModel.addEventListener( | |
94 'change', this.updateRemoveButtonState_.bind(this)); | |
95 | |
96 // Check if we are in the guest mode. | 91 // Check if we are in the guest mode. |
97 if (cr.commandLine.options['--bwsi']) { | 92 if (cr.commandLine.options['--bwsi']) { |
98 // Disable input and button elements under the startup section. | 93 // Disable all controls under the startup section. |
99 var elements = $('startupSection').querySelectorAll('input, button'); | 94 var elements = |
| 95 $('startupSection').querySelectorAll('input, button, list'); |
100 for (var i = 0; i < elements.length; i++) { | 96 for (var i = 0; i < elements.length; i++) { |
101 elements[i].disabled = true; | 97 elements[i].disabled = true; |
102 elements[i].manually_disabled = true; | 98 elements[i].manually_disabled = true; |
103 } | 99 } |
104 } else { | 100 } else { |
105 // Initialize control enabled states. | 101 // Initialize control enabled states. |
106 Preferences.getInstance().addEventListener('session.restore_on_startup', | 102 Preferences.getInstance().addEventListener('session.restore_on_startup', |
107 this.updateCustomStartupPageControlStates_.bind(this)); | 103 this.updateCustomStartupPageControlStates_.bind(this)); |
108 Preferences.getInstance().addEventListener('homepage_is_newtabpage', | 104 Preferences.getInstance().addEventListener('homepage_is_newtabpage', |
109 this.handleHomepageIsNewTabPageChange_.bind(this)); | 105 this.handleHomepageIsNewTabPageChange_.bind(this)); |
110 Preferences.getInstance().addEventListener('homepage', | 106 Preferences.getInstance().addEventListener('homepage', |
111 this.handleHomepageChange_.bind(this)); | 107 this.handleHomepageChange_.bind(this)); |
112 | 108 |
113 this.updateCustomStartupPageControlStates_(); | 109 this.updateCustomStartupPageControlStates_(); |
114 } | 110 } |
115 | |
116 // Remove Windows-style accelerators from button labels. | |
117 // TODO(stuartmorgan): Remove this once the strings are updated. | |
118 $('startupAddButton').textContent = | |
119 localStrings.getStringWithoutAccelerator('startupAddButton'); | |
120 $('startupRemoveButton').textContent = | |
121 localStrings.getStringWithoutAccelerator('startupRemoveButton'); | |
122 }, | 111 }, |
123 | 112 |
124 /** | 113 /** |
125 * Update the Default Browsers section based on the current state. | 114 * Update the Default Browsers section based on the current state. |
126 * @private | 115 * @private |
127 * @param {string} statusString Description of the current default state. | 116 * @param {string} statusString Description of the current default state. |
128 * @param {boolean} isDefault Whether or not the browser is currently | 117 * @param {boolean} isDefault Whether or not the browser is currently |
129 * default. | 118 * default. |
130 * @param {boolean} canBeDefault Whether or not the browser can be default. | 119 * @param {boolean} canBeDefault Whether or not the browser can be default. |
131 */ | 120 */ |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 shouldEnableCustomStartupPageControls_: function(pages) { | 166 shouldEnableCustomStartupPageControls_: function(pages) { |
178 return $('startupShowPagesButton').checked; | 167 return $('startupShowPagesButton').checked; |
179 }, | 168 }, |
180 | 169 |
181 /** | 170 /** |
182 * Updates the startup pages list with the given entries. | 171 * Updates the startup pages list with the given entries. |
183 * @private | 172 * @private |
184 * @param {Array} pages List of startup pages. | 173 * @param {Array} pages List of startup pages. |
185 */ | 174 */ |
186 updateStartupPages_: function(pages) { | 175 updateStartupPages_: function(pages) { |
187 // TODO(stuartmorgan): Once the sub-page is done, handle 0 and > 10 pages. | 176 var list = $('startupPagesShortList'); |
188 $('startupPages').dataModel = new ArrayDataModel(pages); | 177 list.dataModel = new ArrayDataModel(pages); |
189 this.updateRemoveButtonState_(); | 178 if (pages.length > 0 && pages.length <= 10) { |
| 179 list.classList.remove("hidden"); |
| 180 $('startupPageManagement').classList.add('fullView'); |
| 181 $('startupShowPagesLabel').textContent = |
| 182 localStrings.getStringWithoutAccelerator('startupShowPages'); |
| 183 } else { |
| 184 list.classList.add("hidden"); |
| 185 $('startupPageManagement').classList.remove('fullView'); |
| 186 $('startupShowPagesLabel').textContent = |
| 187 localStrings.getStringWithoutAccelerator('startupShowManyPages'); |
| 188 } |
190 }, | 189 }, |
191 | 190 |
192 /** | 191 /** |
193 * Handles change events of the radio button 'homepageUseURLButton'. | 192 * Handles change events of the radio button 'homepageUseURLButton'. |
194 * @private | 193 * @private |
195 * @param {event} change event. | 194 * @param {event} change event. |
196 */ | 195 */ |
197 handleHomepageUseURLButtonChange_: function(event) { | 196 handleHomepageUseURLButtonChange_: function(event) { |
198 Preferences.setBooleanPref('homepage_is_newtabpage', false); | 197 Preferences.setBooleanPref('homepage_is_newtabpage', false); |
199 }, | 198 }, |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 !this.homepage_is_newtabpage_pref_.managed)); | 340 !this.homepage_is_newtabpage_pref_.managed)); |
342 }, | 341 }, |
343 | 342 |
344 /** | 343 /** |
345 * Sets the enabled state of the custom startup page list controls | 344 * Sets the enabled state of the custom startup page list controls |
346 * based on the current startup radio button selection. | 345 * based on the current startup radio button selection. |
347 * @private | 346 * @private |
348 */ | 347 */ |
349 updateCustomStartupPageControlStates_: function() { | 348 updateCustomStartupPageControlStates_: function() { |
350 var disable = !this.shouldEnableCustomStartupPageControls_(); | 349 var disable = !this.shouldEnableCustomStartupPageControls_(); |
351 $('startupPages').disabled = disable; | 350 $('startupPagesShortList').disabled = disable; |
352 $('startupAddButton').disabled = disable; | |
353 $('startupUseCurrentButton').disabled = disable; | 351 $('startupUseCurrentButton').disabled = disable; |
354 this.updateRemoveButtonState_(); | 352 $('startupPageManagerButton').disabled = disable; |
355 }, | 353 }, |
356 | 354 |
357 /** | 355 /** |
358 * Sets the enabled state of the startup page Remove button based on | |
359 * the current selection in the startup pages list. | |
360 * @private | |
361 */ | |
362 updateRemoveButtonState_: function() { | |
363 var groupEnabled = this.shouldEnableCustomStartupPageControls_(); | |
364 $('startupRemoveButton').disabled = !groupEnabled || | |
365 ($('startupPages').selectionModel.selectedIndex == -1); | |
366 }, | |
367 | |
368 /** | |
369 * Removes the selected startup pages. | 356 * Removes the selected startup pages. |
370 * @private | 357 * @private |
371 */ | 358 */ |
372 removeSelectedStartupPages_: function() { | 359 removeSelectedStartupPages_: function() { |
373 var selections = | 360 var selections = |
374 $('startupPages').selectionModel.selectedIndexes.map(String); | 361 $('startupPagesShortList').selectionModel.selectedIndexes.map(String); |
375 chrome.send('removeStartupPages', selections); | 362 chrome.send('removeStartupPages', selections); |
376 }, | 363 }, |
377 | 364 |
378 /** | 365 /** |
379 * Adds the given startup page at the current selection point. | 366 * Adds the given startup page at the current selection point. |
380 * @private | 367 * @private |
381 */ | 368 */ |
382 addStartupPage_: function(url) { | 369 addStartupPage_: function(url) { |
383 var firstSelection = $('startupPages').selectionModel.selectedIndex; | 370 var firstSelection = |
| 371 $('startupPagesShortList').selectionModel.selectedIndex; |
384 chrome.send('addStartupPage', [url, String(firstSelection)]); | 372 chrome.send('addStartupPage', [url, String(firstSelection)]); |
385 }, | 373 }, |
386 | 374 |
387 /** | 375 /** |
388 * Set the default search engine based on the popup selection. | 376 * Set the default search engine based on the popup selection. |
389 */ | 377 */ |
390 setDefaultSearchEngine: function() { | 378 setDefaultSearchEngine: function() { |
391 var engineSelect = $('defaultSearchEngine'); | 379 var engineSelect = $('defaultSearchEngine'); |
392 var selectedIndex = engineSelect.selectedIndex; | 380 var selectedIndex = engineSelect.selectedIndex; |
393 if (selectedIndex >= 0) { | 381 if (selectedIndex >= 0) { |
(...skipping 11 matching lines...) Expand all Loading... |
405 canBeDefault); | 393 canBeDefault); |
406 } | 394 } |
407 }; | 395 }; |
408 | 396 |
409 BrowserOptions.updateSearchEngines = function(engines, defaultValue) { | 397 BrowserOptions.updateSearchEngines = function(engines, defaultValue) { |
410 BrowserOptions.getInstance().updateSearchEngines_(engines, defaultValue); | 398 BrowserOptions.getInstance().updateSearchEngines_(engines, defaultValue); |
411 }; | 399 }; |
412 | 400 |
413 BrowserOptions.updateStartupPages = function(pages) { | 401 BrowserOptions.updateStartupPages = function(pages) { |
414 BrowserOptions.getInstance().updateStartupPages_(pages); | 402 BrowserOptions.getInstance().updateStartupPages_(pages); |
| 403 StartupPageManager.getInstance().updateStartupPages_(pages); |
415 }; | 404 }; |
416 | 405 |
417 BrowserOptions.addStartupPage = function(url) { | 406 BrowserOptions.addStartupPage = function(url) { |
418 BrowserOptions.getInstance().addStartupPage_(url); | 407 BrowserOptions.getInstance().addStartupPage_(url); |
419 }; | 408 }; |
420 | 409 |
421 // Export | 410 // Export |
422 return { | 411 return { |
423 BrowserOptions: BrowserOptions | 412 BrowserOptions: BrowserOptions |
424 }; | 413 }; |
425 | 414 |
426 }); | 415 }); |
OLD | NEW |