| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #include "ash/system/date/tray_date.h" | |
| 6 | |
| 7 #include "ash/common/shelf/wm_shelf_util.h" | |
| 8 #include "ash/common/system/tray/tray_item_view.h" | |
| 9 #include "ash/common/system/tray/wm_system_tray_notifier.h" | |
| 10 #include "ash/common/wm_shell.h" | |
| 11 #include "ash/system/date/date_default_view.h" | |
| 12 #include "ash/system/date/date_view.h" | |
| 13 #include "ash/system/tray/system_tray.h" | |
| 14 | |
| 15 #if defined(OS_CHROMEOS) | |
| 16 #include "ash/system/chromeos/system_clock_observer.h" | |
| 17 #endif | |
| 18 | |
| 19 namespace ash { | |
| 20 | |
| 21 TrayDate::TrayDate(SystemTray* system_tray) | |
| 22 : SystemTrayItem(system_tray), | |
| 23 time_tray_(NULL), | |
| 24 default_view_(NULL), | |
| 25 login_status_(LoginStatus::NOT_LOGGED_IN) { | |
| 26 #if defined(OS_CHROMEOS) | |
| 27 system_clock_observer_.reset(new SystemClockObserver()); | |
| 28 #endif | |
| 29 WmShell::Get()->system_tray_notifier()->AddClockObserver(this); | |
| 30 } | |
| 31 | |
| 32 TrayDate::~TrayDate() { | |
| 33 WmShell::Get()->system_tray_notifier()->RemoveClockObserver(this); | |
| 34 } | |
| 35 | |
| 36 views::View* TrayDate::GetHelpButtonView() const { | |
| 37 if (!default_view_) | |
| 38 return NULL; | |
| 39 return default_view_->GetHelpButtonView(); | |
| 40 } | |
| 41 | |
| 42 const tray::TimeView* TrayDate::GetTimeTrayForTesting() const { | |
| 43 return time_tray_; | |
| 44 } | |
| 45 | |
| 46 const DateDefaultView* TrayDate::GetDefaultViewForTesting() const { | |
| 47 return default_view_; | |
| 48 } | |
| 49 | |
| 50 views::View* TrayDate::CreateDefaultViewForTesting(LoginStatus status) { | |
| 51 return CreateDefaultView(status); | |
| 52 } | |
| 53 | |
| 54 views::View* TrayDate::CreateTrayView(LoginStatus status) { | |
| 55 CHECK(time_tray_ == NULL); | |
| 56 ClockLayout clock_layout = | |
| 57 system_tray()->shelf_alignment() == SHELF_ALIGNMENT_BOTTOM | |
| 58 ? HORIZONTAL_CLOCK | |
| 59 : VERTICAL_CLOCK; | |
| 60 time_tray_ = new tray::TimeView(clock_layout); | |
| 61 views::View* view = new TrayItemView(this); | |
| 62 view->AddChildView(time_tray_); | |
| 63 return view; | |
| 64 } | |
| 65 | |
| 66 views::View* TrayDate::CreateDefaultView(LoginStatus status) { | |
| 67 default_view_ = new DateDefaultView(status); | |
| 68 | |
| 69 #if defined(OS_CHROMEOS) | |
| 70 // Save the login status we created the view with. | |
| 71 login_status_ = status; | |
| 72 | |
| 73 OnSystemClockCanSetTimeChanged(system_clock_observer_->can_set_time()); | |
| 74 #endif | |
| 75 return default_view_; | |
| 76 } | |
| 77 | |
| 78 views::View* TrayDate::CreateDetailedView(LoginStatus status) { | |
| 79 return NULL; | |
| 80 } | |
| 81 | |
| 82 void TrayDate::DestroyTrayView() { | |
| 83 time_tray_ = NULL; | |
| 84 } | |
| 85 | |
| 86 void TrayDate::DestroyDefaultView() { | |
| 87 default_view_ = NULL; | |
| 88 } | |
| 89 | |
| 90 void TrayDate::DestroyDetailedView() { | |
| 91 } | |
| 92 | |
| 93 void TrayDate::UpdateAfterLoginStatusChange(LoginStatus status) {} | |
| 94 | |
| 95 void TrayDate::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) { | |
| 96 if (time_tray_) { | |
| 97 ClockLayout clock_layout = | |
| 98 IsHorizontalAlignment(alignment) ? HORIZONTAL_CLOCK : VERTICAL_CLOCK; | |
| 99 time_tray_->UpdateClockLayout(clock_layout); | |
| 100 } | |
| 101 } | |
| 102 | |
| 103 void TrayDate::OnDateFormatChanged() { | |
| 104 if (time_tray_) | |
| 105 time_tray_->UpdateTimeFormat(); | |
| 106 if (default_view_) | |
| 107 default_view_->GetDateView()->UpdateTimeFormat(); | |
| 108 } | |
| 109 | |
| 110 void TrayDate::OnSystemClockTimeUpdated() { | |
| 111 if (time_tray_) | |
| 112 time_tray_->UpdateTimeFormat(); | |
| 113 if (default_view_) | |
| 114 default_view_->GetDateView()->UpdateTimeFormat(); | |
| 115 } | |
| 116 | |
| 117 void TrayDate::OnSystemClockCanSetTimeChanged(bool can_set_time) { | |
| 118 // Outside of a logged-in session, the date button should launch the set time | |
| 119 // dialog if the time can be set. | |
| 120 if (default_view_ && login_status_ == LoginStatus::NOT_LOGGED_IN) { | |
| 121 default_view_->GetDateView()->SetAction( | |
| 122 can_set_time ? TrayDate::SET_SYSTEM_TIME : TrayDate::NONE); | |
| 123 } | |
| 124 } | |
| 125 | |
| 126 void TrayDate::Refresh() { | |
| 127 if (time_tray_) | |
| 128 time_tray_->UpdateText(); | |
| 129 } | |
| 130 | |
| 131 } // namespace ash | |
| OLD | NEW |