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 cr.define('options', function() { | 5 cr.define('options', function() { |
6 const ArrayDataModel = cr.ui.ArrayDataModel; | 6 const ArrayDataModel = cr.ui.ArrayDataModel; |
7 const OptionsPage = options.OptionsPage; | 7 const OptionsPage = options.OptionsPage; |
8 const SettingsDialog = options.SettingsDialog; | 8 const SettingsDialog = options.SettingsDialog; |
9 | 9 |
10 /** | 10 /** |
(...skipping 15 matching lines...) Expand all Loading... |
26 StartupOverlay.prototype = { | 26 StartupOverlay.prototype = { |
27 __proto__: SettingsDialog.prototype, | 27 __proto__: SettingsDialog.prototype, |
28 | 28 |
29 /** | 29 /** |
30 * An autocomplete list that can be attached to a text field during editing. | 30 * An autocomplete list that can be attached to a text field during editing. |
31 * @type {HTMLElement} | 31 * @type {HTMLElement} |
32 * @private | 32 * @private |
33 */ | 33 */ |
34 autocompleteList_: null, | 34 autocompleteList_: null, |
35 | 35 |
| 36 startup_pages_pref_: { |
| 37 'name': 'session.urls_to_restore_on_startup', |
| 38 'disabled': false |
| 39 }, |
| 40 |
36 /** | 41 /** |
37 * Initialize the page. | 42 * Initialize the page. |
38 */ | 43 */ |
39 initializePage: function() { | 44 initializePage: function() { |
40 SettingsDialog.prototype.initializePage.call(this); | 45 SettingsDialog.prototype.initializePage.call(this); |
41 | 46 |
42 var self = this; | 47 var self = this; |
43 | 48 |
44 var startupPagesList = $('startupPagesList'); | 49 var startupPagesList = $('startupPagesList'); |
45 options.browser_options.StartupPageList.decorate(startupPagesList); | 50 options.browser_options.StartupPageList.decorate(startupPagesList); |
46 startupPagesList.autoExpands = true; | 51 startupPagesList.autoExpands = true; |
47 | 52 |
48 $('startupUseCurrentButton').onclick = function(event) { | 53 $('startupUseCurrentButton').onclick = function(event) { |
49 chrome.send('setStartupPagesToCurrentPages'); | 54 chrome.send('setStartupPagesToCurrentPages'); |
50 }; | 55 }; |
51 | 56 |
| 57 Preferences.getInstance().addEventListener( |
| 58 this.startup_pages_pref_.name, |
| 59 this.handleStartupPageListChange_.bind(this)); |
| 60 |
52 var suggestionList = new cr.ui.AutocompleteList(); | 61 var suggestionList = new cr.ui.AutocompleteList(); |
53 suggestionList.autoExpands = true; | 62 suggestionList.autoExpands = true; |
54 suggestionList.suggestionUpdateRequestCallback = | 63 suggestionList.suggestionUpdateRequestCallback = |
55 this.requestAutocompleteSuggestions_.bind(this); | 64 this.requestAutocompleteSuggestions_.bind(this); |
56 $('startup-overlay').appendChild(suggestionList); | 65 $('startup-overlay').appendChild(suggestionList); |
57 this.autocompleteList_ = suggestionList; | 66 this.autocompleteList_ = suggestionList; |
58 startupPagesList.autocompleteList = suggestionList; | 67 startupPagesList.autocompleteList = suggestionList; |
59 }, | 68 }, |
60 | 69 |
61 /** @inheritDoc */ | 70 /** @inheritDoc */ |
62 handleConfirm: function() { | 71 handleConfirm: function() { |
63 SettingsDialog.prototype.handleConfirm.call(this); | 72 SettingsDialog.prototype.handleConfirm.call(this); |
64 chrome.send('commitStartupPrefChanges'); | 73 chrome.send('commitStartupPrefChanges'); |
65 }, | 74 }, |
66 | 75 |
67 /** @inheritDoc */ | 76 /** @inheritDoc */ |
68 handleCancel: function() { | 77 handleCancel: function() { |
69 SettingsDialog.prototype.handleCancel.call(this); | 78 SettingsDialog.prototype.handleCancel.call(this); |
70 chrome.send('cancelStartupPrefChanges'); | 79 chrome.send('cancelStartupPrefChanges'); |
71 }, | 80 }, |
72 | 81 |
73 /** | 82 /** |
| 83 * Sets the enabled state of the custom startup page list controls |
| 84 * based on the current startup radio button selection. |
| 85 * @private |
| 86 */ |
| 87 updateCustomStartupPageControlStates_: function() { |
| 88 var disable = this.startup_pages_pref_.disabled; |
| 89 var startupPagesList = $('startupPagesList'); |
| 90 startupPagesList.disabled = disable; |
| 91 startupPagesList.setAttribute('tabindex', disable ? -1 : 0); |
| 92 // Explicitly set disabled state for input text elements. |
| 93 var inputs = startupPagesList.querySelectorAll("input[type='text']"); |
| 94 for (var i = 0; i < inputs.length; i++) |
| 95 inputs[i].disabled = disable; |
| 96 $('startupUseCurrentButton').disabled = disable; |
| 97 }, |
| 98 |
| 99 /** |
| 100 * Handles change events of the preference |
| 101 * 'session.urls_to_restore_on_startup'. |
| 102 * @param {event} preference changed event. |
| 103 * @private |
| 104 */ |
| 105 handleStartupPageListChange_: function(event) { |
| 106 this.startup_pages_pref_.disabled = event.value['disabled']; |
| 107 this.updateCustomStartupPageControlStates_(); |
| 108 }, |
| 109 |
| 110 /** |
74 * Updates the startup pages list with the given entries. | 111 * Updates the startup pages list with the given entries. |
75 * @param {Array} pages List of startup pages. | 112 * @param {Array} pages List of startup pages. |
76 * @private | 113 * @private |
77 */ | 114 */ |
78 updateStartupPages_: function(pages) { | 115 updateStartupPages_: function(pages) { |
79 var model = new ArrayDataModel(pages); | 116 var model = new ArrayDataModel(pages); |
80 // Add a "new page" row. | 117 // Add a "new page" row. |
81 model.push({ | 118 model.push({ |
82 'modelIndex': '-1' | 119 'modelIndex': '-1' |
83 }); | 120 }); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 var instance = StartupOverlay.getInstance(); | 158 var instance = StartupOverlay.getInstance(); |
122 return instance[name + '_'].apply(instance, arguments); | 159 return instance[name + '_'].apply(instance, arguments); |
123 }; | 160 }; |
124 }); | 161 }); |
125 | 162 |
126 // Export | 163 // Export |
127 return { | 164 return { |
128 StartupOverlay: StartupOverlay | 165 StartupOverlay: StartupOverlay |
129 }; | 166 }; |
130 }); | 167 }); |
OLD | NEW |