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" | |
| 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); |
| 111 } | 110 } |
| 112 | 111 |
| 112 void LogoutButtonTray::EnsureConfirmationDialogShown() { | |
| 113 if (!confirm_dialog_) { | |
| 114 confirm_dialog_ = (new LogoutConfirmationDialogView())->GetWeakPtr(); | |
|
bartfab (slow)
2013/10/28 16:24:07
The construction in this line is hard to follow.
| |
| 115 confirm_dialog_->Show(dialog_duration_); | |
| 116 } | |
| 117 } | |
| 118 | |
| 119 void LogoutButtonTray::EnsureConfirmationDialogClosed() { | |
| 120 if (!confirm_dialog_) { | |
|
bartfab (slow)
2013/10/28 16:24:07
You want the exact reverse: if (confirm_dialog_)
binjin
2013/10/29 16:07:05
Done.
| |
| 121 confirm_dialog_->GetWidget()->Close(); | |
| 122 } | |
| 123 } | |
| 124 | |
| 113 void LogoutButtonTray::SetShelfAlignment(ShelfAlignment alignment) { | 125 void LogoutButtonTray::SetShelfAlignment(ShelfAlignment alignment) { |
| 114 TrayBackgroundView::SetShelfAlignment(alignment); | 126 TrayBackgroundView::SetShelfAlignment(alignment); |
| 115 tray_container()->set_border(NULL); | 127 tray_container()->set_border(NULL); |
| 116 } | 128 } |
| 117 | 129 |
| 118 base::string16 LogoutButtonTray::GetAccessibleNameForTray() { | 130 base::string16 LogoutButtonTray::GetAccessibleNameForTray() { |
| 119 return button_->GetText(); | 131 return button_->GetText(); |
| 120 } | 132 } |
| 121 | 133 |
| 122 void LogoutButtonTray::HideBubbleWithView( | 134 void LogoutButtonTray::HideBubbleWithView( |
| 123 const views::TrayBubbleView* bubble_view) { | 135 const views::TrayBubbleView* bubble_view) { |
| 124 } | 136 } |
| 125 | 137 |
| 126 bool LogoutButtonTray::ClickedOutsideBubble() { | 138 bool LogoutButtonTray::ClickedOutsideBubble() { |
| 127 return false; | 139 return false; |
| 128 } | 140 } |
| 129 | 141 |
| 130 void LogoutButtonTray::OnShowLogoutButtonInTrayChanged(bool show) { | 142 void LogoutButtonTray::OnShowLogoutButtonInTrayChanged(bool show) { |
| 131 show_logout_button_in_tray_ = show; | 143 show_logout_button_in_tray_ = show; |
| 132 UpdateVisibility(); | 144 UpdateVisibility(); |
| 133 } | 145 } |
| 134 | 146 |
| 147 void LogoutButtonTray::OnLogoutDialogDurationChanged(int duration) { | |
| 148 dialog_duration_ = base::TimeDelta::FromMilliseconds(duration); | |
|
bartfab (slow)
2013/10/28 16:24:07
You need to update the dialog here. It should imme
binjin
2013/10/29 16:07:05
Done.
| |
| 149 } | |
| 150 | |
| 135 void LogoutButtonTray::ButtonPressed(views::Button* sender, | 151 void LogoutButtonTray::ButtonPressed(views::Button* sender, |
| 136 const ui::Event& event) { | 152 const ui::Event& event) { |
| 137 DCHECK_EQ(sender, button_); | 153 DCHECK_EQ(sender, button_); |
| 138 Shell::GetInstance()->system_tray_delegate()->SignOut(); | 154 if (dialog_duration_.InSeconds() <= 0) { |
|
bartfab (slow)
2013/10/28 16:24:07
The correct way to do this would be something like
binjin
2013/10/29 16:07:05
Done.
| |
| 155 Shell::GetInstance()->system_tray_delegate()->SignOut(); | |
| 156 } else { | |
| 157 EnsureConfirmationDialogShown(); | |
| 158 } | |
| 139 } | 159 } |
| 140 | 160 |
| 141 void LogoutButtonTray::UpdateAfterLoginStatusChange( | 161 void LogoutButtonTray::UpdateAfterLoginStatusChange( |
| 142 user::LoginStatus login_status) { | 162 user::LoginStatus login_status) { |
| 143 login_status_ = login_status; | 163 login_status_ = login_status; |
| 144 const base::string16 title = | 164 const base::string16 title = |
| 145 GetLocalizedSignOutStringForStatus(login_status, false); | 165 GetLocalizedSignOutStringForStatus(login_status, false); |
| 146 button_->SetText(title); | 166 button_->SetText(title); |
| 147 button_->SetAccessibleName(title); | 167 button_->SetAccessibleName(title); |
| 148 UpdateVisibility(); | 168 UpdateVisibility(); |
| 149 } | 169 } |
| 150 | 170 |
| 151 void LogoutButtonTray::UpdateVisibility() { | 171 void LogoutButtonTray::UpdateVisibility() { |
| 152 SetVisible(show_logout_button_in_tray_ && | 172 SetVisible(show_logout_button_in_tray_ && |
| 153 login_status_ != user::LOGGED_IN_NONE && | 173 login_status_ != user::LOGGED_IN_NONE && |
| 154 login_status_ != user::LOGGED_IN_LOCKED); | 174 login_status_ != user::LOGGED_IN_LOCKED); |
| 175 if (!show_logout_button_in_tray_) | |
| 176 EnsureConfirmationDialogClosed(); | |
| 155 } | 177 } |
| 156 | 178 |
| 157 } // namespace internal | 179 } // namespace internal |
| 158 } // namespace ash | 180 } // namespace ash |
| OLD | NEW |