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 "ash/system/tray/tray_constants.h" | 9 #include "ash/system/tray/tray_constants.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
11 #include "grit/ash_strings.h" | 11 #include "grit/ash_strings.h" |
| 12 #include "third_party/skia/include/core/SkCanvas.h" |
| 13 #include "third_party/skia/include/core/SkPaint.h" |
| 14 #include "third_party/skia/include/core/SkPath.h" |
| 15 #include "third_party/skia/include/core/SkShader.h" |
12 #include "ui/base/resource/resource_bundle.h" | 16 #include "ui/base/resource/resource_bundle.h" |
13 #include "ui/gfx/canvas.h" | 17 #include "ui/gfx/canvas.h" |
14 #include "ui/gfx/image/image.h" | 18 #include "ui/gfx/image/image.h" |
15 #include "ui/gfx/size.h" | 19 #include "ui/gfx/size.h" |
| 20 #include "ui/gfx/skia_util.h" |
16 #include "ui/views/controls/button/button.h" | 21 #include "ui/views/controls/button/button.h" |
17 #include "ui/views/controls/button/text_button.h" | 22 #include "ui/views/controls/button/text_button.h" |
18 #include "ui/views/controls/image_view.h" | 23 #include "ui/views/controls/image_view.h" |
19 #include "ui/views/controls/label.h" | 24 #include "ui/views/controls/label.h" |
20 #include "ui/views/layout/box_layout.h" | 25 #include "ui/views/layout/box_layout.h" |
21 #include "ui/views/view.h" | 26 #include "ui/views/view.h" |
22 | 27 |
23 namespace { | 28 namespace { |
24 | 29 |
25 const int kPaddingAroundButtons = 5; | 30 const int kPaddingAroundButtons = 5; |
26 | 31 |
27 const int kUserInfoHorizontalPadding = 14; | 32 const int kUserInfoHorizontalPadding = 14; |
28 const int kUserInfoVerticalPadding = 10; | 33 const int kUserInfoVerticalPadding = 10; |
29 const int kUserInfoPaddingBetweenItems = 3; | 34 const int kUserInfoPaddingBetweenItems = 3; |
30 | 35 |
31 const int kUserIconSize = 32; | 36 const int kUserIconSize = 27; |
| 37 const int kUserIconCornerRadius = 2; |
32 | 38 |
33 const SkColor kButtonStrokeColor = SkColorSetRGB(0xdd, 0xdd, 0xdd); | 39 const SkColor kButtonStrokeColor = SkColorSetRGB(0xdd, 0xdd, 0xdd); |
34 | 40 |
35 // A custom textbutton with some extra vertical padding, and custom border, | 41 // A custom textbutton with some extra vertical padding, and custom border, |
36 // alignment and hover-effects. | 42 // alignment and hover-effects. |
37 class TrayButton : public views::TextButton { | 43 class TrayButton : public views::TextButton { |
38 public: | 44 public: |
39 TrayButton(views::ButtonListener* listener, const string16& text) | 45 TrayButton(views::ButtonListener* listener, const string16& text) |
40 : views::TextButton(listener, text), | 46 : views::TextButton(listener, text), |
41 hover_(false), | 47 hover_(false), |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 views::Label* email_; | 259 views::Label* email_; |
254 views::View* update_; | 260 views::View* update_; |
255 | 261 |
256 TrayButton* shutdown_; | 262 TrayButton* shutdown_; |
257 TrayButton* signout_; | 263 TrayButton* signout_; |
258 TrayButton* lock_; | 264 TrayButton* lock_; |
259 | 265 |
260 DISALLOW_COPY_AND_ASSIGN(UserView); | 266 DISALLOW_COPY_AND_ASSIGN(UserView); |
261 }; | 267 }; |
262 | 268 |
| 269 // A custom image view with rounded edges. |
| 270 class RoundedImageView : public views::View { |
| 271 public: |
| 272 // Constructs a new rounded image view with rounded corners of radius |
| 273 // |corner_radius|. |
| 274 explicit RoundedImageView(int corner_radius) : corner_radius_(corner_radius) { |
| 275 } |
| 276 |
| 277 virtual ~RoundedImageView() { |
| 278 } |
| 279 |
| 280 // Set the bitmap that should be displayed from a pointer. The pointer |
| 281 // contents is copied in the receiver's bitmap. |
| 282 void SetImage(const SkBitmap& bm) { |
| 283 image_ = bm; |
| 284 SetImageSize(gfx::Size(bm.width(), bm.height())); |
| 285 } |
| 286 |
| 287 // Set the desired image size. |
| 288 void SetImageSize(const gfx::Size& image_size) { |
| 289 image_size_ = image_size; |
| 290 PreferredSizeChanged(); |
| 291 } |
| 292 |
| 293 // Overridden from views::View. |
| 294 virtual gfx::Size GetPreferredSize() OVERRIDE { |
| 295 return image_size_; |
| 296 } |
| 297 |
| 298 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE { |
| 299 View::OnPaint(canvas); |
| 300 gfx::Rect image_bounds(image_size_); |
| 301 const SkScalar kRadius = SkIntToScalar(corner_radius_); |
| 302 SkPath path; |
| 303 path.addRoundRect(gfx::RectToSkRect(image_bounds), kRadius, kRadius); |
| 304 |
| 305 SkPaint paint; |
| 306 SkShader* shader = SkShader::CreateBitmapShader(image_, |
| 307 SkShader::kRepeat_TileMode, |
| 308 SkShader::kRepeat_TileMode); |
| 309 SkMatrix shader_scale; |
| 310 shader_scale.setScale(SkFloatToScalar( |
| 311 static_cast<float>(image_bounds.width()) / image_.width()), |
| 312 SkFloatToScalar(static_cast<float>( |
| 313 image_bounds.height()) / image_.height())); |
| 314 shader->setLocalMatrix(shader_scale); |
| 315 |
| 316 paint.setShader(shader); |
| 317 paint.setXfermodeMode(SkXfermode::kSrcOver_Mode); |
| 318 shader->unref(); |
| 319 canvas->sk_canvas()->drawPath(path, paint); |
| 320 } |
| 321 |
| 322 private: |
| 323 SkBitmap image_; |
| 324 gfx::Size image_size_; |
| 325 int corner_radius_; |
| 326 |
| 327 DISALLOW_COPY_AND_ASSIGN(RoundedImageView); |
| 328 }; |
| 329 |
263 } // namespace tray | 330 } // namespace tray |
264 | 331 |
265 TrayUser::TrayUser() { | 332 TrayUser::TrayUser() { |
266 } | 333 } |
267 | 334 |
268 TrayUser::~TrayUser() { | 335 TrayUser::~TrayUser() { |
269 } | 336 } |
270 | 337 |
271 views::View* TrayUser::CreateTrayView(user::LoginStatus status) { | 338 views::View* TrayUser::CreateTrayView(user::LoginStatus status) { |
272 avatar_.reset(new views::ImageView); | 339 avatar_.reset(new tray::RoundedImageView(kUserIconCornerRadius)); |
273 if (status == user::LOGGED_IN_USER || status == user::LOGGED_IN_OWNER) { | 340 if (status == user::LOGGED_IN_USER || status == user::LOGGED_IN_OWNER) { |
274 avatar_->SetImage( | 341 avatar_->SetImage( |
275 ash::Shell::GetInstance()->tray_delegate()->GetUserImage()); | 342 ash::Shell::GetInstance()->tray_delegate()->GetUserImage()); |
276 avatar_->SetImageSize(gfx::Size(kUserIconSize, kUserIconSize)); | 343 avatar_->SetImageSize(gfx::Size(kUserIconSize, kUserIconSize)); |
277 } else { | 344 } else { |
278 avatar_->SetVisible(false); | 345 avatar_->SetVisible(false); |
279 } | 346 } |
280 return avatar_.get(); | 347 return avatar_.get(); |
281 } | 348 } |
282 | 349 |
(...skipping 25 matching lines...) Expand all Loading... |
308 user_->RefreshForUpdate(); | 375 user_->RefreshForUpdate(); |
309 } | 376 } |
310 | 377 |
311 void TrayUser::OnUserUpdate() { | 378 void TrayUser::OnUserUpdate() { |
312 avatar_->SetImage( | 379 avatar_->SetImage( |
313 ash::Shell::GetInstance()->tray_delegate()->GetUserImage()); | 380 ash::Shell::GetInstance()->tray_delegate()->GetUserImage()); |
314 } | 381 } |
315 | 382 |
316 } // namespace internal | 383 } // namespace internal |
317 } // namespace ash | 384 } // namespace ash |
OLD | NEW |