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
3 // found in the LICENSE file.
5 #include "ash/system/date/tray_date.h"
8 #include "ash/system/date/date_default_view.h"
9 #include "ash/system/date/date_view.h"
10 #include "ash/system/tray/system_tray.h"
11 #include "ash/system/tray/system_tray_notifier.h"
12 #include "ash/system/tray/tray_item_view.h"
14 #if defined(OS_CHROMEOS)
15 #include "ash/system/chromeos/system_clock_observer.h"
20 TrayDate::TrayDate(SystemTray
* system_tray
)
21 : SystemTrayItem(system_tray
),
24 login_status_(user::LOGGED_IN_NONE
) {
25 #if defined(OS_CHROMEOS)
26 system_clock_observer_
.reset(new SystemClockObserver());
28 Shell::GetInstance()->system_tray_notifier()->AddClockObserver(this);
31 TrayDate::~TrayDate() {
32 Shell::GetInstance()->system_tray_notifier()->RemoveClockObserver(this);
35 views::View
* TrayDate::GetHelpButtonView() const {
38 return default_view_
->GetHelpButtonView();
41 const tray::TimeView
* TrayDate::GetTimeTrayForTesting() const {
45 const DateDefaultView
* TrayDate::GetDefaultViewForTesting() const {
49 views::View
* TrayDate::CreateDefaultViewForTesting(user::LoginStatus status
) {
50 return CreateDefaultView(status
);
53 views::View
* TrayDate::CreateTrayView(user::LoginStatus status
) {
54 CHECK(time_tray_
== NULL
);
55 ClockLayout clock_layout
=
56 (system_tray()->shelf_alignment() == SHELF_ALIGNMENT_BOTTOM
||
57 system_tray()->shelf_alignment() == SHELF_ALIGNMENT_TOP
) ?
58 HORIZONTAL_CLOCK
: VERTICAL_CLOCK
;
59 time_tray_
= new tray::TimeView(clock_layout
);
60 views::View
* view
= new TrayItemView(this);
61 view
->AddChildView(time_tray_
);
65 views::View
* TrayDate::CreateDefaultView(user::LoginStatus status
) {
66 default_view_
= new DateDefaultView(status
);
68 #if defined(OS_CHROMEOS)
69 // Save the login status we created the view with.
70 login_status_
= status
;
72 OnSystemClockCanSetTimeChanged(system_clock_observer_
->can_set_time());
77 views::View
* TrayDate::CreateDetailedView(user::LoginStatus status
) {
81 void TrayDate::DestroyTrayView() {
85 void TrayDate::DestroyDefaultView() {
89 void TrayDate::DestroyDetailedView() {
92 void TrayDate::UpdateAfterLoginStatusChange(user::LoginStatus status
) {
95 void TrayDate::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment
) {
97 ClockLayout clock_layout
= (alignment
== SHELF_ALIGNMENT_BOTTOM
||
98 alignment
== SHELF_ALIGNMENT_TOP
) ?
99 HORIZONTAL_CLOCK
: VERTICAL_CLOCK
;
100 time_tray_
->UpdateClockLayout(clock_layout
);
104 void TrayDate::OnDateFormatChanged() {
106 time_tray_
->UpdateTimeFormat();
108 default_view_
->GetDateView()->UpdateTimeFormat();
111 void TrayDate::OnSystemClockTimeUpdated() {
113 time_tray_
->UpdateTimeFormat();
115 default_view_
->GetDateView()->UpdateTimeFormat();
118 void TrayDate::OnSystemClockCanSetTimeChanged(bool can_set_time
) {
119 // Outside of a logged-in session, the date button should launch the set time
120 // dialog if the time can be set.
121 if (default_view_
&& login_status_
== user::LOGGED_IN_NONE
) {
122 default_view_
->GetDateView()->SetAction(
123 can_set_time
? TrayDate::SET_SYSTEM_TIME
: TrayDate::NONE
);
127 void TrayDate::Refresh() {
129 time_tray_
->UpdateText();