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

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

Issue 2680223002: Remove pre-MD cros tray logout button assets and code. (Closed)
Patch Set: Created 3 years, 10 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 | « no previous file | ash/resources/ash_resources.grd » ('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/common/system/chromeos/session/logout_button_tray.h" 5 #include "ash/common/system/chromeos/session/logout_button_tray.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "ash/common/material_design/material_design_controller.h"
11 #include "ash/common/shelf/wm_shelf_util.h" 10 #include "ash/common/shelf/wm_shelf_util.h"
12 #include "ash/common/system/chromeos/session/logout_confirmation_controller.h" 11 #include "ash/common/system/chromeos/session/logout_confirmation_controller.h"
13 #include "ash/common/system/tray/system_tray_controller.h" 12 #include "ash/common/system/tray/system_tray_controller.h"
14 #include "ash/common/system/tray/system_tray_notifier.h" 13 #include "ash/common/system/tray/system_tray_notifier.h"
15 #include "ash/common/system/tray/tray_constants.h" 14 #include "ash/common/system/tray/tray_constants.h"
16 #include "ash/common/system/tray/tray_utils.h" 15 #include "ash/common/system/tray/tray_utils.h"
17 #include "ash/common/system/user/login_status.h" 16 #include "ash/common/system/user/login_status.h"
18 #include "ash/common/wm_shell.h" 17 #include "ash/common/wm_shell.h"
19 #include "ash/public/cpp/shelf_types.h" 18 #include "ash/public/cpp/shelf_types.h"
20 #include "ash/resources/vector_icons/vector_icons.h" 19 #include "ash/resources/vector_icons/vector_icons.h"
21 #include "base/logging.h" 20 #include "base/logging.h"
22 #include "grit/ash_resources.h" 21 #include "grit/ash_resources.h"
23 #include "third_party/skia/include/core/SkColor.h" 22 #include "third_party/skia/include/core/SkColor.h"
24 #include "ui/events/event.h" 23 #include "ui/events/event.h"
25 #include "ui/gfx/color_palette.h" 24 #include "ui/gfx/color_palette.h"
26 #include "ui/gfx/geometry/insets.h" 25 #include "ui/gfx/geometry/insets.h"
27 #include "ui/gfx/geometry/size.h" 26 #include "ui/gfx/geometry/size.h"
28 #include "ui/gfx/paint_vector_icon.h" 27 #include "ui/gfx/paint_vector_icon.h"
29 #include "ui/views/bubble/tray_bubble_view.h" 28 #include "ui/views/bubble/tray_bubble_view.h"
30 #include "ui/views/controls/button/label_button.h" 29 #include "ui/views/controls/button/label_button.h"
31 #include "ui/views/controls/button/label_button_border.h" 30 #include "ui/views/controls/button/label_button_border.h"
32 #include "ui/views/controls/button/md_text_button.h" 31 #include "ui/views/controls/button/md_text_button.h"
33 #include "ui/views/painter.h" 32 #include "ui/views/painter.h"
34 33
35 namespace ash { 34 namespace ash {
36 namespace {
37
38 const int kLogoutButtonHorizontalExtraPadding = 7;
39
40 const int kLogoutButtonNormalImages[] = {
41 IDR_AURA_UBER_TRAY_LOGOUT_BUTTON_NORMAL_TOP_LEFT,
42 IDR_AURA_UBER_TRAY_LOGOUT_BUTTON_NORMAL_TOP,
43 IDR_AURA_UBER_TRAY_LOGOUT_BUTTON_NORMAL_TOP_RIGHT,
44 IDR_AURA_UBER_TRAY_LOGOUT_BUTTON_NORMAL_LEFT,
45 IDR_AURA_UBER_TRAY_LOGOUT_BUTTON_NORMAL_CENTER,
46 IDR_AURA_UBER_TRAY_LOGOUT_BUTTON_NORMAL_RIGHT,
47 IDR_AURA_UBER_TRAY_LOGOUT_BUTTON_NORMAL_BOTTOM_LEFT,
48 IDR_AURA_UBER_TRAY_LOGOUT_BUTTON_NORMAL_BOTTOM,
49 IDR_AURA_UBER_TRAY_LOGOUT_BUTTON_NORMAL_BOTTOM_RIGHT};
50
51 const int kLogoutButtonPushedImages[] = {
52 IDR_AURA_UBER_TRAY_LOGOUT_BUTTON_PUSHED_TOP_LEFT,
53 IDR_AURA_UBER_TRAY_LOGOUT_BUTTON_PUSHED_TOP,
54 IDR_AURA_UBER_TRAY_LOGOUT_BUTTON_PUSHED_TOP_RIGHT,
55 IDR_AURA_UBER_TRAY_LOGOUT_BUTTON_PUSHED_LEFT,
56 IDR_AURA_UBER_TRAY_LOGOUT_BUTTON_PUSHED_CENTER,
57 IDR_AURA_UBER_TRAY_LOGOUT_BUTTON_PUSHED_RIGHT,
58 IDR_AURA_UBER_TRAY_LOGOUT_BUTTON_PUSHED_BOTTOM_LEFT,
59 IDR_AURA_UBER_TRAY_LOGOUT_BUTTON_PUSHED_BOTTOM,
60 IDR_AURA_UBER_TRAY_LOGOUT_BUTTON_PUSHED_BOTTOM_RIGHT};
61
62 // TODO(estade): LogoutButton is not used in MD; remove it when possible.
63 // See crbug.com/614453
64 class LogoutButton : public views::LabelButton {
65 public:
66 LogoutButton(views::ButtonListener* listener);
67 ~LogoutButton() override;
68
69 private:
70 DISALLOW_COPY_AND_ASSIGN(LogoutButton);
71 };
72
73 } // namespace
74
75 LogoutButton::LogoutButton(views::ButtonListener* listener)
76 : views::LabelButton(listener, base::string16()) {
77 SetupLabelForTray(label());
78 SetFontList(label()->font_list());
79 SetEnabledTextColors(SK_ColorWHITE);
80
81 std::unique_ptr<views::LabelButtonAssetBorder> border(
82 new views::LabelButtonAssetBorder(views::Button::STYLE_TEXTBUTTON));
83 border->SetPainter(
84 false, views::Button::STATE_NORMAL,
85 views::Painter::CreateImageGridPainter(kLogoutButtonNormalImages));
86 border->SetPainter(
87 false, views::Button::STATE_HOVERED,
88 views::Painter::CreateImageGridPainter(kLogoutButtonNormalImages));
89 border->SetPainter(
90 false, views::Button::STATE_PRESSED,
91 views::Painter::CreateImageGridPainter(kLogoutButtonPushedImages));
92 gfx::Insets insets = border->GetInsets();
93 insets += gfx::Insets(0, kLogoutButtonHorizontalExtraPadding, 0,
94 kLogoutButtonHorizontalExtraPadding);
95 border->set_insets(insets);
96 SetBorder(std::move(border));
97 set_animate_on_state_change(false);
98
99 SetMinSize(gfx::Size(0, GetTrayConstant(TRAY_ITEM_HEIGHT_LEGACY)));
100 }
101
102 LogoutButton::~LogoutButton() {}
103 35
104 LogoutButtonTray::LogoutButtonTray(WmShelf* wm_shelf) 36 LogoutButtonTray::LogoutButtonTray(WmShelf* wm_shelf)
105 : TrayBackgroundView(wm_shelf), 37 : TrayBackgroundView(wm_shelf),
106 button_(nullptr), 38 button_(nullptr),
107 login_status_(LoginStatus::NOT_LOGGED_IN), 39 login_status_(LoginStatus::NOT_LOGGED_IN),
108 show_logout_button_in_tray_(false) { 40 show_logout_button_in_tray_(false) {
109 if (MaterialDesignController::IsShelfMaterial()) { 41 views::MdTextButton* button =
110 views::MdTextButton* button = 42 views::MdTextButton::Create(this, base::string16());
111 views::MdTextButton::Create(this, base::string16()); 43 button->SetProminent(true);
112 button->SetProminent(true); 44 button->SetBgColorOverride(gfx::kGoogleRed700);
113 button->SetBgColorOverride(gfx::kGoogleRed700); 45 // Base font size + 2 = 14.
114 // Base font size + 2 = 14. 46 // TODO(estade): should this 2 be shared with other tray views? See
115 // TODO(estade): should this 2 be shared with other tray views? See 47 // crbug.com/623987
116 // crbug.com/623987 48 button->AdjustFontSize(2);
117 button->AdjustFontSize(2); 49 button_ = button;
118 button_ = button;
119 50
120 // Since |logout_button_tray| has a red background and it is distinguished 51 // Since |logout_button_tray| has a red background and it is distinguished
121 // by itself, no separator is needed on its right side. 52 // by itself, no separator is needed on its right side.
122 set_separator_visibility(false); 53 set_separator_visibility(false);
123 } else {
124 button_ = new LogoutButton(this);
125 }
126 tray_container()->AddChildView(button_); 54 tray_container()->AddChildView(button_);
127 if (!MaterialDesignController::IsShelfMaterial())
128 tray_container()->SetBorder(views::NullBorder());
129 WmShell::Get()->system_tray_notifier()->AddLogoutButtonObserver(this); 55 WmShell::Get()->system_tray_notifier()->AddLogoutButtonObserver(this);
130 } 56 }
131 57
132 LogoutButtonTray::~LogoutButtonTray() { 58 LogoutButtonTray::~LogoutButtonTray() {
133 WmShell::Get()->system_tray_notifier()->RemoveLogoutButtonObserver(this); 59 WmShell::Get()->system_tray_notifier()->RemoveLogoutButtonObserver(this);
134 } 60 }
135 61
136 void LogoutButtonTray::SetShelfAlignment(ShelfAlignment alignment) { 62 void LogoutButtonTray::SetShelfAlignment(ShelfAlignment alignment) {
137 // We must first update the button so that 63 // We must first update the button so that
138 // TrayBackgroundView::SetShelfAlignment() can lay it out correctly. 64 // TrayBackgroundView::SetShelfAlignment() can lay it out correctly.
139 UpdateButtonTextAndImage(login_status_, alignment); 65 UpdateButtonTextAndImage(login_status_, alignment);
140 TrayBackgroundView::SetShelfAlignment(alignment); 66 TrayBackgroundView::SetShelfAlignment(alignment);
141 if (!MaterialDesignController::IsShelfMaterial())
142 tray_container()->SetBorder(views::NullBorder());
143 } 67 }
144 68
145 base::string16 LogoutButtonTray::GetAccessibleNameForTray() { 69 base::string16 LogoutButtonTray::GetAccessibleNameForTray() {
146 return button_->GetText(); 70 return button_->GetText();
147 } 71 }
148 72
149 void LogoutButtonTray::HideBubbleWithView( 73 void LogoutButtonTray::HideBubbleWithView(
150 const views::TrayBubbleView* bubble_view) {} 74 const views::TrayBubbleView* bubble_view) {}
151 75
152 void LogoutButtonTray::ClickedOutsideBubble() {} 76 void LogoutButtonTray::ClickedOutsideBubble() {}
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 SetVisible(show_logout_button_in_tray_ && 108 SetVisible(show_logout_button_in_tray_ &&
185 login_status_ != LoginStatus::NOT_LOGGED_IN && 109 login_status_ != LoginStatus::NOT_LOGGED_IN &&
186 login_status_ != LoginStatus::LOCKED); 110 login_status_ != LoginStatus::LOCKED);
187 } 111 }
188 112
189 void LogoutButtonTray::UpdateButtonTextAndImage(LoginStatus login_status, 113 void LogoutButtonTray::UpdateButtonTextAndImage(LoginStatus login_status,
190 ShelfAlignment alignment) { 114 ShelfAlignment alignment) {
191 login_status_ = login_status; 115 login_status_ = login_status;
192 const base::string16 title = 116 const base::string16 title =
193 user::GetLocalizedSignOutStringForStatus(login_status, false); 117 user::GetLocalizedSignOutStringForStatus(login_status, false);
194 const int button_size = MaterialDesignController::IsShelfMaterial() 118 const int button_size = kTrayItemSize;
tdanderson 2017/02/08 01:08:54 Or consider just having kTrayItemSize inlined on l
Evan Stade 2017/02/08 01:56:16 Done.
195 ? kTrayItemSize
196 : GetTrayConstant(TRAY_ITEM_HEIGHT_LEGACY);
197 if (IsHorizontalAlignment(alignment)) { 119 if (IsHorizontalAlignment(alignment)) {
198 button_->SetText(title); 120 button_->SetText(title);
199 button_->SetImage(views::LabelButton::STATE_NORMAL, gfx::ImageSkia()); 121 button_->SetImage(views::LabelButton::STATE_NORMAL, gfx::ImageSkia());
200 button_->SetMinSize(gfx::Size(0, button_size)); 122 button_->SetMinSize(gfx::Size(0, button_size));
201 } else { 123 } else {
202 button_->SetText(base::string16()); 124 button_->SetText(base::string16());
203 button_->SetAccessibleName(title); 125 button_->SetAccessibleName(title);
204 button_->SetImage(views::LabelButton::STATE_NORMAL, 126 button_->SetImage(views::LabelButton::STATE_NORMAL,
205 gfx::CreateVectorIcon(kShelfLogoutIcon, kTrayIconColor)); 127 gfx::CreateVectorIcon(kShelfLogoutIcon, kTrayIconColor));
206 button_->SetMinSize(gfx::Size(button_size, button_size)); 128 button_->SetMinSize(gfx::Size(button_size, button_size));
207 } 129 }
208 UpdateVisibility(); 130 UpdateVisibility();
209 } 131 }
210 132
211 } // namespace ash 133 } // namespace ash
OLDNEW
« no previous file with comments | « no previous file | ash/resources/ash_resources.grd » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698