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 "chrome/browser/profiles/profile_info_util.h" | 5 #include "chrome/browser/profiles/profile_info_util.h" |
6 | 6 |
7 #include "skia/ext/image_operations.h" | 7 #include "skia/ext/image_operations.h" |
8 #include "ui/gfx/canvas.h" | 8 #include "ui/gfx/canvas.h" |
9 #include "ui/gfx/rect.h" | 9 #include "ui/gfx/rect.h" |
10 | 10 |
11 namespace profiles { | 11 namespace profiles { |
12 | 12 |
13 const int kAvatarIconWidth = 38; | 13 const int kAvatarIconWidth = 38; |
14 const int kAvatarIconHeight = 31; | 14 const int kAvatarIconHeight = 31; |
15 const int kAvatarIconBorder = 2; | 15 const int kAvatarIconBorder = 2; |
16 | 16 |
17 gfx::Image GetSizedAvatarIconWithBorder(const gfx::Image& image, | 17 gfx::Image GetSizedAvatarIconWithBorder(const gfx::Image& image, |
18 bool is_gaia_picture, | 18 bool is_gaia_picture, |
19 int width, int height) { | 19 int width, int height) { |
20 if (!is_gaia_picture) | 20 if (!is_gaia_picture) |
21 return image; | 21 return image; |
22 | 22 |
23 int length = std::min(width, height) - kAvatarIconBorder; | 23 int length = std::min(width, height) - kAvatarIconBorder; |
24 SkBitmap bmp = skia::ImageOperations::Resize( | 24 SkBitmap bmp = skia::ImageOperations::Resize( |
25 *image.ToSkBitmap(), skia::ImageOperations::RESIZE_BEST, length, length); | 25 *image.ToSkBitmap(), skia::ImageOperations::RESIZE_BEST, length, length); |
26 gfx::Canvas canvas(gfx::Size(width, height), ui::SCALE_FACTOR_100P, false); | 26 gfx::Canvas canvas(gfx::Size(width, height), 1.0f, false); |
27 | 27 |
28 // Draw the icon centered on the canvas. | 28 // Draw the icon centered on the canvas. |
29 int x = (width - length) / 2; | 29 int x = (width - length) / 2; |
30 int y = (height - length) / 2; | 30 int y = (height - length) / 2; |
31 canvas.DrawImageInt(gfx::ImageSkia::CreateFrom1xBitmap(bmp), x, y); | 31 canvas.DrawImageInt(gfx::ImageSkia::CreateFrom1xBitmap(bmp), x, y); |
32 | 32 |
33 // Draw a gray border on the inside of the icon. | 33 // Draw a gray border on the inside of the icon. |
34 SkColor color = SkColorSetARGB(83, 0, 0, 0); | 34 SkColor color = SkColorSetARGB(83, 0, 0, 0); |
35 canvas.DrawRect(gfx::Rect(x, y, length - 1, length - 1), color); | 35 canvas.DrawRect(gfx::Rect(x, y, length - 1, length - 1), color); |
36 | 36 |
37 return gfx::Image(gfx::ImageSkia(canvas.ExtractImageRep())); | 37 return gfx::Image(gfx::ImageSkia(canvas.ExtractImageRep())); |
38 } | 38 } |
39 | 39 |
40 gfx::Image GetAvatarIconForMenu(const gfx::Image& image, | 40 gfx::Image GetAvatarIconForMenu(const gfx::Image& image, |
41 bool is_gaia_picture) { | 41 bool is_gaia_picture) { |
42 return GetSizedAvatarIconWithBorder( | 42 return GetSizedAvatarIconWithBorder( |
43 image, is_gaia_picture, kAvatarIconWidth, kAvatarIconHeight); | 43 image, is_gaia_picture, kAvatarIconWidth, kAvatarIconHeight); |
44 } | 44 } |
45 | 45 |
46 gfx::Image GetAvatarIconForWebUI(const gfx::Image& image, | 46 gfx::Image GetAvatarIconForWebUI(const gfx::Image& image, |
47 bool is_gaia_picture) { | 47 bool is_gaia_picture) { |
48 if (!is_gaia_picture) | 48 if (!is_gaia_picture) |
49 return image; | 49 return image; |
50 | 50 |
51 int length = | 51 int length = |
52 std::min(kAvatarIconWidth, kAvatarIconHeight) - kAvatarIconBorder; | 52 std::min(kAvatarIconWidth, kAvatarIconHeight) - kAvatarIconBorder; |
53 SkBitmap bmp = skia::ImageOperations::Resize( | 53 SkBitmap bmp = skia::ImageOperations::Resize( |
54 *image.ToSkBitmap(), skia::ImageOperations::RESIZE_BEST, length, length); | 54 *image.ToSkBitmap(), skia::ImageOperations::RESIZE_BEST, length, length); |
55 gfx::Canvas canvas(gfx::Size(kAvatarIconWidth, kAvatarIconHeight), | 55 gfx::Canvas canvas( |
56 ui::SCALE_FACTOR_100P, false); | 56 gfx::Size(kAvatarIconWidth, kAvatarIconHeight), 1.0f, false); |
57 | 57 |
58 // Draw the icon centered on the canvas. | 58 // Draw the icon centered on the canvas. |
59 int x = (kAvatarIconWidth - length) / 2; | 59 int x = (kAvatarIconWidth - length) / 2; |
60 int y = (kAvatarIconHeight - length) / 2; | 60 int y = (kAvatarIconHeight - length) / 2; |
61 canvas.DrawImageInt(gfx::ImageSkia::CreateFrom1xBitmap(bmp), x, y); | 61 canvas.DrawImageInt(gfx::ImageSkia::CreateFrom1xBitmap(bmp), x, y); |
62 | 62 |
63 return gfx::Image(gfx::ImageSkia(canvas.ExtractImageRep())); | 63 return gfx::Image(gfx::ImageSkia(canvas.ExtractImageRep())); |
64 } | 64 } |
65 | 65 |
66 gfx::Image GetAvatarIconForTitleBar(const gfx::Image& image, | 66 gfx::Image GetAvatarIconForTitleBar(const gfx::Image& image, |
67 bool is_gaia_picture, | 67 bool is_gaia_picture, |
68 int dst_width, | 68 int dst_width, |
69 int dst_height) { | 69 int dst_height) { |
70 if (!is_gaia_picture) | 70 if (!is_gaia_picture) |
71 return image; | 71 return image; |
72 | 72 |
73 int length = std::min(std::min(kAvatarIconWidth, kAvatarIconHeight), | 73 int length = std::min(std::min(kAvatarIconWidth, kAvatarIconHeight), |
74 std::min(dst_width, dst_height)) - kAvatarIconBorder; | 74 std::min(dst_width, dst_height)) - kAvatarIconBorder; |
75 SkBitmap bmp = skia::ImageOperations::Resize( | 75 SkBitmap bmp = skia::ImageOperations::Resize( |
76 *image.ToSkBitmap(), skia::ImageOperations::RESIZE_BEST, length, length); | 76 *image.ToSkBitmap(), skia::ImageOperations::RESIZE_BEST, length, length); |
77 gfx::Canvas canvas(gfx::Size(dst_width, dst_height), ui::SCALE_FACTOR_100P, | 77 gfx::Canvas canvas(gfx::Size(dst_width, dst_height), 1.0f, false); |
78 false); | |
79 | 78 |
80 // Draw the icon on the bottom center of the canvas. | 79 // Draw the icon on the bottom center of the canvas. |
81 int x1 = (dst_width - length) / 2; | 80 int x1 = (dst_width - length) / 2; |
82 int x2 = x1 + length; | 81 int x2 = x1 + length; |
83 int y1 = dst_height - length - 1; | 82 int y1 = dst_height - length - 1; |
84 int y2 = y1 + length; | 83 int y2 = y1 + length; |
85 canvas.DrawImageInt(gfx::ImageSkia::CreateFrom1xBitmap(bmp), x1, y1); | 84 canvas.DrawImageInt(gfx::ImageSkia::CreateFrom1xBitmap(bmp), x1, y1); |
86 | 85 |
87 // Give the icon an etched look by drawing a highlight on the bottom edge | 86 // Give the icon an etched look by drawing a highlight on the bottom edge |
88 // and a shadow on the remaining edges. | 87 // and a shadow on the remaining edges. |
89 SkColor highlight_color = SkColorSetARGB(128, 255, 255, 255); | 88 SkColor highlight_color = SkColorSetARGB(128, 255, 255, 255); |
90 SkColor shadow_color = SkColorSetARGB(83, 0, 0, 0); | 89 SkColor shadow_color = SkColorSetARGB(83, 0, 0, 0); |
91 // Bottom highlight. | 90 // Bottom highlight. |
92 canvas.DrawLine(gfx::Point(x1, y2 - 1), gfx::Point(x2, y2 - 1), | 91 canvas.DrawLine(gfx::Point(x1, y2 - 1), gfx::Point(x2, y2 - 1), |
93 highlight_color); | 92 highlight_color); |
94 // Top shadow. | 93 // Top shadow. |
95 canvas.DrawLine(gfx::Point(x1, y1), gfx::Point(x2, y1), shadow_color); | 94 canvas.DrawLine(gfx::Point(x1, y1), gfx::Point(x2, y1), shadow_color); |
96 // Left shadow. | 95 // Left shadow. |
97 canvas.DrawLine(gfx::Point(x1, y1 + 1), gfx::Point(x1, y2 - 1), shadow_color); | 96 canvas.DrawLine(gfx::Point(x1, y1 + 1), gfx::Point(x1, y2 - 1), shadow_color); |
98 // Right shadow. | 97 // Right shadow. |
99 canvas.DrawLine(gfx::Point(x2 - 1, y1 + 1), gfx::Point(x2 - 1, y2 - 1), | 98 canvas.DrawLine(gfx::Point(x2 - 1, y1 + 1), gfx::Point(x2 - 1, y2 - 1), |
100 shadow_color); | 99 shadow_color); |
101 | 100 |
102 return gfx::Image(gfx::ImageSkia(canvas.ExtractImageRep())); | 101 return gfx::Image(gfx::ImageSkia(canvas.ExtractImageRep())); |
103 } | 102 } |
104 | 103 |
105 } // namespace | 104 } // namespace profiles |
OLD | NEW |