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