Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / ash / system / date / tray_date.cc
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/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"
13
14 #if defined(OS_CHROMEOS)
15 #include "ash/system/chromeos/system_clock_observer.h"
16 #endif
17
18 namespace ash {
19 namespace internal {
20
21 TrayDate::TrayDate(SystemTray* system_tray)
22     : SystemTrayItem(system_tray),
23       time_tray_(NULL),
24       default_view_(NULL) {
25 #if defined(OS_CHROMEOS)
26   system_clock_observer_.reset(new SystemClockObserver());
27 #endif
28   Shell::GetInstance()->system_tray_notifier()->AddClockObserver(this);
29 }
30
31 TrayDate::~TrayDate() {
32   Shell::GetInstance()->system_tray_notifier()->RemoveClockObserver(this);
33 }
34
35 views::View* TrayDate::GetHelpButtonView() const {
36   if (!default_view_)
37     return NULL;
38   return default_view_->GetHelpButtonView();
39 }
40
41 const tray::TimeView* TrayDate::GetTimeTrayForTesting() const {
42   return time_tray_;
43 }
44
45 const DateDefaultView* TrayDate::GetDefaultViewForTesting() const {
46   return default_view_;
47 }
48
49 views::View* TrayDate::CreateDefaultViewForTesting(user::LoginStatus status) {
50   return CreateDefaultView(status);
51 }
52
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;
63 }
64
65 views::View* TrayDate::CreateDefaultView(user::LoginStatus status) {
66   default_view_ = new DateDefaultView(status);
67   return default_view_;
68 }
69
70 views::View* TrayDate::CreateDetailedView(user::LoginStatus status) {
71   return NULL;
72 }
73
74 void TrayDate::DestroyTrayView() {
75   time_tray_ = NULL;
76 }
77
78 void TrayDate::DestroyDefaultView() {
79   default_view_ = NULL;
80 }
81
82 void TrayDate::DestroyDetailedView() {
83 }
84
85 void TrayDate::UpdateAfterLoginStatusChange(user::LoginStatus status) {
86 }
87
88 void TrayDate::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) {
89   if (time_tray_) {
90     ClockLayout clock_layout = (alignment == SHELF_ALIGNMENT_BOTTOM ||
91         alignment == SHELF_ALIGNMENT_TOP) ?
92             HORIZONTAL_CLOCK : VERTICAL_CLOCK;
93     time_tray_->UpdateClockLayout(clock_layout);
94   }
95 }
96
97 void TrayDate::OnDateFormatChanged() {
98   if (time_tray_)
99     time_tray_->UpdateTimeFormat();
100   if (default_view_)
101     default_view_->GetDateView()->UpdateTimeFormat();
102 }
103
104 void TrayDate::OnSystemClockTimeUpdated() {
105   if (time_tray_)
106     time_tray_->UpdateTimeFormat();
107   if (default_view_)
108     default_view_->GetDateView()->UpdateTimeFormat();
109 }
110
111 void TrayDate::Refresh() {
112   if (time_tray_)
113     time_tray_->UpdateText();
114 }
115
116 }  // namespace internal
117 }  // namespace ash