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

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

Issue 2807693002: Make LogoutButtonTray a regular View (Closed)
Patch Set: Rebased Created 3 years, 8 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
« no previous file with comments | « ash/system/session/logout_button_tray.h ('k') | ash/system/status_area_widget.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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);
44 button->SetBgColorOverride(gfx::kGoogleRed700);
45 button->AdjustFontSize(kTrayTextFontSizeIncrease);
46 button_ = button;
47 33
48 // Since LogoutButtonTray has a red background and it is distinguished 34 button_->SetProminent(true);
49 // by itself, no separator is needed on its right side. 35 button_->SetBgColorOverride(gfx::kGoogleRed700);
50 set_separator_visibility(false); 36 button_->AdjustFontSize(kTrayTextFontSizeIncrease);
51 tray_container()->AddChildView(button_); 37
38 container_->AddChildView(button_);
52 Shell::Get()->system_tray_notifier()->AddLogoutButtonObserver(this); 39 Shell::Get()->system_tray_notifier()->AddLogoutButtonObserver(this);
40 SetVisible(false);
53 } 41 }
54 42
55 LogoutButtonTray::~LogoutButtonTray() { 43 LogoutButtonTray::~LogoutButtonTray() {
56 Shell::Get()->system_tray_notifier()->RemoveLogoutButtonObserver(this); 44 Shell::Get()->system_tray_notifier()->RemoveLogoutButtonObserver(this);
57 } 45 }
58 46
59 void LogoutButtonTray::SetShelfAlignment(ShelfAlignment alignment) { 47 void LogoutButtonTray::UpdateAfterShelfAlignmentChange() {
60 // We must first update the button so that 48 // We must first update the button so that |container_| can lay it out
61 // TrayBackgroundView::SetShelfAlignment() can lay it out correctly. 49 // correctly.
62 UpdateButtonTextAndImage(login_status_, alignment); 50 UpdateButtonTextAndImage();
63 TrayBackgroundView::SetShelfAlignment(alignment); 51 container_->UpdateAfterShelfAlignmentChange();
64 } 52 }
65 53
66 base::string16 LogoutButtonTray::GetAccessibleNameForTray() {
67 return button_->GetText();
68 }
69
70 void LogoutButtonTray::HideBubbleWithView(
71 const views::TrayBubbleView* bubble_view) {}
72
73 void LogoutButtonTray::ClickedOutsideBubble() {}
74
75 void LogoutButtonTray::ButtonPressed(views::Button* sender, 54 void LogoutButtonTray::ButtonPressed(views::Button* sender,
76 const ui::Event& event) { 55 const ui::Event& event) {
77 if (sender != button_) { 56 DCHECK_EQ(button_, sender);
78 TrayBackgroundView::ButtonPressed(sender, event);
79 return;
80 }
81 57
82 if (dialog_duration_ <= base::TimeDelta()) { 58 if (dialog_duration_ <= base::TimeDelta()) {
83 // Sign out immediately if |dialog_duration_| is non-positive. 59 // Sign out immediately if |dialog_duration_| is non-positive.
84 Shell::Get()->system_tray_controller()->SignOut(); 60 Shell::Get()->system_tray_controller()->SignOut();
85 } else if (Shell::Get()->logout_confirmation_controller()) { 61 } else if (Shell::Get()->logout_confirmation_controller()) {
86 Shell::Get()->logout_confirmation_controller()->ConfirmLogout( 62 Shell::Get()->logout_confirmation_controller()->ConfirmLogout(
87 base::TimeTicks::Now() + dialog_duration_); 63 base::TimeTicks::Now() + dialog_duration_);
88 } 64 }
89 } 65 }
90 66
67 void LogoutButtonTray::GetAccessibleNodeData(ui::AXNodeData* node_data) {
68 View::GetAccessibleNodeData(node_data);
69 node_data->SetName(button_->GetText());
70 }
71
91 void LogoutButtonTray::OnShowLogoutButtonInTrayChanged(bool show) { 72 void LogoutButtonTray::OnShowLogoutButtonInTrayChanged(bool show) {
92 show_logout_button_in_tray_ = show; 73 show_logout_button_in_tray_ = show;
93 UpdateVisibility(); 74 UpdateVisibility();
94 } 75 }
95 76
96 void LogoutButtonTray::OnLogoutDialogDurationChanged(base::TimeDelta duration) { 77 void LogoutButtonTray::OnLogoutDialogDurationChanged(base::TimeDelta duration) {
97 dialog_duration_ = duration; 78 dialog_duration_ = duration;
98 } 79 }
99 80
100 void LogoutButtonTray::UpdateAfterLoginStatusChange(LoginStatus login_status) { 81 void LogoutButtonTray::UpdateAfterLoginStatusChange() {
101 UpdateButtonTextAndImage(login_status, shelf_alignment()); 82 UpdateButtonTextAndImage();
102 } 83 }
103 84
104 void LogoutButtonTray::UpdateVisibility() { 85 void LogoutButtonTray::UpdateVisibility() {
86 LoginStatus login_status = wm_shelf_->GetStatusAreaWidget()->login_status();
105 SetVisible(show_logout_button_in_tray_ && 87 SetVisible(show_logout_button_in_tray_ &&
106 login_status_ != LoginStatus::NOT_LOGGED_IN && 88 login_status != LoginStatus::NOT_LOGGED_IN &&
107 login_status_ != LoginStatus::LOCKED); 89 login_status != LoginStatus::LOCKED);
108 } 90 }
109 91
110 void LogoutButtonTray::UpdateButtonTextAndImage(LoginStatus login_status, 92 void LogoutButtonTray::UpdateButtonTextAndImage() {
111 ShelfAlignment alignment) { 93 LoginStatus login_status = wm_shelf_->GetStatusAreaWidget()->login_status();
112 login_status_ = login_status;
113 const base::string16 title = 94 const base::string16 title =
114 user::GetLocalizedSignOutStringForStatus(login_status, false); 95 user::GetLocalizedSignOutStringForStatus(login_status, false);
115 if (IsHorizontalAlignment(alignment)) { 96 if (wm_shelf_->IsHorizontalAlignment()) {
116 button_->SetText(title); 97 button_->SetText(title);
117 button_->SetImage(views::LabelButton::STATE_NORMAL, gfx::ImageSkia()); 98 button_->SetImage(views::Button::STATE_NORMAL, gfx::ImageSkia());
118 button_->SetMinSize(gfx::Size(0, kTrayItemSize)); 99 button_->SetMinSize(gfx::Size(0, kTrayItemSize));
119 } else { 100 } else {
120 button_->SetText(base::string16()); 101 button_->SetText(base::string16());
121 button_->SetAccessibleName(title); 102 button_->SetAccessibleName(title);
122 button_->SetImage(views::LabelButton::STATE_NORMAL, 103 button_->SetImage(views::Button::STATE_NORMAL,
123 gfx::CreateVectorIcon(kShelfLogoutIcon, kTrayIconColor)); 104 gfx::CreateVectorIcon(kShelfLogoutIcon, kTrayIconColor));
124 button_->SetMinSize(gfx::Size(kTrayItemSize, kTrayItemSize)); 105 button_->SetMinSize(gfx::Size(kTrayItemSize, kTrayItemSize));
125 } 106 }
126 UpdateVisibility(); 107 UpdateVisibility();
127 } 108 }
128 109
129 } // namespace ash 110 } // namespace ash
OLDNEW
« no previous file with comments | « ash/system/session/logout_button_tray.h ('k') | ash/system/status_area_widget.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698