cygprofile: increase timeouts to allow showing web contents
[chromium-blink-merge.git] / ash / system / date / tray_date.cc
blob8a574fed736a125d642adb023d7d7396a2ea511c
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"
7 #include "ash/shell.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"
16 #endif
18 namespace ash {
20 TrayDate::TrayDate(SystemTray* system_tray)
21 : SystemTrayItem(system_tray),
22 time_tray_(NULL),
23 default_view_(NULL),
24 login_status_(user::LOGGED_IN_NONE) {
25 #if defined(OS_CHROMEOS)
26 system_clock_observer_.reset(new SystemClockObserver());
27 #endif
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 {
36 if (!default_view_)
37 return NULL;
38 return default_view_->GetHelpButtonView();
41 const tray::TimeView* TrayDate::GetTimeTrayForTesting() const {
42 return time_tray_;
45 const DateDefaultView* TrayDate::GetDefaultViewForTesting() const {
46 return default_view_;
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_);
62 return view;
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());
73 #endif
74 return default_view_;
77 views::View* TrayDate::CreateDetailedView(user::LoginStatus status) {
78 return NULL;
81 void TrayDate::DestroyTrayView() {
82 time_tray_ = NULL;
85 void TrayDate::DestroyDefaultView() {
86 default_view_ = NULL;
89 void TrayDate::DestroyDetailedView() {
92 void TrayDate::UpdateAfterLoginStatusChange(user::LoginStatus status) {
95 void TrayDate::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) {
96 if (time_tray_) {
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() {
105 if (time_tray_)
106 time_tray_->UpdateTimeFormat();
107 if (default_view_)
108 default_view_->GetDateView()->UpdateTimeFormat();
111 void TrayDate::OnSystemClockTimeUpdated() {
112 if (time_tray_)
113 time_tray_->UpdateTimeFormat();
114 if (default_view_)
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() {
128 if (time_tray_)
129 time_tray_->UpdateText();
132 } // namespace ash