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 "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "third_party/skia/include/core/SkPaint.h" | 8 #include "third_party/skia/include/core/SkPaint.h" |
9 #include "third_party/skia/include/core/SkPath.h" | 9 #include "third_party/skia/include/core/SkPath.h" |
10 #include "third_party/skia/include/core/SkScalar.h" | 10 #include "third_party/skia/include/core/SkScalar.h" |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 paint.setColor(highlight_color); | 164 paint.setColor(highlight_color); |
165 canvas->DrawPath(path, paint); | 165 canvas->DrawPath(path, paint); |
166 } | 166 } |
167 } | 167 } |
168 | 168 |
169 } // namespace | 169 } // namespace |
170 | 170 |
171 namespace profiles { | 171 namespace profiles { |
172 | 172 |
173 const int kAvatarIconWidth = 38; | 173 const int kAvatarIconWidth = 38; |
174 const int kAvatarIconHeight = 31; | 174 const int kAvatarIconHeight = 38; |
175 const int kAvatarIconPadding = 2; | 175 const int kAvatarIconPadding = 2; |
176 | 176 |
177 gfx::Image GetSizedAvatarIconWithBorder(const gfx::Image& image, | 177 gfx::Image GetSizedAvatarIconWithBorder(const gfx::Image& image, |
178 bool is_rectangle, | 178 bool is_gaia_image, |
179 int width, int height) { | 179 int width, int height) { |
180 if (!is_rectangle) | 180 // The image requires no border or resizing. |
| 181 if (!is_gaia_image && image.Height() <= height) |
181 return image; | 182 return image; |
182 | 183 |
183 gfx::Size size(width, height); | 184 gfx::Size size(width, height); |
184 | 185 |
185 // Source for a centered, sized icon with a border. | 186 // Source for a centered, sized icon. |
| 187 // GAIA images get a border. |
186 scoped_ptr<gfx::ImageSkiaSource> source( | 188 scoped_ptr<gfx::ImageSkiaSource> source( |
187 new AvatarImageSource( | 189 new AvatarImageSource( |
188 *image.ToImageSkia(), | 190 *image.ToImageSkia(), |
189 size, | 191 size, |
190 std::min(width, height), | 192 std::min(width, height), |
191 AvatarImageSource::POSITION_CENTER, | 193 AvatarImageSource::POSITION_CENTER, |
192 AvatarImageSource::BORDER_NORMAL)); | 194 is_gaia_image ? AvatarImageSource::BORDER_NORMAL : |
| 195 AvatarImageSource::BORDER_NONE)); |
193 | 196 |
194 return gfx::Image(gfx::ImageSkia(source.release(), size)); | 197 return gfx::Image(gfx::ImageSkia(source.release(), size)); |
195 } | 198 } |
196 | 199 |
197 gfx::Image GetAvatarIconForMenu(const gfx::Image& image, | 200 gfx::Image GetAvatarIconForMenu(const gfx::Image& image, |
198 bool is_rectangle) { | 201 bool is_gaia_image) { |
199 return GetSizedAvatarIconWithBorder( | 202 return GetSizedAvatarIconWithBorder( |
200 image, is_rectangle, kAvatarIconWidth, kAvatarIconHeight); | 203 image, is_gaia_image, kAvatarIconWidth, kAvatarIconHeight); |
201 } | 204 } |
202 | 205 |
203 gfx::Image GetAvatarIconForWebUI(const gfx::Image& image, | 206 gfx::Image GetAvatarIconForWebUI(const gfx::Image& image, |
204 bool is_rectangle) { | 207 bool is_gaia_image) { |
205 if (!is_rectangle) | 208 // The image requires no border or resizing. |
| 209 if (!is_gaia_image && image.Height() <= kAvatarIconHeight) |
206 return image; | 210 return image; |
207 | 211 |
208 gfx::Size size(kAvatarIconWidth, kAvatarIconHeight); | 212 gfx::Size size(kAvatarIconWidth, kAvatarIconHeight); |
209 | 213 |
210 // Source for a centered, sized icon. | 214 // Source for a centered, sized icon. |
211 scoped_ptr<gfx::ImageSkiaSource> source( | 215 scoped_ptr<gfx::ImageSkiaSource> source( |
212 new AvatarImageSource( | 216 new AvatarImageSource( |
213 *image.ToImageSkia(), | 217 *image.ToImageSkia(), |
214 size, | 218 size, |
215 std::min(kAvatarIconWidth, kAvatarIconHeight), | 219 std::min(kAvatarIconWidth, kAvatarIconHeight), |
216 AvatarImageSource::POSITION_CENTER, | 220 AvatarImageSource::POSITION_CENTER, |
217 AvatarImageSource::BORDER_NONE)); | 221 AvatarImageSource::BORDER_NONE)); |
218 | 222 |
219 return gfx::Image(gfx::ImageSkia(source.release(), size)); | 223 return gfx::Image(gfx::ImageSkia(source.release(), size)); |
220 } | 224 } |
221 | 225 |
222 gfx::Image GetAvatarIconForTitleBar(const gfx::Image& image, | 226 gfx::Image GetAvatarIconForTitleBar(const gfx::Image& image, |
223 bool is_rectangle, | 227 bool is_gaia_image, |
224 int dst_width, | 228 int dst_width, |
225 int dst_height) { | 229 int dst_height) { |
226 if (!is_rectangle) | 230 // The image requires no border or resizing. |
| 231 if (!is_gaia_image && image.Height() <= kAvatarIconHeight) |
227 return image; | 232 return image; |
228 | 233 |
229 int size = std::min(std::min(kAvatarIconWidth, kAvatarIconHeight), | 234 int size = std::min(std::min(kAvatarIconWidth, kAvatarIconHeight), |
230 std::min(dst_width, dst_height)); | 235 std::min(dst_width, dst_height)); |
231 gfx::Size dst_size(dst_width, dst_height); | 236 gfx::Size dst_size(dst_width, dst_height); |
232 | 237 |
233 // Source for a sized icon drawn at the bottom center of the canvas, | 238 // Source for a sized icon drawn at the bottom center of the canvas, |
234 // with an etched border. | 239 // with an etched border (for GAIA images). |
235 scoped_ptr<gfx::ImageSkiaSource> source( | 240 scoped_ptr<gfx::ImageSkiaSource> source( |
236 new AvatarImageSource( | 241 new AvatarImageSource( |
237 *image.ToImageSkia(), | 242 *image.ToImageSkia(), |
238 dst_size, | 243 dst_size, |
239 size, | 244 size, |
240 AvatarImageSource::POSITION_BOTTOM_CENTER, | 245 AvatarImageSource::POSITION_BOTTOM_CENTER, |
241 AvatarImageSource::BORDER_ETCHED)); | 246 is_gaia_image ? AvatarImageSource::BORDER_ETCHED : |
| 247 AvatarImageSource::BORDER_NONE)); |
242 | 248 |
243 return gfx::Image(gfx::ImageSkia(source.release(), dst_size)); | 249 return gfx::Image(gfx::ImageSkia(source.release(), dst_size)); |
244 } | 250 } |
245 | 251 |
246 } // namespace profiles | 252 } // namespace profiles |
OLD | NEW |