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

Side by Side Diff: ash/system/power/power_status_view.cc

Issue 10907037: Only update system power indicators on change (Closed) Base URL: https://git.chromium.org/git/chromium/src@git-svn
Patch Set: Updated comments, rebased to ToT, moved textfield opts to separte CL Created 8 years, 3 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) 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/system/power/power_status_view.h" 5 #include "ash/system/power/power_status_view.h"
6 6
7 #include "ash/shell.h" 7 #include "ash/shell.h"
8 #include "ash/shell_delegate.h" 8 #include "ash/shell_delegate.h"
9 #include "ash/system/power/tray_power.h" 9 #include "ash/system/power/tray_power.h"
10 #include "ash/system/tray/tray_constants.h" 10 #include "ash/system/tray/tray_constants.h"
(...skipping 21 matching lines...) Expand all
32 const int kPaddingBetweenBatteryStatusAndIcon = 3; 32 const int kPaddingBetweenBatteryStatusAndIcon = 3;
33 } // namespace 33 } // namespace
34 34
35 PowerStatusView::PowerStatusView(ViewType view_type, 35 PowerStatusView::PowerStatusView(ViewType view_type,
36 bool default_view_right_align) 36 bool default_view_right_align)
37 : default_view_right_align_(default_view_right_align), 37 : default_view_right_align_(default_view_right_align),
38 status_label_(NULL), 38 status_label_(NULL),
39 time_label_(NULL), 39 time_label_(NULL),
40 time_status_label_(NULL), 40 time_status_label_(NULL),
41 icon_(NULL), 41 icon_(NULL),
42 icon_image_index_(-1),
42 view_type_(view_type) { 43 view_type_(view_type) {
43 if (view_type == VIEW_DEFAULT) { 44 if (view_type == VIEW_DEFAULT) {
44 time_status_label_ = new views::Label; 45 time_status_label_ = new views::Label;
45 LayoutDefaultView(); 46 LayoutDefaultView();
46 } else { 47 } else {
47 status_label_ = new views::Label; 48 status_label_ = new views::Label;
48 time_label_ = new views::Label; 49 time_label_ = new views::Label;
49 LayoutNotificationView(); 50 LayoutNotificationView();
50 } 51 }
51 Update(); 52 Update();
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 static_cast<int>(supply_status_.battery_percentage)))); 173 static_cast<int>(supply_status_.battery_percentage))));
173 } 174 }
174 175
175 if (supply_status_.is_calculating_battery_time) { 176 if (supply_status_.is_calculating_battery_time) {
176 time_label_->SetText( 177 time_label_->SetText(
177 ui::ResourceBundle::GetSharedInstance().GetLocalizedString( 178 ui::ResourceBundle::GetSharedInstance().GetLocalizedString(
178 IDS_ASH_STATUS_TRAY_BATTERY_CALCULATING)); 179 IDS_ASH_STATUS_TRAY_BATTERY_CALCULATING));
179 } else if (hour || min) { 180 } else if (hour || min) {
180 if (supply_status_.line_power_on) { 181 if (supply_status_.line_power_on) {
181 time_label_->SetText( 182 time_label_->SetText(
182 l10n_util::GetStringFUTF16( 183 l10n_util::GetStringFUTF16(
183 IDS_ASH_STATUS_TRAY_BATTERY_TIME_UNTIL_FULL, 184 IDS_ASH_STATUS_TRAY_BATTERY_TIME_UNTIL_FULL,
184 base::IntToString16(hour), 185 base::IntToString16(hour),
185 base::IntToString16(min))); 186 base::IntToString16(min)));
186 } else { 187 } else {
187 // This is a low battery warning, which prompts user when battery 188 // This is a low battery warning, which prompts user when battery
188 // time left is not much (ie in minutes). 189 // time left is not much (ie in minutes).
189 min = hour * 60 + min; 190 min = hour * 60 + min;
190 ShellDelegate* delegate = Shell::GetInstance()->delegate(); 191 ShellDelegate* delegate = Shell::GetInstance()->delegate();
191 if (delegate) { 192 if (delegate) {
192 time_label_->SetText(delegate->GetTimeRemainingString( 193 time_label_->SetText(delegate->GetTimeRemainingString(
193 base::TimeDelta::FromMinutes(min))); 194 base::TimeDelta::FromMinutes(min)));
194 } else { 195 } else {
195 time_label_->SetText(string16()); 196 time_label_->SetText(string16());
196 } 197 }
197 } 198 }
198 } else { 199 } else {
199 time_label_->SetText(string16()); 200 time_label_->SetText(string16());
200 } 201 }
201
202 } 202 }
203 203
204 void PowerStatusView::UpdateIcon() { 204 void PowerStatusView::UpdateIcon() {
205 if (icon_) { 205 if (icon_) {
206 icon_->SetImage(TrayPower::GetBatteryImage(supply_status_, ICON_DARK, 206 int index = TrayPower::GetBatteryImageIndex(supply_status_);
207 icon_->GetImage())); 207 if (icon_image_index_ != index) {
208 icon_image_index_ = index;
209 if (icon_image_index_ == -1)
Daniel Erat 2012/09/11 22:17:09 use curly-brackets for multi-line if statements
210 // Default in case supply_status_ is uncertain
Daniel Erat 2012/09/11 22:17:09 nit: add period at end of comment.
211 icon_->SetImage(icon_->GetImage());
Daniel Erat 2012/09/11 22:17:09 this call seems strange...
212 else
213 icon_->SetImage(
214 TrayPower::GetBatteryImage(icon_image_index_, ICON_DARK));
215 }
208 icon_->SetVisible(true); 216 icon_->SetVisible(true);
209 } 217 }
210 } 218 }
211 219
212 void PowerStatusView::Update() { 220 void PowerStatusView::Update() {
213 UpdateText(); 221 UpdateText();
214 UpdateIcon(); 222 UpdateIcon();
215 } 223 }
216 224
217 void PowerStatusView::ChildPreferredSizeChanged(views::View* child) { 225 void PowerStatusView::ChildPreferredSizeChanged(views::View* child) {
218 PreferredSizeChanged(); 226 PreferredSizeChanged();
219 } 227 }
220 228
221 gfx::Size PowerStatusView::GetPreferredSize() { 229 gfx::Size PowerStatusView::GetPreferredSize() {
222 gfx::Size size = views::View::GetPreferredSize(); 230 gfx::Size size = views::View::GetPreferredSize();
223 return gfx::Size(size.width(), kTrayPopupItemHeight); 231 return gfx::Size(size.width(), kTrayPopupItemHeight);
224 } 232 }
225 233
226 } // namespace internal 234 } // namespace internal
227 } // namespace ash 235 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698