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

Side by Side Diff: ash/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: 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
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_SYSTEM_CHROMEOS_POWER_POWER_STATUS_H_ 5 #ifndef ASH_SYSTEM_CHROMEOS_POWER_POWER_STATUS_H_
6 #define ASH_SYSTEM_CHROMEOS_POWER_POWER_STATUS_H_ 6 #define ASH_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 over top of a battery icon.
28 enum IconBadge {
29 ICON_BADGE_NONE,
30 ICON_BADGE_ALERT,
31 ICON_BADGE_X,
32 ICON_BADGE_BOLT,
33 ICON_BADGE_QUESTION,
34 ICON_BADGE_UNRELIABLE
35 };
36
27 // Different styles of battery icons. 37 // Different styles of battery icons.
28 enum IconSet { 38 enum IconSet {
29 ICON_LIGHT, 39 ICON_LIGHT,
30 ICON_DARK 40 ICON_DARK
31 }; 41 };
32 42
33 // Interface for classes that wish to be notified when the power status 43 // Interface for classes that wish to be notified when the power status
34 // has changed. 44 // has changed.
35 class Observer { 45 class Observer {
36 public: 46 public:
(...skipping 18 matching lines...) Expand all
55 // ID provided by kernel. 65 // ID provided by kernel.
56 std::string id; 66 std::string id;
57 67
58 // Type of power source. 68 // Type of power source.
59 DeviceType type; 69 DeviceType type;
60 70
61 // Message ID of a description for this port. 71 // Message ID of a description for this port.
62 int description_id; 72 int description_id;
63 }; 73 };
64 74
65 // Information about the battery image corresponding to the status at a given 75 // A version of BatteryImageInfo used when material design is not enabled.
66 // point in time. This can be cached and later compared to avoid unnecessarily 76 // TODO(tdanderson): Remove this once material design is enabled by default.
67 // updating onscreen icons (GetBatteryImage() creates a new image on each 77 // See crbug.com/614453.
68 // call). 78 struct BatteryImageInfoNonMD {
69 struct BatteryImageInfo { 79 BatteryImageInfoNonMD() : resource_id(-1), offset(-1), index(-1) {}
70 BatteryImageInfo() : resource_id(-1), offset(-1), index(-1) {}
71 80
72 bool operator==(const BatteryImageInfo& o) const { 81 bool operator==(const BatteryImageInfoNonMD& o) const {
73 return resource_id == o.resource_id && offset == o.offset && 82 return resource_id == o.resource_id && offset == o.offset &&
74 index == o.index; 83 index == o.index;
75 } 84 }
76 bool operator!=(const BatteryImageInfo& o) const { return !(*this == o); } 85 bool operator!=(const BatteryImageInfoNonMD& o) const {
86 return !(*this == o);
87 }
77 88
78 // Resource ID of the image containing the specific battery icon to use. 89 // Resource ID of the image containing the specific battery icon to use.
79 int resource_id; 90 int resource_id;
80 91
81 // Horizontal offset in the battery icon array image. The USB / "unreliable 92 // 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 93 // 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. 94 // "battery" column on the left and a "line power" column on the right.
84 int offset; 95 int offset;
85 96
86 // Vertical offset corresponding to the current battery level. 97 // Vertical offset corresponding to the current battery level.
87 int index; 98 int index;
88 }; 99 };
89 100
101 // Information about the battery image corresponding to the status at a given
102 // point in time. This can be cached and later compared to avoid unnecessarily
103 // updating onscreen icons (GetBatteryImage() creates a new image on each
104 // call).
105 struct BatteryImageInfo {
106 BatteryImageInfo() : icon_set(ICON_LIGHT), icon_badge(ICON_BADGE_NONE), fill _level(-1) {}
107
108 bool operator==(const BatteryImageInfo& o) const {
109 return icon_set == o.icon_set &&
110 icon_badge == o.icon_badge &&
111 fill_level == o.fill_level;
112 }
113
114 bool operator!=(const BatteryImageInfo& o) const {
115 return !(*this == o);
116 }
117
118 // The color scheme that should be used for the icon. ICON_LIGHT is used
119 // for the system tray, and ICON_DARK is used elsewhere.
120 IconSet icon_set;
121
122 // The badge (lightning bolt, exclamation mark, etc) that should be drawn
123 // on top of the battery icon.
124 // TODO(tdanderson): Consider using gfx::VectorIconId instead of this enum
125 // once all possible badges have been vectorized. See crbug.com/617298.
126 IconBadge icon_badge;
127
128 // A value between 0 and 14 representing the number of pixels that should
129 // be drawn as the fill color, upwards from the bottom of the 16x16 grid
130 // containing the battery image. Note that there is 2px of bottom padding
131 // baked into the battery icon, which means that no fill amount will be
132 // visible inside the battery for a |fill_level| of 0 or 1.
133 int fill_level;
134 };
135
90 // Maximum battery time-to-full or time-to-empty that should be displayed 136 // 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 137 // in the UI. If the current is close to zero, battery time estimates can
92 // get very large; avoid displaying these large numbers. 138 // get very large; avoid displaying these large numbers.
93 static const int kMaxBatteryTimeToDisplaySec; 139 static const int kMaxBatteryTimeToDisplaySec;
94 140
95 // Sets the global instance. Must be called before any calls to Get(). 141 // Sets the global instance. Must be called before any calls to Get().
96 static void Initialize(); 142 static void Initialize();
97 143
98 // Destroys the global instance. 144 // Destroys the global instance.
99 static void Shutdown(); 145 static void Shutdown();
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 232
187 // Returns the ID of the currently used power source, or an empty string if no 233 // Returns the ID of the currently used power source, or an empty string if no
188 // power source is selected. 234 // power source is selected.
189 std::string GetCurrentPowerSourceID() const; 235 std::string GetCurrentPowerSourceID() const;
190 236
191 // Returns information about the image that would be returned by 237 // Returns information about the image that would be returned by
192 // GetBatteryImage(). This can be cached and compared against future objects 238 // GetBatteryImage(). This can be cached and compared against future objects
193 // returned by this method to avoid creating new images unnecessarily. 239 // returned by this method to avoid creating new images unnecessarily.
194 BatteryImageInfo GetBatteryImageInfo(IconSet icon_set) const; 240 BatteryImageInfo GetBatteryImageInfo(IconSet icon_set) const;
195 241
242 // Returns the BatteryImageInfoNonMD struct corresponding to |info|.
243 // TODO(tdanderson): Remove this once material design is enabled by default.
244 // See crbug.com/614453.
245 BatteryImageInfoNonMD ConvertToBatteryImageInfoNonMD(
246 const BatteryImageInfo info) const;
247
196 // Creates a new image that should be shown for the battery's current state. 248 // Creates a new image that should be shown for the battery's current state.
197 gfx::ImageSkia GetBatteryImage(IconSet icon_set) const; 249 gfx::ImageSkia GetBatteryImage(const BatteryImageInfo info) const;
250
251 // A version of GetBatteryImage() that is used when material design is not
252 // enabled.
253 // TODO(tdanderson): Remove this once material design is enabled by default.
254 // See crbug.com/614453.
255 gfx::ImageSkia GetBatteryImageNonMD(const BatteryImageInfoNonMD info) const;
198 256
199 // Returns an string describing the current state for accessibility. 257 // Returns an string describing the current state for accessibility.
200 base::string16 GetAccessibleNameString(bool full_description) const; 258 base::string16 GetAccessibleNameString(bool full_description) const;
201 259
202 // Updates |proto_|. Does not notify observers. 260 // Updates |proto_|. Does not notify observers.
203 void SetProtoForTesting(const power_manager::PowerSupplyProperties& proto); 261 void SetProtoForTesting(const power_manager::PowerSupplyProperties& proto);
204 262
205 protected: 263 protected:
206 PowerStatus(); 264 PowerStatus();
207 ~PowerStatus() override; 265 ~PowerStatus() override;
208 266
209 private: 267 private:
210 // Overriden from PowerManagerClient::Observer. 268 // Overriden from PowerManagerClient::Observer.
211 void PowerChanged(const power_manager::PowerSupplyProperties& proto) override; 269 void PowerChanged(const power_manager::PowerSupplyProperties& proto) override;
212 270
213 base::ObserverList<Observer> observers_; 271 base::ObserverList<Observer> observers_;
214 272
215 // Current state. 273 // Current state.
216 power_manager::PowerSupplyProperties proto_; 274 power_manager::PowerSupplyProperties proto_;
217 275
218 DISALLOW_COPY_AND_ASSIGN(PowerStatus); 276 DISALLOW_COPY_AND_ASSIGN(PowerStatus);
219 }; 277 };
220 278
221 } // namespace ash 279 } // namespace ash
222 280
223 #endif // ASH_SYSTEM_CHROMEOS_POWER_POWER_STATUS_H_ 281 #endif // ASH_SYSTEM_CHROMEOS_POWER_POWER_STATUS_H_
OLDNEW
« no previous file with comments | « no previous file | ash/system/chromeos/power/power_status.cc » ('j') | ash/system/chromeos/power/power_status.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698