Chromium Code Reviews| 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" | |
|
bartfab (slow)
2013/10/30 11:17:28
This is still used. system_tray_delegate() returns
binjin
2013/11/19 14:43:46
Done.
| |
| 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" |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 89 set_animate_on_state_change(false); | 89 set_animate_on_state_change(false); |
| 90 | 90 |
| 91 set_min_size(gfx::Size(0, GetShelfItemHeight())); | 91 set_min_size(gfx::Size(0, GetShelfItemHeight())); |
| 92 } | 92 } |
| 93 | 93 |
| 94 LogoutButton::~LogoutButton() { | 94 LogoutButton::~LogoutButton() { |
| 95 } | 95 } |
| 96 | 96 |
| 97 LogoutButtonTray::LogoutButtonTray(StatusAreaWidget* status_area_widget) | 97 LogoutButtonTray::LogoutButtonTray(StatusAreaWidget* status_area_widget) |
| 98 : TrayBackgroundView(status_area_widget), | 98 : TrayBackgroundView(status_area_widget), |
| 99 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) { |
| 102 button_ = new LogoutButton(this); | 101 button_ = new LogoutButton(this); |
| 103 tray_container()->AddChildView(button_); | 102 tray_container()->AddChildView(button_); |
| 104 tray_container()->set_border(NULL); | 103 tray_container()->set_border(NULL); |
| 105 Shell::GetInstance()->system_tray_notifier()->AddLogoutButtonObserver(this); | 104 Shell::GetInstance()->system_tray_notifier()->AddLogoutButtonObserver(this); |
| 106 } | 105 } |
| 107 | 106 |
| 108 LogoutButtonTray::~LogoutButtonTray() { | 107 LogoutButtonTray::~LogoutButtonTray() { |
| 109 Shell::GetInstance()->system_tray_notifier()-> | 108 Shell::GetInstance()->system_tray_notifier()-> |
| 110 RemoveLogoutButtonObserver(this); | 109 RemoveLogoutButtonObserver(this); |
| 110 if (confirmation_dialog_) { | |
| 111 confirmation_dialog_->DeleteDelegate(); | |
|
bartfab (slow)
2013/10/30 11:17:28
This is the wrong method. DeleteDelegate() is how
binjin
2013/11/19 14:43:46
Done.
| |
| 112 } | |
| 113 } | |
| 114 | |
| 115 void LogoutButtonTray::EnsureConfirmationDialogIsShowing() { | |
| 116 if (!confirmation_dialog_) { | |
| 117 confirmation_dialog_ = (new LogoutConfirmationDialogView())->AsWeakPtr(); | |
| 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/10/30 11:17:28
Can you destroy the dialog here? Otherwise, we are
binjin
2013/11/19 14:43:46
Done.
| |
| 111 } | 125 } |
| 112 | 126 |
| 113 void LogoutButtonTray::SetShelfAlignment(ShelfAlignment alignment) { | 127 void LogoutButtonTray::SetShelfAlignment(ShelfAlignment alignment) { |
| 114 TrayBackgroundView::SetShelfAlignment(alignment); | 128 TrayBackgroundView::SetShelfAlignment(alignment); |
| 115 tray_container()->set_border(NULL); | 129 tray_container()->set_border(NULL); |
| 116 } | 130 } |
| 117 | 131 |
| 118 base::string16 LogoutButtonTray::GetAccessibleNameForTray() { | 132 base::string16 LogoutButtonTray::GetAccessibleNameForTray() { |
| 119 return button_->GetText(); | 133 return button_->GetText(); |
| 120 } | 134 } |
| 121 | 135 |
| 122 void LogoutButtonTray::HideBubbleWithView( | 136 void LogoutButtonTray::HideBubbleWithView( |
| 123 const views::TrayBubbleView* bubble_view) { | 137 const views::TrayBubbleView* bubble_view) { |
| 124 } | 138 } |
| 125 | 139 |
| 126 bool LogoutButtonTray::ClickedOutsideBubble() { | 140 bool LogoutButtonTray::ClickedOutsideBubble() { |
| 127 return false; | 141 return false; |
| 128 } | 142 } |
| 129 | 143 |
| 130 void LogoutButtonTray::OnShowLogoutButtonInTrayChanged(bool show) { | 144 void LogoutButtonTray::OnShowLogoutButtonInTrayChanged(bool show) { |
| 131 show_logout_button_in_tray_ = show; | 145 show_logout_button_in_tray_ = show; |
| 132 UpdateVisibility(); | 146 UpdateVisibility(); |
| 133 } | 147 } |
| 134 | 148 |
| 149 void LogoutButtonTray::OnLogoutDialogDurationChanged(int duration) { | |
| 150 dialog_duration_ = base::TimeDelta::FromMilliseconds(duration); | |
| 151 if (confirmation_dialog_) | |
| 152 confirmation_dialog_->UpdateDialogDuration(dialog_duration_); | |
| 153 } | |
| 154 | |
| 135 void LogoutButtonTray::ButtonPressed(views::Button* sender, | 155 void LogoutButtonTray::ButtonPressed(views::Button* sender, |
| 136 const ui::Event& event) { | 156 const ui::Event& event) { |
| 137 DCHECK_EQ(sender, button_); | 157 DCHECK_EQ(sender, button_); |
| 138 Shell::GetInstance()->system_tray_delegate()->SignOut(); | 158 // Sign out immediately if kLogoutDialogDurationMs is non-positive. |
| 159 if (dialog_duration_ <= base::TimeDelta::FromSeconds(0)) { | |
|
bartfab (slow)
2013/10/30 11:17:28
Nit: No curly braces for single-line conditionals.
binjin
2013/11/19 14:43:46
Done.
| |
| 160 Shell::GetInstance()->system_tray_delegate()->SignOut(); | |
| 161 } else { | |
| 162 EnsureConfirmationDialogIsShowing(); | |
| 163 } | |
| 139 } | 164 } |
| 140 | 165 |
| 141 void LogoutButtonTray::UpdateAfterLoginStatusChange( | 166 void LogoutButtonTray::UpdateAfterLoginStatusChange( |
| 142 user::LoginStatus login_status) { | 167 user::LoginStatus login_status) { |
| 143 login_status_ = login_status; | 168 login_status_ = login_status; |
| 144 const base::string16 title = | 169 const base::string16 title = |
| 145 GetLocalizedSignOutStringForStatus(login_status, false); | 170 GetLocalizedSignOutStringForStatus(login_status, false); |
| 146 button_->SetText(title); | 171 button_->SetText(title); |
| 147 button_->SetAccessibleName(title); | 172 button_->SetAccessibleName(title); |
| 148 UpdateVisibility(); | 173 UpdateVisibility(); |
| 149 } | 174 } |
| 150 | 175 |
| 151 void LogoutButtonTray::UpdateVisibility() { | 176 void LogoutButtonTray::UpdateVisibility() { |
| 152 SetVisible(show_logout_button_in_tray_ && | 177 SetVisible(show_logout_button_in_tray_ && |
| 153 login_status_ != user::LOGGED_IN_NONE && | 178 login_status_ != user::LOGGED_IN_NONE && |
| 154 login_status_ != user::LOGGED_IN_LOCKED); | 179 login_status_ != user::LOGGED_IN_LOCKED); |
| 180 if (!show_logout_button_in_tray_) | |
| 181 EnsureConfirmationDialogIsClosed(); | |
| 155 } | 182 } |
| 156 | 183 |
| 157 } // namespace internal | 184 } // namespace internal |
| 158 } // namespace ash | 185 } // namespace ash |
| OLD | NEW |