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

Side by Side 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, 8 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
« no previous file with comments | « ash/common/system/chromeos/power/power_status_view_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include "ash/common/system/chromeos/power/tray_power.h" 5 #include "ash/common/system/chromeos/power/tray_power.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "ash/common/accessibility_delegate.h" 9 #include "ash/common/accessibility_delegate.h"
10 #include "ash/common/ash_switches.h" 10 #include "ash/common/ash_switches.h"
11 #include "ash/common/system/chromeos/devicetype_utils.h" 11 #include "ash/common/system/chromeos/devicetype_utils.h"
12 #include "ash/common/system/chromeos/power/battery_notification.h" 12 #include "ash/common/system/chromeos/power/battery_notification.h"
13 #include "ash/common/system/chromeos/power/dual_role_notification.h" 13 #include "ash/common/system/chromeos/power/dual_role_notification.h"
14 #include "ash/common/system/date/date_view.h" 14 #include "ash/common/system/date/date_view.h"
15 #include "ash/common/system/system_notifier.h" 15 #include "ash/common/system/system_notifier.h"
16 #include "ash/common/system/tray/system_tray_delegate.h" 16 #include "ash/common/system/tray/system_tray_delegate.h"
17 #include "ash/common/system/tray/tray_constants.h" 17 #include "ash/common/system/tray/tray_constants.h"
18 #include "ash/common/system/tray/tray_item_view.h" 18 #include "ash/common/system/tray/tray_item_view.h"
19 #include "ash/common/system/tray/tray_utils.h" 19 #include "ash/common/system/tray/tray_utils.h"
20 #include "ash/resources/grit/ash_resources.h" 20 #include "ash/resources/grit/ash_resources.h"
21 #include "ash/strings/grit/ash_strings.h" 21 #include "ash/strings/grit/ash_strings.h"
22 #include "base/command_line.h" 22 #include "base/command_line.h"
23 #include "base/logging.h" 23 #include "base/logging.h"
24 #include "base/metrics/histogram.h" 24 #include "base/metrics/histogram.h"
25 #include "base/time/time.h" 25 #include "base/time/time.h"
26 #include "ui/accessibility/ax_node_data.h" 26 #include "ui/accessibility/ax_node_data.h"
27 #include "ui/base/resource/resource_bundle.h" 27 #include "ui/base/resource/resource_bundle.h"
28 #include "ui/gfx/image/image_skia_source.h"
28 #include "ui/message_center/message_center.h" 29 #include "ui/message_center/message_center.h"
29 #include "ui/message_center/notification.h" 30 #include "ui/message_center/notification.h"
30 #include "ui/message_center/notification_delegate.h" 31 #include "ui/message_center/notification_delegate.h"
31 #include "ui/views/controls/image_view.h" 32 #include "ui/views/controls/image_view.h"
32 #include "ui/views/view.h" 33 #include "ui/views/view.h"
33 34
34 using message_center::MessageCenter; 35 using message_center::MessageCenter;
35 using message_center::Notification; 36 using message_center::Notification;
36 37
37 namespace ash { 38 namespace ash {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 // This view is used only for the tray. 94 // This view is used only for the tray.
94 class PowerTrayView : public TrayItemView { 95 class PowerTrayView : public TrayItemView {
95 public: 96 public:
96 explicit PowerTrayView(SystemTrayItem* owner) : TrayItemView(owner) { 97 explicit PowerTrayView(SystemTrayItem* owner) : TrayItemView(owner) {
97 CreateImageView(); 98 CreateImageView();
98 UpdateImage(); 99 UpdateImage();
99 } 100 }
100 101
101 ~PowerTrayView() override {} 102 ~PowerTrayView() override {}
102 103
103 // Overriden from views::View. 104 // Overridden from views::View.
104 void GetAccessibleNodeData(ui::AXNodeData* node_data) override { 105 void GetAccessibleNodeData(ui::AXNodeData* node_data) override {
105 node_data->SetName(accessible_name_); 106 node_data->SetName(accessible_name_);
106 node_data->role = ui::AX_ROLE_BUTTON; 107 node_data->role = ui::AX_ROLE_BUTTON;
107 } 108 }
108 109
109 void UpdateStatus(bool battery_alert) { 110 void UpdateStatus(bool battery_alert) {
110 UpdateImage(); 111 UpdateImage();
111 SetVisible(PowerStatus::Get()->IsBatteryPresent()); 112 SetVisible(PowerStatus::Get()->IsBatteryPresent());
112 113
113 if (battery_alert) { 114 if (battery_alert) {
114 accessible_name_ = PowerStatus::Get()->GetAccessibleNameString(true); 115 accessible_name_ = PowerStatus::Get()->GetAccessibleNameString(true);
115 NotifyAccessibilityEvent(ui::AX_EVENT_ALERT, true); 116 NotifyAccessibilityEvent(ui::AX_EVENT_ALERT, true);
116 } 117 }
117 } 118 }
118 119
119 private: 120 private:
121 class PowerTrayImageSource : public gfx::ImageSkiaSource {
122 public:
123 explicit PowerTrayImageSource(const PowerStatus::BatteryImageInfo& info)
124 : info_(info) {}
125
126 // gfx::ImageSkiaSource implementation.
127 gfx::ImageSkiaRep GetImageForScale(float scale) override {
128 return PowerStatus::Get()->GetBatteryImage(info_, scale);
129 }
130
131 const PowerStatus::BatteryImageInfo& info() const { return info_; }
132
133 private:
134 PowerStatus::BatteryImageInfo info_;
135
136 DISALLOW_COPY_AND_ASSIGN(PowerTrayImageSource);
137 };
138
120 void UpdateImage() { 139 void UpdateImage() {
121 const PowerStatus::BatteryImageInfo info = 140 const PowerStatus::BatteryImageInfo& info =
122 PowerStatus::Get()->GetBatteryImageInfo(PowerStatus::ICON_LIGHT); 141 PowerStatus::Get()->GetBatteryImageInfo();
123 if (info != previous_image_info_) { 142 // Only change the image when the info changes. http://crbug.com/589348
124 image_view()->SetImage(PowerStatus::Get()->GetBatteryImage(info)); 143 if (image_source_ && image_source_->info() == info)
125 previous_image_info_ = info; 144 return;
126 } 145 image_source_ = new PowerTrayImageSource(info);
146 // gfx::ImageSkia takes ownership of image_source_. It will stay alive until
147 // we call SetImage() again, which only happens here.
148 image_view()->SetImage(
149 gfx::ImageSkia(image_source_, PowerStatus::GetBatteryImageSizeInDip()));
127 } 150 }
128 151
129 base::string16 accessible_name_; 152 base::string16 accessible_name_;
130 153 PowerTrayImageSource* image_source_ = nullptr;
131 // Information about the last-used image. Cached to avoid unnecessary updates
132 // (http://crbug.com/589348).
133 PowerStatus::BatteryImageInfo previous_image_info_;
134 154
135 DISALLOW_COPY_AND_ASSIGN(PowerTrayView); 155 DISALLOW_COPY_AND_ASSIGN(PowerTrayView);
136 }; 156 };
137 157
138 } // namespace tray 158 } // namespace tray
139 159
140 const int TrayPower::kCriticalMinutes = 5; 160 const int TrayPower::kCriticalMinutes = 5;
141 const int TrayPower::kLowPowerMinutes = 15; 161 const int TrayPower::kLowPowerMinutes = 15;
142 const int TrayPower::kNoWarningMinutes = 30; 162 const int TrayPower::kNoWarningMinutes = 30;
143 const int TrayPower::kCriticalPercentage = 5; 163 const int TrayPower::kCriticalPercentage = 5;
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 } 366 }
347 NOTREACHED(); 367 NOTREACHED();
348 return false; 368 return false;
349 } 369 }
350 370
351 void TrayPower::NotifyUsbNotificationClosedByUser() { 371 void TrayPower::NotifyUsbNotificationClosedByUser() {
352 usb_notification_dismissed_ = true; 372 usb_notification_dismissed_ = true;
353 } 373 }
354 374
355 } // namespace ash 375 } // namespace ash
OLDNEW
« 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