OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ash/system/date/date_default_view.h" | 5 #include "ash/system/date/date_default_view.h" |
6 | 6 |
7 #include "ash/metrics/user_metrics_recorder.h" | 7 #include "ash/metrics/user_metrics_recorder.h" |
8 #include "ash/session/session_state_delegate.h" | 8 #include "ash/session/session_state_delegate.h" |
9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
10 #include "ash/system/date/date_view.h" | 10 #include "ash/system/date/date_view.h" |
11 #include "ash/system/tray/special_popup_row.h" | 11 #include "ash/system/tray/special_popup_row.h" |
12 #include "ash/system/tray/system_tray_delegate.h" | 12 #include "ash/system/tray/system_tray_delegate.h" |
13 #include "ash/system/tray/tray_constants.h" | 13 #include "ash/system/tray/tray_constants.h" |
14 #include "ash/system/tray/tray_popup_header_button.h" | 14 #include "ash/system/tray/tray_popup_header_button.h" |
15 #include "base/bind.h" | |
15 #include "grit/ash_resources.h" | 16 #include "grit/ash_resources.h" |
16 #include "grit/ash_strings.h" | 17 #include "grit/ash_strings.h" |
17 #include "ui/base/l10n/l10n_util.h" | 18 #include "ui/base/l10n/l10n_util.h" |
18 #include "ui/views/border.h" | 19 #include "ui/views/border.h" |
19 #include "ui/views/controls/button/button.h" | 20 #include "ui/views/controls/button/button.h" |
20 #include "ui/views/layout/fill_layout.h" | 21 #include "ui/views/layout/fill_layout.h" |
21 #include "ui/views/view.h" | 22 #include "ui/views/view.h" |
22 | 23 |
23 namespace { | 24 namespace { |
24 | 25 |
25 const int kPaddingVertical = 19; | 26 const int kPaddingVertical = 19; |
26 | 27 |
27 } // namespace | 28 } // namespace |
28 | 29 |
29 namespace ash { | 30 namespace ash { |
30 | 31 |
31 DateDefaultView::DateDefaultView(ash::user::LoginStatus login) | 32 DateDefaultView::DateDefaultView(ash::user::LoginStatus login) |
32 : help_(NULL), | 33 : help_(NULL), |
34 reboot_(NULL), | |
33 shutdown_(NULL), | 35 shutdown_(NULL), |
34 lock_(NULL), | 36 lock_(NULL), |
35 date_view_(NULL) { | 37 date_view_(NULL), |
38 weak_factory_(this) { | |
36 SetLayoutManager(new views::FillLayout); | 39 SetLayoutManager(new views::FillLayout); |
37 | 40 |
38 date_view_ = new tray::DateView(); | 41 date_view_ = new tray::DateView(); |
39 date_view_->SetBorder(views::Border::CreateEmptyBorder( | 42 date_view_->SetBorder(views::Border::CreateEmptyBorder( |
40 kPaddingVertical, ash::kTrayPopupPaddingHorizontal, 0, 0)); | 43 kPaddingVertical, ash::kTrayPopupPaddingHorizontal, 0, 0)); |
41 SpecialPopupRow* view = new SpecialPopupRow(); | 44 SpecialPopupRow* view = new SpecialPopupRow(); |
42 view->SetContent(date_view_); | 45 view->SetContent(date_view_); |
43 AddChildView(view); | 46 AddChildView(view); |
44 | 47 |
45 bool userAddingRunning = ash::Shell::GetInstance() | 48 bool userAddingRunning = ash::Shell::GetInstance() |
(...skipping 20 matching lines...) Expand all Loading... | |
66 login != ash::user::LOGGED_IN_RETAIL_MODE) { | 69 login != ash::user::LOGGED_IN_RETAIL_MODE) { |
67 shutdown_ = new TrayPopupHeaderButton(this, | 70 shutdown_ = new TrayPopupHeaderButton(this, |
68 IDR_AURA_UBER_TRAY_SHUTDOWN, | 71 IDR_AURA_UBER_TRAY_SHUTDOWN, |
69 IDR_AURA_UBER_TRAY_SHUTDOWN, | 72 IDR_AURA_UBER_TRAY_SHUTDOWN, |
70 IDR_AURA_UBER_TRAY_SHUTDOWN_HOVER, | 73 IDR_AURA_UBER_TRAY_SHUTDOWN_HOVER, |
71 IDR_AURA_UBER_TRAY_SHUTDOWN_HOVER, | 74 IDR_AURA_UBER_TRAY_SHUTDOWN_HOVER, |
72 IDS_ASH_STATUS_TRAY_SHUTDOWN); | 75 IDS_ASH_STATUS_TRAY_SHUTDOWN); |
73 shutdown_->SetTooltipText( | 76 shutdown_->SetTooltipText( |
74 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_SHUTDOWN)); | 77 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_SHUTDOWN)); |
75 view->AddButton(shutdown_); | 78 view->AddButton(shutdown_); |
79 | |
80 reboot_ = new TrayPopupHeaderButton( | |
81 this, IDR_AURA_UBER_TRAY_SHUTDOWN, IDR_AURA_UBER_TRAY_SHUTDOWN, | |
82 IDR_AURA_UBER_TRAY_SHUTDOWN_HOVER, IDR_AURA_UBER_TRAY_SHUTDOWN_HOVER, | |
83 IDS_ASH_STATUS_TRAY_REBOOT); | |
84 reboot_->SetTooltipText( | |
85 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_REBOOT)); | |
86 reboot_->SetVisible(false); | |
87 view->AddButton(reboot_); | |
stevenjb
2014/12/17 19:09:02
Rather than having two separate buttons and the UI
cschuet (SLOW)
2015/01/07 14:37:07
Done.
| |
76 } | 88 } |
77 | 89 |
78 if (ash::Shell::GetInstance()->session_state_delegate()->CanLockScreen()) { | 90 if (ash::Shell::GetInstance()->session_state_delegate()->CanLockScreen()) { |
79 lock_ = new TrayPopupHeaderButton(this, | 91 lock_ = new TrayPopupHeaderButton(this, |
80 IDR_AURA_UBER_TRAY_LOCKSCREEN, | 92 IDR_AURA_UBER_TRAY_LOCKSCREEN, |
81 IDR_AURA_UBER_TRAY_LOCKSCREEN, | 93 IDR_AURA_UBER_TRAY_LOCKSCREEN, |
82 IDR_AURA_UBER_TRAY_LOCKSCREEN_HOVER, | 94 IDR_AURA_UBER_TRAY_LOCKSCREEN_HOVER, |
83 IDR_AURA_UBER_TRAY_LOCKSCREEN_HOVER, | 95 IDR_AURA_UBER_TRAY_LOCKSCREEN_HOVER, |
84 IDS_ASH_STATUS_TRAY_LOCK); | 96 IDS_ASH_STATUS_TRAY_LOCK); |
85 lock_->SetTooltipText(l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_LOCK)); | 97 lock_->SetTooltipText(l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_LOCK)); |
86 view->AddButton(lock_); | 98 view->AddButton(lock_); |
87 } | 99 } |
100 SystemTrayDelegate* systemTrayDelegate = | |
stevenjb
2014/12/17 19:09:02
system_tray_delegate
cschuet (SLOW)
2015/01/07 14:37:07
Done.
| |
101 Shell::GetInstance()->system_tray_delegate(); | |
102 systemTrayDelegate->AddShutdownPolicyObserver(this); | |
103 systemTrayDelegate->ShouldRebootOnShutdown(base::Bind( | |
104 &DateDefaultView::OnShutdownPolicyChanged, weak_factory_.GetWeakPtr())); | |
88 #endif // !defined(OS_WIN) | 105 #endif // !defined(OS_WIN) |
89 } | 106 } |
90 | 107 |
91 DateDefaultView::~DateDefaultView() { | 108 DateDefaultView::~DateDefaultView() { |
109 // We need the check as on shell destruction, the delegate is destroyed first. | |
110 SystemTrayDelegate* system_tray_delegate = | |
111 Shell::GetInstance()->system_tray_delegate(); | |
112 if (system_tray_delegate) | |
113 system_tray_delegate->RemoveShutdownPolicyObserver(this); | |
114 } | |
115 | |
116 views::View* DateDefaultView::GetShutdownButtonView() { | |
117 return shutdown_; | |
118 } | |
119 | |
120 views::View* DateDefaultView::GetRebootButtonView() { | |
121 return reboot_; | |
92 } | 122 } |
93 | 123 |
94 views::View* DateDefaultView::GetHelpButtonView() { | 124 views::View* DateDefaultView::GetHelpButtonView() { |
95 return help_; | 125 return help_; |
96 } | 126 } |
97 | 127 |
98 tray::DateView* DateDefaultView::GetDateView() { | 128 tray::DateView* DateDefaultView::GetDateView() { |
99 return date_view_; | 129 return date_view_; |
100 } | 130 } |
101 | 131 |
102 const tray::DateView* DateDefaultView::GetDateView() const { | 132 const tray::DateView* DateDefaultView::GetDateView() const { |
103 return date_view_; | 133 return date_view_; |
104 } | 134 } |
105 | 135 |
106 void DateDefaultView::ButtonPressed(views::Button* sender, | 136 void DateDefaultView::ButtonPressed(views::Button* sender, |
107 const ui::Event& event) { | 137 const ui::Event& event) { |
108 ash::Shell* shell = ash::Shell::GetInstance(); | 138 ash::Shell* shell = ash::Shell::GetInstance(); |
109 ash::SystemTrayDelegate* tray_delegate = shell->system_tray_delegate(); | 139 ash::SystemTrayDelegate* tray_delegate = shell->system_tray_delegate(); |
110 if (sender == help_) { | 140 if (sender == help_) { |
111 shell->metrics()->RecordUserMetricsAction(ash::UMA_TRAY_HELP); | 141 shell->metrics()->RecordUserMetricsAction(ash::UMA_TRAY_HELP); |
112 tray_delegate->ShowHelp(); | 142 tray_delegate->ShowHelp(); |
143 } else if (sender == reboot_) { | |
Daniel Erat
2014/12/17 16:21:04
you should probably add a metric for this to match
cschuet (SLOW)
2015/01/07 14:37:07
I have followed stevenjb's suggestion and there is
| |
144 tray_delegate->Restart(); | |
113 } else if (sender == shutdown_) { | 145 } else if (sender == shutdown_) { |
114 shell->metrics()->RecordUserMetricsAction(ash::UMA_TRAY_SHUT_DOWN); | 146 shell->metrics()->RecordUserMetricsAction(ash::UMA_TRAY_SHUT_DOWN); |
115 tray_delegate->ShutDown(); | 147 tray_delegate->ShutDown(); |
116 } else if (sender == lock_) { | 148 } else if (sender == lock_) { |
117 shell->metrics()->RecordUserMetricsAction(ash::UMA_TRAY_LOCK_SCREEN); | 149 shell->metrics()->RecordUserMetricsAction(ash::UMA_TRAY_LOCK_SCREEN); |
118 tray_delegate->RequestLockScreen(); | 150 tray_delegate->RequestLockScreen(); |
119 } else { | 151 } else { |
120 NOTREACHED(); | 152 NOTREACHED(); |
121 } | 153 } |
122 } | 154 } |
123 | 155 |
156 void DateDefaultView::OnShutdownPolicyChanged(bool reboot_on_shutdown) { | |
157 shutdown_->SetVisible(!reboot_on_shutdown); | |
158 reboot_->SetVisible(reboot_on_shutdown); | |
159 } | |
160 | |
124 } // namespace ash | 161 } // namespace ash |
OLD | NEW |