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

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: tests added 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_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 "ash/common/material_design/material_design_controller.h"
12 #include "base/macros.h" 13 #include "base/macros.h"
13 #include "base/observer_list.h" 14 #include "base/observer_list.h"
14 #include "base/strings/string16.h" 15 #include "base/strings/string16.h"
15 #include "base/time/time.h" 16 #include "base/time/time.h"
16 #include "chromeos/dbus/power_manager/power_supply_properties.pb.h" 17 #include "chromeos/dbus/power_manager/power_supply_properties.pb.h"
17 #include "chromeos/dbus/power_manager_client.h" 18 #include "chromeos/dbus/power_manager_client.h"
18 #include "ui/gfx/image/image_skia.h" 19 #include "ui/gfx/image/image_skia.h"
19 20
20 namespace ash { 21 namespace ash {
21 22
22 // PowerStatus is a singleton that receives updates about the system's 23 // PowerStatus is a singleton that receives updates about the system's
23 // power status from chromeos::PowerManagerClient and makes the information 24 // power status from chromeos::PowerManagerClient and makes the information
24 // available to interested classes within Ash. 25 // available to interested classes within Ash.
25 class ASH_EXPORT PowerStatus : public chromeos::PowerManagerClient::Observer { 26 class ASH_EXPORT PowerStatus : public chromeos::PowerManagerClient::Observer {
26 public: 27 public:
28 // Types of badges which can be drawn over top of a battery icon.
James Cook 2016/06/21 23:19:00 nit: "on top of a" or "over a"
tdanderson 2016/06/22 15:25:00 Done.
29 enum IconBadge {
30 ICON_BADGE_NONE,
31 ICON_BADGE_ALERT,
32 ICON_BADGE_BOLT,
33 ICON_BADGE_X,
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 23 matching lines...) Expand all
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 // 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 76 // point in time. This can be cached and later compared to avoid unnecessarily
67 // updating onscreen icons (GetBatteryImage() creates a new image on each 77 // updating onscreen icons (GetBatteryImage() creates a new image on each
68 // call). 78 // call).
69 struct BatteryImageInfo { 79 struct BatteryImageInfo {
70 BatteryImageInfo() : resource_id(-1), offset(-1), index(-1) {} 80 BatteryImageInfo()
81 : resource_id(-1),
82 offset(-1),
83 index(-1),
84 icon_badge(ICON_BADGE_NONE),
85 charge_level(-1) {}
71 86
72 bool operator==(const BatteryImageInfo& o) const { 87 bool operator==(const BatteryImageInfo& o) const {
88 if (ash::MaterialDesignController::UseMaterialDesignSystemIcons())
James Cook 2016/06/21 23:19:00 please define this function in the .cc file so you
tdanderson 2016/06/22 15:25:00 Done.
89 return icon_badge == o.icon_badge && charge_level == o.charge_level;
90
91 // TODO(tdanderson): |resource_id|, |offset|, and |index| are only used
92 // for non-MD. Remove these once MD is enabled by default. See
93 // crbug.com/614453.
73 return resource_id == o.resource_id && offset == o.offset && 94 return resource_id == o.resource_id && offset == o.offset &&
74 index == o.index; 95 index == o.index;
75 } 96 }
97
76 bool operator!=(const BatteryImageInfo& o) const { return !(*this == o); } 98 bool operator!=(const BatteryImageInfo& o) const { return !(*this == o); }
77 99
78 // Resource ID of the image containing the specific battery icon to use. 100 // Resource ID of the image containing the specific battery icon to use.
101 // Only used in non-MD.
79 int resource_id; 102 int resource_id;
80 103
81 // Horizontal offset in the battery icon array image. The USB / "unreliable 104 // 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 105 // 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. 106 // "battery" column on the left and a "line power" column on the right.
107 // Only used in non-MD.
84 int offset; 108 int offset;
85 109
86 // Vertical offset corresponding to the current battery level. 110 // Vertical offset corresponding to the current battery level. Only used in
111 // non-MD.
87 int index; 112 int index;
113
114 // The badge (lightning bolt, exclamation mark, etc) that should be drawn
115 // on top of the battery icon. Only used for MD.
116 // TODO(tdanderson): Consider using gfx::VectorIconId instead of this enum
117 // once all possible badges have been vectorized. See crbug.com/617298.
118 IconBadge icon_badge;
119
120 // A value between 0 and kBatteryImageHeightMD representing the height
121 // of the battery's charge level in dp. Only used for MD.
122 int charge_level;
88 }; 123 };
89 124
90 // Maximum battery time-to-full or time-to-empty that should be displayed 125 // 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 126 // in the UI. If the current is close to zero, battery time estimates can
92 // get very large; avoid displaying these large numbers. 127 // get very large; avoid displaying these large numbers.
93 static const int kMaxBatteryTimeToDisplaySec; 128 static const int kMaxBatteryTimeToDisplaySec;
94 129
95 // Sets the global instance. Must be called before any calls to Get(). 130 // Sets the global instance. Must be called before any calls to Get().
96 static void Initialize(); 131 static void Initialize();
97 132
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 221
187 // Returns the ID of the currently used power source, or an empty string if no 222 // Returns the ID of the currently used power source, or an empty string if no
188 // power source is selected. 223 // power source is selected.
189 std::string GetCurrentPowerSourceID() const; 224 std::string GetCurrentPowerSourceID() const;
190 225
191 // Returns information about the image that would be returned by 226 // Returns information about the image that would be returned by
192 // GetBatteryImage(). This can be cached and compared against future objects 227 // GetBatteryImage(). This can be cached and compared against future objects
193 // returned by this method to avoid creating new images unnecessarily. 228 // returned by this method to avoid creating new images unnecessarily.
194 BatteryImageInfo GetBatteryImageInfo(IconSet icon_set) const; 229 BatteryImageInfo GetBatteryImageInfo(IconSet icon_set) const;
195 230
231 // A helper function called by GetBatteryImageInfo(). Populates the
232 // MD-specific fields of |info|.
233 void CalculateBatteryImageInfoMD(BatteryImageInfo* info) const;
234
235 // A helper function called by GetBatteryImageInfo(). Populates the
236 // non-MD-specific fields of |info|.
237 void CalculateBatteryImageInfoNonMD(BatteryImageInfo* info,
238 const IconSet& icon_set) const;
239
196 // Creates a new image that should be shown for the battery's current state. 240 // Creates a new image that should be shown for the battery's current state.
197 gfx::ImageSkia GetBatteryImage(IconSet icon_set) const; 241 gfx::ImageSkia GetBatteryImage(const BatteryImageInfo& info) const;
242
243 // A version of GetBatteryImage() that is used when material design is not
244 // enabled.
245 // TODO(tdanderson): Remove this once material design is enabled by default.
246 // See crbug.com/614453.
247 gfx::ImageSkia GetBatteryImageNonMD(const BatteryImageInfo& info) const;
198 248
199 // Returns an string describing the current state for accessibility. 249 // Returns an string describing the current state for accessibility.
200 base::string16 GetAccessibleNameString(bool full_description) const; 250 base::string16 GetAccessibleNameString(bool full_description) const;
201 251
202 // Updates |proto_|. Does not notify observers. 252 // Updates |proto_|. Does not notify observers.
203 void SetProtoForTesting(const power_manager::PowerSupplyProperties& proto); 253 void SetProtoForTesting(const power_manager::PowerSupplyProperties& proto);
204 254
205 protected: 255 protected:
206 PowerStatus(); 256 PowerStatus();
207 ~PowerStatus() override; 257 ~PowerStatus() override;
208 258
209 private: 259 private:
210 // Overriden from PowerManagerClient::Observer. 260 // Overriden from PowerManagerClient::Observer.
211 void PowerChanged(const power_manager::PowerSupplyProperties& proto) override; 261 void PowerChanged(const power_manager::PowerSupplyProperties& proto) override;
212 262
213 base::ObserverList<Observer> observers_; 263 base::ObserverList<Observer> observers_;
214 264
215 // Current state. 265 // Current state.
216 power_manager::PowerSupplyProperties proto_; 266 power_manager::PowerSupplyProperties proto_;
217 267
218 DISALLOW_COPY_AND_ASSIGN(PowerStatus); 268 DISALLOW_COPY_AND_ASSIGN(PowerStatus);
219 }; 269 };
220 270
221 } // namespace ash 271 } // namespace ash
222 272
223 #endif // ASH_COMMON_SYSTEM_CHROMEOS_POWER_POWER_STATUS_H_ 273 #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') | ash/common/system/chromeos/power/power_status.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698