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