Chromium Code Reviews| Index: chrome/browser/resources/settings/device_page/device_page.js |
| diff --git a/chrome/browser/resources/settings/device_page/device_page.js b/chrome/browser/resources/settings/device_page/device_page.js |
| index 18f39843cb4200b4926ae776c14a8424fdc261eb..1ac89bc56fd8ab38121cbee086b663a4c80dbe97 100644 |
| --- a/chrome/browser/resources/settings/device_page/device_page.js |
| +++ b/chrome/browser/resources/settings/device_page/device_page.js |
| @@ -39,6 +39,62 @@ Polymer({ |
| }, |
| readOnly: true, |
| }, |
| + |
| + /** |
| + * Whether power status and settings should be fetched and displayed. |
| + * @private |
| + */ |
| + enablePowerSettings_: { |
| + type: Boolean, |
| + value: function() { |
| + return loadTimeData.getBoolean('enablePowerSettings'); |
| + }, |
| + readOnly: true, |
| + }, |
| + |
| + /** @private {string} ID of the selected power source, or ''. */ |
| + selectedPowerSourceId_: String, |
| + |
| + /** @private {!settings.BatteryStatus|undefined} */ |
| + batteryStatus_: Object, |
| + |
| + /** @private {boolean} Whether a low-power (USB) charger is being used. */ |
| + lowPowerCharger_: Boolean, |
| + |
| + /** |
| + * List of available dual-role power sources, if enablePowerSettings_ is on. |
| + * @private {!Array<!settings.PowerSource>|undefined} |
| + */ |
| + powerSources_: Array, |
| + |
| + /** @private */ |
| + batteryIcon_: { |
| + type: String, |
| + computed: 'computeBatteryIcon_(batteryStatus_, lowPowerCharger_)', |
| + value: 'settings:battery-unknown', |
| + }, |
| + |
| + /** @private */ |
| + powerLabel_: { |
| + type: String, |
| + computed: 'computePowerLabel_(powerSources_, batteryStatus_.calculating)', |
| + }, |
| + |
| + /** @private */ |
| + showPowerDropdown_: { |
| + type: Boolean, |
| + computed: 'computeShowPowerDropdown_(powerSources_)', |
| + value: false, |
| + }, |
| + |
| + /** |
| + * The name of the dedicated charging device being used, if present. |
| + * @private {string} |
| + */ |
| + powerSourceName_: { |
| + type: String, |
| + computed: 'computePowerSourceName_(powerSources_, lowPowerCharger_)', |
| + }, |
| }, |
| observers: [ |
| @@ -46,16 +102,20 @@ Polymer({ |
| ], |
| /** @override */ |
| - ready: function() { |
| - settings.DevicePageBrowserProxyImpl.getInstance().initializePointers(); |
| - }, |
| - |
| - /** @override */ |
| attached: function() { |
| this.addWebUIListener( |
| 'has-mouse-changed', this.set.bind(this, 'hasMouse_')); |
| this.addWebUIListener( |
| 'has-touchpad-changed', this.set.bind(this, 'hasTouchpad_')); |
| + settings.DevicePageBrowserProxyImpl.getInstance().initializePointers(); |
| + |
| + if (this.enablePowerSettings_) { |
| + this.addWebUIListener( |
| + 'battery-status-changed', this.set.bind(this, 'batteryStatus_')); |
| + this.addWebUIListener( |
| + 'power-sources-changed', this.powerSourcesChanged_.bind(this)); |
| + settings.DevicePageBrowserProxyImpl.getInstance().updatePowerStatus(); |
| + } |
| }, |
| /** |
| @@ -85,6 +145,89 @@ Polymer({ |
| }, |
| /** |
| + * @param {*} lhs |
| + * @param {*} rhs |
| + * True if lhs === rhs. |
|
stevenjb
2017/01/13 17:22:42
@return {boolean} (comment is pretty unnecessary..
michaelpg
2017/01/13 18:52:03
Done.
|
| + */ |
| + isEqual_: function(lhs, rhs) { |
| + return lhs === rhs; |
| + }, |
| + |
| + /** |
| + * @param {!settings.BatteryStatus} batteryStatus |
| + * @param {boolean} lowPowerCharger |
| + * @return {string} |
| + */ |
| + computeBatteryIcon_: function(batteryStatus, lowPowerCharger) { |
| + var icon = 'settings:battery-'; |
|
stevenjb
2017/01/13 17:22:42
nit: prefix since by itself this is not a valid ic
michaelpg
2017/01/13 18:52:03
Done.
|
| + |
| + if (batteryStatus.calculating) |
| + return icon + 'unknown'; |
| + |
| + if (lowPowerCharger) |
| + return icon + 'unreliable'; |
| + |
| + if (!batteryStatus.charging && batteryStatus.percent < 5) |
| + return icon + 'alert'; |
| + |
| + // Compute the icon suffix: '[charging-]<percent>'. |
| + if (batteryStatus.charging) |
| + icon += 'charging-'; |
| + |
| + // Show the highest level icon that doesn't go over the actual percentage. |
| + if (batteryStatus.percent < 30) |
| + return icon + '20'; |
| + if (batteryStatus.percent < 50) |
| + return icon + '30'; |
| + if (batteryStatus.percent < 60) |
| + return icon + '50'; |
| + if (batteryStatus.percent < 80) |
| + return icon + '60'; |
| + if (batteryStatus.percent < 90) |
| + return icon + '80'; |
| + if (batteryStatus.percent < 100) |
| + return icon + '90'; |
| + return icon + 'full'; |
| + }, |
| + |
| + /** |
| + * @param {!Array<!settings.PowerSource>|undefined} powerSources |
| + * @param {boolean} calculating |
| + * @return {string} The primary label for the power row. |
| + * @private |
| + */ |
| + computePowerLabel_: function(powerSources, calculating) { |
| + return this.i18n(calculating ? 'calculatingPower' : |
| + powerSources.length ? 'powerSourceLabel' : 'powerSourceBattery'); |
| + }, |
| + |
| + /** |
| + * @param {!Array<!settings.PowerSource>} powerSources |
| + * @return {boolean} True if at least one dual-role USB power source is found |
| + * and no dedicated chargers are attached. |
|
stevenjb
2017/01/13 17:22:42
nit: 'no non dual-role USB (i.e. dedicated) power
michaelpg
2017/01/13 18:52:03
How's this? "True if at least one power source is
|
| + * @private |
| + */ |
| + computeShowPowerDropdown_: function(powerSources) { |
| + return powerSources.length > 0 && powerSources.every(function(source) { |
| + return source.type == settings.PowerDeviceType.DUAL_ROLE_USB; |
| + }); |
| + }, |
| + |
| + /** |
| + * @param {!Array<!settings.PowerSource>} powerSources |
| + * @param {boolean} lowPowerCharger |
| + * @private |
| + * @return {string} Description of the power source. |
|
stevenjb
2017/01/13 17:22:42
nit: consistent @private / @return order.
michaelpg
2017/01/13 18:52:03
Done.
|
| + */ |
| + computePowerSourceName_(powerSources, lowPowerCharger) { |
| + if (lowPowerCharger) |
| + return this.i18n('powerSourceLowPowerCharger'); |
| + if (powerSources.length) |
| + return this.i18n('powerSourceAcAdapter'); |
| + return ''; |
| + }, |
| + |
| + /** |
| * Handler for tapping the mouse and touchpad settings menu item. |
| * @private |
| */ |
| @@ -124,6 +267,11 @@ Polymer({ |
| settings.navigateTo(settings.Route.STORAGE); |
| }, |
| + onPowerSourceChange_: function() { |
| + settings.DevicePageBrowserProxyImpl.getInstance().setPowerSource( |
| + this.$$('#powerSource').value); |
|
stevenjb
2017/01/13 17:22:42
nit: this.$.powerSource.value ?
michaelpg
2017/01/13 18:52:03
powerSource lives in a dom-if so it's not part of
|
| + }, |
| + |
| /** @protected */ |
| currentRouteChanged: function() { |
| this.checkPointerSubpage_(); |
| @@ -140,6 +288,19 @@ Polymer({ |
| }, |
| /** |
| + * @param {!Array<settings.PowerSource>} sources External power sources. |
| + * @param {string} selectedId The ID of the currently used power source. |
| + * @param {boolean} lowPowerCharger Whether the currently used power source |
| + * is a low-powered USB charger. |
| + * @private |
| + */ |
| + powerSourcesChanged_: function(sources, selectedId, lowPowerCharger) { |
| + this.powerSources_ = sources; |
| + this.selectedPowerSourceId_ = selectedId; |
| + this.lowPowerCharger_ = lowPowerCharger; |
| + }, |
| + |
| + /** |
| * Leaves the pointer subpage if all pointing devices are detached. |
| * @private |
| */ |