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