[go: nahoru, domu]

blob: a2783a91858f083280ba165acaaa8fef0dda57f4 [file] [log] [blame]
James Cook6def4d9d2017-03-05 22:13:471// 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
James Cooka35a1e22017-04-08 02:33:085#include "ash/system/session/logout_button_tray.h"
James Cook6def4d9d2017-03-05 22:13:476
James Cook6def4d9d2017-03-05 22:13:477#include "ash/resources/vector_icons/vector_icons.h"
mohsene6704a02017-04-20 06:30:208#include "ash/shelf/wm_shelf.h"
sky79fa34712017-03-20 23:46:479#include "ash/shell.h"
James Cooka35a1e22017-04-08 02:33:0810#include "ash/system/session/logout_confirmation_controller.h"
mohsene6704a02017-04-20 06:30:2011#include "ash/system/status_area_widget.h"
James Cookb0bf8e82017-04-09 17:01:4412#include "ash/system/tray/system_tray_controller.h"
13#include "ash/system/tray/system_tray_notifier.h"
14#include "ash/system/tray/tray_constants.h"
mohsene6704a02017-04-20 06:30:2015#include "ash/system/tray/tray_container.h"
James Cookb0bf8e82017-04-09 17:01:4416#include "ash/system/user/login_status.h"
mohsene6704a02017-04-20 06:30:2017#include "ui/accessibility/ax_node_data.h"
James Cook6def4d9d2017-03-05 22:13:4718#include "ui/gfx/color_palette.h"
James Cook6def4d9d2017-03-05 22:13:4719#include "ui/gfx/geometry/size.h"
20#include "ui/gfx/paint_vector_icon.h"
James Cook6def4d9d2017-03-05 22:13:4721#include "ui/views/controls/button/md_text_button.h"
mohsene6704a02017-04-20 06:30:2022#include "ui/views/layout/fill_layout.h"
James Cook6def4d9d2017-03-05 22:13:4723
24namespace ash {
25
26LogoutButtonTray::LogoutButtonTray(WmShelf* wm_shelf)
mohsene6704a02017-04-20 06:30:2027 : wm_shelf_(wm_shelf),
28 container_(new TrayContainer(wm_shelf)),
29 button_(views::MdTextButton::Create(this, base::string16())),
James Cook6def4d9d2017-03-05 22:13:4730 show_logout_button_in_tray_(false) {
mohsene6704a02017-04-20 06:30:2031 SetLayoutManager(new views::FillLayout);
32 AddChildView(container_);
James Cook6def4d9d2017-03-05 22:13:4733
mohsene6704a02017-04-20 06:30:2034 button_->SetProminent(true);
35 button_->SetBgColorOverride(gfx::kGoogleRed700);
36 button_->AdjustFontSize(kTrayTextFontSizeIncrease);
37
38 container_->AddChildView(button_);
sky5b45ed82017-03-27 02:54:2339 Shell::Get()->system_tray_notifier()->AddLogoutButtonObserver(this);
mohsene6704a02017-04-20 06:30:2040 SetVisible(false);
James Cook6def4d9d2017-03-05 22:13:4741}
42
43LogoutButtonTray::~LogoutButtonTray() {
sky5b45ed82017-03-27 02:54:2344 Shell::Get()->system_tray_notifier()->RemoveLogoutButtonObserver(this);
James Cook6def4d9d2017-03-05 22:13:4745}
46
mohsene6704a02017-04-20 06:30:2047void LogoutButtonTray::UpdateAfterShelfAlignmentChange() {
48 // We must first update the button so that |container_| can lay it out
49 // correctly.
50 UpdateButtonTextAndImage();
51 container_->UpdateAfterShelfAlignmentChange();
James Cook6def4d9d2017-03-05 22:13:4752}
53
James Cook6def4d9d2017-03-05 22:13:4754void LogoutButtonTray::ButtonPressed(views::Button* sender,
55 const ui::Event& event) {
mohsene6704a02017-04-20 06:30:2056 DCHECK_EQ(button_, sender);
James Cook6def4d9d2017-03-05 22:13:4757
58 if (dialog_duration_ <= base::TimeDelta()) {
59 // Sign out immediately if |dialog_duration_| is non-positive.
sky79fa34712017-03-20 23:46:4760 Shell::Get()->system_tray_controller()->SignOut();
61 } else if (Shell::Get()->logout_confirmation_controller()) {
62 Shell::Get()->logout_confirmation_controller()->ConfirmLogout(
James Cook6def4d9d2017-03-05 22:13:4763 base::TimeTicks::Now() + dialog_duration_);
64 }
65}
66
mohsene6704a02017-04-20 06:30:2067void LogoutButtonTray::GetAccessibleNodeData(ui::AXNodeData* node_data) {
68 View::GetAccessibleNodeData(node_data);
69 node_data->SetName(button_->GetText());
70}
71
James Cook6def4d9d2017-03-05 22:13:4772void LogoutButtonTray::OnShowLogoutButtonInTrayChanged(bool show) {
73 show_logout_button_in_tray_ = show;
74 UpdateVisibility();
75}
76
77void LogoutButtonTray::OnLogoutDialogDurationChanged(base::TimeDelta duration) {
78 dialog_duration_ = duration;
79}
80
mohsene6704a02017-04-20 06:30:2081void LogoutButtonTray::UpdateAfterLoginStatusChange() {
82 UpdateButtonTextAndImage();
James Cook6def4d9d2017-03-05 22:13:4783}
84
85void LogoutButtonTray::UpdateVisibility() {
mohsene6704a02017-04-20 06:30:2086 LoginStatus login_status = wm_shelf_->GetStatusAreaWidget()->login_status();
James Cook6def4d9d2017-03-05 22:13:4787 SetVisible(show_logout_button_in_tray_ &&
mohsene6704a02017-04-20 06:30:2088 login_status != LoginStatus::NOT_LOGGED_IN &&
89 login_status != LoginStatus::LOCKED);
James Cook6def4d9d2017-03-05 22:13:4790}
91
mohsene6704a02017-04-20 06:30:2092void LogoutButtonTray::UpdateButtonTextAndImage() {
93 LoginStatus login_status = wm_shelf_->GetStatusAreaWidget()->login_status();
James Cook6def4d9d2017-03-05 22:13:4794 const base::string16 title =
95 user::GetLocalizedSignOutStringForStatus(login_status, false);
mohsene6704a02017-04-20 06:30:2096 if (wm_shelf_->IsHorizontalAlignment()) {
James Cook6def4d9d2017-03-05 22:13:4797 button_->SetText(title);
mohsene6704a02017-04-20 06:30:2098 button_->SetImage(views::Button::STATE_NORMAL, gfx::ImageSkia());
James Cook6def4d9d2017-03-05 22:13:4799 button_->SetMinSize(gfx::Size(0, kTrayItemSize));
100 } else {
101 button_->SetText(base::string16());
102 button_->SetAccessibleName(title);
mohsene6704a02017-04-20 06:30:20103 button_->SetImage(views::Button::STATE_NORMAL,
James Cook6def4d9d2017-03-05 22:13:47104 gfx::CreateVectorIcon(kShelfLogoutIcon, kTrayIconColor));
105 button_->SetMinSize(gfx::Size(kTrayItemSize, kTrayItemSize));
106 }
107 UpdateVisibility();
108}
109
110} // namespace ash