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/logout_button/logout_confirmation_dialog_view.h" | |
9 #include "ash/system/status_area_widget.h" | 10 #include "ash/system/status_area_widget.h" |
10 #include "ash/system/tray/system_tray_delegate.h" | 11 #include "ash/system/tray/system_tray_delegate.h" |
11 #include "ash/system/tray/system_tray_notifier.h" | 12 #include "ash/system/tray/system_tray_notifier.h" |
12 #include "ash/system/tray/tray_constants.h" | 13 #include "ash/system/tray/tray_constants.h" |
13 #include "ash/system/tray/tray_utils.h" | 14 #include "ash/system/tray/tray_utils.h" |
14 #include "base/logging.h" | 15 #include "base/logging.h" |
15 #include "grit/ash_resources.h" | 16 #include "grit/ash_resources.h" |
16 #include "third_party/skia/include/core/SkColor.h" | 17 #include "third_party/skia/include/core/SkColor.h" |
17 #include "ui/events/event.h" | 18 #include "ui/events/event.h" |
18 #include "ui/gfx/font.h" | 19 #include "ui/gfx/font.h" |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
89 set_animate_on_state_change(false); | 90 set_animate_on_state_change(false); |
90 | 91 |
91 set_min_size(gfx::Size(0, GetShelfItemHeight())); | 92 set_min_size(gfx::Size(0, GetShelfItemHeight())); |
92 } | 93 } |
93 | 94 |
94 LogoutButton::~LogoutButton() { | 95 LogoutButton::~LogoutButton() { |
95 } | 96 } |
96 | 97 |
97 LogoutButtonTray::LogoutButtonTray(StatusAreaWidget* status_area_widget) | 98 LogoutButtonTray::LogoutButtonTray(StatusAreaWidget* status_area_widget) |
98 : TrayBackgroundView(status_area_widget), | 99 : TrayBackgroundView(status_area_widget), |
99 button_(NULL), | |
100 login_status_(user::LOGGED_IN_NONE), | 100 login_status_(user::LOGGED_IN_NONE), |
101 show_logout_button_in_tray_(false) { | 101 show_logout_button_in_tray_(false), |
102 weak_factory_(this) { | |
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 // For testing purpose. |
107 if (Shell::HasInstance()) | |
108 Shell::GetInstance()->system_tray_notifier()->AddLogoutButtonObserver(this); | |
106 } | 109 } |
107 | 110 |
108 LogoutButtonTray::~LogoutButtonTray() { | 111 LogoutButtonTray::~LogoutButtonTray() { |
109 Shell::GetInstance()->system_tray_notifier()-> | 112 EnsureConfirmationDialogIsClosed(); |
110 RemoveLogoutButtonObserver(this); | 113 if (Shell::HasInstance()) |
114 Shell::GetInstance()->system_tray_notifier()-> | |
115 RemoveLogoutButtonObserver(this); | |
116 } | |
117 | |
118 void LogoutButtonTray::EnsureConfirmationDialogIsShowing() { | |
119 if (!confirmation_dialog_) { | |
120 confirmation_dialog_.reset(new LogoutConfirmationDialogView( | |
121 weak_factory_.GetWeakPtr())); | |
122 confirmation_dialog_->Show(dialog_duration_); | |
123 } | |
124 } | |
125 | |
126 void LogoutButtonTray::EnsureConfirmationDialogIsClosed() { | |
127 if (confirmation_dialog_ && Shell::HasInstance()) | |
128 confirmation_dialog_->GetWidget()->Close(); | |
129 } | |
130 | |
131 bool LogoutButtonTray::IsConfirmationDialogShowing() { | |
132 return (bool)confirmation_dialog_; | |
bartfab (slow)
2013/12/03 19:46:04
Nit: We use C++-style casts. In this case though,
binjin
2013/12/04 10:47:03
Done.
| |
111 } | 133 } |
112 | 134 |
113 void LogoutButtonTray::SetShelfAlignment(ShelfAlignment alignment) { | 135 void LogoutButtonTray::SetShelfAlignment(ShelfAlignment alignment) { |
114 TrayBackgroundView::SetShelfAlignment(alignment); | 136 TrayBackgroundView::SetShelfAlignment(alignment); |
115 tray_container()->set_border(NULL); | 137 tray_container()->set_border(NULL); |
116 } | 138 } |
117 | 139 |
118 base::string16 LogoutButtonTray::GetAccessibleNameForTray() { | 140 base::string16 LogoutButtonTray::GetAccessibleNameForTray() { |
119 return button_->GetText(); | 141 return button_->GetText(); |
120 } | 142 } |
121 | 143 |
122 void LogoutButtonTray::HideBubbleWithView( | 144 void LogoutButtonTray::HideBubbleWithView( |
123 const views::TrayBubbleView* bubble_view) { | 145 const views::TrayBubbleView* bubble_view) { |
124 } | 146 } |
125 | 147 |
126 bool LogoutButtonTray::ClickedOutsideBubble() { | 148 bool LogoutButtonTray::ClickedOutsideBubble() { |
127 return false; | 149 return false; |
128 } | 150 } |
129 | 151 |
130 void LogoutButtonTray::OnShowLogoutButtonInTrayChanged(bool show) { | 152 void LogoutButtonTray::OnShowLogoutButtonInTrayChanged(bool show) { |
131 show_logout_button_in_tray_ = show; | 153 show_logout_button_in_tray_ = show; |
132 UpdateVisibility(); | 154 UpdateVisibility(); |
133 } | 155 } |
134 | 156 |
157 void LogoutButtonTray::OnLogoutDialogDurationChanged(base::TimeDelta duration) { | |
158 dialog_duration_ = duration; | |
159 if (confirmation_dialog_) | |
160 confirmation_dialog_->UpdateDialogDuration(dialog_duration_); | |
161 } | |
162 | |
135 void LogoutButtonTray::ButtonPressed(views::Button* sender, | 163 void LogoutButtonTray::ButtonPressed(views::Button* sender, |
136 const ui::Event& event) { | 164 const ui::Event& event) { |
137 DCHECK_EQ(sender, button_); | 165 DCHECK_EQ(sender, button_); |
138 Shell::GetInstance()->system_tray_delegate()->SignOut(); | 166 OnUserLogoutEvent(); |
139 } | 167 } |
140 | 168 |
141 void LogoutButtonTray::UpdateAfterLoginStatusChange( | 169 void LogoutButtonTray::UpdateAfterLoginStatusChange( |
142 user::LoginStatus login_status) { | 170 user::LoginStatus login_status) { |
143 login_status_ = login_status; | 171 login_status_ = login_status; |
144 const base::string16 title = | 172 const base::string16 title = |
145 GetLocalizedSignOutStringForStatus(login_status, false); | 173 GetLocalizedSignOutStringForStatus(login_status, false); |
146 button_->SetText(title); | 174 button_->SetText(title); |
147 button_->SetAccessibleName(title); | 175 button_->SetAccessibleName(title); |
148 UpdateVisibility(); | 176 UpdateVisibility(); |
149 } | 177 } |
150 | 178 |
179 void LogoutButtonTray::DeleteConfirmationDialog() { | |
180 confirmation_dialog_.reset(); | |
181 } | |
182 | |
183 void LogoutButtonTray::OnUserLogoutEvent() { | |
184 // Sign out immediately if kLogoutDialogDurationMs is non-positive. | |
185 if (dialog_duration_ <= base::TimeDelta::FromSeconds(0)) | |
186 LogoutConfirmationDialogView::GetProvider()->LogoutCurrentUser(NULL); | |
187 else | |
188 EnsureConfirmationDialogIsShowing(); | |
189 } | |
190 | |
191 LogoutConfirmationDialogView *LogoutButtonTray::GetConfirmationDialog() { | |
192 return confirmation_dialog_.get(); | |
193 } | |
194 | |
151 void LogoutButtonTray::UpdateVisibility() { | 195 void LogoutButtonTray::UpdateVisibility() { |
152 SetVisible(show_logout_button_in_tray_ && | 196 SetVisible(show_logout_button_in_tray_ && |
153 login_status_ != user::LOGGED_IN_NONE && | 197 login_status_ != user::LOGGED_IN_NONE && |
154 login_status_ != user::LOGGED_IN_LOCKED); | 198 login_status_ != user::LOGGED_IN_LOCKED); |
199 if (!show_logout_button_in_tray_) | |
200 EnsureConfirmationDialogIsClosed(); | |
155 } | 201 } |
156 | 202 |
157 } // namespace internal | 203 } // namespace internal |
204 | |
bartfab (slow)
2013/12/03 19:46:04
Nit: No blank line needed.
binjin
2013/12/04 10:47:03
Done.
| |
158 } // namespace ash | 205 } // namespace ash |
OLD | NEW |