Chromium Code Reviews| Index: chrome/browser/resources/chromeos/emulator/battery_settings.js |
| diff --git a/chrome/browser/resources/chromeos/emulator/battery_settings.js b/chrome/browser/resources/chromeos/emulator/battery_settings.js |
| index b70921f072a6c4988512a916f4e5770edd4af27f..0fd44e4669134744e546d89942b967db0ea82ea8 100644 |
| --- a/chrome/browser/resources/chromeos/emulator/battery_settings.js |
| +++ b/chrome/browser/resources/chromeos/emulator/battery_settings.js |
| @@ -11,22 +11,45 @@ var BatterySettings = Polymer({ |
| */ |
| batteryPercent: { |
| type: Number, |
| + observer: 'batteryPercentChanged', |
| }, |
| /** |
| - * A string representing the value of an |
| + * A string representing a value in the |
| + * PowerSupplyProperties_BatteryState enumeration. |
| + */ |
| + batteryState: { |
| + type: String, |
| + observer: 'batteryStateChanged', |
| + }, |
| + |
| + /** |
| + * An array representing the battery state options. |
| + * The names are ordered based on the |
| + * PowerSupplyProperties_BatteryState enumeration. These values must be |
| + * in sync. |
| + */ |
| + batteryStateOptions: { |
| + type: Array, |
| + value: function() { return ['Full', 'Charging', 'Disharging', |
| + 'Not Present']; }, |
|
michaelpg
2015/07/30 03:02:09
nit: indent (preferably to align with 'Full')
mozartalouis
2015/07/30 21:18:18
Done.
|
| + }, |
| + |
| + /** |
| + * A string representing a value in the |
| * PowerSupplyProperties_ExternalPower enumeration. |
| */ |
| externalPower: { |
| type: String, |
| + observer: 'externalPowerChanged', |
| }, |
| /** |
| - * An array representing the external power options. |
| - * The names are ordered based on the |
| - * PowerSupplyProperties_ExternalPower enumeration. These values must be |
| - * in sync. |
| - */ |
| + * An array representing the external power options. |
| + * The names are ordered based on the |
| + * PowerSupplyProperties_ExternalPower enumeration. These values must be |
| + * in sync. |
| + */ |
| externalPowerOptions: { |
| type: Array, |
| value: function() { return ['AC', 'USB (Low Power)', 'Disconnected']; } |
| @@ -37,6 +60,7 @@ var BatterySettings = Polymer({ |
| */ |
| timeUntilEmpty: { |
| type: String, |
| + observer: 'timeUntilEmptyChanged', |
| }, |
| /** |
| @@ -44,6 +68,7 @@ var BatterySettings = Polymer({ |
| */ |
| timeUntilFull: { |
| type: String, |
| + observer: 'timeUntilFullChanged', |
| }, |
| /** |
| @@ -58,44 +83,46 @@ var BatterySettings = Polymer({ |
| this.title = 'Power Settings'; |
| }, |
| - observers: [ |
| - 'batteryPercentChanged(batteryPercent)', |
| - 'externalPowerChanged(externalPower)', |
| - 'timeUntilEmptyChanged(timeUntilEmpty)', |
| - 'timeUntilFullChanged(timeUntilFull)', |
| - ], |
| - |
| - batteryPercentChanged: function(percent) { |
| + batteryPercentChanged: function(percent, oldPercent) { |
| + if (oldPercent != undefined) |
| chrome.send('updateBatteryPercent', [parseInt(percent)]); |
|
michaelpg
2015/07/30 03:02:09
indent
|
| }, |
| - externalPowerChanged: function(source) { |
| - var index = -1; |
| + batteryStateChanged: function(state, oldState) { |
| + // Find the index of the selected battery state. |
| + if (oldState != undefined) { |
|
michaelpg
2015/07/30 03:02:09
This check is to ignore default values set by pape
mozartalouis
2015/07/30 21:18:18
Done.
|
| + var index = this.batteryStateOptions.indexOf(state); |
| + if (index >= 0) |
| + chrome.send('updateBatteryState', [index]); |
| + } |
| + }, |
| + externalPowerChanged: function(source, oldSource) { |
| // Find the index of the selected power source. |
| - for (var i = 0; i < this.externalPowerOptions.length; i++) { |
| - if (this.externalPowerOptions[i] == source) { |
| - index = i; |
| - break; |
| - } |
| + if (oldSource != undefined) { |
| + var index = this.externalPowerOptions.indexOf(source); |
| + if (index >= 0) |
| + chrome.send('updateExternalPower', [index]); |
| } |
| - |
| - if (index >= 0) |
| - chrome.send('updateExternalPower', [index]); |
| }, |
| - timeUntilEmptyChanged: function(time) { |
| - chrome.send('updateTimeToEmpty', [parseInt(time)]); |
| + timeUntilEmptyChanged: function(time, oldTime) { |
| + if (oldTime != undefined) |
| + chrome.send('updateTimeToEmpty', [parseInt(time)]); |
| }, |
| - timeUntilFullChanged: function(time) { |
| - chrome.send('updateTimeToFull', [parseInt(time)]); |
| + timeUntilFullChanged: function(time, oldTime) { |
| + if (oldTime != undefined) |
| + chrome.send('updateTimeToFull', [parseInt(time)]); |
| }, |
| - updatePowerProperties: function(percent, external_power, empty, full) { |
| - this.batteryPercent = percent; |
| - this.externalPower = this.externalPowerOptions[external_power]; |
| - this.timeUntilEmpty = empty; |
| - this.timeUntilFull = full; |
| + updatePowerProperties: function(power_properties) { |
| + this.batteryPercent = power_properties.battery_percent; |
| + this.batteryState = |
| + this.batteryStateOptions[power_properties.battery_state]; |
|
michaelpg
2015/07/30 03:02:09
indent 4 spaces
mozartalouis
2015/07/30 21:18:18
Done.
|
| + this.externalPower = |
| + this.externalPowerOptions[power_properties.external_power]; |
|
michaelpg
2015/07/30 03:02:09
same
mozartalouis
2015/07/30 21:18:18
Done.
|
| + this.timeUntilEmpty = power_properties.battery_time_to_empty_sec; |
| + this.timeUntilFull = power_properties.battery_time_to_full_sec; |
| } |
| }); |