Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 Loading... | |
| 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) { | |
| 210 // Default in case supply_status_ is uncertain. | |
| 211 icon_->SetImage(icon_->GetImage()); | |
|
Daniel Erat
2012/09/11 23:31:04
didn't see any explanation for this: it looks like
| |
| 212 } else { | |
| 213 icon_->SetImage( | |
| 214 TrayPower::GetBatteryImage(icon_image_index_, ICON_DARK)); | |
| 215 } | |
| 216 } | |
| 208 icon_->SetVisible(true); | 217 icon_->SetVisible(true); |
| 209 } | 218 } |
| 210 } | 219 } |
| 211 | 220 |
| 212 void PowerStatusView::Update() { | 221 void PowerStatusView::Update() { |
| 213 UpdateText(); | 222 UpdateText(); |
| 214 UpdateIcon(); | 223 UpdateIcon(); |
| 215 } | 224 } |
| 216 | 225 |
| 217 void PowerStatusView::ChildPreferredSizeChanged(views::View* child) { | 226 void PowerStatusView::ChildPreferredSizeChanged(views::View* child) { |
| 218 PreferredSizeChanged(); | 227 PreferredSizeChanged(); |
| 219 } | 228 } |
| 220 | 229 |
| 221 gfx::Size PowerStatusView::GetPreferredSize() { | 230 gfx::Size PowerStatusView::GetPreferredSize() { |
| 222 gfx::Size size = views::View::GetPreferredSize(); | 231 gfx::Size size = views::View::GetPreferredSize(); |
| 223 return gfx::Size(size.width(), kTrayPopupItemHeight); | 232 return gfx::Size(size.width(), kTrayPopupItemHeight); |
| 224 } | 233 } |
| 225 | 234 |
| 226 } // namespace internal | 235 } // namespace internal |
| 227 } // namespace ash | 236 } // namespace ash |
| OLD | NEW |