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/power_status.h" | 9 #include "ash/system/chromeos/power/power_status.h" |
10 #include "ash/system/chromeos/power/tray_power.h" | 10 #include "ash/system/chromeos/power/tray_power.h" |
11 #include "ash/system/tray/fixed_sized_image_view.h" | 11 #include "ash/system/tray/fixed_sized_image_view.h" |
12 #include "ash/system/tray/tray_constants.h" | 12 #include "ash/system/tray/tray_constants.h" |
13 #include "base/strings/string_number_conversions.h" | 13 #include "base/i18n/number_formatting.h" |
14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
15 #include "grit/ash_strings.h" | 15 #include "grit/ash_strings.h" |
16 #include "ui/base/l10n/l10n_util.h" | 16 #include "ui/base/l10n/l10n_util.h" |
17 #include "ui/base/l10n/time_format.h" | 17 #include "ui/base/l10n/time_format.h" |
18 #include "ui/base/resource/resource_bundle.h" | 18 #include "ui/base/resource/resource_bundle.h" |
19 #include "ui/views/controls/image_view.h" | 19 #include "ui/views/controls/image_view.h" |
20 #include "ui/views/controls/label.h" | 20 #include "ui/views/controls/label.h" |
21 #include "ui/views/layout/box_layout.h" | 21 #include "ui/views/layout/box_layout.h" |
22 #include "ui/views/layout/grid_layout.h" | 22 #include "ui/views/layout/grid_layout.h" |
23 | 23 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
85 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 85 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
86 base::string16 battery_percentage; | 86 base::string16 battery_percentage; |
87 base::string16 battery_time_status; | 87 base::string16 battery_time_status; |
88 | 88 |
89 if (status.IsBatteryFull()) { | 89 if (status.IsBatteryFull()) { |
90 battery_time_status = | 90 battery_time_status = |
91 rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_BATTERY_FULL); | 91 rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_BATTERY_FULL); |
92 } else { | 92 } else { |
93 battery_percentage = l10n_util::GetStringFUTF16( | 93 battery_percentage = l10n_util::GetStringFUTF16( |
94 IDS_ASH_STATUS_TRAY_BATTERY_PERCENT_ONLY, | 94 IDS_ASH_STATUS_TRAY_BATTERY_PERCENT_ONLY, |
95 base::IntToString16(status.GetRoundedBatteryPercent())); | 95 base::FormatNumber(status.GetRoundedBatteryPercent())); |
jungshik at Google
2016/05/10 08:50:44
To be 100% i18n-safe, you should use MessageFormat
jungshik at Google
2016/05/10 09:28:17
Oops. The 1st argument should be |base::ASCIIToUTF
Greg Levin
2016/05/10 23:33:43
Done.
| |
96 if (status.IsUsbChargerConnected()) { | 96 if (status.IsUsbChargerConnected()) { |
97 battery_time_status = rb.GetLocalizedString( | 97 battery_time_status = rb.GetLocalizedString( |
98 IDS_ASH_STATUS_TRAY_BATTERY_CHARGING_UNRELIABLE); | 98 IDS_ASH_STATUS_TRAY_BATTERY_CHARGING_UNRELIABLE); |
99 } else if (status.IsBatteryTimeBeingCalculated()) { | 99 } else if (status.IsBatteryTimeBeingCalculated()) { |
100 battery_time_status = | 100 battery_time_status = |
101 rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_BATTERY_CALCULATING); | 101 rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_BATTERY_CALCULATING); |
102 } else { | 102 } else { |
103 base::TimeDelta time = status.IsBatteryCharging() ? | 103 base::TimeDelta time = status.IsBatteryCharging() ? |
104 status.GetBatteryTimeToFull() : status.GetBatteryTimeToEmpty(); | 104 status.GetBatteryTimeToFull() : status.GetBatteryTimeToEmpty(); |
105 if (PowerStatus::ShouldDisplayBatteryTime(time) && | 105 if (PowerStatus::ShouldDisplayBatteryTime(time) && |
106 !status.IsBatteryDischargingOnLinePower()) { | 106 !status.IsBatteryDischargingOnLinePower()) { |
107 int hour = 0, min = 0; | 107 int hour = 0, min = 0; |
108 PowerStatus::SplitTimeIntoHoursAndMinutes(time, &hour, &min); | 108 PowerStatus::SplitTimeIntoHoursAndMinutes(time, &hour, &min); |
109 base::string16 minute = min < 10 ? | 109 base::string16 minute = |
110 base::ASCIIToUTF16("0") + base::IntToString16(min) : | 110 min < 10 ? base::FormatNumber(0) + base::FormatNumber(min) |
111 base::IntToString16(min); | 111 : base::FormatNumber(min); |
Daniel Erat
2016/05/03 19:17:33
i'm also curious about the i18n-ness of this zero-
stevenjb
2016/05/03 19:49:09
It seems like if we are going to switch this to Fo
jungshik at Google
2016/05/10 08:50:44
There are two ways to handle this better depending
Greg Levin
2016/05/10 23:33:43
I went with the second option. Two points, though
Greg Levin
2016/05/11 19:43:02
EDIT: I updated it to use the new TimeDurationForm
| |
112 battery_time_status = | 112 battery_time_status = l10n_util::GetStringFUTF16( |
113 l10n_util::GetStringFUTF16( | 113 status.IsBatteryCharging() |
114 status.IsBatteryCharging() ? | 114 ? IDS_ASH_STATUS_TRAY_BATTERY_TIME_UNTIL_FULL_SHORT |
115 IDS_ASH_STATUS_TRAY_BATTERY_TIME_UNTIL_FULL_SHORT : | 115 : IDS_ASH_STATUS_TRAY_BATTERY_TIME_LEFT_SHORT, |
116 IDS_ASH_STATUS_TRAY_BATTERY_TIME_LEFT_SHORT, | 116 base::FormatNumber(hour), minute); |
117 base::IntToString16(hour), | |
118 minute); | |
119 } | 117 } |
120 } | 118 } |
121 battery_percentage = battery_time_status.empty() ? | 119 battery_percentage = battery_time_status.empty() ? |
122 battery_percentage : battery_percentage + base::ASCIIToUTF16(" - "); | 120 battery_percentage : battery_percentage + base::ASCIIToUTF16(" - "); |
123 } | 121 } |
124 percentage_label_->SetVisible(!battery_percentage.empty()); | 122 percentage_label_->SetVisible(!battery_percentage.empty()); |
125 percentage_label_->SetText(battery_percentage); | 123 percentage_label_->SetText(battery_percentage); |
126 time_status_label_->SetVisible(!battery_time_status.empty()); | 124 time_status_label_->SetVisible(!battery_time_status.empty()); |
127 time_status_label_->SetText(battery_time_status); | 125 time_status_label_->SetText(battery_time_status); |
jungshik at Google
2016/05/10 08:50:44
wow... has appending ' - ' to battery_percentage
Greg Levin
2016/05/10 23:33:43
Good catch... just checked, and that's exactly wha
| |
128 } | 126 } |
129 | 127 |
130 void PowerStatusView::ChildPreferredSizeChanged(views::View* child) { | 128 void PowerStatusView::ChildPreferredSizeChanged(views::View* child) { |
131 PreferredSizeChanged(); | 129 PreferredSizeChanged(); |
132 } | 130 } |
133 | 131 |
134 gfx::Size PowerStatusView::GetPreferredSize() const { | 132 gfx::Size PowerStatusView::GetPreferredSize() const { |
135 gfx::Size size = views::View::GetPreferredSize(); | 133 gfx::Size size = views::View::GetPreferredSize(); |
136 return gfx::Size(size.width(), kTrayPopupItemHeight); | 134 return gfx::Size(size.width(), kTrayPopupItemHeight); |
137 } | 135 } |
138 | 136 |
139 int PowerStatusView::GetHeightForWidth(int width) const { | 137 int PowerStatusView::GetHeightForWidth(int width) const { |
140 return kTrayPopupItemHeight; | 138 return kTrayPopupItemHeight; |
141 } | 139 } |
142 | 140 |
143 void PowerStatusView::Layout() { | 141 void PowerStatusView::Layout() { |
144 views::View::Layout(); | 142 views::View::Layout(); |
145 | 143 |
146 // Move the time_status_label_ closer to percentage_label_. | 144 // Move the time_status_label_ closer to percentage_label_. |
147 if (percentage_label_ && time_status_label_ && | 145 if (percentage_label_ && time_status_label_ && |
148 percentage_label_->visible() && time_status_label_->visible()) { | 146 percentage_label_->visible() && time_status_label_->visible()) { |
149 time_status_label_->SetX(percentage_label_->bounds().right() + 1); | 147 time_status_label_->SetX(percentage_label_->bounds().right() + 1); |
150 } | 148 } |
151 } | 149 } |
152 | 150 |
153 } // namespace ash | 151 } // namespace ash |
OLD | NEW |