OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 #ifndef ASH_COMMON_SYSTEM_CHROMEOS_POWER_POWER_STATUS_H_ | 5 #ifndef ASH_COMMON_SYSTEM_CHROMEOS_POWER_POWER_STATUS_H_ |
6 #define ASH_COMMON_SYSTEM_CHROMEOS_POWER_POWER_STATUS_H_ | 6 #define ASH_COMMON_SYSTEM_CHROMEOS_POWER_POWER_STATUS_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "ash/ash_export.h" | 11 #include "ash/ash_export.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/observer_list.h" | 13 #include "base/observer_list.h" |
14 #include "base/strings/string16.h" | 14 #include "base/strings/string16.h" |
15 #include "base/time/time.h" | 15 #include "base/time/time.h" |
16 #include "chromeos/dbus/power_manager/power_supply_properties.pb.h" | 16 #include "chromeos/dbus/power_manager/power_supply_properties.pb.h" |
17 #include "chromeos/dbus/power_manager_client.h" | 17 #include "chromeos/dbus/power_manager_client.h" |
18 #include "ui/gfx/image/image_skia.h" | 18 #include "ui/gfx/image/image_skia.h" |
19 | 19 |
20 namespace gfx { | |
21 struct VectorIcon; | |
22 } | |
23 | |
24 namespace ash { | 20 namespace ash { |
25 | 21 |
26 // PowerStatus is a singleton that receives updates about the system's | 22 // PowerStatus is a singleton that receives updates about the system's |
27 // power status from chromeos::PowerManagerClient and makes the information | 23 // power status from chromeos::PowerManagerClient and makes the information |
28 // available to interested classes within Ash. | 24 // available to interested classes within Ash. |
29 class ASH_EXPORT PowerStatus : public chromeos::PowerManagerClient::Observer { | 25 class ASH_EXPORT PowerStatus : public chromeos::PowerManagerClient::Observer { |
30 public: | 26 public: |
| 27 // Types of badges which can be drawn on top of a battery icon. |
| 28 enum IconBadge { |
| 29 ICON_BADGE_NONE, |
| 30 ICON_BADGE_ALERT, |
| 31 ICON_BADGE_BOLT, |
| 32 ICON_BADGE_X, |
| 33 ICON_BADGE_UNRELIABLE |
| 34 }; |
| 35 |
31 // Different styles of battery icons. | 36 // Different styles of battery icons. |
32 enum IconSet { ICON_LIGHT, ICON_DARK }; | 37 enum IconSet { ICON_LIGHT, ICON_DARK }; |
33 | 38 |
34 // Interface for classes that wish to be notified when the power status | 39 // Interface for classes that wish to be notified when the power status |
35 // has changed. | 40 // has changed. |
36 class Observer { | 41 class Observer { |
37 public: | 42 public: |
38 // Called when the power status changes. | 43 // Called when the power status changes. |
39 virtual void OnPowerStatusChanged() = 0; | 44 virtual void OnPowerStatusChanged() = 0; |
40 | 45 |
(...skipping 20 matching lines...) Expand all Loading... |
61 | 66 |
62 // Message ID of a description for this port. | 67 // Message ID of a description for this port. |
63 int description_id; | 68 int description_id; |
64 }; | 69 }; |
65 | 70 |
66 // Information about the battery image corresponding to the status at a given | 71 // Information about the battery image corresponding to the status at a given |
67 // point in time. This can be cached and later compared to avoid unnecessarily | 72 // point in time. This can be cached and later compared to avoid unnecessarily |
68 // updating onscreen icons (GetBatteryImage() creates a new image on each | 73 // updating onscreen icons (GetBatteryImage() creates a new image on each |
69 // call). | 74 // call). |
70 struct BatteryImageInfo { | 75 struct BatteryImageInfo { |
71 BatteryImageInfo() : icon_badge(nullptr), charge_level(-1) {} | 76 BatteryImageInfo() |
| 77 : resource_id(-1), |
| 78 offset(-1), |
| 79 index(-1), |
| 80 icon_badge(ICON_BADGE_NONE), |
| 81 charge_level(-1) {} |
72 | 82 |
73 bool operator==(const BatteryImageInfo& o) const; | 83 bool operator==(const BatteryImageInfo& o) const; |
74 | 84 |
75 bool operator!=(const BatteryImageInfo& o) const { return !(*this == o); } | 85 bool operator!=(const BatteryImageInfo& o) const { return !(*this == o); } |
76 | 86 |
| 87 // Resource ID of the image containing the specific battery icon to use. |
| 88 // Only used in non-MD. |
| 89 int resource_id; |
| 90 |
| 91 // Horizontal offset in the battery icon array image. The USB / "unreliable |
| 92 // charging" image has a single column of icons; the other image contains a |
| 93 // "battery" column on the left and a "line power" column on the right. |
| 94 // Only used in non-MD. |
| 95 int offset; |
| 96 |
| 97 // Vertical offset corresponding to the current battery level. Only used in |
| 98 // non-MD. |
| 99 int index; |
| 100 |
77 // The badge (lightning bolt, exclamation mark, etc) that should be drawn | 101 // The badge (lightning bolt, exclamation mark, etc) that should be drawn |
78 // on top of the battery icon. | 102 // on top of the battery icon. Only used for MD. |
79 const gfx::VectorIcon* icon_badge; | 103 // TODO(tdanderson): Consider using gfx::VectorIconId instead of this enum |
| 104 // once all possible badges have been vectorized. See crbug.com/617298. |
| 105 IconBadge icon_badge; |
80 | 106 |
81 // A value between 0 and kBatteryImageHeight representing the height | 107 // A value between 0 and kBatteryImageHeightMD representing the height |
82 // of the battery's charge level in dp. | 108 // of the battery's charge level in dp. Only used for MD. |
83 int charge_level; | 109 int charge_level; |
84 }; | 110 }; |
85 | 111 |
86 // Maximum battery time-to-full or time-to-empty that should be displayed | 112 // Maximum battery time-to-full or time-to-empty that should be displayed |
87 // in the UI. If the current is close to zero, battery time estimates can | 113 // in the UI. If the current is close to zero, battery time estimates can |
88 // get very large; avoid displaying these large numbers. | 114 // get very large; avoid displaying these large numbers. |
89 static const int kMaxBatteryTimeToDisplaySec; | 115 static const int kMaxBatteryTimeToDisplaySec; |
90 | 116 |
91 // An alert badge is drawn over the battery icon if the battery is not | 117 // An alert badge is drawn over the material design battery icon if the |
92 // connected to a charger and has less than |kCriticalBatteryChargePercentage| | 118 // battery is not connected to a charger and has less than |
93 // percentage of charge remaining. | 119 // |kCriticalBatteryChargePercentageMd| percentage of charge remaining. |
94 static const double kCriticalBatteryChargePercentage; | 120 static const double kCriticalBatteryChargePercentageMd; |
95 | 121 |
96 // Sets the global instance. Must be called before any calls to Get(). | 122 // Sets the global instance. Must be called before any calls to Get(). |
97 static void Initialize(); | 123 static void Initialize(); |
98 | 124 |
99 // Destroys the global instance. | 125 // Destroys the global instance. |
100 static void Shutdown(); | 126 static void Shutdown(); |
101 | 127 |
102 // Returns true if the global instance is initialized. | 128 // Returns true if the global instance is initialized. |
103 static bool IsInitialized(); | 129 static bool IsInitialized(); |
104 | 130 |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 | 213 |
188 // Returns the ID of the currently used power source, or an empty string if no | 214 // Returns the ID of the currently used power source, or an empty string if no |
189 // power source is selected. | 215 // power source is selected. |
190 std::string GetCurrentPowerSourceID() const; | 216 std::string GetCurrentPowerSourceID() const; |
191 | 217 |
192 // Returns information about the image that would be returned by | 218 // Returns information about the image that would be returned by |
193 // GetBatteryImage(). This can be cached and compared against future objects | 219 // GetBatteryImage(). This can be cached and compared against future objects |
194 // returned by this method to avoid creating new images unnecessarily. | 220 // returned by this method to avoid creating new images unnecessarily. |
195 BatteryImageInfo GetBatteryImageInfo(IconSet icon_set) const; | 221 BatteryImageInfo GetBatteryImageInfo(IconSet icon_set) const; |
196 | 222 |
197 // A helper function called by GetBatteryImageInfo(). Populates the fields of | 223 // A helper function called by GetBatteryImageInfo(). Populates the |
198 // |info|. | 224 // MD-specific fields of |info|. |
199 void CalculateBatteryImageInfo(BatteryImageInfo* info) const; | 225 void CalculateBatteryImageInfoMd(BatteryImageInfo* info) const; |
| 226 |
| 227 // A helper function called by GetBatteryImageInfo(). Populates the |
| 228 // non-MD-specific fields of |info|. |
| 229 void CalculateBatteryImageInfoNonMd(BatteryImageInfo* info, |
| 230 const IconSet& icon_set) const; |
200 | 231 |
201 // Creates a new image that should be shown for the battery's current state. | 232 // Creates a new image that should be shown for the battery's current state. |
202 gfx::ImageSkia GetBatteryImage(const BatteryImageInfo& info) const; | 233 gfx::ImageSkia GetBatteryImage(const BatteryImageInfo& info) const; |
203 | 234 |
| 235 // A version of GetBatteryImage() that is used when material design is not |
| 236 // enabled. |
| 237 // TODO(tdanderson): Remove this once material design is enabled by default. |
| 238 // See crbug.com/614453. |
| 239 gfx::ImageSkia GetBatteryImageNonMd(const BatteryImageInfo& info) const; |
| 240 |
204 // Returns an string describing the current state for accessibility. | 241 // Returns an string describing the current state for accessibility. |
205 base::string16 GetAccessibleNameString(bool full_description) const; | 242 base::string16 GetAccessibleNameString(bool full_description) const; |
206 | 243 |
207 // Updates |proto_|. Does not notify observers. | 244 // Updates |proto_|. Does not notify observers. |
208 void SetProtoForTesting(const power_manager::PowerSupplyProperties& proto); | 245 void SetProtoForTesting(const power_manager::PowerSupplyProperties& proto); |
209 | 246 |
210 protected: | 247 protected: |
211 PowerStatus(); | 248 PowerStatus(); |
212 ~PowerStatus() override; | 249 ~PowerStatus() override; |
213 | 250 |
214 private: | 251 private: |
215 // Overriden from PowerManagerClient::Observer. | 252 // Overriden from PowerManagerClient::Observer. |
216 void PowerChanged(const power_manager::PowerSupplyProperties& proto) override; | 253 void PowerChanged(const power_manager::PowerSupplyProperties& proto) override; |
217 | 254 |
218 base::ObserverList<Observer> observers_; | 255 base::ObserverList<Observer> observers_; |
219 | 256 |
220 // Current state. | 257 // Current state. |
221 power_manager::PowerSupplyProperties proto_; | 258 power_manager::PowerSupplyProperties proto_; |
222 | 259 |
223 DISALLOW_COPY_AND_ASSIGN(PowerStatus); | 260 DISALLOW_COPY_AND_ASSIGN(PowerStatus); |
224 }; | 261 }; |
225 | 262 |
226 } // namespace ash | 263 } // namespace ash |
227 | 264 |
228 #endif // ASH_COMMON_SYSTEM_CHROMEOS_POWER_POWER_STATUS_H_ | 265 #endif // ASH_COMMON_SYSTEM_CHROMEOS_POWER_POWER_STATUS_H_ |
OLD | NEW |