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

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: rebase Created 6 years, 11 months 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_list.h" 18 #include "ui/gfx/font_list.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 19 matching lines...) Expand all
57 56
58 class LogoutButton : public views::LabelButton { 57 class LogoutButton : public views::LabelButton {
59 public: 58 public:
60 LogoutButton(views::ButtonListener* listener); 59 LogoutButton(views::ButtonListener* listener);
61 virtual ~LogoutButton(); 60 virtual ~LogoutButton();
62 61
63 private: 62 private:
64 DISALLOW_COPY_AND_ASSIGN(LogoutButton); 63 DISALLOW_COPY_AND_ASSIGN(LogoutButton);
65 }; 64 };
66 65
66 class LogoutConfirmationDialogDelegate
67 : public LogoutConfirmationDialogView::Delegate {
68
69 public:
70 LogoutConfirmationDialogDelegate() {}
71 virtual ~LogoutConfirmationDialogDelegate() {}
72
73 virtual void LogoutCurrentUser() OVERRIDE;
74 virtual base::TimeTicks GetCurrentTime() const OVERRIDE;
75 virtual void ShowDialog(views::DialogDelegate* dialog) OVERRIDE;
76
77 private:
78 DISALLOW_COPY_AND_ASSIGN(LogoutConfirmationDialogDelegate);
79 };
80
67 } // namespace 81 } // namespace
68 82
69 LogoutButton::LogoutButton(views::ButtonListener* listener) 83 LogoutButton::LogoutButton(views::ButtonListener* listener)
70 : views::LabelButton(listener, base::string16()) { 84 : views::LabelButton(listener, base::string16()) {
71 SetupLabelForTray(label()); 85 SetupLabelForTray(label());
72 SetFontList( 86 SetFontList(
73 GetFontList().DeriveFontListWithSizeDeltaAndStyle(0, gfx::Font::NORMAL)); 87 GetFontList().DeriveFontListWithSizeDeltaAndStyle(0, gfx::Font::NORMAL));
74 for (size_t state = 0; state < views::Button::STATE_COUNT; ++state) 88 for (size_t state = 0; state < views::Button::STATE_COUNT; ++state)
75 SetTextColor(static_cast<views::Button::ButtonState>(state), SK_ColorWHITE); 89 SetTextColor(static_cast<views::Button::ButtonState>(state), SK_ColorWHITE);
76 90
(...skipping 11 matching lines...) Expand all
88 border->set_insets(insets); 102 border->set_insets(insets);
89 set_border(border); 103 set_border(border);
90 set_animate_on_state_change(false); 104 set_animate_on_state_change(false);
91 105
92 set_min_size(gfx::Size(0, GetShelfItemHeight())); 106 set_min_size(gfx::Size(0, GetShelfItemHeight()));
93 } 107 }
94 108
95 LogoutButton::~LogoutButton() { 109 LogoutButton::~LogoutButton() {
96 } 110 }
97 111
112 void LogoutConfirmationDialogDelegate::LogoutCurrentUser() {
113 Shell::GetInstance()->system_tray_delegate()->SignOut();
114 }
115
116 base::TimeTicks LogoutConfirmationDialogDelegate::GetCurrentTime() const {
117 return base::TimeTicks::Now();
118 }
119
120 void LogoutConfirmationDialogDelegate::ShowDialog(
121 views::DialogDelegate *dialog) {
122 views::DialogDelegate::CreateDialogWidget(
123 dialog, ash::Shell::GetPrimaryRootWindow(), NULL);
124 dialog->GetWidget()->Show();
125 }
126
98 LogoutButtonTray::LogoutButtonTray(StatusAreaWidget* status_area_widget) 127 LogoutButtonTray::LogoutButtonTray(StatusAreaWidget* status_area_widget)
99 : TrayBackgroundView(status_area_widget), 128 : TrayBackgroundView(status_area_widget),
100 button_(NULL), 129 button_(NULL),
101 login_status_(user::LOGGED_IN_NONE), 130 login_status_(user::LOGGED_IN_NONE),
102 show_logout_button_in_tray_(false) { 131 show_logout_button_in_tray_(false),
132 confirmation_dialog_(NULL),
133 confirmation_delegate_(new LogoutConfirmationDialogDelegate) {
103 button_ = new LogoutButton(this); 134 button_ = new LogoutButton(this);
104 tray_container()->AddChildView(button_); 135 tray_container()->AddChildView(button_);
105 tray_container()->set_border(NULL); 136 tray_container()->set_border(NULL);
106 Shell::GetInstance()->system_tray_notifier()->AddLogoutButtonObserver(this); 137 // The Shell may not exist in some unit tests.
138 if (Shell::HasInstance()) {
139 Shell::GetInstance()->system_tray_notifier()->
140 AddLogoutButtonObserver(this);
141 }
107 } 142 }
108 143
109 LogoutButtonTray::~LogoutButtonTray() { 144 LogoutButtonTray::~LogoutButtonTray() {
110 Shell::GetInstance()->system_tray_notifier()-> 145 EnsureConfirmationDialogIsClosed();
111 RemoveLogoutButtonObserver(this); 146 // The Shell may not exist in some unit tests.
147 if (Shell::HasInstance()) {
148 Shell::GetInstance()->system_tray_notifier()->
149 RemoveLogoutButtonObserver(this);
150 }
151 }
152
153 bool LogoutButtonTray::IsConfirmationDialogShowing() const {
154 return confirmation_dialog_ != NULL;
155 }
156
157 void LogoutButtonTray::EnsureConfirmationDialogIsShowing() {
158 if (!confirmation_dialog_) {
159 confirmation_dialog_ = new LogoutConfirmationDialogView(
160 this, confirmation_delegate_.get());
161 confirmation_dialog_->Show(dialog_duration_);
162 }
163 }
164
165 void LogoutButtonTray::EnsureConfirmationDialogIsClosed() {
166 if (confirmation_dialog_)
167 confirmation_dialog_->Close();
112 } 168 }
113 169
114 void LogoutButtonTray::SetShelfAlignment(ShelfAlignment alignment) { 170 void LogoutButtonTray::SetShelfAlignment(ShelfAlignment alignment) {
115 TrayBackgroundView::SetShelfAlignment(alignment); 171 TrayBackgroundView::SetShelfAlignment(alignment);
116 tray_container()->set_border(NULL); 172 tray_container()->set_border(NULL);
117 } 173 }
118 174
119 base::string16 LogoutButtonTray::GetAccessibleNameForTray() { 175 base::string16 LogoutButtonTray::GetAccessibleNameForTray() {
120 return button_->GetText(); 176 return button_->GetText();
121 } 177 }
122 178
123 void LogoutButtonTray::HideBubbleWithView( 179 void LogoutButtonTray::HideBubbleWithView(
124 const views::TrayBubbleView* bubble_view) { 180 const views::TrayBubbleView* bubble_view) {
125 } 181 }
126 182
127 bool LogoutButtonTray::ClickedOutsideBubble() { 183 bool LogoutButtonTray::ClickedOutsideBubble() {
128 return false; 184 return false;
129 } 185 }
130 186
131 void LogoutButtonTray::OnShowLogoutButtonInTrayChanged(bool show) { 187 void LogoutButtonTray::OnShowLogoutButtonInTrayChanged(bool show) {
132 show_logout_button_in_tray_ = show; 188 show_logout_button_in_tray_ = show;
133 UpdateVisibility(); 189 UpdateVisibility();
134 } 190 }
135 191
192 void LogoutButtonTray::OnLogoutDialogDurationChanged(base::TimeDelta duration) {
193 dialog_duration_ = duration;
194 if (confirmation_dialog_)
195 confirmation_dialog_->UpdateDialogDuration(dialog_duration_);
196 }
197
136 void LogoutButtonTray::ButtonPressed(views::Button* sender, 198 void LogoutButtonTray::ButtonPressed(views::Button* sender,
137 const ui::Event& event) { 199 const ui::Event& event) {
138 DCHECK_EQ(sender, button_); 200 DCHECK_EQ(sender, button_);
139 Shell::GetInstance()->system_tray_delegate()->SignOut(); 201 // Sign out immediately if |dialog_duration_| is non-positive.
202 if (dialog_duration_ <= base::TimeDelta())
203 confirmation_delegate_->LogoutCurrentUser();
204 else
205 EnsureConfirmationDialogIsShowing();
140 } 206 }
141 207
142 void LogoutButtonTray::UpdateAfterLoginStatusChange( 208 void LogoutButtonTray::UpdateAfterLoginStatusChange(
143 user::LoginStatus login_status) { 209 user::LoginStatus login_status) {
144 login_status_ = login_status; 210 login_status_ = login_status;
145 const base::string16 title = 211 const base::string16 title =
146 GetLocalizedSignOutStringForStatus(login_status, false); 212 GetLocalizedSignOutStringForStatus(login_status, false);
147 button_->SetText(title); 213 button_->SetText(title);
148 button_->SetAccessibleName(title); 214 button_->SetAccessibleName(title);
149 UpdateVisibility(); 215 UpdateVisibility();
150 } 216 }
151 217
218 void LogoutButtonTray::ReleaseConfirmationDialog() {
219 confirmation_dialog_ = NULL;
220 }
221
222 void LogoutButtonTray::SetDelegateForTest(
223 scoped_ptr<LogoutConfirmationDialogView::Delegate> delegate) {
224 confirmation_delegate_ = delegate.Pass();
225 }
226
152 void LogoutButtonTray::UpdateVisibility() { 227 void LogoutButtonTray::UpdateVisibility() {
153 SetVisible(show_logout_button_in_tray_ && 228 SetVisible(show_logout_button_in_tray_ &&
154 login_status_ != user::LOGGED_IN_NONE && 229 login_status_ != user::LOGGED_IN_NONE &&
155 login_status_ != user::LOGGED_IN_LOCKED); 230 login_status_ != user::LOGGED_IN_LOCKED);
231 if (!show_logout_button_in_tray_)
232 EnsureConfirmationDialogIsClosed();
156 } 233 }
157 234
158 } // namespace internal 235 } // namespace internal
159 } // namespace ash 236 } // namespace ash
OLDNEW
« no previous file with comments | « ash/system/logout_button/logout_button_tray.h ('k') | ash/system/logout_button/logout_button_tray_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698