OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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.exportPath('options'); |
| 6 |
| 7 /** |
| 8 * Copied from ash/system/chromeos/power/power_status.h. |
| 9 * @enum {number} |
| 10 */ |
| 11 options.PowerStatusDeviceType = { |
| 12 DEDICATED_CHARGER: 0, |
| 13 DUAL_ROLE_USB: 1, |
| 14 }; |
| 15 |
| 16 /** |
| 17 * @typedef {{ |
| 18 * id: string, |
| 19 * type: options.PowerStatusDeviceType, |
| 20 * description: string |
| 21 * }} |
| 22 */ |
| 23 options.PowerSource; |
| 24 |
5 cr.define('options', function() { | 25 cr.define('options', function() { |
6 var Page = cr.ui.pageManager.Page; | 26 var Page = cr.ui.pageManager.Page; |
7 var PageManager = cr.ui.pageManager.PageManager; | 27 var PageManager = cr.ui.pageManager.PageManager; |
8 | 28 |
9 /** @enum {number} */ var DeviceType = { | |
10 CHARGER: loadTimeData.getInteger('powerSourceCharger'), | |
11 DUAL_ROLE: loadTimeData.getInteger('powerSourceDualRole'), | |
12 }; | |
13 | |
14 /** | |
15 * @typedef {{ | |
16 * id: string, | |
17 * type: DeviceType, | |
18 * description: string | |
19 * }} | |
20 */ | |
21 var PowerSource; | |
22 | |
23 /** | 29 /** |
24 * Encapsulated handling of the power overlay. | 30 * Encapsulated handling of the power overlay. |
25 * @constructor | 31 * @constructor |
26 * @extends {cr.ui.pageManager.Page} | 32 * @extends {cr.ui.pageManager.Page} |
27 */ | 33 */ |
28 function PowerOverlay() { | 34 function PowerOverlay() { |
29 Page.call(this, 'power-overlay', | 35 Page.call(this, 'power-overlay', |
30 loadTimeData.getString('powerOverlayTabTitle'), | 36 loadTimeData.getString('powerOverlayTabTitle'), |
31 'power-overlay'); | 37 'power-overlay'); |
32 } | 38 } |
(...skipping 20 matching lines...) Expand all Loading... |
53 | 59 |
54 /** | 60 /** |
55 * @param {string} status | 61 * @param {string} status |
56 * @private | 62 * @private |
57 */ | 63 */ |
58 setBatteryStatusText_: function(status) { | 64 setBatteryStatusText_: function(status) { |
59 $('battery-status-value').textContent = status; | 65 $('battery-status-value').textContent = status; |
60 }, | 66 }, |
61 | 67 |
62 /** | 68 /** |
63 * @param {Array<PowerSource>} sources External power sources. | 69 * @param {Array<options.PowerSource>} sources External power sources. |
64 * @param {string} selectedId The ID of the currently used power source. | 70 * @param {string} selectedId The ID of the currently used power source. |
65 * @param {boolean} isUsbCharger Whether the currently used power source | 71 * @param {boolean} isUsbCharger Whether the currently used power source |
66 * is a USB (low-powered) charger. | 72 * is a USB (low-powered) charger. |
67 * @param {boolean} isCalculating Whether the power info is still | 73 * @param {boolean} isCalculating Whether the power info is still |
68 * being calculated. | 74 * being calculated. |
69 * @private | 75 * @private |
70 */ | 76 */ |
71 setPowerSources_: function(sources, selectedId, isUsbCharger, | 77 setPowerSources_: function(sources, selectedId, isUsbCharger, |
72 isCalculating) { | 78 isCalculating) { |
73 if (this.lastPowerSource_ != selectedId) { | 79 if (this.lastPowerSource_ != selectedId) { |
(...skipping 21 matching lines...) Expand all Loading... |
95 $('power-source-charger-type').textContent = | 101 $('power-source-charger-type').textContent = |
96 loadTimeData.getString('calculatingPower'); | 102 loadTimeData.getString('calculatingPower'); |
97 chargerRow.hidden = false; | 103 chargerRow.hidden = false; |
98 return; | 104 return; |
99 } | 105 } |
100 | 106 |
101 // Check if a dedicated charger is being used. | 107 // Check if a dedicated charger is being used. |
102 var usingDedicatedCharger = false; | 108 var usingDedicatedCharger = false; |
103 if (selectedId) { | 109 if (selectedId) { |
104 usingDedicatedCharger = sources.some(function(source) { | 110 usingDedicatedCharger = sources.some(function(source) { |
105 return source.id == selectedId && source.type == DeviceType.CHARGER; | 111 return source.id == selectedId && |
| 112 source.type == options.PowerStatusDeviceType.DEDICATED_CHARGER; |
106 }); | 113 }); |
107 } | 114 } |
108 | 115 |
109 if (usingDedicatedCharger) { | 116 if (usingDedicatedCharger) { |
110 // Show charger information. | 117 // Show charger information. |
111 $('power-source-charger-type').textContent = loadTimeData.getString( | 118 $('power-source-charger-type').textContent = loadTimeData.getString( |
112 isUsbCharger ? 'powerSourceLowPowerCharger' : | 119 isUsbCharger ? 'powerSourceLowPowerCharger' : |
113 'powerSourceAcAdapter'); | 120 'powerSourceAcAdapter'); |
114 chargerRow.hidden = false; | 121 chargerRow.hidden = false; |
115 chargingDescRow.hidden = isUsbCharger; | 122 chargingDescRow.hidden = isUsbCharger; |
116 } else { | 123 } else { |
117 this.showPowerSourceList_(sources, selectedId); | 124 this.showPowerSourceList_(sources, selectedId); |
118 } | 125 } |
119 }, | 126 }, |
120 | 127 |
121 /** | 128 /** |
122 * Populates and shows the dropdown of available power sources. | 129 * Populates and shows the dropdown of available power sources. |
123 * @param {Array<PowerSource>} sources External power sources. | 130 * @param {Array<options.PowerSource>} sources External power sources. |
124 * @param {string} selectedId The ID of the currently used power source. | 131 * @param {string} selectedId The ID of the currently used power source. |
125 * The empty string indicates no external power source is in use | 132 * The empty string indicates no external power source is in use |
126 * (running on battery). | 133 * (running on battery). |
127 * @private | 134 * @private |
128 */ | 135 */ |
129 showPowerSourceList_: function(sources, selectedId) { | 136 showPowerSourceList_: function(sources, selectedId) { |
130 // Clear the dropdown. | 137 // Clear the dropdown. |
131 var dropdown = $('power-source-dropdown'); | 138 var dropdown = $('power-source-dropdown'); |
132 dropdown.innerHTML = ''; | 139 dropdown.innerHTML = ''; |
133 | 140 |
(...skipping 25 matching lines...) Expand all Loading... |
159 cr.makePublic(PowerOverlay, [ | 166 cr.makePublic(PowerOverlay, [ |
160 'setBatteryStatusText', | 167 'setBatteryStatusText', |
161 'setPowerSources', | 168 'setPowerSources', |
162 ]); | 169 ]); |
163 | 170 |
164 // Export | 171 // Export |
165 return { | 172 return { |
166 PowerOverlay: PowerOverlay | 173 PowerOverlay: PowerOverlay |
167 }; | 174 }; |
168 }); | 175 }); |
OLD | NEW |