Allow only one bookmark to be added for multiple fast starring
[chromium-blink-merge.git] / chrome / browser / resources / chromeos / emulator / battery_settings.js
blob73db39e5dba4db3982f305f2c8539cfa76c9eaba
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 var BatterySettings = Polymer({
6 is: 'battery-settings',
8 properties: {
9 /**
10 * The system's battery percentage.
12 batteryPercent: {
13 type: Number,
14 observer: 'batteryPercentChanged',
17 /**
18 * A string representing a value in the
19 * PowerSupplyProperties_BatteryState enumeration.
21 batteryState: {
22 type: String,
23 observer: 'batteryStateChanged',
26 /**
27 * An array representing the battery state options.
28 * The names are ordered based on the
29 * PowerSupplyProperties_BatteryState enumeration. These values must be
30 * in sync.
32 batteryStateOptions: {
33 type: Array,
34 value: function() { return ['Full', 'Charging', 'Disharging',
35 'Not Present']; },
38 /**
39 * A string representing a value in the
40 * PowerSupplyProperties_ExternalPower enumeration.
42 externalPower: {
43 type: String,
44 observer: 'externalPowerChanged',
47 /**
48 * An array representing the external power options.
49 * The names are ordered based on the
50 * PowerSupplyProperties_ExternalPower enumeration. These values must be
51 * in sync.
53 externalPowerOptions: {
54 type: Array,
55 value: function() { return ['AC', 'USB (Low Power)', 'Disconnected']; }
58 /**
59 * A string representing the time left until the battery is discharged.
61 timeUntilEmpty: {
62 type: String,
63 observer: 'timeUntilEmptyChanged',
66 /**
67 * A string representing the time left until the battery is at 100%.
69 timeUntilFull: {
70 type: String,
71 observer: 'timeUntilFullChanged',
74 /**
75 * The title for the settings section.
77 title: {
78 type: String,
82 ready: function() {
83 this.title = 'Power Settings';
86 batteryPercentChanged: function(percent, oldPercent) {
87 if (oldPercent != undefined)
88 chrome.send('updateBatteryPercent', [parseInt(percent)]);
91 batteryStateChanged: function(state) {
92 // Find the index of the selected battery state.
93 var index = this.batteryStateOptions.indexOf(state);
94 if (index >= 0)
95 chrome.send('updateBatteryState', [index]);
98 externalPowerChanged: function(source) {
99 // Find the index of the selected power source.
100 var index = this.externalPowerOptions.indexOf(source);
101 if (index >= 0)
102 chrome.send('updateExternalPower', [index]);
105 timeUntilEmptyChanged: function(time, oldTime) {
106 if (oldTime != undefined)
107 chrome.send('updateTimeToEmpty', [parseInt(time)]);
110 timeUntilFullChanged: function(time, oldTime) {
111 if (oldTime != undefined)
112 chrome.send('updateTimeToFull', [parseInt(time)]);
115 updatePowerProperties: function(power_properties) {
116 this.batteryPercent = power_properties.battery_percent;
117 this.batteryState =
118 this.batteryStateOptions[power_properties.battery_state];
119 this.externalPower =
120 this.externalPowerOptions[power_properties.external_power];
121 this.timeUntilEmpty = power_properties.battery_time_to_empty_sec;
122 this.timeUntilFull = power_properties.battery_time_to_full_sec;