| 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..5ec0105aac1c89b88f7d31acc7fb856f43e36131 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
|
| + * @return {boolean}
|
| + */
|
| + isEqual_: function(lhs, rhs) {
|
| + return lhs === rhs;
|
| + },
|
| +
|
| + /**
|
| + * @param {!settings.BatteryStatus} batteryStatus
|
| + * @param {boolean} lowPowerCharger
|
| + * @return {string}
|
| + */
|
| + computeBatteryIcon_: function(batteryStatus, lowPowerCharger) {
|
| + var iconPrefix = 'settings:battery-';
|
| +
|
| + if (batteryStatus.calculating)
|
| + return iconPrefix + 'unknown';
|
| +
|
| + if (lowPowerCharger)
|
| + return iconPrefix + 'unreliable';
|
| +
|
| + if (!batteryStatus.charging && batteryStatus.percent < 5)
|
| + return iconPrefix + 'alert';
|
| +
|
| + // Compute the rest of the icon: iconPrefix + '[charging-]<percent>'.
|
| + if (batteryStatus.charging)
|
| + iconPrefix += 'charging-';
|
| +
|
| + // Show the highest level icon that doesn't go over the actual percentage.
|
| + if (batteryStatus.percent < 30)
|
| + return iconPrefix + '20';
|
| + if (batteryStatus.percent < 50)
|
| + return iconPrefix + '30';
|
| + if (batteryStatus.percent < 60)
|
| + return iconPrefix + '50';
|
| + if (batteryStatus.percent < 80)
|
| + return iconPrefix + '60';
|
| + if (batteryStatus.percent < 90)
|
| + return iconPrefix + '80';
|
| + if (batteryStatus.percent < 100)
|
| + return iconPrefix + '90';
|
| + return iconPrefix + '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 power source is attached and all of
|
| + * them are dual-role (no dedicated chargers).
|
| + * @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
|
| + * @return {string} Description of the power source.
|
| + * @private
|
| + */
|
| + 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);
|
| + },
|
| +
|
| /** @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
|
| */
|
|
|