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

Side by Side Diff: chrome/browser/resources/options2/chromeos/system_options.js

Issue 9232010: [uber page] Migrate all elements in the 'System' (cros) page to new locations. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 8 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 cr.define('options', function() {
6
7 var OptionsPage = options.OptionsPage;
8 var RepeatingButton = cr.ui.RepeatingButton;
9
10 /////////////////////////////////////////////////////////////////////////////
11 // SystemOptions class:
12
13 /**
14 * Encapsulated handling of ChromeOS system options page.
15 * @constructor
16 */
17 function SystemOptions() {
18 OptionsPage.call(this, 'system', templateData.systemPageTabTitle,
19 'systemPage');
20 }
21
22 cr.addSingletonGetter(SystemOptions);
23
24 // Inherit SystemOptions from OptionsPage.
25 SystemOptions.prototype = {
26 __proto__: options.OptionsPage.prototype,
27
28 /**
29 * Flag indicating if currently scanning for Bluetooth devices.
30 * @type {boolean}
31 */
32 isScanning_: false,
33
34 /**
35 * Initializes SystemOptions page.
36 * Calls base class implementation to starts preference initialization.
37 */
38 initializePage: function() {
39 OptionsPage.prototype.initializePage.call(this);
40
41 // Disable time-related settings if we're not logged in as a real user.
42 if (AccountsOptions.loggedInAsGuest()) {
43 var timezone = $('timezone-select');
44 if (timezone)
45 timezone.disabled = true;
46 var use_24hour_clock = $('use-24hour-clock');
47 if (use_24hour_clock)
48 use_24hour_clock.disabled = true;
49 }
50
51 options.system.bluetooth.BluetoothDeviceList.decorate(
52 $('bluetooth-paired-devices-list'));
53
54 $('bluetooth-add-device').onclick = function(event) {
55 if (! this.isScanning_)
56 findBluetoothDevices_(true);
57 OptionsPage.navigateToPage('bluetooth');
58 };
59
60 $('enable-bluetooth').onchange = function(event) {
61 var state = $('enable-bluetooth').checked;
62 chrome.send('bluetoothEnableChange', [Boolean(state)]);
63 };
64
65 $('bluetooth-reconnect-device').onclick = function(event) {
66 var device = $('bluetooth-paired-devices-list').selectedItem;
67 var address = device.address;
68 chrome.send('updateBluetoothDevice', [address, 'connect']);
69 OptionsPage.closeOverlay();
70 };
71
72 $('bluetooth-reconnect-device').onmousedown = function(event) {
73 // Prevent 'blur' event, which would reset the list selection,
74 // thereby disabling the apply button.
75 event.preventDefault();
76 };
77
78 $('bluetooth-paired-devices-list').addEventListener('change', function() {
79 var item = $('bluetooth-paired-devices-list').selectedItem;
80 var disabled = !item || !item.paired || item.connected;
81 $('bluetooth-reconnect-device').disabled = disabled;
82 });
83
84 $('language-button').onclick = function(event) {
85 OptionsPage.navigateToPage('language');
86 };
87 $('modifier-keys-button').onclick = function(event) {
88 OptionsPage.navigateToPage('languageCustomizeModifierKeysOverlay');
89 };
90 $('accessibility-spoken-feedback-check').onchange = function(event) {
91 chrome.send('spokenFeedbackChange',
92 [$('accessibility-spoken-feedback-check').checked]);
93 };
94 $('accessibility-high-contrast-check').onchange = function(event) {
95 chrome.send('highContrastChange',
96 [$('accessibility-high-contrast-check').checked]);
97 };
98 $('accessibility-screen-magnifier-check').onchange = function(event) {
99 chrome.send('screenMagnifierChange',
100 [$('accessibility-screen-magnifier-check').checked]);
101 };
102 $('accessibility-virtual-keyboard-check').onchange = function(event) {
103 chrome.send('virtualKeyboardChange',
104 [$('accessibility-virtual-keyboard-check').checked]);
105 };
106 initializeBrightnessButton_('brightness-decrease-button',
107 'decreaseScreenBrightness');
108 initializeBrightnessButton_('brightness-increase-button',
109 'increaseScreenBrightness');
110 }
111 };
112
113 /**
114 * Initializes a button for controlling screen brightness.
115 * @param {string} id Button ID.
116 * @param {string} callback Name of the callback function.
117 */
118 function initializeBrightnessButton_(id, callback) {
119 var button = $(id);
120 cr.ui.decorate(button, RepeatingButton);
121 button.repeatInterval = 300;
122 button.addEventListener(RepeatingButton.Event.BUTTON_HELD, function(e) {
123 chrome.send(callback);
124 });
125 }
126
127 /**
128 * Scan for bluetooth devices.
129 * @param {boolean} reset Indicates if the list of unpaired devices should be
130 * cleared.
131 * @private
132 */
133 function findBluetoothDevices_(reset) {
134 this.isScanning_ = true;
135 if (reset)
136 $('bluetooth-unpaired-devices-list').clear();
137 chrome.send('findBluetoothDevices');
138 }
139
140 //
141 // Chrome callbacks
142 //
143
144 /**
145 * Set the initial state of the spoken feedback checkbox.
146 */
147 SystemOptions.setSpokenFeedbackCheckboxState = function(checked) {
148 $('accessibility-spoken-feedback-check').checked = checked;
149 };
150
151 /**
152 * Set the initial state of the high contrast checkbox.
153 */
154 SystemOptions.setHighContrastCheckboxState = function(checked) {
155 $('accessibility-high-contrast-check').checked = checked;
156 };
157
158 /**
159 * Set the initial state of the screen magnifier checkbox.
160 */
161 SystemOptions.setScreenMagnifierCheckboxState = function(checked) {
162 $('accessibility-screen-magnifier-check').checked = checked;
163 };
164
165 /**
166 * Set the initial state of the virtual keyboard checkbox.
167 */
168 SystemOptions.setVirtualKeyboardCheckboxState = function(checked) {
169 $('accessibility-virtual-keyboard-check').checked = checked;
170 };
171
172 /**
173 * Activate the bluetooth settings section on the System settings page.
174 */
175 SystemOptions.showBluetoothSettings = function() {
176 $('bluetooth-devices').hidden = false;
177 };
178
179 /**
180 * Sets the state of the checkbox indicating if bluetooth is turned on. The
181 * state of the "Find devices" button and the list of discovered devices may
182 * also be affected by a change to the state.
183 * @param {boolean} checked Flag Indicating if Bluetooth is turned on.
184 */
185 SystemOptions.setBluetoothState = function(checked) {
186 $('enable-bluetooth').checked = checked;
187 $('bluetooth-paired-devices-list').parentNode.hidden = !checked;
188 $('bluetooth-add-device').hidden = !checked;
189 $('bluetooth-reconnect-device').hidden = !checked;
190 // Flush list of previously discovered devices if bluetooth is turned off.
191 if (!checked) {
192 $('bluetooth-paired-devices-list').clear();
193 $('bluetooth-unpaired-devices-list').clear();
194 }
195 // TODO(kevers): Replace following with a call to fetch the list of
196 // previously discovered devices rather than searching for all available
197 // devices.
198 if (checked && ! this.isScanning_)
199 findBluetoothDevices_(true);
200 }
201
202 /**
203 * Adds an element to the list of available bluetooth devices. If an element
204 * with a matching address is found, the existing element is updated.
205 * @param {{name: string,
206 * address: string,
207 * icon: string,
208 * paired: boolean,
209 * connected: boolean}} device
210 * Decription of the bluetooth device.
211 */
212 SystemOptions.addBluetoothDevice = function(device) {
213 var list = $('bluetooth-unpaired-devices-list');
214 if (device.paired) {
215 // Test to see if the device is currently in the unpaired list, in which
216 // case it should be removed from that list.
217 var index = $('bluetooth-unpaired-devices-list').find(device.address);
218 if (index != undefined)
219 $('bluetooth-unpaired-devices-list').deleteItemAtIndex(index);
220 list = $('bluetooth-paired-devices-list');
221 }
222 list.appendDevice(device);
223
224 // One device can be in the process of pairing. If found, display
225 // the Bluetooth pairing overlay.
226 if (device.pairing)
227 BluetoothPairing.showDialog(device);
228 };
229
230 /**
231 * Notification that a single pass of device discovery has completed.
232 */
233 SystemOptions.notifyBluetoothSearchComplete = function() {
234 // TODO(kevers): Determine the fate of this method once continuous
235 // scanning is implemented in the Bluetooth code.
236 this.isScanning_ = false;
237 };
238
239 /**
240 * Displays the touchpad controls section when we detect a touchpad, hides it
241 * otherwise.
242 */
243 SystemOptions.showTouchpadControls = function(show) {
244 $('touchpad-controls').hidden = !show;
245 };
246
247 /**
248 * Displays the mouse controls section when we detect a mouse, hides it
249 * otherwise.
250 */
251 SystemOptions.showMouseControls = function(show) {
252 $('mouse-controls').hidden = !show;
253 };
254
255 // Export
256 return {
257 SystemOptions: SystemOptions
258 };
259
260 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698