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

Unified Diff: ash/system/power/tray_power.cc

Issue 10907037: Only update system power indicators on change (Closed) Base URL: https://git.chromium.org/git/chromium/src@git-svn
Patch Set: Created 8 years, 4 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
« ash/system/power/tray_power.h ('K') | « ash/system/power/tray_power.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ash/system/power/tray_power.cc
diff --git a/ash/system/power/tray_power.cc b/ash/system/power/tray_power.cc
index cb8f03738a255246942b1731b033fa548f947a2c..8a12ef769bb09f2f1a17f6b646df2ef1900c7815 100644
--- a/ash/system/power/tray_power.cc
+++ b/ash/system/power/tray_power.cc
@@ -63,7 +63,8 @@ namespace tray {
// This view is used only for the tray.
class PowerTrayView : public views::ImageView {
public:
- PowerTrayView() {
+ PowerTrayView()
+ : battery_image_index_(-1) {
UpdateImage();
}
@@ -82,10 +83,15 @@ class PowerTrayView : public views::ImageView {
private:
void UpdateImage() {
- SetImage(TrayPower::GetBatteryImage(supply_status_, ICON_LIGHT));
+ int index = TrayPower::GetBatteryImageIndex(supply_status_);
+ if (battery_image_index_ != index) {
+ battery_image_index_ = index;
+ SetImage(TrayPower::GetBatteryImage(battery_image_index_, ICON_LIGHT));
+ }
}
PowerSupplyStatus supply_status_;
+ int battery_image_index_;
DISALLOW_COPY_AND_ASSIGN(PowerTrayView);
};
@@ -93,19 +99,25 @@ class PowerTrayView : public views::ImageView {
class PowerNotificationView : public TrayNotificationView {
public:
explicit PowerNotificationView(TrayPower* tray)
- : TrayNotificationView(tray, 0) {
+ : TrayNotificationView(tray, 0),
+ battery_image_index_(-1) {
power_status_view_ =
new PowerStatusView(PowerStatusView::VIEW_NOTIFICATION, true);
InitView(power_status_view_);
}
void UpdatePowerStatus(const PowerSupplyStatus& status) {
- SetIconImage(TrayPower::GetBatteryImage(status, ICON_DARK));
+ int index = TrayPower::GetBatteryImageIndex(status);
+ if (battery_image_index_ != index) {
+ battery_image_index_ = index;
+ SetIconImage(TrayPower::GetBatteryImage(battery_image_index_, ICON_DARK));
+ }
power_status_view_->UpdatePowerStatus(status);
}
private:
PowerStatusView* power_status_view_;
+ int battery_image_index_;
DISALLOW_COPY_AND_ASSIGN(PowerNotificationView);
};
@@ -124,13 +136,7 @@ TrayPower::~TrayPower() {
}
// static
-gfx::ImageSkia TrayPower::GetBatteryImage(
- const PowerSupplyStatus& supply_status,
- IconSet icon_set) {
- gfx::Image all = ui::ResourceBundle::GetSharedInstance().GetImageNamed(
- icon_set == ICON_DARK ?
- IDR_AURA_UBER_TRAY_POWER_SMALL_DARK : IDR_AURA_UBER_TRAY_POWER_SMALL);
-
+int TrayPower::GetBatteryImageIndex(const PowerSupplyStatus& supply_status) {
int image_index = 0;
if (supply_status.battery_percentage >= 100) {
image_index = kNumPowerImages - 1;
@@ -142,12 +148,20 @@ gfx::ImageSkia TrayPower::GetBatteryImage(
image_index = static_cast<int>(percentage / 100.0 * (kNumPowerImages - 1));
image_index = std::max(std::min(image_index, kNumPowerImages - 2), 0);
}
+ return (image_index << 1) | (supply_status.line_power_on ? 1 : 0);
+}
+
+// static
+gfx::ImageSkia TrayPower::GetBatteryImage(int image_index, IconSet icon_set) {
+ gfx::Image all = ui::ResourceBundle::GetSharedInstance().GetImageNamed(
+ icon_set == ICON_DARK ?
+ IDR_AURA_UBER_TRAY_POWER_SMALL_DARK : IDR_AURA_UBER_TRAY_POWER_SMALL);
// TODO(mbolohan): Remove the 2px offset when the assets are centered. See
// crbug.com/119832.
gfx::Rect region(
- (supply_status.line_power_on ? kBatteryImageWidth : 0) + 2,
- image_index * kBatteryImageHeight,
+ ((image_index & 0x1) ? kBatteryImageWidth : 0) + 2,
+ (image_index >> 1) * kBatteryImageHeight,
kBatteryImageWidth - 2, kBatteryImageHeight);
return gfx::ImageSkiaOperations::ExtractSubset(*all.ToImageSkia(), region);
}
« ash/system/power/tray_power.h ('K') | « ash/system/power/tray_power.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698