OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/user/tray_user.h" | 5 #include "ash/system/user/tray_user.h" |
6 | 6 |
7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
8 #include "ash/system/tray/system_tray_delegate.h" | 8 #include "ash/system/tray/system_tray_delegate.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "grit/ash_strings.h" | 10 #include "grit/ash_strings.h" |
11 #include "ui/base/resource/resource_bundle.h" | 11 #include "ui/base/resource/resource_bundle.h" |
| 12 #include "ui/gfx/canvas.h" |
12 #include "ui/gfx/image/image.h" | 13 #include "ui/gfx/image/image.h" |
13 #include "ui/gfx/size.h" | 14 #include "ui/gfx/size.h" |
14 #include "ui/views/controls/button/button.h" | 15 #include "ui/views/controls/button/button.h" |
15 #include "ui/views/controls/button/text_button.h" | 16 #include "ui/views/controls/button/text_button.h" |
16 #include "ui/views/controls/image_view.h" | 17 #include "ui/views/controls/image_view.h" |
17 #include "ui/views/controls/label.h" | 18 #include "ui/views/controls/label.h" |
18 #include "ui/views/layout/box_layout.h" | 19 #include "ui/views/layout/box_layout.h" |
19 #include "ui/views/view.h" | 20 #include "ui/views/view.h" |
20 | 21 |
21 namespace { | 22 namespace { |
22 | 23 |
23 const int kUpdateNotificationPadding = 5; | 24 const int kPaddingAroundButtons = 5; |
| 25 |
| 26 const int kUserInfoHorizontalPadding = 14; |
| 27 const int kUserInfoVerticalPadding = 10; |
| 28 const int kUserInfoPaddingBetweenItems = 3; |
| 29 |
| 30 const SkColor kButtonStrokeColor = SkColorSetRGB(0xdd, 0xdd, 0xdd); |
24 | 31 |
25 // A custom textbutton with some extra vertical padding, and custom border, | 32 // A custom textbutton with some extra vertical padding, and custom border, |
26 // alignment and hover-effects. | 33 // alignment and hover-effects. |
27 class TrayButton : public views::TextButton { | 34 class TrayButton : public views::TextButton { |
28 public: | 35 public: |
29 TrayButton(views::ButtonListener* listener, const string16& text) | 36 TrayButton(views::ButtonListener* listener, const string16& text) |
30 : views::TextButton(listener, text), | 37 : views::TextButton(listener, text), |
31 hover_(false), | 38 hover_(false), |
32 hover_bg_(views::Background::CreateSolidBackground(SkColorSetARGB( | 39 hover_bg_(views::Background::CreateSolidBackground(SkColorSetARGB( |
33 10, 0, 0, 0))) { | 40 10, 0, 0, 0))), |
| 41 hover_border_(views::Border::CreateSolidBorder(1, kButtonStrokeColor)) { |
34 set_alignment(ALIGN_CENTER); | 42 set_alignment(ALIGN_CENTER); |
| 43 set_border(NULL); |
35 } | 44 } |
36 | 45 |
37 virtual ~TrayButton() {} | 46 virtual ~TrayButton() {} |
38 | 47 |
39 private: | 48 private: |
40 // Overridden from views::View. | 49 // Overridden from views::View. |
41 virtual gfx::Size GetPreferredSize() OVERRIDE { | 50 virtual gfx::Size GetPreferredSize() OVERRIDE { |
42 gfx::Size size = views::TextButton::GetPreferredSize(); | 51 gfx::Size size = views::TextButton::GetPreferredSize(); |
43 size.Enlarge(0, 16); | 52 size.Enlarge(0, 16); |
44 return size; | 53 return size; |
45 } | 54 } |
46 | 55 |
47 virtual void OnMouseEntered(const views::MouseEvent& event) OVERRIDE { | 56 virtual void OnMouseEntered(const views::MouseEvent& event) OVERRIDE { |
48 hover_ = true; | 57 hover_ = true; |
49 SchedulePaint(); | 58 SchedulePaint(); |
50 } | 59 } |
51 | 60 |
52 virtual void OnMouseExited(const views::MouseEvent& event) OVERRIDE { | 61 virtual void OnMouseExited(const views::MouseEvent& event) OVERRIDE { |
53 hover_ = false; | 62 hover_ = false; |
54 SchedulePaint(); | 63 SchedulePaint(); |
55 } | 64 } |
56 | 65 |
57 virtual void OnPaintBackground(gfx::Canvas* canvas) OVERRIDE { | 66 virtual void OnPaintBackground(gfx::Canvas* canvas) OVERRIDE { |
58 if (hover_) | 67 if (hover_) |
59 hover_bg_->Paint(canvas, this); | 68 hover_bg_->Paint(canvas, this); |
60 else | 69 else |
61 views::TextButton::OnPaintBackground(canvas); | 70 views::TextButton::OnPaintBackground(canvas); |
62 } | 71 } |
63 | 72 |
| 73 virtual void OnPaintBorder(gfx::Canvas* canvas) OVERRIDE { |
| 74 if (hover_) |
| 75 hover_border_->Paint(*this, canvas); |
| 76 else |
| 77 views::TextButton::OnPaintBorder(canvas); |
| 78 } |
| 79 |
64 bool hover_; | 80 bool hover_; |
65 views::Background* hover_bg_; | 81 scoped_ptr<views::Background> hover_bg_; |
| 82 scoped_ptr<views::Border> hover_border_; |
66 | 83 |
67 DISALLOW_COPY_AND_ASSIGN(TrayButton); | 84 DISALLOW_COPY_AND_ASSIGN(TrayButton); |
68 }; | 85 }; |
69 | 86 |
70 } // namespace | 87 } // namespace |
71 | 88 |
72 namespace ash { | 89 namespace ash { |
73 namespace internal { | 90 namespace internal { |
74 | 91 |
75 namespace tray { | 92 namespace tray { |
76 | 93 |
77 class UserView : public views::View, | 94 class UserView : public views::View, |
78 public views::ButtonListener { | 95 public views::ButtonListener { |
79 public: | 96 public: |
80 explicit UserView(ash::user::LoginStatus status) | 97 explicit UserView(ash::user::LoginStatus status) |
81 : username_(NULL), | 98 : username_(NULL), |
82 email_(NULL), | 99 email_(NULL), |
83 update_(NULL), | 100 update_(NULL), |
84 shutdown_(NULL), | 101 shutdown_(NULL), |
85 signout_(NULL), | 102 signout_(NULL), |
86 lock_(NULL) { | 103 lock_(NULL) { |
87 CHECK(status != ash::user::LOGGED_IN_NONE); | 104 CHECK(status != ash::user::LOGGED_IN_NONE); |
88 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, | 105 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, |
89 0, 0, 3)); | 106 0, 0, 0)); |
90 | 107 |
91 if (status != ash::user::LOGGED_IN_GUEST) | 108 if (status != ash::user::LOGGED_IN_GUEST) |
92 AddUserInfo(); | 109 AddUserInfo(); |
93 | 110 |
94 views::View* button_container = new views::View; | 111 views::View* button_container = new views::View; |
95 views::BoxLayout *layout = new | 112 views::BoxLayout *layout = new |
96 views::BoxLayout(views::BoxLayout::kHorizontal, 0, 5, 0); | 113 views::BoxLayout(views::BoxLayout::kHorizontal, |
| 114 kPaddingAroundButtons, |
| 115 kPaddingAroundButtons, |
| 116 -1); |
97 layout->set_spread_blank_space(true); | 117 layout->set_spread_blank_space(true); |
98 button_container->SetLayoutManager(layout); | 118 button_container->SetLayoutManager(layout); |
99 | 119 |
100 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | 120 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
101 | 121 |
102 shutdown_ = new TrayButton(this, bundle.GetLocalizedString( | 122 shutdown_ = new TrayButton(this, bundle.GetLocalizedString( |
103 IDS_ASH_STATUS_TRAY_SHUT_DOWN)); | 123 IDS_ASH_STATUS_TRAY_SHUT_DOWN)); |
104 shutdown_->set_border(NULL); | 124 shutdown_->set_border(views::Border::CreateSolidSidedBorder(0, 0, 0, 1, |
| 125 kButtonStrokeColor)); |
105 button_container->AddChildView(shutdown_); | 126 button_container->AddChildView(shutdown_); |
106 | 127 |
107 signout_ = new TrayButton(this, bundle.GetLocalizedString( | 128 signout_ = new TrayButton(this, bundle.GetLocalizedString( |
108 status == ash::user::LOGGED_IN_GUEST ? IDS_ASH_STATUS_TRAY_EXIT_GUEST : | 129 status == ash::user::LOGGED_IN_GUEST ? IDS_ASH_STATUS_TRAY_EXIT_GUEST : |
109 IDS_ASH_STATUS_TRAY_SIGN_OUT)); | 130 IDS_ASH_STATUS_TRAY_SIGN_OUT)); |
110 signout_->set_border(views::Border::CreateSolidSidedBorder( | |
111 0, 1, 0, 1, SkColorSetARGB(25, 0, 0, 0))); | |
112 button_container->AddChildView(signout_); | 131 button_container->AddChildView(signout_); |
113 | 132 |
114 if (status != ash::user::LOGGED_IN_GUEST) { | 133 if (status != ash::user::LOGGED_IN_GUEST) { |
| 134 signout_->set_border(views::Border::CreateSolidSidedBorder(0, 0, 0, 1, |
| 135 kButtonStrokeColor)); |
115 lock_ = new TrayButton(this, bundle.GetLocalizedString( | 136 lock_ = new TrayButton(this, bundle.GetLocalizedString( |
116 IDS_ASH_STATUS_TRAY_LOCK)); | 137 IDS_ASH_STATUS_TRAY_LOCK)); |
117 button_container->AddChildView(lock_); | 138 button_container->AddChildView(lock_); |
118 lock_->set_border(NULL); | |
119 } | 139 } |
120 | 140 |
121 AddChildView(button_container); | 141 AddChildView(button_container); |
122 } | 142 } |
123 | 143 |
124 virtual ~UserView() {} | 144 virtual ~UserView() {} |
125 | 145 |
126 // Shows update notification if available. | 146 // Shows update notification if available. |
127 void RefreshForUpdate() { | 147 void RefreshForUpdate() { |
128 ash::SystemTrayDelegate* tray = ash::Shell::GetInstance()->tray_delegate(); | 148 ash::SystemTrayDelegate* tray = ash::Shell::GetInstance()->tray_delegate(); |
129 if (tray->SystemShouldUpgrade()) { | 149 if (tray->SystemShouldUpgrade()) { |
130 if (update_) | 150 if (update_) |
131 return; | 151 return; |
132 update_ = new views::View; | 152 update_ = new views::View; |
133 update_->SetLayoutManager(new | 153 update_->SetLayoutManager(new |
134 views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 3)); | 154 views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 3)); |
135 | 155 |
136 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | 156 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
137 views::Label *label = new views::Label(bundle.GetLocalizedString( | 157 views::Label *label = new views::Label(bundle.GetLocalizedString( |
138 IDS_ASH_STATUS_TRAY_UPDATE)); | 158 IDS_ASH_STATUS_TRAY_UPDATE)); |
139 label->SetFont(label->font().DeriveFont(-1)); | 159 label->SetFont(label->font().DeriveFont(-1)); |
140 update_->AddChildView(label); | 160 update_->AddChildView(label); |
141 | 161 |
142 views::ImageView* icon = new views::ImageView; | 162 views::ImageView* icon = new views::ImageView; |
143 icon->SetImage(bundle.GetImageNamed(tray->GetSystemUpdateIconResource()). | 163 icon->SetImage(bundle.GetImageNamed(tray->GetSystemUpdateIconResource()). |
144 ToSkBitmap()); | 164 ToSkBitmap()); |
145 update_->AddChildView(icon); | 165 update_->AddChildView(icon); |
146 | 166 |
147 update_->set_border(views::Border::CreateEmptyBorder( | 167 update_->set_border(views::Border::CreateEmptyBorder( |
148 kUpdateNotificationPadding, | 168 kUserInfoVerticalPadding, |
149 kUpdateNotificationPadding, | 169 kUserInfoHorizontalPadding, |
150 kUpdateNotificationPadding, | 170 kUserInfoVerticalPadding, |
151 kUpdateNotificationPadding)); | 171 kUserInfoHorizontalPadding)); |
152 | 172 |
153 user_info_->AddChildView(update_); | 173 user_info_->AddChildView(update_); |
154 } else if (update_) { | 174 } else if (update_) { |
155 delete update_; | 175 delete update_; |
156 update_ = NULL; | 176 update_ = NULL; |
157 } | 177 } |
158 user_info_->InvalidateLayout(); | 178 user_info_->InvalidateLayout(); |
159 user_info_->SchedulePaint(); | 179 user_info_->SchedulePaint(); |
160 } | 180 } |
161 | 181 |
162 private: | 182 private: |
163 void AddUserInfo() { | 183 void AddUserInfo() { |
164 user_info_ = new views::View; | 184 user_info_ = new views::View; |
165 user_info_->SetLayoutManager(new views::BoxLayout( | 185 user_info_->SetLayoutManager(new views::BoxLayout( |
166 views::BoxLayout::kHorizontal, 0, 0, 3)); | 186 views::BoxLayout::kHorizontal, kUserInfoHorizontalPadding, |
| 187 kUserInfoVerticalPadding, kUserInfoPaddingBetweenItems)); |
167 | 188 |
168 views::View* user = new views::View; | 189 views::View* user = new views::View; |
169 user->SetLayoutManager(new views::BoxLayout( | 190 user->SetLayoutManager(new views::BoxLayout( |
170 views::BoxLayout::kVertical, 14, 5, 0)); | 191 views::BoxLayout::kVertical, 0, 5, 0)); |
171 ash::SystemTrayDelegate* tray = | 192 ash::SystemTrayDelegate* tray = |
172 ash::Shell::GetInstance()->tray_delegate(); | 193 ash::Shell::GetInstance()->tray_delegate(); |
173 username_ = new views::Label(ASCIIToUTF16(tray->GetUserDisplayName())); | 194 username_ = new views::Label(UTF8ToUTF16(tray->GetUserDisplayName())); |
174 username_->SetFont(username_->font().DeriveFont(2)); | 195 username_->SetFont(username_->font().DeriveFont(2)); |
175 username_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | 196 username_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
176 user->AddChildView(username_); | 197 user->AddChildView(username_); |
177 | 198 |
178 email_ = new views::Label(ASCIIToUTF16(tray->GetUserEmail())); | 199 email_ = new views::Label(UTF8ToUTF16(tray->GetUserEmail())); |
179 email_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | 200 email_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
180 email_->SetEnabled(false); | 201 email_->SetEnabled(false); |
181 user->AddChildView(email_); | 202 user->AddChildView(email_); |
182 | 203 |
183 user_info_->AddChildView(user); | 204 user_info_->AddChildView(user); |
184 AddChildView(user_info_); | 205 AddChildView(user_info_); |
185 | 206 |
186 RefreshForUpdate(); | 207 RefreshForUpdate(); |
187 } | 208 } |
188 | 209 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 void TrayUser::DestroyDetailedView() { | 285 void TrayUser::DestroyDetailedView() { |
265 } | 286 } |
266 | 287 |
267 void TrayUser::OnUpdateRecommended() { | 288 void TrayUser::OnUpdateRecommended() { |
268 if (user_.get()) | 289 if (user_.get()) |
269 user_->RefreshForUpdate(); | 290 user_->RefreshForUpdate(); |
270 } | 291 } |
271 | 292 |
272 } // namespace internal | 293 } // namespace internal |
273 } // namespace ash | 294 } // namespace ash |
OLD | NEW |