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/chromeos/power/power_status_view.h" | 5 #include "ash/system/chromeos/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/chromeos/power/tray_power.h" | 9 #include "ash/system/chromeos/power/tray_power.h" |
10 #include "ash/system/tray/fixed_sized_image_view.h" | 10 #include "ash/system/tray/fixed_sized_image_view.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 namespace { | 25 namespace { |
26 | 26 |
27 // Top/bottom padding of the text items. | 27 // Top/bottom padding of the text items. |
28 const int kPaddingVertical = 10; | 28 const int kPaddingVertical = 10; |
29 // Specify min width of status label for layout. | 29 // Specify min width of status label for layout. |
30 const int kLabelMinWidth = 120; | 30 const int kLabelMinWidth = 120; |
31 // Padding between battery status text and battery icon on default view. | 31 // Padding between battery status text and battery icon on default view. |
32 const int kPaddingBetweenBatteryStatusAndIcon = 3; | 32 const int kPaddingBetweenBatteryStatusAndIcon = 3; |
33 // Minimum battery percentage rendered in UI. | 33 // Minimum battery percentage rendered in UI. |
34 const int kMinBatteryPercent = 1; | 34 const int kMinBatteryPercent = 1; |
| 35 |
| 36 base::string16 GetChargingUnreliableString() { |
| 37 // String is intentionally hard-coded in English for backport to M28 only. |
| 38 // See crbug.com/246336 for details. |
| 39 return UTF8ToUTF16("Low-power charger"); |
| 40 } |
| 41 |
35 } // namespace | 42 } // namespace |
36 | 43 |
37 PowerStatusView::PowerStatusView(ViewType view_type, | 44 PowerStatusView::PowerStatusView(ViewType view_type, |
38 bool default_view_right_align) | 45 bool default_view_right_align) |
39 : default_view_right_align_(default_view_right_align), | 46 : default_view_right_align_(default_view_right_align), |
40 status_label_(NULL), | 47 status_label_(NULL), |
41 time_label_(NULL), | 48 time_label_(NULL), |
42 time_status_label_(NULL), | 49 time_status_label_(NULL), |
43 percentage_label_(NULL), | 50 percentage_label_(NULL), |
44 icon_(NULL), | 51 icon_(NULL), |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 void PowerStatusView::UpdateTextForDefaultView() { | 123 void PowerStatusView::UpdateTextForDefaultView() { |
117 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 124 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
118 base::string16 battery_percentage; | 125 base::string16 battery_percentage; |
119 base::string16 battery_time_status; | 126 base::string16 battery_time_status; |
120 bool is_charging_unreliable = | 127 bool is_charging_unreliable = |
121 TrayPower::IsBatteryChargingUnreliable(supply_status_); | 128 TrayPower::IsBatteryChargingUnreliable(supply_status_); |
122 if (supply_status_.line_power_on && supply_status_.battery_is_full) { | 129 if (supply_status_.line_power_on && supply_status_.battery_is_full) { |
123 battery_time_status = | 130 battery_time_status = |
124 rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_BATTERY_FULL); | 131 rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_BATTERY_FULL); |
125 } else if (supply_status_.battery_percentage < 0.0f) { | 132 } else if (supply_status_.battery_percentage < 0.0f) { |
126 battery_time_status = | 133 battery_time_status = is_charging_unreliable ? |
127 is_charging_unreliable ? | 134 GetChargingUnreliableString() : |
128 rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_BATTERY_CHARGING_UNRELIABLE) : | |
129 rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_BATTERY_CALCULATING); | 135 rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_BATTERY_CALCULATING); |
130 } else { | 136 } else { |
131 battery_percentage = l10n_util::GetStringFUTF16( | 137 battery_percentage = l10n_util::GetStringFUTF16( |
132 IDS_ASH_STATUS_TRAY_BATTERY_PERCENT_ONLY, | 138 IDS_ASH_STATUS_TRAY_BATTERY_PERCENT_ONLY, |
133 base::IntToString16(TrayPower::GetRoundedBatteryPercentage( | 139 base::IntToString16(TrayPower::GetRoundedBatteryPercentage( |
134 supply_status_.battery_percentage))); | 140 supply_status_.battery_percentage))); |
135 if (is_charging_unreliable) { | 141 if (is_charging_unreliable) { |
136 battery_time_status = rb.GetLocalizedString( | 142 battery_time_status = GetChargingUnreliableString(); |
137 IDS_ASH_STATUS_TRAY_BATTERY_CHARGING_UNRELIABLE); | |
138 } else { | 143 } else { |
139 if (supply_status_.is_calculating_battery_time) { | 144 if (supply_status_.is_calculating_battery_time) { |
140 battery_time_status = | 145 battery_time_status = |
141 rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_BATTERY_CALCULATING); | 146 rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_BATTERY_CALCULATING); |
142 } else { | 147 } else { |
143 base::TimeDelta time = base::TimeDelta::FromSeconds( | 148 base::TimeDelta time = base::TimeDelta::FromSeconds( |
144 supply_status_.line_power_on ? | 149 supply_status_.line_power_on ? |
145 supply_status_.battery_seconds_to_full : | 150 supply_status_.battery_seconds_to_full : |
146 supply_status_.battery_seconds_to_empty); | 151 supply_status_.battery_seconds_to_empty); |
147 int hour = time.InHours(); | 152 int hour = time.InHours(); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 } else { | 205 } else { |
201 status_label_->SetText( | 206 status_label_->SetText( |
202 l10n_util::GetStringFUTF16( | 207 l10n_util::GetStringFUTF16( |
203 IDS_ASH_STATUS_TRAY_BATTERY_PERCENT, | 208 IDS_ASH_STATUS_TRAY_BATTERY_PERCENT, |
204 base::IntToString16(TrayPower::GetRoundedBatteryPercentage( | 209 base::IntToString16(TrayPower::GetRoundedBatteryPercentage( |
205 supply_status_.battery_percentage)))); | 210 supply_status_.battery_percentage)))); |
206 } | 211 } |
207 } | 212 } |
208 | 213 |
209 if (is_charging_unreliable) { | 214 if (is_charging_unreliable) { |
210 time_label_->SetText( | 215 time_label_->SetText(GetChargingUnreliableString()); |
211 ui::ResourceBundle::GetSharedInstance().GetLocalizedString( | |
212 IDS_ASH_STATUS_TRAY_BATTERY_CHARGING_UNRELIABLE)); | |
213 } else if (supply_status_.is_calculating_battery_time) { | 216 } else if (supply_status_.is_calculating_battery_time) { |
214 time_label_->SetText( | 217 time_label_->SetText( |
215 ui::ResourceBundle::GetSharedInstance().GetLocalizedString( | 218 ui::ResourceBundle::GetSharedInstance().GetLocalizedString( |
216 IDS_ASH_STATUS_TRAY_BATTERY_CALCULATING)); | 219 IDS_ASH_STATUS_TRAY_BATTERY_CALCULATING)); |
217 } else if (hour || min) { | 220 } else if (hour || min) { |
218 if (supply_status_.line_power_on) { | 221 if (supply_status_.line_power_on) { |
219 time_label_->SetText( | 222 time_label_->SetText( |
220 l10n_util::GetStringFUTF16( | 223 l10n_util::GetStringFUTF16( |
221 IDS_ASH_STATUS_TRAY_BATTERY_TIME_UNTIL_FULL, | 224 IDS_ASH_STATUS_TRAY_BATTERY_TIME_UNTIL_FULL, |
222 base::IntToString16(hour), | 225 base::IntToString16(hour), |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 | 307 |
305 // Move the time_status_label_ closer to percentage_label_. | 308 // Move the time_status_label_ closer to percentage_label_. |
306 if (percentage_label_ && time_status_label_ && | 309 if (percentage_label_ && time_status_label_ && |
307 percentage_label_->visible() && time_status_label_->visible()) { | 310 percentage_label_->visible() && time_status_label_->visible()) { |
308 time_status_label_->SetX(percentage_label_->bounds().right() + 1); | 311 time_status_label_->SetX(percentage_label_->bounds().right() + 1); |
309 } | 312 } |
310 } | 313 } |
311 | 314 |
312 } // namespace internal | 315 } // namespace internal |
313 } // namespace ash | 316 } // namespace ash |
OLD | NEW |