| 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/system/session/logout_button_tray.h" | 5 #include "ash/system/session/logout_button_tray.h" |
| 6 | 6 |
| 7 #include <memory> | |
| 8 #include <utility> | |
| 9 | |
| 10 #include "ash/public/cpp/shelf_types.h" | |
| 11 #include "ash/resources/grit/ash_resources.h" | |
| 12 #include "ash/resources/vector_icons/vector_icons.h" | 7 #include "ash/resources/vector_icons/vector_icons.h" |
| 13 #include "ash/shelf/wm_shelf_util.h" | 8 #include "ash/shelf/wm_shelf.h" |
| 14 #include "ash/shell.h" | 9 #include "ash/shell.h" |
| 15 #include "ash/system/session/logout_confirmation_controller.h" | 10 #include "ash/system/session/logout_confirmation_controller.h" |
| 11 #include "ash/system/status_area_widget.h" |
| 16 #include "ash/system/tray/system_tray_controller.h" | 12 #include "ash/system/tray/system_tray_controller.h" |
| 17 #include "ash/system/tray/system_tray_notifier.h" | 13 #include "ash/system/tray/system_tray_notifier.h" |
| 18 #include "ash/system/tray/tray_constants.h" | 14 #include "ash/system/tray/tray_constants.h" |
| 19 #include "ash/system/tray/tray_utils.h" | 15 #include "ash/system/tray/tray_container.h" |
| 20 #include "ash/system/user/login_status.h" | 16 #include "ash/system/user/login_status.h" |
| 21 #include "base/logging.h" | 17 #include "ui/accessibility/ax_node_data.h" |
| 22 #include "third_party/skia/include/core/SkColor.h" | |
| 23 #include "ui/events/event.h" | |
| 24 #include "ui/gfx/color_palette.h" | 18 #include "ui/gfx/color_palette.h" |
| 25 #include "ui/gfx/geometry/insets.h" | |
| 26 #include "ui/gfx/geometry/size.h" | 19 #include "ui/gfx/geometry/size.h" |
| 27 #include "ui/gfx/paint_vector_icon.h" | 20 #include "ui/gfx/paint_vector_icon.h" |
| 28 #include "ui/views/bubble/tray_bubble_view.h" | |
| 29 #include "ui/views/controls/button/label_button.h" | |
| 30 #include "ui/views/controls/button/label_button_border.h" | |
| 31 #include "ui/views/controls/button/md_text_button.h" | 21 #include "ui/views/controls/button/md_text_button.h" |
| 32 #include "ui/views/painter.h" | 22 #include "ui/views/layout/fill_layout.h" |
| 33 | 23 |
| 34 namespace ash { | 24 namespace ash { |
| 35 | 25 |
| 36 LogoutButtonTray::LogoutButtonTray(WmShelf* wm_shelf) | 26 LogoutButtonTray::LogoutButtonTray(WmShelf* wm_shelf) |
| 37 : TrayBackgroundView(wm_shelf, false), | 27 : wm_shelf_(wm_shelf), |
| 38 button_(nullptr), | 28 container_(new TrayContainer(wm_shelf)), |
| 39 login_status_(LoginStatus::NOT_LOGGED_IN), | 29 button_(views::MdTextButton::Create(this, base::string16())), |
| 40 show_logout_button_in_tray_(false) { | 30 show_logout_button_in_tray_(false) { |
| 41 views::MdTextButton* button = | 31 SetLayoutManager(new views::FillLayout); |
| 42 views::MdTextButton::Create(this, base::string16()); | 32 AddChildView(container_); |
| 43 button->SetProminent(true); | 33 |
| 44 button->SetBgColorOverride(gfx::kGoogleRed700); | 34 button_->SetProminent(true); |
| 35 button_->SetBgColorOverride(gfx::kGoogleRed700); |
| 45 // Base font size + 2 = 14. | 36 // Base font size + 2 = 14. |
| 46 // TODO(estade): should this 2 be shared with other tray views? See | 37 // TODO(estade): should this 2 be shared with other tray views? See |
| 47 // crbug.com/623987 | 38 // crbug.com/623987 |
| 48 button->AdjustFontSize(2); | 39 button_->AdjustFontSize(2); |
| 49 button_ = button; | |
| 50 | 40 |
| 51 // Since LogoutButtonTray has a red background and it is distinguished | 41 container_->AddChildView(button_); |
| 52 // by itself, no separator is needed on its right side. | |
| 53 set_separator_visibility(false); | |
| 54 tray_container()->AddChildView(button_); | |
| 55 Shell::Get()->system_tray_notifier()->AddLogoutButtonObserver(this); | 42 Shell::Get()->system_tray_notifier()->AddLogoutButtonObserver(this); |
| 43 SetVisible(false); |
| 56 } | 44 } |
| 57 | 45 |
| 58 LogoutButtonTray::~LogoutButtonTray() { | 46 LogoutButtonTray::~LogoutButtonTray() { |
| 59 Shell::Get()->system_tray_notifier()->RemoveLogoutButtonObserver(this); | 47 Shell::Get()->system_tray_notifier()->RemoveLogoutButtonObserver(this); |
| 60 } | 48 } |
| 61 | 49 |
| 62 void LogoutButtonTray::SetShelfAlignment(ShelfAlignment alignment) { | 50 void LogoutButtonTray::UpdateAfterShelfAlignmentChange() { |
| 63 // We must first update the button so that | 51 // We must first update the button so that |container_| can lay it out |
| 64 // TrayBackgroundView::SetShelfAlignment() can lay it out correctly. | 52 // correctly. |
| 65 UpdateButtonTextAndImage(login_status_, alignment); | 53 UpdateButtonTextAndImage(); |
| 66 TrayBackgroundView::SetShelfAlignment(alignment); | 54 container_->UpdateAfterShelfAlignmentChange(); |
| 67 } | 55 } |
| 68 | 56 |
| 69 base::string16 LogoutButtonTray::GetAccessibleNameForTray() { | |
| 70 return button_->GetText(); | |
| 71 } | |
| 72 | |
| 73 void LogoutButtonTray::HideBubbleWithView( | |
| 74 const views::TrayBubbleView* bubble_view) {} | |
| 75 | |
| 76 void LogoutButtonTray::ClickedOutsideBubble() {} | |
| 77 | |
| 78 void LogoutButtonTray::ButtonPressed(views::Button* sender, | 57 void LogoutButtonTray::ButtonPressed(views::Button* sender, |
| 79 const ui::Event& event) { | 58 const ui::Event& event) { |
| 80 if (sender != button_) { | 59 DCHECK_EQ(button_, sender); |
| 81 TrayBackgroundView::ButtonPressed(sender, event); | |
| 82 return; | |
| 83 } | |
| 84 | 60 |
| 85 if (dialog_duration_ <= base::TimeDelta()) { | 61 if (dialog_duration_ <= base::TimeDelta()) { |
| 86 // Sign out immediately if |dialog_duration_| is non-positive. | 62 // Sign out immediately if |dialog_duration_| is non-positive. |
| 87 Shell::Get()->system_tray_controller()->SignOut(); | 63 Shell::Get()->system_tray_controller()->SignOut(); |
| 88 } else if (Shell::Get()->logout_confirmation_controller()) { | 64 } else if (Shell::Get()->logout_confirmation_controller()) { |
| 89 Shell::Get()->logout_confirmation_controller()->ConfirmLogout( | 65 Shell::Get()->logout_confirmation_controller()->ConfirmLogout( |
| 90 base::TimeTicks::Now() + dialog_duration_); | 66 base::TimeTicks::Now() + dialog_duration_); |
| 91 } | 67 } |
| 92 } | 68 } |
| 93 | 69 |
| 70 void LogoutButtonTray::GetAccessibleNodeData(ui::AXNodeData* node_data) { |
| 71 View::GetAccessibleNodeData(node_data); |
| 72 node_data->SetName(button_->GetText()); |
| 73 } |
| 74 |
| 94 void LogoutButtonTray::OnShowLogoutButtonInTrayChanged(bool show) { | 75 void LogoutButtonTray::OnShowLogoutButtonInTrayChanged(bool show) { |
| 95 show_logout_button_in_tray_ = show; | 76 show_logout_button_in_tray_ = show; |
| 96 UpdateVisibility(); | 77 UpdateVisibility(); |
| 97 } | 78 } |
| 98 | 79 |
| 99 void LogoutButtonTray::OnLogoutDialogDurationChanged(base::TimeDelta duration) { | 80 void LogoutButtonTray::OnLogoutDialogDurationChanged(base::TimeDelta duration) { |
| 100 dialog_duration_ = duration; | 81 dialog_duration_ = duration; |
| 101 } | 82 } |
| 102 | 83 |
| 103 void LogoutButtonTray::UpdateAfterLoginStatusChange(LoginStatus login_status) { | 84 void LogoutButtonTray::UpdateAfterLoginStatusChange() { |
| 104 UpdateButtonTextAndImage(login_status, shelf_alignment()); | 85 UpdateButtonTextAndImage(); |
| 105 } | 86 } |
| 106 | 87 |
| 107 void LogoutButtonTray::UpdateVisibility() { | 88 void LogoutButtonTray::UpdateVisibility() { |
| 89 LoginStatus login_status = wm_shelf_->GetStatusAreaWidget()->login_status(); |
| 108 SetVisible(show_logout_button_in_tray_ && | 90 SetVisible(show_logout_button_in_tray_ && |
| 109 login_status_ != LoginStatus::NOT_LOGGED_IN && | 91 login_status != LoginStatus::NOT_LOGGED_IN && |
| 110 login_status_ != LoginStatus::LOCKED); | 92 login_status != LoginStatus::LOCKED); |
| 111 } | 93 } |
| 112 | 94 |
| 113 void LogoutButtonTray::UpdateButtonTextAndImage(LoginStatus login_status, | 95 void LogoutButtonTray::UpdateButtonTextAndImage() { |
| 114 ShelfAlignment alignment) { | 96 LoginStatus login_status = wm_shelf_->GetStatusAreaWidget()->login_status(); |
| 115 login_status_ = login_status; | |
| 116 const base::string16 title = | 97 const base::string16 title = |
| 117 user::GetLocalizedSignOutStringForStatus(login_status, false); | 98 user::GetLocalizedSignOutStringForStatus(login_status, false); |
| 118 if (IsHorizontalAlignment(alignment)) { | 99 if (wm_shelf_->IsHorizontalAlignment()) { |
| 119 button_->SetText(title); | 100 button_->SetText(title); |
| 120 button_->SetImage(views::LabelButton::STATE_NORMAL, gfx::ImageSkia()); | 101 button_->SetImage(views::Button::STATE_NORMAL, gfx::ImageSkia()); |
| 121 button_->SetMinSize(gfx::Size(0, kTrayItemSize)); | 102 button_->SetMinSize(gfx::Size(0, kTrayItemSize)); |
| 122 } else { | 103 } else { |
| 123 button_->SetText(base::string16()); | 104 button_->SetText(base::string16()); |
| 124 button_->SetAccessibleName(title); | 105 button_->SetAccessibleName(title); |
| 125 button_->SetImage(views::LabelButton::STATE_NORMAL, | 106 button_->SetImage(views::Button::STATE_NORMAL, |
| 126 gfx::CreateVectorIcon(kShelfLogoutIcon, kTrayIconColor)); | 107 gfx::CreateVectorIcon(kShelfLogoutIcon, kTrayIconColor)); |
| 127 button_->SetMinSize(gfx::Size(kTrayItemSize, kTrayItemSize)); | 108 button_->SetMinSize(gfx::Size(kTrayItemSize, kTrayItemSize)); |
| 128 } | 109 } |
| 129 UpdateVisibility(); | 110 UpdateVisibility(); |
| 130 } | 111 } |
| 131 | 112 |
| 132 } // namespace ash | 113 } // namespace ash |
| OLD | NEW |