| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/common/system/chromeos/session/logout_button_tray.h" | 5 #include "ash/common/system/chromeos/session/logout_button_tray.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "ash/common/material_design/material_design_controller.h" | 10 #include "ash/common/material_design/material_design_controller.h" |
| 11 #include "ash/common/shelf/shelf_types.h" | 11 #include "ash/common/shelf/shelf_types.h" |
| 12 #include "ash/common/system/chromeos/session/logout_confirmation_controller.h" | 12 #include "ash/common/system/chromeos/session/logout_confirmation_controller.h" |
| 13 #include "ash/common/system/tray/system_tray_delegate.h" | 13 #include "ash/common/system/tray/system_tray_delegate.h" |
| 14 #include "ash/common/system/tray/system_tray_notifier.h" | 14 #include "ash/common/system/tray/system_tray_notifier.h" |
| 15 #include "ash/common/system/tray/tray_constants.h" | 15 #include "ash/common/system/tray/tray_constants.h" |
| 16 #include "ash/common/system/tray/tray_utils.h" | 16 #include "ash/common/system/tray/tray_utils.h" |
| 17 #include "ash/common/system/user/login_status.h" | 17 #include "ash/common/system/user/login_status.h" |
| 18 #include "ash/common/wm_shell.h" | 18 #include "ash/common/wm_shell.h" |
| 19 #include "base/logging.h" | 19 #include "base/logging.h" |
| 20 #include "grit/ash_resources.h" | 20 #include "grit/ash_resources.h" |
| 21 #include "third_party/skia/include/core/SkColor.h" | 21 #include "third_party/skia/include/core/SkColor.h" |
| 22 #include "ui/events/event.h" | 22 #include "ui/events/event.h" |
| 23 #include "ui/gfx/color_palette.h" | 23 #include "ui/gfx/color_palette.h" |
| 24 #include "ui/gfx/geometry/insets.h" | 24 #include "ui/gfx/geometry/insets.h" |
| 25 #include "ui/gfx/geometry/size.h" | 25 #include "ui/gfx/geometry/size.h" |
| 26 #include "ui/gfx/paint_vector_icon.h" |
| 27 #include "ui/gfx/vector_icons_public.h" |
| 26 #include "ui/views/bubble/tray_bubble_view.h" | 28 #include "ui/views/bubble/tray_bubble_view.h" |
| 27 #include "ui/views/controls/button/label_button.h" | 29 #include "ui/views/controls/button/label_button.h" |
| 28 #include "ui/views/controls/button/label_button_border.h" | 30 #include "ui/views/controls/button/label_button_border.h" |
| 29 #include "ui/views/controls/button/md_text_button.h" | 31 #include "ui/views/controls/button/md_text_button.h" |
| 30 #include "ui/views/painter.h" | 32 #include "ui/views/painter.h" |
| 31 | 33 |
| 32 namespace ash { | 34 namespace ash { |
| 33 namespace { | 35 namespace { |
| 34 | 36 |
| 35 const int kLogoutButtonHorizontalExtraPadding = 7; | 37 const int kLogoutButtonHorizontalExtraPadding = 7; |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 show_logout_button_in_tray_(false) { | 107 show_logout_button_in_tray_(false) { |
| 106 if (MaterialDesignController::IsShelfMaterial()) { | 108 if (MaterialDesignController::IsShelfMaterial()) { |
| 107 views::MdTextButton* button = | 109 views::MdTextButton* button = |
| 108 views::MdTextButton::CreateMdButton(this, base::string16()); | 110 views::MdTextButton::CreateMdButton(this, base::string16()); |
| 109 button->SetCallToAction(true); | 111 button->SetCallToAction(true); |
| 110 button->set_bg_color_override(gfx::kGoogleRed700); | 112 button->set_bg_color_override(gfx::kGoogleRed700); |
| 111 // Base font size + 2 = 14. | 113 // Base font size + 2 = 14. |
| 112 // TODO(estade): should this 2 be shared with other tray views? See | 114 // TODO(estade): should this 2 be shared with other tray views? See |
| 113 // crbug.com/623987 | 115 // crbug.com/623987 |
| 114 button->AdjustFontSize(2); | 116 button->AdjustFontSize(2); |
| 115 button->SetMinSize(gfx::Size(0, kTrayItemSize)); | |
| 116 button_ = button; | 117 button_ = button; |
| 117 } else { | 118 } else { |
| 118 button_ = new LogoutButton(this); | 119 button_ = new LogoutButton(this); |
| 119 } | 120 } |
| 120 tray_container()->AddChildView(button_); | 121 tray_container()->AddChildView(button_); |
| 121 tray_container()->SetBorder(views::Border::NullBorder()); | 122 tray_container()->SetBorder(views::Border::NullBorder()); |
| 122 WmShell::Get()->system_tray_notifier()->AddLogoutButtonObserver(this); | 123 WmShell::Get()->system_tray_notifier()->AddLogoutButtonObserver(this); |
| 123 } | 124 } |
| 124 | 125 |
| 125 LogoutButtonTray::~LogoutButtonTray() { | 126 LogoutButtonTray::~LogoutButtonTray() { |
| 126 WmShell::Get()->system_tray_notifier()->RemoveLogoutButtonObserver(this); | 127 WmShell::Get()->system_tray_notifier()->RemoveLogoutButtonObserver(this); |
| 127 } | 128 } |
| 128 | 129 |
| 129 void LogoutButtonTray::SetShelfAlignment(ShelfAlignment alignment) { | 130 void LogoutButtonTray::SetShelfAlignment(ShelfAlignment alignment) { |
| 131 // We must first update the button so that |
| 132 // TrayBackgroundView::SetShelfAlignment() can lay it out correctly. |
| 133 UpdateButtonTextAndImage(login_status_, alignment); |
| 130 TrayBackgroundView::SetShelfAlignment(alignment); | 134 TrayBackgroundView::SetShelfAlignment(alignment); |
| 131 tray_container()->SetBorder(views::Border::NullBorder()); | 135 tray_container()->SetBorder(views::Border::NullBorder()); |
| 132 } | 136 } |
| 133 | 137 |
| 134 base::string16 LogoutButtonTray::GetAccessibleNameForTray() { | 138 base::string16 LogoutButtonTray::GetAccessibleNameForTray() { |
| 135 return button_->GetText(); | 139 return button_->GetText(); |
| 136 } | 140 } |
| 137 | 141 |
| 138 void LogoutButtonTray::HideBubbleWithView( | 142 void LogoutButtonTray::HideBubbleWithView( |
| 139 const views::TrayBubbleView* bubble_view) {} | 143 const views::TrayBubbleView* bubble_view) {} |
| (...skipping 15 matching lines...) Expand all Loading... |
| 155 if (dialog_duration_ <= base::TimeDelta()) { | 159 if (dialog_duration_ <= base::TimeDelta()) { |
| 156 // Sign out immediately if |dialog_duration_| is non-positive. | 160 // Sign out immediately if |dialog_duration_| is non-positive. |
| 157 WmShell::Get()->system_tray_delegate()->SignOut(); | 161 WmShell::Get()->system_tray_delegate()->SignOut(); |
| 158 } else if (WmShell::Get()->logout_confirmation_controller()) { | 162 } else if (WmShell::Get()->logout_confirmation_controller()) { |
| 159 WmShell::Get()->logout_confirmation_controller()->ConfirmLogout( | 163 WmShell::Get()->logout_confirmation_controller()->ConfirmLogout( |
| 160 base::TimeTicks::Now() + dialog_duration_); | 164 base::TimeTicks::Now() + dialog_duration_); |
| 161 } | 165 } |
| 162 } | 166 } |
| 163 | 167 |
| 164 void LogoutButtonTray::UpdateAfterLoginStatusChange(LoginStatus login_status) { | 168 void LogoutButtonTray::UpdateAfterLoginStatusChange(LoginStatus login_status) { |
| 165 login_status_ = login_status; | 169 UpdateButtonTextAndImage(login_status, shelf_alignment()); |
| 166 const base::string16 title = | |
| 167 user::GetLocalizedSignOutStringForStatus(login_status, false); | |
| 168 button_->SetText(title); | |
| 169 button_->SetAccessibleName(title); | |
| 170 UpdateVisibility(); | |
| 171 } | 170 } |
| 172 | 171 |
| 173 void LogoutButtonTray::UpdateVisibility() { | 172 void LogoutButtonTray::UpdateVisibility() { |
| 174 SetVisible(show_logout_button_in_tray_ && | 173 SetVisible(show_logout_button_in_tray_ && |
| 175 login_status_ != LoginStatus::NOT_LOGGED_IN && | 174 login_status_ != LoginStatus::NOT_LOGGED_IN && |
| 176 login_status_ != LoginStatus::LOCKED); | 175 login_status_ != LoginStatus::LOCKED); |
| 177 } | 176 } |
| 178 | 177 |
| 178 void LogoutButtonTray::UpdateButtonTextAndImage(LoginStatus login_status, |
| 179 ShelfAlignment alignment) { |
| 180 login_status_ = login_status; |
| 181 const base::string16 title = |
| 182 user::GetLocalizedSignOutStringForStatus(login_status, false); |
| 183 if (alignment == SHELF_ALIGNMENT_BOTTOM) { |
| 184 button_->SetText(title); |
| 185 button_->SetImage(views::LabelButton::STATE_NORMAL, gfx::ImageSkia()); |
| 186 button_->SetMinSize(gfx::Size(0, kTrayItemSize)); |
| 187 } else { |
| 188 button_->SetText(base::string16()); |
| 189 button_->SetAccessibleName(title); |
| 190 button_->SetImage( |
| 191 views::LabelButton::STATE_NORMAL, |
| 192 gfx::CreateVectorIcon(gfx::VectorIconId::SHELF_LOGOUT, kTrayIconColor)); |
| 193 button_->SetMinSize(gfx::Size(kTrayItemSize, kTrayItemSize)); |
| 194 } |
| 195 UpdateVisibility(); |
| 196 } |
| 197 |
| 179 } // namespace ash | 198 } // namespace ash |
| OLD | NEW |