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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: ash/common/system/chromeos/power/power_status.h
diff --git a/ash/common/system/chromeos/power/power_status.h b/ash/common/system/chromeos/power/power_status.h
index 26c4b1947ad5f8b34cf4c6feb463cbadbba7a480..e7cd65373d1cb1b6ec24ae46eb5c692da30db16f 100644
--- a/ash/common/system/chromeos/power/power_status.h
+++ b/ash/common/system/chromeos/power/power_status.h
@@ -9,6 +9,7 @@
#include <vector>
#include "ash/ash_export.h"
+#include "ash/common/material_design/material_design_controller.h"
#include "base/macros.h"
#include "base/observer_list.h"
#include "base/strings/string16.h"
@@ -24,6 +25,15 @@ namespace ash {
// available to interested classes within Ash.
class ASH_EXPORT PowerStatus : public chromeos::PowerManagerClient::Observer {
public:
+ // 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.
+ enum IconBadge {
+ ICON_BADGE_NONE,
+ ICON_BADGE_ALERT,
+ ICON_BADGE_BOLT,
+ ICON_BADGE_X,
+ ICON_BADGE_UNRELIABLE
+ };
+
// Different styles of battery icons.
enum IconSet {
ICON_LIGHT,
@@ -67,24 +77,49 @@ class ASH_EXPORT PowerStatus : public chromeos::PowerManagerClient::Observer {
// updating onscreen icons (GetBatteryImage() creates a new image on each
// call).
struct BatteryImageInfo {
- BatteryImageInfo() : resource_id(-1), offset(-1), index(-1) {}
+ BatteryImageInfo()
+ : resource_id(-1),
+ offset(-1),
+ index(-1),
+ icon_badge(ICON_BADGE_NONE),
+ charge_level(-1) {}
bool operator==(const BatteryImageInfo& o) const {
+ 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.
+ return icon_badge == o.icon_badge && charge_level == o.charge_level;
+
+ // TODO(tdanderson): |resource_id|, |offset|, and |index| are only used
+ // for non-MD. Remove these once MD is enabled by default. See
+ // crbug.com/614453.
return resource_id == o.resource_id && offset == o.offset &&
index == o.index;
}
+
bool operator!=(const BatteryImageInfo& o) const { return !(*this == o); }
// Resource ID of the image containing the specific battery icon to use.
+ // Only used in non-MD.
int resource_id;
// Horizontal offset in the battery icon array image. The USB / "unreliable
// charging" image has a single column of icons; the other image contains a
// "battery" column on the left and a "line power" column on the right.
+ // Only used in non-MD.
int offset;
- // Vertical offset corresponding to the current battery level.
+ // Vertical offset corresponding to the current battery level. Only used in
+ // non-MD.
int index;
+
+ // The badge (lightning bolt, exclamation mark, etc) that should be drawn
+ // on top of the battery icon. Only used for MD.
+ // TODO(tdanderson): Consider using gfx::VectorIconId instead of this enum
+ // once all possible badges have been vectorized. See crbug.com/617298.
+ IconBadge icon_badge;
+
+ // A value between 0 and kBatteryImageHeightMD representing the height
+ // of the battery's charge level in dp. Only used for MD.
+ int charge_level;
};
// Maximum battery time-to-full or time-to-empty that should be displayed
@@ -193,8 +228,23 @@ class ASH_EXPORT PowerStatus : public chromeos::PowerManagerClient::Observer {
// returned by this method to avoid creating new images unnecessarily.
BatteryImageInfo GetBatteryImageInfo(IconSet icon_set) const;
+ // A helper function called by GetBatteryImageInfo(). Populates the
+ // MD-specific fields of |info|.
+ void CalculateBatteryImageInfoMD(BatteryImageInfo* info) const;
+
+ // A helper function called by GetBatteryImageInfo(). Populates the
+ // non-MD-specific fields of |info|.
+ void CalculateBatteryImageInfoNonMD(BatteryImageInfo* info,
+ const IconSet& icon_set) const;
+
// Creates a new image that should be shown for the battery's current state.
- gfx::ImageSkia GetBatteryImage(IconSet icon_set) const;
+ gfx::ImageSkia GetBatteryImage(const BatteryImageInfo& info) const;
+
+ // A version of GetBatteryImage() that is used when material design is not
+ // enabled.
+ // TODO(tdanderson): Remove this once material design is enabled by default.
+ // See crbug.com/614453.
+ gfx::ImageSkia GetBatteryImageNonMD(const BatteryImageInfo& info) const;
// Returns an string describing the current state for accessibility.
base::string16 GetAccessibleNameString(bool full_description) const;
« 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