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

Side by Side Diff: ash/common/system/user/rounded_image_view.cc

Issue 2732813002: chromeos: Move files in //ash/common to //ash, part 1 (Closed)
Patch Set: rebase Created 3 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
« no previous file with comments | « ash/common/system/user/rounded_image_view.h ('k') | ash/common/system/user/tray_user.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 2014 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/common/system/user/rounded_image_view.h"
6
7 #include "skia/ext/image_operations.h"
8 #include "third_party/skia/include/core/SkPath.h"
9 #include "ui/gfx/canvas.h"
10 #include "ui/gfx/image/image_skia_operations.h"
11 #include "ui/gfx/skia_util.h"
12
13 namespace ash {
14 namespace tray {
15
16 RoundedImageView::RoundedImageView(int corner_radius) {
17 for (int i = 0; i < 4; ++i)
18 corner_radius_[i] = corner_radius;
19 }
20
21 RoundedImageView::~RoundedImageView() {}
22
23 void RoundedImageView::SetImage(const gfx::ImageSkia& img,
24 const gfx::Size& size) {
25 image_ = img;
26 image_size_ = size;
27
28 // Try to get the best image quality for the avatar.
29 resized_ = gfx::ImageSkiaOperations::CreateResizedImage(
30 image_, skia::ImageOperations::RESIZE_BEST, size);
31 if (GetWidget() && visible()) {
32 PreferredSizeChanged();
33 SchedulePaint();
34 }
35 }
36
37 void RoundedImageView::SetCornerRadii(int top_left,
38 int top_right,
39 int bottom_right,
40 int bottom_left) {
41 corner_radius_[0] = top_left;
42 corner_radius_[1] = top_right;
43 corner_radius_[2] = bottom_right;
44 corner_radius_[3] = bottom_left;
45 }
46
47 gfx::Size RoundedImageView::GetPreferredSize() const {
48 return gfx::Size(image_size_.width() + GetInsets().width(),
49 image_size_.height() + GetInsets().height());
50 }
51
52 void RoundedImageView::OnPaint(gfx::Canvas* canvas) {
53 View::OnPaint(canvas);
54 gfx::Rect image_bounds(size());
55 image_bounds.ClampToCenteredSize(GetPreferredSize());
56 image_bounds.Inset(GetInsets());
57 const SkScalar kRadius[8] = {
58 SkIntToScalar(corner_radius_[0]), SkIntToScalar(corner_radius_[0]),
59 SkIntToScalar(corner_radius_[1]), SkIntToScalar(corner_radius_[1]),
60 SkIntToScalar(corner_radius_[2]), SkIntToScalar(corner_radius_[2]),
61 SkIntToScalar(corner_radius_[3]), SkIntToScalar(corner_radius_[3])};
62 SkPath path;
63 path.addRoundRect(gfx::RectToSkRect(image_bounds), kRadius);
64 cc::PaintFlags flags;
65 flags.setAntiAlias(true);
66 canvas->DrawImageInPath(resized_, image_bounds.x(), image_bounds.y(), path,
67 flags);
68 }
69
70 } // namespace tray
71 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/system/user/rounded_image_view.h ('k') | ash/common/system/user/tray_user.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698