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 "ash/wm/lock_state_controller.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), |
33 shutdown_(NULL), | 34 shutdown_(NULL), |
34 lock_(NULL), | 35 lock_(NULL), |
35 date_view_(NULL) { | 36 date_view_(NULL), |
37 weak_factory_(this) { | |
36 SetLayoutManager(new views::FillLayout); | 38 SetLayoutManager(new views::FillLayout); |
37 | 39 |
38 date_view_ = new tray::DateView(); | 40 date_view_ = new tray::DateView(); |
39 date_view_->SetBorder(views::Border::CreateEmptyBorder( | 41 date_view_->SetBorder(views::Border::CreateEmptyBorder( |
40 kPaddingVertical, ash::kTrayPopupPaddingHorizontal, 0, 0)); | 42 kPaddingVertical, ash::kTrayPopupPaddingHorizontal, 0, 0)); |
41 SpecialPopupRow* view = new SpecialPopupRow(); | 43 SpecialPopupRow* view = new SpecialPopupRow(); |
42 view->SetContent(date_view_); | 44 view->SetContent(date_view_); |
43 AddChildView(view); | 45 AddChildView(view); |
44 | 46 |
45 bool userAddingRunning = ash::Shell::GetInstance() | 47 bool userAddingRunning = ash::Shell::GetInstance() |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
77 if (ash::Shell::GetInstance()->session_state_delegate()->CanLockScreen()) { | 79 if (ash::Shell::GetInstance()->session_state_delegate()->CanLockScreen()) { |
78 lock_ = new TrayPopupHeaderButton(this, | 80 lock_ = new TrayPopupHeaderButton(this, |
79 IDR_AURA_UBER_TRAY_LOCKSCREEN, | 81 IDR_AURA_UBER_TRAY_LOCKSCREEN, |
80 IDR_AURA_UBER_TRAY_LOCKSCREEN, | 82 IDR_AURA_UBER_TRAY_LOCKSCREEN, |
81 IDR_AURA_UBER_TRAY_LOCKSCREEN_HOVER, | 83 IDR_AURA_UBER_TRAY_LOCKSCREEN_HOVER, |
82 IDR_AURA_UBER_TRAY_LOCKSCREEN_HOVER, | 84 IDR_AURA_UBER_TRAY_LOCKSCREEN_HOVER, |
83 IDS_ASH_STATUS_TRAY_LOCK); | 85 IDS_ASH_STATUS_TRAY_LOCK); |
84 lock_->SetTooltipText(l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_LOCK)); | 86 lock_->SetTooltipText(l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_LOCK)); |
85 view->AddButton(lock_); | 87 view->AddButton(lock_); |
86 } | 88 } |
89 SystemTrayDelegate* system_tray_delegate = | |
90 Shell::GetInstance()->system_tray_delegate(); | |
91 system_tray_delegate->AddShutdownPolicyObserver(this); | |
92 system_tray_delegate->ShouldRebootOnShutdown(base::Bind( | |
93 &DateDefaultView::OnShutdownPolicyChanged, weak_factory_.GetWeakPtr())); | |
87 #endif // !defined(OS_WIN) | 94 #endif // !defined(OS_WIN) |
88 } | 95 } |
89 | 96 |
90 DateDefaultView::~DateDefaultView() { | 97 DateDefaultView::~DateDefaultView() { |
98 // We need the check as on shell destruction, the delegate is destroyed first. | |
99 SystemTrayDelegate* system_tray_delegate = | |
100 Shell::GetInstance()->system_tray_delegate(); | |
101 if (system_tray_delegate) | |
102 system_tray_delegate->RemoveShutdownPolicyObserver(this); | |
91 } | 103 } |
92 | 104 |
93 views::View* DateDefaultView::GetHelpButtonView() { | 105 views::View* DateDefaultView::GetHelpButtonView() { |
94 return help_; | 106 return help_; |
95 } | 107 } |
96 | 108 |
97 tray::DateView* DateDefaultView::GetDateView() { | 109 tray::DateView* DateDefaultView::GetDateView() { |
98 return date_view_; | 110 return date_view_; |
99 } | 111 } |
100 | 112 |
101 const tray::DateView* DateDefaultView::GetDateView() const { | 113 const tray::DateView* DateDefaultView::GetDateView() const { |
102 return date_view_; | 114 return date_view_; |
103 } | 115 } |
104 | 116 |
105 void DateDefaultView::ButtonPressed(views::Button* sender, | 117 void DateDefaultView::ButtonPressed(views::Button* sender, |
106 const ui::Event& event) { | 118 const ui::Event& event) { |
107 ash::Shell* shell = ash::Shell::GetInstance(); | 119 ash::Shell* shell = ash::Shell::GetInstance(); |
108 ash::SystemTrayDelegate* tray_delegate = shell->system_tray_delegate(); | 120 ash::SystemTrayDelegate* tray_delegate = shell->system_tray_delegate(); |
109 if (sender == help_) { | 121 if (sender == help_) { |
110 shell->metrics()->RecordUserMetricsAction(ash::UMA_TRAY_HELP); | 122 shell->metrics()->RecordUserMetricsAction(ash::UMA_TRAY_HELP); |
111 tray_delegate->ShowHelp(); | 123 tray_delegate->ShowHelp(); |
112 } else if (sender == shutdown_) { | 124 } else if (sender == shutdown_) { |
113 shell->metrics()->RecordUserMetricsAction(ash::UMA_TRAY_SHUT_DOWN); | 125 shell->metrics()->RecordUserMetricsAction(ash::UMA_TRAY_SHUT_DOWN); |
114 tray_delegate->ShutDown(); | 126 ash::Shell::GetInstance() |
127 ->lock_state_controller() | |
128 ->RequestShutdownOrRestart(); | |
115 } else if (sender == lock_) { | 129 } else if (sender == lock_) { |
116 shell->metrics()->RecordUserMetricsAction(ash::UMA_TRAY_LOCK_SCREEN); | 130 shell->metrics()->RecordUserMetricsAction(ash::UMA_TRAY_LOCK_SCREEN); |
117 tray_delegate->RequestLockScreen(); | 131 tray_delegate->RequestLockScreen(); |
118 } else { | 132 } else { |
119 NOTREACHED(); | 133 NOTREACHED(); |
120 } | 134 } |
121 } | 135 } |
122 | 136 |
137 void DateDefaultView::OnShutdownPolicyChanged(bool reboot_on_shutdown) { | |
138 if (!shutdown_) | |
139 return; | |
140 | |
141 if (reboot_on_shutdown) { | |
Daniel Erat
2015/01/07 16:18:40
just do:
shutdown_->SetTooltipText(l10n_util::Get
cschuet (SLOW)
2015/01/13 10:38:28
Done.
| |
142 shutdown_->SetTooltipText( | |
143 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_REBOOT)); | |
144 return; | |
145 } | |
146 shutdown_->SetTooltipText( | |
147 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_SHUTDOWN)); | |
148 } | |
149 | |
123 } // namespace ash | 150 } // namespace ash |
OLD | NEW |