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

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: enhence tests; simplify code; fix win build(hope so) 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 border->set_insets(insets); 86 border->set_insets(insets);
88 set_border(border); 87 set_border(border);
89 set_animate_on_state_change(false); 88 set_animate_on_state_change(false);
90 89
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,
bartfab (slow) 2013/12/10 12:41:16 Nit: Indentation: All arguments must be aligned.
binjin 2013/12/12 13:56:55 Done.
97 LogoutConfirmationDialogView::LogoutConfirmationDelegate* delegate)
98 : TrayBackgroundView(status_area_widget), 98 : TrayBackgroundView(status_area_widget),
99 button_(NULL),
bartfab (slow) 2013/12/10 12:41:16 Nit: Do not remove this. You will be setting |butt
binjin 2013/12/12 13:56:55 Done.
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 weak_factory_(this) {
102 if (!delegate) {
103 confirmation_delegate_.reset(
104 new LogoutConfirmationDialogView::LogoutConfirmationDelegate());
bartfab (slow) 2013/12/10 12:41:16 Nit: No need for ().
binjin 2013/12/12 13:56:55 Done.
105 } else
bartfab (slow) 2013/12/10 12:41:16 Nit 1: Style guide: If the if part has curly brace
binjin 2013/12/12 13:56:55 Done.
106 confirmation_delegate_.reset(delegate);
102 button_ = new LogoutButton(this); 107 button_ = new LogoutButton(this);
103 tray_container()->AddChildView(button_); 108 tray_container()->AddChildView(button_);
104 tray_container()->set_border(NULL); 109 tray_container()->set_border(NULL);
105 Shell::GetInstance()->system_tray_notifier()->AddLogoutButtonObserver(this); 110 // For testing purpose.
bartfab (slow) 2013/12/10 12:41:16 Nit: "For testing purpose" is slightly misleading.
binjin 2013/12/12 13:56:55 Done.
111 if (Shell::HasInstance())
112 Shell::GetInstance()->system_tray_notifier()->AddLogoutButtonObserver(this);
106 } 113 }
107 114
108 LogoutButtonTray::~LogoutButtonTray() { 115 LogoutButtonTray::~LogoutButtonTray() {
109 Shell::GetInstance()->system_tray_notifier()-> 116 EnsureConfirmationDialogIsClosed();
110 RemoveLogoutButtonObserver(this); 117 if (Shell::HasInstance())
bartfab (slow) 2013/12/10 12:41:16 Nit: Style guide: Multi-line conditionals require
binjin 2013/12/12 13:56:55 Done.
118 Shell::GetInstance()->system_tray_notifier()->
119 RemoveLogoutButtonObserver(this);
120 }
121
122 void LogoutButtonTray::EnsureConfirmationDialogIsShowing() {
123 if (!confirmation_dialog_) {
124 confirmation_dialog_.reset(new LogoutConfirmationDialogView(
125 weak_factory_.GetWeakPtr(), confirmation_delegate_.get()));
126 confirmation_dialog_->Show(dialog_duration_);
127 }
128 }
129
130 void LogoutButtonTray::EnsureConfirmationDialogIsClosed() {
131 if (confirmation_dialog_ && Shell::HasInstance())
132 confirmation_dialog_->GetWidget()->Close();
bartfab (slow) 2013/12/10 12:41:16 1) After this method has run, the dialog is closed
binjin 2013/12/12 13:56:55 Done.
133 }
134
135 bool LogoutButtonTray::IsConfirmationDialogShowing() {
136 return confirmation_dialog_;
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 kLogoutDialogDurationMs is non-positive.
bartfab (slow) 2013/12/10 12:41:16 Nit: Do not refer to the pref name here. Ash knows
binjin 2013/12/12 13:56:55 Done.
171 if (dialog_duration_ <= base::TimeDelta::FromSeconds(0))
bartfab (slow) 2013/12/10 12:41:16 Nit: The default constructor base::TimeDelta() pro
binjin 2013/12/12 13:56:55 Done.
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::DeleteConfirmationDialog() {
188 confirmation_dialog_.reset();
189 }
190
191 LogoutConfirmationDialogView *LogoutButtonTray::GetConfirmationDialogForTest() {
bartfab (slow) 2013/12/10 12:41:16 Nit: Style guide: The * goes on the type.
binjin 2013/12/12 13:56:55 Done.
192 return confirmation_dialog_.get();
193 }
194
195 LogoutConfirmationDialogView::LogoutConfirmationDelegate*
196 LogoutButtonTray::GetConfirmationDelegateForTest() {
197 return confirmation_delegate_.get();
198 }
199
151 void LogoutButtonTray::UpdateVisibility() { 200 void LogoutButtonTray::UpdateVisibility() {
152 SetVisible(show_logout_button_in_tray_ && 201 SetVisible(show_logout_button_in_tray_ &&
153 login_status_ != user::LOGGED_IN_NONE && 202 login_status_ != user::LOGGED_IN_NONE &&
154 login_status_ != user::LOGGED_IN_LOCKED); 203 login_status_ != user::LOGGED_IN_LOCKED);
204 if (!show_logout_button_in_tray_)
205 EnsureConfirmationDialogIsClosed();
155 } 206 }
156 207
157 } // namespace internal 208 } // namespace internal
158 } // namespace ash 209 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698