Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(166)

Side by Side Diff: ash/common/system/chromeos/power/power_status.h

Issue 2063633002: Render Ash material design battery image icon without PNGs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add battery percentage constant Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | ash/common/system/chromeos/power/power_status.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 ash { 20 namespace ash {
21 21
22 // PowerStatus is a singleton that receives updates about the system's 22 // PowerStatus is a singleton that receives updates about the system's
23 // power status from chromeos::PowerManagerClient and makes the information 23 // power status from chromeos::PowerManagerClient and makes the information
24 // available to interested classes within Ash. 24 // available to interested classes within Ash.
25 class ASH_EXPORT PowerStatus : public chromeos::PowerManagerClient::Observer { 25 class ASH_EXPORT PowerStatus : public chromeos::PowerManagerClient::Observer {
26 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
27 // Different styles of battery icons. 36 // Different styles of battery icons.
28 enum IconSet { 37 enum IconSet {
29 ICON_LIGHT, 38 ICON_LIGHT,
30 ICON_DARK 39 ICON_DARK
31 }; 40 };
32 41
33 // Interface for classes that wish to be notified when the power status 42 // Interface for classes that wish to be notified when the power status
34 // has changed. 43 // has changed.
35 class Observer { 44 class Observer {
36 public: 45 public:
(...skipping 23 matching lines...) Expand all
60 69
61 // Message ID of a description for this port. 70 // Message ID of a description for this port.
62 int description_id; 71 int description_id;
63 }; 72 };
64 73
65 // Information about the battery image corresponding to the status at a given 74 // Information about the battery image corresponding to the status at a given
66 // point in time. This can be cached and later compared to avoid unnecessarily 75 // point in time. This can be cached and later compared to avoid unnecessarily
67 // updating onscreen icons (GetBatteryImage() creates a new image on each 76 // updating onscreen icons (GetBatteryImage() creates a new image on each
68 // call). 77 // call).
69 struct BatteryImageInfo { 78 struct BatteryImageInfo {
70 BatteryImageInfo() : resource_id(-1), offset(-1), index(-1) {} 79 BatteryImageInfo()
80 : resource_id(-1),
81 offset(-1),
82 index(-1),
83 icon_badge(ICON_BADGE_NONE),
84 charge_level(-1) {}
71 85
72 bool operator==(const BatteryImageInfo& o) const { 86 bool operator==(const BatteryImageInfo& o) const;
73 return resource_id == o.resource_id && offset == o.offset && 87
74 index == o.index;
75 }
76 bool operator!=(const BatteryImageInfo& o) const { return !(*this == o); } 88 bool operator!=(const BatteryImageInfo& o) const { return !(*this == o); }
77 89
78 // Resource ID of the image containing the specific battery icon to use. 90 // Resource ID of the image containing the specific battery icon to use.
91 // Only used in non-MD.
79 int resource_id; 92 int resource_id;
80 93
81 // Horizontal offset in the battery icon array image. The USB / "unreliable 94 // Horizontal offset in the battery icon array image. The USB / "unreliable
82 // charging" image has a single column of icons; the other image contains a 95 // charging" image has a single column of icons; the other image contains a
83 // "battery" column on the left and a "line power" column on the right. 96 // "battery" column on the left and a "line power" column on the right.
97 // Only used in non-MD.
84 int offset; 98 int offset;
85 99
86 // Vertical offset corresponding to the current battery level. 100 // Vertical offset corresponding to the current battery level. Only used in
101 // non-MD.
87 int index; 102 int index;
103
104 // The badge (lightning bolt, exclamation mark, etc) that should be drawn
105 // on top of the battery icon. Only used for MD.
106 // TODO(tdanderson): Consider using gfx::VectorIconId instead of this enum
107 // once all possible badges have been vectorized. See crbug.com/617298.
108 IconBadge icon_badge;
109
110 // A value between 0 and kBatteryImageHeightMD representing the height
111 // of the battery's charge level in dp. Only used for MD.
112 int charge_level;
88 }; 113 };
89 114
90 // Maximum battery time-to-full or time-to-empty that should be displayed 115 // Maximum battery time-to-full or time-to-empty that should be displayed
91 // in the UI. If the current is close to zero, battery time estimates can 116 // in the UI. If the current is close to zero, battery time estimates can
92 // get very large; avoid displaying these large numbers. 117 // get very large; avoid displaying these large numbers.
93 static const int kMaxBatteryTimeToDisplaySec; 118 static const int kMaxBatteryTimeToDisplaySec;
94 119
120 // An alert badge is drawn over the material design battery icon if the
121 // battery is not connected to a charger and has less than
122 // |kCriticalBatteryChargePercentageMd| percentage of charge remaining.
123 static const double kCriticalBatteryChargePercentageMd;
124
95 // Sets the global instance. Must be called before any calls to Get(). 125 // Sets the global instance. Must be called before any calls to Get().
96 static void Initialize(); 126 static void Initialize();
97 127
98 // Destroys the global instance. 128 // Destroys the global instance.
99 static void Shutdown(); 129 static void Shutdown();
100 130
101 // Returns true if the global instance is initialized. 131 // Returns true if the global instance is initialized.
102 static bool IsInitialized(); 132 static bool IsInitialized();
103 133
104 // Gets the global instance. Initialize must be called first. 134 // Gets the global instance. Initialize must be called first.
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 216
187 // Returns the ID of the currently used power source, or an empty string if no 217 // Returns the ID of the currently used power source, or an empty string if no
188 // power source is selected. 218 // power source is selected.
189 std::string GetCurrentPowerSourceID() const; 219 std::string GetCurrentPowerSourceID() const;
190 220
191 // Returns information about the image that would be returned by 221 // Returns information about the image that would be returned by
192 // GetBatteryImage(). This can be cached and compared against future objects 222 // GetBatteryImage(). This can be cached and compared against future objects
193 // returned by this method to avoid creating new images unnecessarily. 223 // returned by this method to avoid creating new images unnecessarily.
194 BatteryImageInfo GetBatteryImageInfo(IconSet icon_set) const; 224 BatteryImageInfo GetBatteryImageInfo(IconSet icon_set) const;
195 225
226 // A helper function called by GetBatteryImageInfo(). Populates the
227 // MD-specific fields of |info|.
228 void CalculateBatteryImageInfoMd(BatteryImageInfo* info) const;
229
230 // A helper function called by GetBatteryImageInfo(). Populates the
231 // non-MD-specific fields of |info|.
232 void CalculateBatteryImageInfoNonMd(BatteryImageInfo* info,
233 const IconSet& icon_set) const;
234
196 // Creates a new image that should be shown for the battery's current state. 235 // Creates a new image that should be shown for the battery's current state.
197 gfx::ImageSkia GetBatteryImage(IconSet icon_set) const; 236 gfx::ImageSkia GetBatteryImage(const BatteryImageInfo& info) const;
237
238 // A version of GetBatteryImage() that is used when material design is not
239 // enabled.
240 // TODO(tdanderson): Remove this once material design is enabled by default.
241 // See crbug.com/614453.
242 gfx::ImageSkia GetBatteryImageNonMd(const BatteryImageInfo& info) const;
198 243
199 // Returns an string describing the current state for accessibility. 244 // Returns an string describing the current state for accessibility.
200 base::string16 GetAccessibleNameString(bool full_description) const; 245 base::string16 GetAccessibleNameString(bool full_description) const;
201 246
202 // Updates |proto_|. Does not notify observers. 247 // Updates |proto_|. Does not notify observers.
203 void SetProtoForTesting(const power_manager::PowerSupplyProperties& proto); 248 void SetProtoForTesting(const power_manager::PowerSupplyProperties& proto);
204 249
205 protected: 250 protected:
206 PowerStatus(); 251 PowerStatus();
207 ~PowerStatus() override; 252 ~PowerStatus() override;
208 253
209 private: 254 private:
210 // Overriden from PowerManagerClient::Observer. 255 // Overriden from PowerManagerClient::Observer.
211 void PowerChanged(const power_manager::PowerSupplyProperties& proto) override; 256 void PowerChanged(const power_manager::PowerSupplyProperties& proto) override;
212 257
213 base::ObserverList<Observer> observers_; 258 base::ObserverList<Observer> observers_;
214 259
215 // Current state. 260 // Current state.
216 power_manager::PowerSupplyProperties proto_; 261 power_manager::PowerSupplyProperties proto_;
217 262
218 DISALLOW_COPY_AND_ASSIGN(PowerStatus); 263 DISALLOW_COPY_AND_ASSIGN(PowerStatus);
219 }; 264 };
220 265
221 } // namespace ash 266 } // namespace ash
222 267
223 #endif // ASH_COMMON_SYSTEM_CHROMEOS_POWER_POWER_STATUS_H_ 268 #endif // ASH_COMMON_SYSTEM_CHROMEOS_POWER_POWER_STATUS_H_
OLDNEW
« no previous file with comments | « no previous file | ash/common/system/chromeos/power/power_status.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698