OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/logout_button/logout_button_tray.h" | 5 #include "ash/system/logout_button/logout_button_tray.h" |
6 | 6 |
7 #include "ash/shelf/shelf_types.h" | 7 #include "ash/shelf/shelf_types.h" |
8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
9 #include "ash/system/status_area_widget.h" | 9 #include "ash/system/status_area_widget.h" |
10 #include "ash/system/tray/system_tray_delegate.h" | 10 #include "ash/system/tray/system_tray_delegate.h" |
11 #include "ash/system/tray/system_tray_notifier.h" | 11 #include "ash/system/tray/system_tray_notifier.h" |
12 #include "ash/system/tray/tray_constants.h" | 12 #include "ash/system/tray/tray_constants.h" |
13 #include "ash/system/tray/tray_utils.h" | 13 #include "ash/system/tray/tray_utils.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "grit/ash_resources.h" | 15 #include "grit/ash_resources.h" |
16 #include "third_party/skia/include/core/SkColor.h" | 16 #include "third_party/skia/include/core/SkColor.h" |
17 #include "ui/events/event.h" | 17 #include "ui/events/event.h" |
18 #include "ui/gfx/font.h" | 18 #include "ui/gfx/font.h" |
19 #include "ui/gfx/insets.h" | 19 #include "ui/gfx/insets.h" |
20 #include "ui/gfx/size.h" | 20 #include "ui/gfx/size.h" |
21 #include "ui/views/bubble/tray_bubble_view.h" | 21 #include "ui/views/bubble/tray_bubble_view.h" |
22 #include "ui/views/controls/button/label_button.h" | 22 #include "ui/views/controls/button/label_button.h" |
23 #include "ui/views/controls/button/label_button_border.h" | 23 #include "ui/views/controls/button/label_button_border.h" |
24 #include "ui/views/painter.h" | 24 #include "ui/views/painter.h" |
25 | 25 |
26 namespace ash { | 26 namespace ash { |
27 | |
28 namespace internal { | 27 namespace internal { |
29 | 28 |
30 namespace { | 29 namespace { |
31 | 30 |
32 const int kLogoutButtonHorizontalExtraPadding = 7; | 31 const int kLogoutButtonHorizontalExtraPadding = 7; |
33 | 32 |
34 const int kLogoutButtonNormalImages[] = { | 33 const int kLogoutButtonNormalImages[] = { |
35 IDR_AURA_UBER_TRAY_LOGOUT_BUTTON_NORMAL_TOP_LEFT, | 34 IDR_AURA_UBER_TRAY_LOGOUT_BUTTON_NORMAL_TOP_LEFT, |
36 IDR_AURA_UBER_TRAY_LOGOUT_BUTTON_NORMAL_TOP, | 35 IDR_AURA_UBER_TRAY_LOGOUT_BUTTON_NORMAL_TOP, |
37 IDR_AURA_UBER_TRAY_LOGOUT_BUTTON_NORMAL_TOP_RIGHT, | 36 IDR_AURA_UBER_TRAY_LOGOUT_BUTTON_NORMAL_TOP_RIGHT, |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 set_min_size(gfx::Size(0, GetShelfItemHeight())); | 90 set_min_size(gfx::Size(0, GetShelfItemHeight())); |
92 } | 91 } |
93 | 92 |
94 LogoutButton::~LogoutButton() { | 93 LogoutButton::~LogoutButton() { |
95 } | 94 } |
96 | 95 |
97 LogoutButtonTray::LogoutButtonTray(StatusAreaWidget* status_area_widget) | 96 LogoutButtonTray::LogoutButtonTray(StatusAreaWidget* status_area_widget) |
98 : TrayBackgroundView(status_area_widget), | 97 : TrayBackgroundView(status_area_widget), |
99 button_(NULL), | 98 button_(NULL), |
100 login_status_(user::LOGGED_IN_NONE), | 99 login_status_(user::LOGGED_IN_NONE), |
101 show_logout_button_in_tray_(false) { | 100 show_logout_button_in_tray_(false), |
| 101 confirmation_dialog_(NULL), |
| 102 confirmation_delegate_(new LogoutConfirmationDialogView::Delegate) { |
102 button_ = new LogoutButton(this); | 103 button_ = new LogoutButton(this); |
103 tray_container()->AddChildView(button_); | 104 tray_container()->AddChildView(button_); |
104 tray_container()->set_border(NULL); | 105 tray_container()->set_border(NULL); |
105 Shell::GetInstance()->system_tray_notifier()->AddLogoutButtonObserver(this); | 106 // The Shell may not exist in some unit tests. |
| 107 if (Shell::HasInstance()) { |
| 108 Shell::GetInstance()->system_tray_notifier()-> |
| 109 AddLogoutButtonObserver(this); |
| 110 } |
106 } | 111 } |
107 | 112 |
108 LogoutButtonTray::~LogoutButtonTray() { | 113 LogoutButtonTray::~LogoutButtonTray() { |
109 Shell::GetInstance()->system_tray_notifier()-> | 114 EnsureConfirmationDialogIsClosed(); |
110 RemoveLogoutButtonObserver(this); | 115 // The Shell may not exist in some unit tests. |
| 116 if (Shell::HasInstance()) { |
| 117 Shell::GetInstance()->system_tray_notifier()-> |
| 118 RemoveLogoutButtonObserver(this); |
| 119 } |
| 120 } |
| 121 |
| 122 bool LogoutButtonTray::IsConfirmationDialogShowing() const { |
| 123 return confirmation_dialog_; |
| 124 } |
| 125 |
| 126 void LogoutButtonTray::EnsureConfirmationDialogIsShowing() { |
| 127 if (!confirmation_dialog_) { |
| 128 confirmation_dialog_ = new LogoutConfirmationDialogView( |
| 129 this, confirmation_delegate_.get()); |
| 130 confirmation_dialog_->Show(dialog_duration_); |
| 131 } |
| 132 } |
| 133 |
| 134 void LogoutButtonTray::EnsureConfirmationDialogIsClosed() { |
| 135 if (confirmation_dialog_) |
| 136 confirmation_dialog_->Close(); |
111 } | 137 } |
112 | 138 |
113 void LogoutButtonTray::SetShelfAlignment(ShelfAlignment alignment) { | 139 void LogoutButtonTray::SetShelfAlignment(ShelfAlignment alignment) { |
114 TrayBackgroundView::SetShelfAlignment(alignment); | 140 TrayBackgroundView::SetShelfAlignment(alignment); |
115 tray_container()->set_border(NULL); | 141 tray_container()->set_border(NULL); |
116 } | 142 } |
117 | 143 |
118 base::string16 LogoutButtonTray::GetAccessibleNameForTray() { | 144 base::string16 LogoutButtonTray::GetAccessibleNameForTray() { |
119 return button_->GetText(); | 145 return button_->GetText(); |
120 } | 146 } |
121 | 147 |
122 void LogoutButtonTray::HideBubbleWithView( | 148 void LogoutButtonTray::HideBubbleWithView( |
123 const views::TrayBubbleView* bubble_view) { | 149 const views::TrayBubbleView* bubble_view) { |
124 } | 150 } |
125 | 151 |
126 bool LogoutButtonTray::ClickedOutsideBubble() { | 152 bool LogoutButtonTray::ClickedOutsideBubble() { |
127 return false; | 153 return false; |
128 } | 154 } |
129 | 155 |
130 void LogoutButtonTray::OnShowLogoutButtonInTrayChanged(bool show) { | 156 void LogoutButtonTray::OnShowLogoutButtonInTrayChanged(bool show) { |
131 show_logout_button_in_tray_ = show; | 157 show_logout_button_in_tray_ = show; |
132 UpdateVisibility(); | 158 UpdateVisibility(); |
133 } | 159 } |
134 | 160 |
| 161 void LogoutButtonTray::OnLogoutDialogDurationChanged(base::TimeDelta duration) { |
| 162 dialog_duration_ = duration; |
| 163 if (confirmation_dialog_) |
| 164 confirmation_dialog_->UpdateDialogDuration(dialog_duration_); |
| 165 } |
| 166 |
135 void LogoutButtonTray::ButtonPressed(views::Button* sender, | 167 void LogoutButtonTray::ButtonPressed(views::Button* sender, |
136 const ui::Event& event) { | 168 const ui::Event& event) { |
137 DCHECK_EQ(sender, button_); | 169 DCHECK_EQ(sender, button_); |
138 Shell::GetInstance()->system_tray_delegate()->SignOut(); | 170 // Sign out immediately if |dialog_duration_| is non-positive. |
| 171 if (dialog_duration_ <= base::TimeDelta()) |
| 172 confirmation_delegate_->LogoutCurrentUser(); |
| 173 else |
| 174 EnsureConfirmationDialogIsShowing(); |
139 } | 175 } |
140 | 176 |
141 void LogoutButtonTray::UpdateAfterLoginStatusChange( | 177 void LogoutButtonTray::UpdateAfterLoginStatusChange( |
142 user::LoginStatus login_status) { | 178 user::LoginStatus login_status) { |
143 login_status_ = login_status; | 179 login_status_ = login_status; |
144 const base::string16 title = | 180 const base::string16 title = |
145 GetLocalizedSignOutStringForStatus(login_status, false); | 181 GetLocalizedSignOutStringForStatus(login_status, false); |
146 button_->SetText(title); | 182 button_->SetText(title); |
147 button_->SetAccessibleName(title); | 183 button_->SetAccessibleName(title); |
148 UpdateVisibility(); | 184 UpdateVisibility(); |
149 } | 185 } |
150 | 186 |
| 187 void LogoutButtonTray::ReleaseConfirmationDialog() { |
| 188 confirmation_dialog_ = NULL; |
| 189 } |
| 190 |
| 191 void LogoutButtonTray::SetDelegateForTest( |
| 192 scoped_ptr<LogoutConfirmationDialogView::Delegate> delegate) { |
| 193 confirmation_delegate_ = delegate.Pass(); |
| 194 } |
| 195 |
151 void LogoutButtonTray::UpdateVisibility() { | 196 void LogoutButtonTray::UpdateVisibility() { |
152 SetVisible(show_logout_button_in_tray_ && | 197 SetVisible(show_logout_button_in_tray_ && |
153 login_status_ != user::LOGGED_IN_NONE && | 198 login_status_ != user::LOGGED_IN_NONE && |
154 login_status_ != user::LOGGED_IN_LOCKED); | 199 login_status_ != user::LOGGED_IN_LOCKED); |
| 200 if (!show_logout_button_in_tray_) |
| 201 EnsureConfirmationDialogIsClosed(); |
155 } | 202 } |
156 | 203 |
157 } // namespace internal | 204 } // namespace internal |
158 } // namespace ash | 205 } // namespace ash |
OLD | NEW |