Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1784)

Side by Side Diff: ash/system/logout_button/logout_button_tray.cc

Issue 40053002: Implements the dialog view for logout button tray in public sessions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: minor fixes Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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_delegate_(new LogoutConfirmationDialogView::Delegate) {
102 button_ = new LogoutButton(this); 102 button_ = new LogoutButton(this);
103 tray_container()->AddChildView(button_); 103 tray_container()->AddChildView(button_);
104 tray_container()->set_border(NULL); 104 tray_container()->set_border(NULL);
105 Shell::GetInstance()->system_tray_notifier()->AddLogoutButtonObserver(this); 105 // The Shell may not exist in some unit tests.
106 if (Shell::HasInstance()) {
107 Shell::GetInstance()->system_tray_notifier()->
108 AddLogoutButtonObserver(this);
109 }
106 } 110 }
107 111
108 LogoutButtonTray::~LogoutButtonTray() { 112 LogoutButtonTray::~LogoutButtonTray() {
109 Shell::GetInstance()->system_tray_notifier()-> 113 EnsureConfirmationDialogIsClosed();
110 RemoveLogoutButtonObserver(this); 114 // The Shell may not exist in some unit tests.
115 if (Shell::HasInstance()) {
116 Shell::GetInstance()->system_tray_notifier()->
117 RemoveLogoutButtonObserver(this);
118 }
119 }
120
121 bool LogoutButtonTray::IsConfirmationDialogShowing() const {
122 return confirmation_dialog_;
123 }
124
125 void LogoutButtonTray::EnsureConfirmationDialogIsShowing() {
126 if (!confirmation_dialog_) {
127 confirmation_dialog_.reset(new LogoutConfirmationDialogView(
128 this, confirmation_delegate_.get()));
129 confirmation_dialog_->Show(dialog_duration_);
130 }
131 }
132
133 void LogoutButtonTray::EnsureConfirmationDialogIsClosed() {
134 if (confirmation_dialog_)
135 confirmation_dialog_->DeleteDelegate();
bartfab (slow) 2013/12/12 16:04:13 Would it be possible to call confirmation_dialog_-
binjin 2013/12/17 10:29:49 Done.
111 } 136 }
112 137
113 void LogoutButtonTray::SetShelfAlignment(ShelfAlignment alignment) { 138 void LogoutButtonTray::SetShelfAlignment(ShelfAlignment alignment) {
114 TrayBackgroundView::SetShelfAlignment(alignment); 139 TrayBackgroundView::SetShelfAlignment(alignment);
115 tray_container()->set_border(NULL); 140 tray_container()->set_border(NULL);
116 } 141 }
117 142
118 base::string16 LogoutButtonTray::GetAccessibleNameForTray() { 143 base::string16 LogoutButtonTray::GetAccessibleNameForTray() {
119 return button_->GetText(); 144 return button_->GetText();
120 } 145 }
121 146
122 void LogoutButtonTray::HideBubbleWithView( 147 void LogoutButtonTray::HideBubbleWithView(
123 const views::TrayBubbleView* bubble_view) { 148 const views::TrayBubbleView* bubble_view) {
124 } 149 }
125 150
126 bool LogoutButtonTray::ClickedOutsideBubble() { 151 bool LogoutButtonTray::ClickedOutsideBubble() {
127 return false; 152 return false;
128 } 153 }
129 154
130 void LogoutButtonTray::OnShowLogoutButtonInTrayChanged(bool show) { 155 void LogoutButtonTray::OnShowLogoutButtonInTrayChanged(bool show) {
131 show_logout_button_in_tray_ = show; 156 show_logout_button_in_tray_ = show;
132 UpdateVisibility(); 157 UpdateVisibility();
133 } 158 }
134 159
160 void LogoutButtonTray::OnLogoutDialogDurationChanged(base::TimeDelta duration) {
161 dialog_duration_ = duration;
162 if (confirmation_dialog_)
163 confirmation_dialog_->UpdateDialogDuration(dialog_duration_);
164 }
165
135 void LogoutButtonTray::ButtonPressed(views::Button* sender, 166 void LogoutButtonTray::ButtonPressed(views::Button* sender,
136 const ui::Event& event) { 167 const ui::Event& event) {
137 DCHECK_EQ(sender, button_); 168 DCHECK_EQ(sender, button_);
138 Shell::GetInstance()->system_tray_delegate()->SignOut(); 169 // Sign out immediately if |dialog_duration_| is non-positive.
170 if (dialog_duration_ <= base::TimeDelta())
171 confirmation_delegate_->LogoutCurrentUser();
172 else
173 EnsureConfirmationDialogIsShowing();
139 } 174 }
140 175
141 void LogoutButtonTray::UpdateAfterLoginStatusChange( 176 void LogoutButtonTray::UpdateAfterLoginStatusChange(
142 user::LoginStatus login_status) { 177 user::LoginStatus login_status) {
143 login_status_ = login_status; 178 login_status_ = login_status;
144 const base::string16 title = 179 const base::string16 title =
145 GetLocalizedSignOutStringForStatus(login_status, false); 180 GetLocalizedSignOutStringForStatus(login_status, false);
146 button_->SetText(title); 181 button_->SetText(title);
147 button_->SetAccessibleName(title); 182 button_->SetAccessibleName(title);
148 UpdateVisibility(); 183 UpdateVisibility();
149 } 184 }
150 185
186 void LogoutButtonTray::DeleteConfirmationDialog() {
187 ignore_result(confirmation_dialog_.release());
188 }
189
190 LogoutConfirmationDialogView* LogoutButtonTray::GetConfirmationDialogForTest() {
191 return confirmation_dialog_.get();
192 }
193
194 LogoutConfirmationDialogView::Delegate*
195 LogoutButtonTray::GetConfirmationDelegateForTest() {
196 return confirmation_delegate_.get();
197 }
198
199 void LogoutButtonTray::SetDelegateForTest(
200 scoped_ptr<LogoutConfirmationDialogView::Delegate> delegate) {
201 confirmation_delegate_ = delegate.Pass();
202 }
203
151 void LogoutButtonTray::UpdateVisibility() { 204 void LogoutButtonTray::UpdateVisibility() {
152 SetVisible(show_logout_button_in_tray_ && 205 SetVisible(show_logout_button_in_tray_ &&
153 login_status_ != user::LOGGED_IN_NONE && 206 login_status_ != user::LOGGED_IN_NONE &&
154 login_status_ != user::LOGGED_IN_LOCKED); 207 login_status_ != user::LOGGED_IN_LOCKED);
208 if (!show_logout_button_in_tray_)
209 EnsureConfirmationDialogIsClosed();
155 } 210 }
156 211
157 } // namespace internal 212 } // namespace internal
158 } // namespace ash 213 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698