| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "ash/system/chromeos/session/logout_button_tray.h" | |
| 6 | |
| 7 #include <memory> | |
| 8 #include <utility> | |
| 9 | |
| 10 #include "ash/common/shelf/shelf_types.h" | |
| 11 #include "ash/common/system/tray/system_tray_delegate.h" | |
| 12 #include "ash/common/system/tray/system_tray_notifier.h" | |
| 13 #include "ash/common/system/tray/tray_constants.h" | |
| 14 #include "ash/common/system/tray/tray_utils.h" | |
| 15 #include "ash/common/system/user/login_status.h" | |
| 16 #include "ash/common/wm_shell.h" | |
| 17 #include "ash/shell.h" | |
| 18 #include "ash/system/chromeos/session/logout_confirmation_controller.h" | |
| 19 #include "base/logging.h" | |
| 20 #include "grit/ash_resources.h" | |
| 21 #include "third_party/skia/include/core/SkColor.h" | |
| 22 #include "ui/events/event.h" | |
| 23 #include "ui/gfx/geometry/insets.h" | |
| 24 #include "ui/gfx/geometry/size.h" | |
| 25 #include "ui/views/bubble/tray_bubble_view.h" | |
| 26 #include "ui/views/controls/button/label_button.h" | |
| 27 #include "ui/views/controls/button/label_button_border.h" | |
| 28 #include "ui/views/painter.h" | |
| 29 | |
| 30 namespace ash { | |
| 31 namespace { | |
| 32 | |
| 33 const int kLogoutButtonHorizontalExtraPadding = 7; | |
| 34 | |
| 35 const int kLogoutButtonNormalImages[] = { | |
| 36 IDR_AURA_UBER_TRAY_LOGOUT_BUTTON_NORMAL_TOP_LEFT, | |
| 37 IDR_AURA_UBER_TRAY_LOGOUT_BUTTON_NORMAL_TOP, | |
| 38 IDR_AURA_UBER_TRAY_LOGOUT_BUTTON_NORMAL_TOP_RIGHT, | |
| 39 IDR_AURA_UBER_TRAY_LOGOUT_BUTTON_NORMAL_LEFT, | |
| 40 IDR_AURA_UBER_TRAY_LOGOUT_BUTTON_NORMAL_CENTER, | |
| 41 IDR_AURA_UBER_TRAY_LOGOUT_BUTTON_NORMAL_RIGHT, | |
| 42 IDR_AURA_UBER_TRAY_LOGOUT_BUTTON_NORMAL_BOTTOM_LEFT, | |
| 43 IDR_AURA_UBER_TRAY_LOGOUT_BUTTON_NORMAL_BOTTOM, | |
| 44 IDR_AURA_UBER_TRAY_LOGOUT_BUTTON_NORMAL_BOTTOM_RIGHT}; | |
| 45 | |
| 46 const int kLogoutButtonPushedImages[] = { | |
| 47 IDR_AURA_UBER_TRAY_LOGOUT_BUTTON_PUSHED_TOP_LEFT, | |
| 48 IDR_AURA_UBER_TRAY_LOGOUT_BUTTON_PUSHED_TOP, | |
| 49 IDR_AURA_UBER_TRAY_LOGOUT_BUTTON_PUSHED_TOP_RIGHT, | |
| 50 IDR_AURA_UBER_TRAY_LOGOUT_BUTTON_PUSHED_LEFT, | |
| 51 IDR_AURA_UBER_TRAY_LOGOUT_BUTTON_PUSHED_CENTER, | |
| 52 IDR_AURA_UBER_TRAY_LOGOUT_BUTTON_PUSHED_RIGHT, | |
| 53 IDR_AURA_UBER_TRAY_LOGOUT_BUTTON_PUSHED_BOTTOM_LEFT, | |
| 54 IDR_AURA_UBER_TRAY_LOGOUT_BUTTON_PUSHED_BOTTOM, | |
| 55 IDR_AURA_UBER_TRAY_LOGOUT_BUTTON_PUSHED_BOTTOM_RIGHT}; | |
| 56 | |
| 57 class LogoutButton : public views::LabelButton { | |
| 58 public: | |
| 59 LogoutButton(views::ButtonListener* listener); | |
| 60 ~LogoutButton() override; | |
| 61 | |
| 62 private: | |
| 63 DISALLOW_COPY_AND_ASSIGN(LogoutButton); | |
| 64 }; | |
| 65 | |
| 66 } // namespace | |
| 67 | |
| 68 LogoutButton::LogoutButton(views::ButtonListener* listener) | |
| 69 : views::LabelButton(listener, base::string16()) { | |
| 70 SetupLabelForTray(label()); | |
| 71 SetFontList(label()->font_list()); | |
| 72 SetEnabledTextColors(SK_ColorWHITE); | |
| 73 | |
| 74 std::unique_ptr<views::LabelButtonAssetBorder> border( | |
| 75 new views::LabelButtonAssetBorder(views::Button::STYLE_TEXTBUTTON)); | |
| 76 border->SetPainter( | |
| 77 false, views::Button::STATE_NORMAL, | |
| 78 views::Painter::CreateImageGridPainter(kLogoutButtonNormalImages)); | |
| 79 border->SetPainter( | |
| 80 false, views::Button::STATE_HOVERED, | |
| 81 views::Painter::CreateImageGridPainter(kLogoutButtonNormalImages)); | |
| 82 border->SetPainter( | |
| 83 false, views::Button::STATE_PRESSED, | |
| 84 views::Painter::CreateImageGridPainter(kLogoutButtonPushedImages)); | |
| 85 gfx::Insets insets = border->GetInsets(); | |
| 86 insets += gfx::Insets(0, kLogoutButtonHorizontalExtraPadding, 0, | |
| 87 kLogoutButtonHorizontalExtraPadding); | |
| 88 border->set_insets(insets); | |
| 89 SetBorder(std::move(border)); | |
| 90 set_animate_on_state_change(false); | |
| 91 | |
| 92 SetMinSize(gfx::Size(0, kShelfItemHeight)); | |
| 93 } | |
| 94 | |
| 95 LogoutButton::~LogoutButton() {} | |
| 96 | |
| 97 LogoutButtonTray::LogoutButtonTray(WmShelf* wm_shelf) | |
| 98 : TrayBackgroundView(wm_shelf), | |
| 99 button_(NULL), | |
| 100 login_status_(LoginStatus::NOT_LOGGED_IN), | |
| 101 show_logout_button_in_tray_(false) { | |
| 102 button_ = new LogoutButton(this); | |
| 103 tray_container()->AddChildView(button_); | |
| 104 tray_container()->SetBorder(views::Border::NullBorder()); | |
| 105 WmShell::Get()->system_tray_notifier()->AddLogoutButtonObserver(this); | |
| 106 } | |
| 107 | |
| 108 LogoutButtonTray::~LogoutButtonTray() { | |
| 109 WmShell::Get()->system_tray_notifier()->RemoveLogoutButtonObserver(this); | |
| 110 } | |
| 111 | |
| 112 void LogoutButtonTray::SetShelfAlignment(ShelfAlignment alignment) { | |
| 113 TrayBackgroundView::SetShelfAlignment(alignment); | |
| 114 tray_container()->SetBorder(views::Border::NullBorder()); | |
| 115 } | |
| 116 | |
| 117 base::string16 LogoutButtonTray::GetAccessibleNameForTray() { | |
| 118 return button_->GetText(); | |
| 119 } | |
| 120 | |
| 121 void LogoutButtonTray::HideBubbleWithView( | |
| 122 const views::TrayBubbleView* bubble_view) {} | |
| 123 | |
| 124 void LogoutButtonTray::ClickedOutsideBubble() {} | |
| 125 | |
| 126 void LogoutButtonTray::OnShowLogoutButtonInTrayChanged(bool show) { | |
| 127 show_logout_button_in_tray_ = show; | |
| 128 UpdateVisibility(); | |
| 129 } | |
| 130 | |
| 131 void LogoutButtonTray::OnLogoutDialogDurationChanged(base::TimeDelta duration) { | |
| 132 dialog_duration_ = duration; | |
| 133 } | |
| 134 | |
| 135 void LogoutButtonTray::ButtonPressed(views::Button* sender, | |
| 136 const ui::Event& event) { | |
| 137 DCHECK_EQ(sender, button_); | |
| 138 if (dialog_duration_ <= base::TimeDelta()) { | |
| 139 // Sign out immediately if |dialog_duration_| is non-positive. | |
| 140 WmShell::Get()->system_tray_delegate()->SignOut(); | |
| 141 } else if (Shell::GetInstance()->logout_confirmation_controller()) { | |
| 142 Shell::GetInstance()->logout_confirmation_controller()->ConfirmLogout( | |
| 143 base::TimeTicks::Now() + dialog_duration_); | |
| 144 } | |
| 145 } | |
| 146 | |
| 147 void LogoutButtonTray::UpdateAfterLoginStatusChange(LoginStatus login_status) { | |
| 148 login_status_ = login_status; | |
| 149 const base::string16 title = | |
| 150 user::GetLocalizedSignOutStringForStatus(login_status, false); | |
| 151 button_->SetText(title); | |
| 152 button_->SetAccessibleName(title); | |
| 153 UpdateVisibility(); | |
| 154 } | |
| 155 | |
| 156 void LogoutButtonTray::UpdateVisibility() { | |
| 157 SetVisible(show_logout_button_in_tray_ && | |
| 158 login_status_ != LoginStatus::NOT_LOGGED_IN && | |
| 159 login_status_ != LoginStatus::LOCKED); | |
| 160 } | |
| 161 | |
| 162 } // namespace ash | |
| OLD | NEW |