Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(15)

Side by Side Diff: ash/common/system/chromeos/session/logout_button_tray.cc

Issue 2734653002: chromeos: Move files in //ash/common to //ash (Closed)
Patch Set: fix a11y tests, fix docs Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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/common/system/chromeos/session/logout_button_tray.h"
6
7 #include <memory>
8 #include <utility>
9
10 #include "ash/common/shelf/wm_shelf_util.h"
11 #include "ash/common/system/chromeos/session/logout_confirmation_controller.h"
12 #include "ash/common/system/tray/system_tray_controller.h"
13 #include "ash/common/system/tray/system_tray_notifier.h"
14 #include "ash/common/system/tray/tray_constants.h"
15 #include "ash/common/system/tray/tray_utils.h"
16 #include "ash/common/system/user/login_status.h"
17 #include "ash/common/wm_shell.h"
18 #include "ash/public/cpp/shelf_types.h"
19 #include "ash/resources/grit/ash_resources.h"
20 #include "ash/resources/vector_icons/vector_icons.h"
21 #include "base/logging.h"
22 #include "third_party/skia/include/core/SkColor.h"
23 #include "ui/events/event.h"
24 #include "ui/gfx/color_palette.h"
25 #include "ui/gfx/geometry/insets.h"
26 #include "ui/gfx/geometry/size.h"
27 #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"
32 #include "ui/views/painter.h"
33
34 namespace ash {
35
36 LogoutButtonTray::LogoutButtonTray(WmShelf* wm_shelf)
37 : TrayBackgroundView(wm_shelf),
38 button_(nullptr),
39 login_status_(LoginStatus::NOT_LOGGED_IN),
40 show_logout_button_in_tray_(false) {
41 views::MdTextButton* button =
42 views::MdTextButton::Create(this, base::string16());
43 button->SetProminent(true);
44 button->SetBgColorOverride(gfx::kGoogleRed700);
45 // Base font size + 2 = 14.
46 // TODO(estade): should this 2 be shared with other tray views? See
47 // crbug.com/623987
48 button->AdjustFontSize(2);
49 button_ = button;
50
51 // Since LogoutButtonTray has a red background and it is distinguished
52 // by itself, no separator is needed on its right side.
53 set_separator_visibility(false);
54 tray_container()->AddChildView(button_);
55 WmShell::Get()->system_tray_notifier()->AddLogoutButtonObserver(this);
56 }
57
58 LogoutButtonTray::~LogoutButtonTray() {
59 WmShell::Get()->system_tray_notifier()->RemoveLogoutButtonObserver(this);
60 }
61
62 void LogoutButtonTray::SetShelfAlignment(ShelfAlignment alignment) {
63 // We must first update the button so that
64 // TrayBackgroundView::SetShelfAlignment() can lay it out correctly.
65 UpdateButtonTextAndImage(login_status_, alignment);
66 TrayBackgroundView::SetShelfAlignment(alignment);
67 }
68
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,
79 const ui::Event& event) {
80 if (sender != button_) {
81 TrayBackgroundView::ButtonPressed(sender, event);
82 return;
83 }
84
85 if (dialog_duration_ <= base::TimeDelta()) {
86 // Sign out immediately if |dialog_duration_| is non-positive.
87 WmShell::Get()->system_tray_controller()->SignOut();
88 } else if (WmShell::Get()->logout_confirmation_controller()) {
89 WmShell::Get()->logout_confirmation_controller()->ConfirmLogout(
90 base::TimeTicks::Now() + dialog_duration_);
91 }
92 }
93
94 void LogoutButtonTray::OnShowLogoutButtonInTrayChanged(bool show) {
95 show_logout_button_in_tray_ = show;
96 UpdateVisibility();
97 }
98
99 void LogoutButtonTray::OnLogoutDialogDurationChanged(base::TimeDelta duration) {
100 dialog_duration_ = duration;
101 }
102
103 void LogoutButtonTray::UpdateAfterLoginStatusChange(LoginStatus login_status) {
104 UpdateButtonTextAndImage(login_status, shelf_alignment());
105 }
106
107 void LogoutButtonTray::UpdateVisibility() {
108 SetVisible(show_logout_button_in_tray_ &&
109 login_status_ != LoginStatus::NOT_LOGGED_IN &&
110 login_status_ != LoginStatus::LOCKED);
111 }
112
113 void LogoutButtonTray::UpdateButtonTextAndImage(LoginStatus login_status,
114 ShelfAlignment alignment) {
115 login_status_ = login_status;
116 const base::string16 title =
117 user::GetLocalizedSignOutStringForStatus(login_status, false);
118 if (IsHorizontalAlignment(alignment)) {
119 button_->SetText(title);
120 button_->SetImage(views::LabelButton::STATE_NORMAL, gfx::ImageSkia());
121 button_->SetMinSize(gfx::Size(0, kTrayItemSize));
122 } else {
123 button_->SetText(base::string16());
124 button_->SetAccessibleName(title);
125 button_->SetImage(views::LabelButton::STATE_NORMAL,
126 gfx::CreateVectorIcon(kShelfLogoutIcon, kTrayIconColor));
127 button_->SetMinSize(gfx::Size(kTrayItemSize, kTrayItemSize));
128 }
129 UpdateVisibility();
130 }
131
132 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698