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/tray_power_date.h" | 5 #include "ash/system/power/tray_power_date.h" |
6 | 6 |
7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
8 #include "ash/system/power/power_supply_status.h" | 8 #include "ash/system/power/power_supply_status.h" |
9 #include "ash/system/tray/system_tray_delegate.h" | 9 #include "ash/system/tray/system_tray_delegate.h" |
10 #include "base/i18n/time_formatting.h" | 10 #include "base/i18n/time_formatting.h" |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 namespace tray { | 72 namespace tray { |
73 | 73 |
74 // This view is used for both the tray and the popup. | 74 // This view is used for both the tray and the popup. |
75 class DateView : public views::View { | 75 class DateView : public views::View { |
76 public: | 76 public: |
77 enum TimeType { | 77 enum TimeType { |
78 TIME, | 78 TIME, |
79 DATE | 79 DATE |
80 }; | 80 }; |
81 | 81 |
82 DateView(base::HourClockType hour_type, TimeType type) | 82 explicit DateView(TimeType type) |
83 : hour_type_(hour_type), | 83 : hour_type_(ash::Shell::GetInstance()->tray_delegate()-> |
| 84 GetHourClockType()), |
84 type_(type), | 85 type_(type), |
85 actionable_(false) { | 86 actionable_(false) { |
86 SetLayoutManager(new views::FillLayout()); | 87 SetLayoutManager(new views::FillLayout()); |
87 label_ = new views::Label; | 88 label_ = new views::Label; |
88 UpdateText(); | 89 UpdateText(); |
89 AddChildView(label_); | 90 AddChildView(label_); |
90 } | 91 } |
91 | 92 |
92 virtual ~DateView() { | 93 virtual ~DateView() { |
93 timer_.Stop(); | 94 timer_.Stop(); |
94 } | 95 } |
95 | 96 |
| 97 void UpdateTimeFormat() { |
| 98 hour_type_ = ash::Shell::GetInstance()->tray_delegate()->GetHourClockType(); |
| 99 UpdateText(); |
| 100 } |
| 101 |
96 views::Label* label() const { return label_; } | 102 views::Label* label() const { return label_; } |
97 | 103 |
98 void set_actionable(bool actionable) { actionable_ = actionable; } | 104 void set_actionable(bool actionable) { actionable_ = actionable; } |
99 | 105 |
100 private: | 106 private: |
101 void UpdateText() { | 107 void UpdateText() { |
102 base::Time now = base::Time::Now(); | 108 base::Time now = base::Time::Now(); |
103 if (type_ == TIME) { | 109 if (type_ == DATE) { |
| 110 label_->SetText(FormatNicely(now)); |
| 111 } else { |
104 label_->SetText(base::TimeFormatTimeOfDayWithHourClockType( | 112 label_->SetText(base::TimeFormatTimeOfDayWithHourClockType( |
105 now, hour_type_, base::kDropAmPm)); | 113 now, hour_type_, base::kDropAmPm)); |
106 } else { | |
107 label_->SetText(FormatNicely(now)); | |
108 } | 114 } |
109 | 115 |
110 label_->SetTooltipText(base::TimeFormatFriendlyDate(now)); | 116 label_->SetTooltipText(base::TimeFormatFriendlyDate(now)); |
111 SchedulePaint(); | 117 SchedulePaint(); |
112 | 118 |
113 // Try to set the timer to go off at the next change of the minute. We don't | 119 // Try to set the timer to go off at the next change of the minute. We don't |
114 // want to have the timer go off more than necessary since that will cause | 120 // want to have the timer go off more than necessary since that will cause |
115 // the CPU to wake up and consume power. | 121 // the CPU to wake up and consume power. |
116 base::Time::Exploded exploded; | 122 base::Time::Exploded exploded; |
117 now.LocalExplode(&exploded); | 123 now.LocalExplode(&exploded); |
118 | 124 |
119 // Often this will be called at minute boundaries, and we'll actually want | 125 // Often this will be called at minute boundaries, and we'll actually want |
120 // 60 seconds from now. | 126 // 60 seconds from now. |
121 int seconds_left = 60 - exploded.second; | 127 int seconds_left = 60 - exploded.second; |
122 if (seconds_left == 0) | 128 if (seconds_left == 0) |
123 seconds_left = 60; | 129 seconds_left = 60; |
124 | 130 |
125 // Make sure that the timer fires on the next minute. Without this, if it is | 131 // Make sure that the timer fires on the next minute. Without this, if it is |
126 // called just a teeny bit early, then it will skip the next minute. | 132 // called just a teeny bit early, then it will skip the next minute. |
127 seconds_left += kTimerSlopSeconds; | 133 seconds_left += kTimerSlopSeconds; |
128 | 134 |
| 135 timer_.Stop(); |
129 timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(seconds_left), this, | 136 timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(seconds_left), this, |
130 &DateView::UpdateText); | 137 &DateView::UpdateText); |
131 } | 138 } |
132 | 139 |
133 // Overridden from views::View. | 140 // Overridden from views::View. |
134 virtual bool OnMousePressed(const views::MouseEvent& event) OVERRIDE { | 141 virtual bool OnMousePressed(const views::MouseEvent& event) OVERRIDE { |
135 if (!actionable_) | 142 if (!actionable_) |
136 return false; | 143 return false; |
137 | 144 |
138 ash::Shell::GetInstance()->tray_delegate()->ShowDateSettings(); | 145 ash::Shell::GetInstance()->tray_delegate()->ShowDateSettings(); |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 | 272 |
266 TrayPowerDate::TrayPowerDate() | 273 TrayPowerDate::TrayPowerDate() |
267 : power_(NULL), | 274 : power_(NULL), |
268 power_tray_(NULL) { | 275 power_tray_(NULL) { |
269 } | 276 } |
270 | 277 |
271 TrayPowerDate::~TrayPowerDate() { | 278 TrayPowerDate::~TrayPowerDate() { |
272 } | 279 } |
273 | 280 |
274 views::View* TrayPowerDate::CreateTrayView(user::LoginStatus status) { | 281 views::View* TrayPowerDate::CreateTrayView(user::LoginStatus status) { |
275 date_tray_.reset(new tray::DateView(base::k24HourClock, | 282 date_tray_.reset(new tray::DateView(tray::DateView::TIME)); |
276 tray::DateView::TIME)); | |
277 date_tray_->label()->SetFont( | 283 date_tray_->label()->SetFont( |
278 date_tray_->label()->font().DeriveFont(-1, gfx::Font::BOLD)); | 284 date_tray_->label()->font().DeriveFont(-1, gfx::Font::BOLD)); |
279 date_tray_->label()->SetAutoColorReadabilityEnabled(false); | 285 date_tray_->label()->SetAutoColorReadabilityEnabled(false); |
280 date_tray_->label()->SetEnabledColor(SK_ColorWHITE); | 286 date_tray_->label()->SetEnabledColor(SK_ColorWHITE); |
281 | 287 |
282 power_tray_.reset(new tray::PowerTrayView()); | 288 power_tray_.reset(new tray::PowerTrayView()); |
283 | 289 |
284 views::View* container = new views::View; | 290 views::View* container = new views::View; |
285 container->SetLayoutManager(new views::BoxLayout( | 291 container->SetLayoutManager(new views::BoxLayout( |
286 views::BoxLayout::kHorizontal, 0, 0, 0)); | 292 views::BoxLayout::kHorizontal, 0, 0, 0)); |
287 container->AddChildView(power_tray_.get()); | 293 container->AddChildView(power_tray_.get()); |
288 container->AddChildView(date_tray_.get()); | 294 container->AddChildView(date_tray_.get()); |
289 | 295 |
290 return container; | 296 return container; |
291 } | 297 } |
292 | 298 |
293 views::View* TrayPowerDate::CreateDefaultView(user::LoginStatus status) { | 299 views::View* TrayPowerDate::CreateDefaultView(user::LoginStatus status) { |
294 date_.reset(new tray::DateView(base::k24HourClock, | 300 date_.reset(new tray::DateView(tray::DateView::DATE)); |
295 tray::DateView::DATE)); | |
296 if (status != user::LOGGED_IN_NONE) | 301 if (status != user::LOGGED_IN_NONE) |
297 date_->set_actionable(true); | 302 date_->set_actionable(true); |
298 | 303 |
299 power_.reset(new tray::PowerPopupView()); | 304 power_.reset(new tray::PowerPopupView()); |
300 | 305 |
301 views::View* container = new views::View; | 306 views::View* container = new views::View; |
302 views::BoxLayout* layout = new | 307 views::BoxLayout* layout = new |
303 views::BoxLayout(views::BoxLayout::kHorizontal, 0, 10, 0); | 308 views::BoxLayout(views::BoxLayout::kHorizontal, 0, 10, 0); |
304 layout->set_spread_blank_space(true); | 309 layout->set_spread_blank_space(true); |
305 container->SetLayoutManager(layout); | 310 container->SetLayoutManager(layout); |
(...skipping 20 matching lines...) Expand all Loading... |
326 | 331 |
327 void TrayPowerDate::DestroyDetailedView() { | 332 void TrayPowerDate::DestroyDetailedView() { |
328 } | 333 } |
329 | 334 |
330 void TrayPowerDate::OnPowerStatusChanged(const PowerSupplyStatus& status) { | 335 void TrayPowerDate::OnPowerStatusChanged(const PowerSupplyStatus& status) { |
331 power_tray_->UpdatePowerStatus(status); | 336 power_tray_->UpdatePowerStatus(status); |
332 if (power_.get()) | 337 if (power_.get()) |
333 power_->UpdatePowerStatus(status); | 338 power_->UpdatePowerStatus(status); |
334 } | 339 } |
335 | 340 |
| 341 void TrayPowerDate::OnDateFormatChanged() { |
| 342 date_tray_->UpdateTimeFormat(); |
| 343 } |
| 344 |
336 } // namespace internal | 345 } // namespace internal |
337 } // namespace ash | 346 } // namespace ash |
OLD | NEW |