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

Side by Side Diff: ash/system/tray_user.cc

Issue 9580024: ash uber tray: Allow customizing each item depending on whether the user is logged in or not. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: missing file Created 8 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 | Annotate | Revision Log
« no previous file with comments | « ash/system/tray_user.h ('k') | ash/system/user/login_status.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2012 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/tray_user.h"
6
7 #include "ash/shell.h"
8 #include "ash/system/tray/system_tray_delegate.h"
9 #include "base/utf_string_conversions.h"
10 #include "grit/ash_strings.h"
11 #include "ui/base/resource/resource_bundle.h"
12 #include "ui/gfx/size.h"
13 #include "ui/views/controls/button/button.h"
14 #include "ui/views/controls/button/text_button.h"
15 #include "ui/views/controls/image_view.h"
16 #include "ui/views/controls/label.h"
17 #include "ui/views/layout/box_layout.h"
18 #include "ui/views/view.h"
19
20 namespace {
21
22 // A custom textbutton with some extra vertical padding, and custom border,
23 // alignment and hover-effects.
24 class TrayButton : public views::TextButton {
25 public:
26 TrayButton(views::ButtonListener* listener, const string16& text)
27 : views::TextButton(listener, text),
28 hover_(false),
29 hover_bg_(views::Background::CreateSolidBackground(SkColorSetARGB(
30 10, 0, 0, 0))) {
31 set_alignment(ALIGN_CENTER);
32 }
33
34 private:
35 // Overridden from views::View.
36 virtual gfx::Size GetPreferredSize() OVERRIDE {
37 gfx::Size size = views::TextButton::GetPreferredSize();
38 size.Enlarge(0, 16);
39 return size;
40 }
41
42 virtual void OnMouseEntered(const views::MouseEvent& event) OVERRIDE {
43 hover_ = true;
44 SchedulePaint();
45 }
46
47 virtual void OnMouseExited(const views::MouseEvent& event) OVERRIDE {
48 hover_ = false;
49 SchedulePaint();
50 }
51
52 virtual void OnPaintBackground(gfx::Canvas* canvas) OVERRIDE {
53 if (hover_)
54 hover_bg_->Paint(canvas, this);
55 else
56 views::TextButton::OnPaintBackground(canvas);
57 }
58
59 bool hover_;
60 views::Background* hover_bg_;
61
62 DISALLOW_COPY_AND_ASSIGN(TrayButton);
63 };
64
65 class UserView : public views::View,
66 public views::ButtonListener {
67 public:
68 UserView() {
69 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical,
70 0, 0, 3));
71
72 views::View* user = new views::View;
73 user->SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical,
74 14, 5, 0));
75 ash::SystemTrayDelegate* tray = ash::Shell::GetInstance()->tray_delegate();
76 username_ = new views::Label(ASCIIToUTF16(tray->GetUserDisplayName()));
77 username_->SetFont(username_->font().DeriveFont(2));
78 username_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
79 user->AddChildView(username_);
80
81 email_ = new views::Label(ASCIIToUTF16(tray->GetUserEmail()));
82 email_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
83 email_->SetEnabled(false);
84 user->AddChildView(email_);
85
86 AddChildView(user);
87
88 views::View* button_container = new views::View;
89 views::BoxLayout *layout = new
90 views::BoxLayout(views::BoxLayout::kHorizontal, 0, 5, 0);
91 layout->set_spread_blank_space(true);
92 button_container->SetLayoutManager(layout);
93
94 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
95
96 shutdown_ = new TrayButton(this, bundle.GetLocalizedString(
97 IDS_ASH_STATUS_TRAY_SHUT_DOWN));
98 signout_ = new TrayButton(this, bundle.GetLocalizedString(
99 IDS_ASH_STATUS_TRAY_SIGN_OUT));
100 lock_ = new TrayButton(this, bundle.GetLocalizedString(
101 IDS_ASH_STATUS_TRAY_LOCK));
102 button_container->AddChildView(shutdown_);
103 button_container->AddChildView(signout_);
104 button_container->AddChildView(lock_);
105
106 shutdown_->set_border(NULL);
107 signout_->set_border(views::Border::CreateSolidSidedBorder(
108 0, 1, 0, 1, SkColorSetARGB(25, 0, 0, 0)));
109 lock_->set_border(NULL);
110
111 AddChildView(button_container);
112 }
113
114 private:
115 // Overridden from views::ButtonListener.
116 virtual void ButtonPressed(views::Button* sender,
117 const views::Event& event) OVERRIDE {
118 ash::SystemTrayDelegate* tray = ash::Shell::GetInstance()->tray_delegate();
119 if (sender == shutdown_)
120 tray->ShutDown();
121 else if (sender == signout_)
122 tray->SignOut();
123 else if (sender == lock_)
124 tray->LockScreen();
125 }
126
127 views::Label* username_;
128 views::Label* email_;
129
130 TrayButton* shutdown_;
131 TrayButton* signout_;
132 TrayButton* lock_;
133
134 DISALLOW_COPY_AND_ASSIGN(UserView);
135 };
136
137 } // namespace
138
139 namespace ash {
140 namespace internal {
141
142 TrayUser::TrayUser() {
143 }
144
145 TrayUser::~TrayUser() {
146 }
147
148 views::View* TrayUser::CreateTrayView() {
149 views::ImageView* avatar = new views::ImageView;
150 avatar->SetImage(ash::Shell::GetInstance()->tray_delegate()->GetUserImage());
151 avatar->SetImageSize(gfx::Size(32, 32));
152 return avatar;
153 }
154
155 views::View* TrayUser::CreateDefaultView() {
156 return new UserView;
157 }
158
159 views::View* TrayUser::CreateDetailedView() {
160 return NULL;
161 }
162
163 void TrayUser::DestroyTrayView() {
164 }
165
166 void TrayUser::DestroyDefaultView() {
167 }
168
169 void TrayUser::DestroyDetailedView() {
170 }
171
172 } // namespace internal
173 } // namespace ash
OLDNEW
« no previous file with comments | « ash/system/tray_user.h ('k') | ash/system/user/login_status.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698