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

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

Issue 2774093002: Change PowerStatus::GetBatteryImage to not use ExtractImageRep and scale (Closed)
Patch Set: powericon: removedeadunittestcode Created 3 years, 9 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
« no previous file with comments | « ash/common/system/chromeos/power/power_status_view_unittest.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ash/common/system/chromeos/power/tray_power.cc
diff --git a/ash/common/system/chromeos/power/tray_power.cc b/ash/common/system/chromeos/power/tray_power.cc
index 8e694e15c41542f9c14ca7a21cdbd7323a2d7ac2..b8c13bfa581ee777243a79de875c3736e2af7a69 100644
--- a/ash/common/system/chromeos/power/tray_power.cc
+++ b/ash/common/system/chromeos/power/tray_power.cc
@@ -25,6 +25,7 @@
#include "base/time/time.h"
#include "ui/accessibility/ax_node_data.h"
#include "ui/base/resource/resource_bundle.h"
+#include "ui/gfx/image/image_skia_source.h"
#include "ui/message_center/message_center.h"
#include "ui/message_center/notification.h"
#include "ui/message_center/notification_delegate.h"
@@ -100,7 +101,7 @@ class PowerTrayView : public TrayItemView {
~PowerTrayView() override {}
- // Overriden from views::View.
+ // Overridden from views::View.
void GetAccessibleNodeData(ui::AXNodeData* node_data) override {
node_data->SetName(accessible_name_);
node_data->role = ui::AX_ROLE_BUTTON;
@@ -117,20 +118,39 @@ class PowerTrayView : public TrayItemView {
}
private:
- void UpdateImage() {
- const PowerStatus::BatteryImageInfo info =
- PowerStatus::Get()->GetBatteryImageInfo(PowerStatus::ICON_LIGHT);
- if (info != previous_image_info_) {
- image_view()->SetImage(PowerStatus::Get()->GetBatteryImage(info));
- previous_image_info_ = info;
+ class PowerTrayImageSource : public gfx::ImageSkiaSource {
+ public:
+ explicit PowerTrayImageSource(const PowerStatus::BatteryImageInfo& info)
+ : info_(info) {}
+
+ // gfx::ImageSkiaSource implementation.
+ gfx::ImageSkiaRep GetImageForScale(float scale) override {
+ return PowerStatus::Get()->GetBatteryImage(info_, scale);
}
+
+ const PowerStatus::BatteryImageInfo& info() const { return info_; }
+
+ private:
+ PowerStatus::BatteryImageInfo info_;
+
+ DISALLOW_COPY_AND_ASSIGN(PowerTrayImageSource);
+ };
+
+ void UpdateImage() {
+ const PowerStatus::BatteryImageInfo& info =
+ PowerStatus::Get()->GetBatteryImageInfo();
+ // Only change the image when the info changes. http://crbug.com/589348
+ if (image_source_ && image_source_->info() == info)
+ return;
+ image_source_ = new PowerTrayImageSource(info);
+ // gfx::ImageSkia takes ownership of image_source_. It will stay alive until
+ // we call SetImage() again, which only happens here.
+ image_view()->SetImage(
+ gfx::ImageSkia(image_source_, PowerStatus::GetBatteryImageSizeInDip()));
}
base::string16 accessible_name_;
-
- // Information about the last-used image. Cached to avoid unnecessary updates
- // (http://crbug.com/589348).
- PowerStatus::BatteryImageInfo previous_image_info_;
+ PowerTrayImageSource* image_source_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(PowerTrayView);
};
« no previous file with comments | « ash/common/system/chromeos/power/power_status_view_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698