OLD | NEW |
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/user/rounded_image_view.h" | 5 #include "ash/common/system/user/rounded_image_view.h" |
6 | 6 |
7 #include "skia/ext/image_operations.h" | 7 #include "skia/ext/image_operations.h" |
8 #include "third_party/skia/include/core/SkPath.h" | 8 #include "third_party/skia/include/core/SkPath.h" |
9 #include "ui/gfx/canvas.h" | 9 #include "ui/gfx/canvas.h" |
10 #include "ui/gfx/image/image_skia_operations.h" | 10 #include "ui/gfx/image/image_skia_operations.h" |
11 #include "ui/gfx/skia_util.h" | 11 #include "ui/gfx/skia_util.h" |
12 | 12 |
13 namespace ash { | 13 namespace ash { |
14 namespace tray { | 14 namespace tray { |
15 | 15 |
16 RoundedImageView::RoundedImageView(int corner_radius) { | 16 RoundedImageView::RoundedImageView(int corner_radius) { |
17 for (int i = 0; i < 4; ++i) | 17 for (int i = 0; i < 4; ++i) |
18 corner_radius_[i] = corner_radius; | 18 corner_radius_[i] = corner_radius; |
19 } | 19 } |
20 | 20 |
21 RoundedImageView::~RoundedImageView() {} | 21 RoundedImageView::~RoundedImageView() {} |
22 | 22 |
23 void RoundedImageView::SetImage(const gfx::ImageSkia& img, | 23 void RoundedImageView::SetImage(const gfx::ImageSkia& image, |
24 const gfx::Size& size) { | 24 const gfx::Size& size) { |
25 image_ = img; | |
26 image_size_ = size; | 25 image_size_ = size; |
27 | 26 |
28 // Try to get the best image quality for the avatar. | 27 // Try to get the best image quality for the avatar. |
29 resized_ = gfx::ImageSkiaOperations::CreateResizedImage( | 28 resized_ = gfx::ImageSkiaOperations::CreateResizedImage( |
30 image_, skia::ImageOperations::RESIZE_BEST, size); | 29 image, skia::ImageOperations::RESIZE_BEST, size); |
31 if (GetWidget() && visible()) { | 30 if (GetWidget() && visible()) { |
32 PreferredSizeChanged(); | 31 PreferredSizeChanged(); |
33 SchedulePaint(); | 32 SchedulePaint(); |
34 } | 33 } |
35 } | 34 } |
36 | 35 |
37 void RoundedImageView::SetCornerRadii(int top_left, | 36 void RoundedImageView::SetCornerRadii(int top_left, |
38 int top_right, | 37 int top_right, |
39 int bottom_right, | 38 int bottom_right, |
40 int bottom_left) { | 39 int bottom_left) { |
(...skipping 21 matching lines...) Expand all Loading... |
62 SkPath path; | 61 SkPath path; |
63 path.addRoundRect(gfx::RectToSkRect(image_bounds), kRadius); | 62 path.addRoundRect(gfx::RectToSkRect(image_bounds), kRadius); |
64 cc::PaintFlags flags; | 63 cc::PaintFlags flags; |
65 flags.setAntiAlias(true); | 64 flags.setAntiAlias(true); |
66 canvas->DrawImageInPath(resized_, image_bounds.x(), image_bounds.y(), path, | 65 canvas->DrawImageInPath(resized_, image_bounds.x(), image_bounds.y(), path, |
67 flags); | 66 flags); |
68 } | 67 } |
69 | 68 |
70 } // namespace tray | 69 } // namespace tray |
71 } // namespace ash | 70 } // namespace ash |
OLD | NEW |