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

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; use scoped_ptr; fix timer Created 7 years, 1 month 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/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"
16 #include "base/message_loop/message_loop.h"
15 #include "grit/ash_resources.h" 17 #include "grit/ash_resources.h"
16 #include "third_party/skia/include/core/SkColor.h" 18 #include "third_party/skia/include/core/SkColor.h"
17 #include "ui/events/event.h" 19 #include "ui/events/event.h"
18 #include "ui/gfx/font.h" 20 #include "ui/gfx/font.h"
19 #include "ui/gfx/insets.h" 21 #include "ui/gfx/insets.h"
20 #include "ui/gfx/size.h" 22 #include "ui/gfx/size.h"
21 #include "ui/views/bubble/tray_bubble_view.h" 23 #include "ui/views/bubble/tray_bubble_view.h"
22 #include "ui/views/controls/button/label_button.h" 24 #include "ui/views/controls/button/label_button.h"
23 #include "ui/views/controls/button/label_button_border.h" 25 #include "ui/views/controls/button/label_button_border.h"
24 #include "ui/views/painter.h" 26 #include "ui/views/painter.h"
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 set_animate_on_state_change(false); 91 set_animate_on_state_change(false);
90 92
91 set_min_size(gfx::Size(0, GetShelfItemHeight())); 93 set_min_size(gfx::Size(0, GetShelfItemHeight()));
92 } 94 }
93 95
94 LogoutButton::~LogoutButton() { 96 LogoutButton::~LogoutButton() {
95 } 97 }
96 98
97 LogoutButtonTray::LogoutButtonTray(StatusAreaWidget* status_area_widget) 99 LogoutButtonTray::LogoutButtonTray(StatusAreaWidget* status_area_widget)
98 : TrayBackgroundView(status_area_widget), 100 : TrayBackgroundView(status_area_widget),
99 button_(NULL),
100 login_status_(user::LOGGED_IN_NONE), 101 login_status_(user::LOGGED_IN_NONE),
101 show_logout_button_in_tray_(false) { 102 show_logout_button_in_tray_(false) {
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 Shell::GetInstance()->system_tray_notifier()->AddLogoutButtonObserver(this);
106 } 107 }
107 108
108 LogoutButtonTray::~LogoutButtonTray() { 109 LogoutButtonTray::~LogoutButtonTray() {
110 EnsureConfirmationDialogIsClosed();
109 Shell::GetInstance()->system_tray_notifier()-> 111 Shell::GetInstance()->system_tray_notifier()->
110 RemoveLogoutButtonObserver(this); 112 RemoveLogoutButtonObserver(this);
111 } 113 }
112 114
115 void LogoutButtonTray::EnsureConfirmationDialogIsShowing() {
116 if (!confirmation_dialog_) {
117 confirmation_dialog_.reset(new LogoutConfirmationDialogView(this));
118 confirmation_dialog_->Show(dialog_duration_);
119 }
120 }
121
122 void LogoutButtonTray::EnsureConfirmationDialogIsClosed() {
123 if (confirmation_dialog_) {
124 confirmation_dialog_->GetWidget()->Close();
bartfab (slow) 2013/11/20 18:00:44 Are you sure that closing the widget will not dest
125 LogoutConfirmationDialogView* dialog = UnbindWithConfirmationDialog();
126 if (dialog)
127 base::MessageLoop::current()->DeleteSoon(FROM_HERE, dialog);
128 }
129 }
130
113 void LogoutButtonTray::SetShelfAlignment(ShelfAlignment alignment) { 131 void LogoutButtonTray::SetShelfAlignment(ShelfAlignment alignment) {
114 TrayBackgroundView::SetShelfAlignment(alignment); 132 TrayBackgroundView::SetShelfAlignment(alignment);
115 tray_container()->set_border(NULL); 133 tray_container()->set_border(NULL);
116 } 134 }
117 135
118 base::string16 LogoutButtonTray::GetAccessibleNameForTray() { 136 base::string16 LogoutButtonTray::GetAccessibleNameForTray() {
119 return button_->GetText(); 137 return button_->GetText();
120 } 138 }
121 139
122 void LogoutButtonTray::HideBubbleWithView( 140 void LogoutButtonTray::HideBubbleWithView(
123 const views::TrayBubbleView* bubble_view) { 141 const views::TrayBubbleView* bubble_view) {
124 } 142 }
125 143
126 bool LogoutButtonTray::ClickedOutsideBubble() { 144 bool LogoutButtonTray::ClickedOutsideBubble() {
127 return false; 145 return false;
128 } 146 }
129 147
130 void LogoutButtonTray::OnShowLogoutButtonInTrayChanged(bool show) { 148 void LogoutButtonTray::OnShowLogoutButtonInTrayChanged(bool show) {
131 show_logout_button_in_tray_ = show; 149 show_logout_button_in_tray_ = show;
132 UpdateVisibility(); 150 UpdateVisibility();
133 } 151 }
134 152
153 void LogoutButtonTray::OnLogoutDialogDurationChanged(base::TimeDelta duration) {
154 dialog_duration_ = duration;
155 if (confirmation_dialog_)
156 confirmation_dialog_->UpdateDialogDuration(dialog_duration_);
157 }
158
135 void LogoutButtonTray::ButtonPressed(views::Button* sender, 159 void LogoutButtonTray::ButtonPressed(views::Button* sender,
136 const ui::Event& event) { 160 const ui::Event& event) {
137 DCHECK_EQ(sender, button_); 161 DCHECK_EQ(sender, button_);
138 Shell::GetInstance()->system_tray_delegate()->SignOut(); 162 // Sign out immediately if kLogoutDialogDurationMs is non-positive.
163 if (dialog_duration_ <= base::TimeDelta::FromSeconds(0))
164 Shell::GetInstance()->system_tray_delegate()->SignOut();
165 else
166 EnsureConfirmationDialogIsShowing();
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 LogoutConfirmationDialogView* LogoutButtonTray::UnbindWithConfirmationDialog() {
180 // Use atomic operation to nullify two pointers. This function can be called
181 // from both LogoutButtonTray and LogoutConfirmationDialogView, and the
182 // destroy order of these two class doesn't matter now. Be careful this
183 // function is not thread safe, and the dialog might not be destroyed yet.
184 if (confirmation_dialog_) {
185 LogoutConfirmationDialogView *dialog = confirmation_dialog_.release();
186 dialog->ClearOwner();
187 return dialog;
188 }
189 return NULL;
190 }
191
151 void LogoutButtonTray::UpdateVisibility() { 192 void LogoutButtonTray::UpdateVisibility() {
152 SetVisible(show_logout_button_in_tray_ && 193 SetVisible(show_logout_button_in_tray_ &&
153 login_status_ != user::LOGGED_IN_NONE && 194 login_status_ != user::LOGGED_IN_NONE &&
154 login_status_ != user::LOGGED_IN_LOCKED); 195 login_status_ != user::LOGGED_IN_LOCKED);
196 if (!show_logout_button_in_tray_)
197 EnsureConfirmationDialogIsClosed();
155 } 198 }
156 199
157 } // namespace internal 200 } // namespace internal
158 } // namespace ash 201 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698