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'); | 5 cr.exportPath('options'); |
6 | 6 |
7 /** | 7 /** |
8 * Copied from ash/system/power/power_status.h. | 8 * Copied from ash/system/power/power_status.h. |
9 * @enum {number} | 9 * @enum {number} |
10 */ | 10 */ |
(...skipping 14 matching lines...) Expand all Loading... |
25 cr.define('options', function() { | 25 cr.define('options', function() { |
26 var Page = cr.ui.pageManager.Page; | 26 var Page = cr.ui.pageManager.Page; |
27 var PageManager = cr.ui.pageManager.PageManager; | 27 var PageManager = cr.ui.pageManager.PageManager; |
28 | 28 |
29 /** | 29 /** |
30 * Encapsulated handling of the power overlay. | 30 * Encapsulated handling of the power overlay. |
31 * @constructor | 31 * @constructor |
32 * @extends {cr.ui.pageManager.Page} | 32 * @extends {cr.ui.pageManager.Page} |
33 */ | 33 */ |
34 function PowerOverlay() { | 34 function PowerOverlay() { |
35 Page.call(this, 'power-overlay', | 35 Page.call( |
36 loadTimeData.getString('powerOverlayTabTitle'), | 36 this, 'power-overlay', loadTimeData.getString('powerOverlayTabTitle'), |
37 'power-overlay'); | 37 'power-overlay'); |
38 } | 38 } |
39 | 39 |
40 cr.addSingletonGetter(PowerOverlay); | 40 cr.addSingletonGetter(PowerOverlay); |
41 | 41 |
42 PowerOverlay.prototype = { | 42 PowerOverlay.prototype = { |
43 __proto__: Page.prototype, | 43 __proto__: Page.prototype, |
44 | 44 |
45 /** @override */ | 45 /** @override */ |
46 initializePage: function() { | 46 initializePage: function() { |
47 Page.prototype.initializePage.call(this); | 47 Page.prototype.initializePage.call(this); |
48 | 48 |
49 $('power-confirm').onclick = | 49 $('power-confirm').onclick = PageManager.closeOverlay.bind(PageManager); |
50 PageManager.closeOverlay.bind(PageManager); | 50 $('power-source-dropdown').onchange = this.powerSourceChanged_.bind(this); |
51 $('power-source-dropdown').onchange = | |
52 this.powerSourceChanged_.bind(this); | |
53 }, | 51 }, |
54 | 52 |
55 /** @override */ | 53 /** @override */ |
56 didShowPage: function() { | 54 didShowPage: function() { |
57 chrome.send('updatePowerStatus'); | 55 chrome.send('updatePowerStatus'); |
58 }, | 56 }, |
59 | 57 |
60 /** | 58 /** |
61 * @param {string} status | 59 * @param {string} status |
62 * @private | 60 * @private |
63 */ | 61 */ |
64 setBatteryStatusText_: function(status) { | 62 setBatteryStatusText_: function(status) { |
65 $('battery-status-value').textContent = status; | 63 $('battery-status-value').textContent = status; |
66 }, | 64 }, |
67 | 65 |
68 /** | 66 /** |
69 * @param {Array<options.PowerSource>} sources External power sources. | 67 * @param {Array<options.PowerSource>} sources External power sources. |
70 * @param {string} selectedId The ID of the currently used power source. | 68 * @param {string} selectedId The ID of the currently used power source. |
71 * @param {boolean} isUsbCharger Whether the currently used power source | 69 * @param {boolean} isUsbCharger Whether the currently used power source |
72 * is a USB (low-powered) charger. | 70 * is a USB (low-powered) charger. |
73 * @param {boolean} isCalculating Whether the power info is still | 71 * @param {boolean} isCalculating Whether the power info is still |
74 * being calculated. | 72 * being calculated. |
75 * @private | 73 * @private |
76 */ | 74 */ |
77 setPowerSources_: function(sources, selectedId, isUsbCharger, | 75 setPowerSources_: function( |
78 isCalculating) { | 76 sources, selectedId, isUsbCharger, isCalculating) { |
79 if (this.lastPowerSource_ != selectedId) { | 77 if (this.lastPowerSource_ != selectedId) { |
80 this.lastPowerSource_ = selectedId; | 78 this.lastPowerSource_ = selectedId; |
81 if (selectedId && !isUsbCharger) { | 79 if (selectedId && !isUsbCharger) { |
82 // It can take a while to detect a USB charger, but triggering a | 80 // It can take a while to detect a USB charger, but triggering a |
83 // power status update makes the determination faster. | 81 // power status update makes the determination faster. |
84 setTimeout(chrome.send.bind(null, 'updatePowerStatus'), 1000); | 82 setTimeout(chrome.send.bind(null, 'updatePowerStatus'), 1000); |
85 } | 83 } |
86 } | 84 } |
87 | 85 |
88 var chargerRow = $('power-source-charger'); | 86 var chargerRow = $('power-source-charger'); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 $('power-sources').hidden = false; | 152 $('power-sources').hidden = false; |
155 }, | 153 }, |
156 | 154 |
157 /** @private */ | 155 /** @private */ |
158 powerSourceChanged_: function() { | 156 powerSourceChanged_: function() { |
159 chrome.send('setPowerSource', [$('power-source-dropdown').value]); | 157 chrome.send('setPowerSource', [$('power-source-dropdown').value]); |
160 }, | 158 }, |
161 }; | 159 }; |
162 | 160 |
163 cr.makePublic(PowerOverlay, [ | 161 cr.makePublic(PowerOverlay, [ |
164 'setBatteryStatusText', | 162 'setBatteryStatusText', |
165 'setPowerSources', | 163 'setPowerSources', |
166 ]); | 164 ]); |
167 | 165 |
168 // Export | 166 // Export |
169 return { | 167 return {PowerOverlay: PowerOverlay}; |
170 PowerOverlay: PowerOverlay | |
171 }; | |
172 }); | 168 }); |
OLD | NEW |