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/session_length_limit/tray_session_length_limit.h" | 5 #include "ash/system/session_length_limit/tray_session_length_limit.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 | 8 |
9 #include "ash/shelf_types.h" | 9 #include "ash/shelf_types.h" |
10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 | 201 |
202 void RemainingSessionTimeTrayView::UpdateText() { | 202 void RemainingSessionTimeTrayView::UpdateText() { |
203 if (!visible()) | 203 if (!visible()) |
204 return; | 204 return; |
205 | 205 |
206 // Calculate the remaining session time, clamping so that it never falls below | 206 // Calculate the remaining session time, clamping so that it never falls below |
207 // zero or exceeds 99 hours. | 207 // zero or exceeds 99 hours. |
208 int seconds = floor( | 208 int seconds = floor( |
209 (limit_ - (base::Time::Now() - session_start_time_)).InSecondsF() + .5); | 209 (limit_ - (base::Time::Now() - session_start_time_)).InSecondsF() + .5); |
210 seconds = std::min(std::max(seconds, 0), 99 * 60 * 60); | 210 seconds = std::min(std::max(seconds, 0), 99 * 60 * 60); |
| 211 const SkColor color = seconds < kRemainingTimeWarningThresholdInSeconds ? |
| 212 kRemainingTimeWarningColor : kRemainingTimeColor; |
211 int minutes = seconds / 60; | 213 int minutes = seconds / 60; |
212 seconds %= 60; | 214 seconds %= 60; |
213 const int hours = minutes / 60; | 215 const int hours = minutes / 60; |
214 minutes %= 60; | 216 minutes %= 60; |
215 | 217 |
216 const string16 hours_str = IntToTwoDigitString(hours); | 218 const string16 hours_str = IntToTwoDigitString(hours); |
217 const string16 minutes_str = IntToTwoDigitString(minutes); | 219 const string16 minutes_str = IntToTwoDigitString(minutes); |
218 const string16 seconds_str = IntToTwoDigitString(seconds); | 220 const string16 seconds_str = IntToTwoDigitString(seconds); |
219 const SkColor color = seconds < kRemainingTimeWarningThresholdInSeconds ? | |
220 kRemainingTimeWarningColor : kRemainingTimeColor; | |
221 | 221 |
222 if (horizontal_layout_label_) { | 222 if (horizontal_layout_label_) { |
223 horizontal_layout_label_->SetText(l10n_util::GetStringFUTF16( | 223 horizontal_layout_label_->SetText(l10n_util::GetStringFUTF16( |
224 IDS_ASH_STATUS_TRAY_REMAINING_SESSION_TIME, | 224 IDS_ASH_STATUS_TRAY_REMAINING_SESSION_TIME, |
225 hours_str, minutes_str, seconds_str)); | 225 hours_str, minutes_str, seconds_str)); |
226 horizontal_layout_label_->SetEnabledColor(color); | 226 horizontal_layout_label_->SetEnabledColor(color); |
227 } else if (vertical_layout_label_hours_left_) { | 227 } else if (vertical_layout_label_hours_left_) { |
228 vertical_layout_label_hours_left_->SetText(hours_str.substr(0, 1)); | 228 vertical_layout_label_hours_left_->SetText(hours_str.substr(0, 1)); |
229 vertical_layout_label_hours_right_->SetText(hours_str.substr(1, 1)); | 229 vertical_layout_label_hours_right_->SetText(hours_str.substr(1, 1)); |
230 vertical_layout_label_minutes_left_->SetText(minutes_str.substr(0, 1)); | 230 vertical_layout_label_minutes_left_->SetText(minutes_str.substr(0, 1)); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 tray_view_->SetSessionStartTime(start_time); | 298 tray_view_->SetSessionStartTime(start_time); |
299 } | 299 } |
300 | 300 |
301 void TraySessionLengthLimit::OnSessionLengthLimitChanged( | 301 void TraySessionLengthLimit::OnSessionLengthLimitChanged( |
302 const base::TimeDelta& limit) { | 302 const base::TimeDelta& limit) { |
303 tray_view_->SetSessionLengthLimit(limit); | 303 tray_view_->SetSessionLengthLimit(limit); |
304 } | 304 } |
305 | 305 |
306 } // namespace internal | 306 } // namespace internal |
307 } // namespace ash | 307 } // namespace ash |
OLD | NEW |