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 "chrome/browser/profiles/profile_avatar_icon_util.h" | 5 #include "chrome/browser/profiles/profile_avatar_icon_util.h" |
6 | 6 |
7 #include "base/format_macros.h" | 7 #include "base/format_macros.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 paint.setColor(highlight_color); | 170 paint.setColor(highlight_color); |
171 canvas->DrawPath(path, paint); | 171 canvas->DrawPath(path, paint); |
172 } | 172 } |
173 } | 173 } |
174 | 174 |
175 } // namespace | 175 } // namespace |
176 | 176 |
177 namespace profiles { | 177 namespace profiles { |
178 | 178 |
179 const int kAvatarIconWidth = 38; | 179 const int kAvatarIconWidth = 38; |
180 const int kAvatarIconHeight = 38; | 180 const int kAvatarIconHeight = 31; |
181 const int kAvatarIconPadding = 2; | 181 const int kAvatarIconPadding = 2; |
182 const SkColor kAvatarTutorialBackgroundColor = SkColorSetRGB(0x42, 0x85, 0xf4); | 182 const SkColor kAvatarTutorialBackgroundColor = SkColorSetRGB(0x42, 0x85, 0xf4); |
183 const SkColor kAvatarTutorialContentTextColor = SkColorSetRGB(0xc6, 0xda, 0xfc); | 183 const SkColor kAvatarTutorialContentTextColor = SkColorSetRGB(0xc6, 0xda, 0xfc); |
184 | 184 |
185 const char kDefaultUrlPrefix[] = "chrome://theme/IDR_PROFILE_AVATAR_"; | 185 const char kDefaultUrlPrefix[] = "chrome://theme/IDR_PROFILE_AVATAR_"; |
186 const char kGAIAPictureFileName[] = "Google Profile Picture.png"; | 186 const char kGAIAPictureFileName[] = "Google Profile Picture.png"; |
187 const char kHighResAvatarFolderName[] = "Avatars"; | 187 const char kHighResAvatarFolderName[] = "Avatars"; |
188 | 188 |
189 const int kDefaultAvatarIconResources[] = { | 189 const int kDefaultAvatarIconResources[] = { |
190 IDR_PROFILE_AVATAR_0, | 190 IDR_PROFILE_AVATAR_0, |
(...skipping 15 matching lines...) Expand all Loading... |
206 IDR_PROFILE_AVATAR_16, | 206 IDR_PROFILE_AVATAR_16, |
207 IDR_PROFILE_AVATAR_17, | 207 IDR_PROFILE_AVATAR_17, |
208 IDR_PROFILE_AVATAR_18, | 208 IDR_PROFILE_AVATAR_18, |
209 IDR_PROFILE_AVATAR_19, | 209 IDR_PROFILE_AVATAR_19, |
210 IDR_PROFILE_AVATAR_20, | 210 IDR_PROFILE_AVATAR_20, |
211 IDR_PROFILE_AVATAR_21, | 211 IDR_PROFILE_AVATAR_21, |
212 IDR_PROFILE_AVATAR_22, | 212 IDR_PROFILE_AVATAR_22, |
213 IDR_PROFILE_AVATAR_23, | 213 IDR_PROFILE_AVATAR_23, |
214 IDR_PROFILE_AVATAR_24, | 214 IDR_PROFILE_AVATAR_24, |
215 IDR_PROFILE_AVATAR_25, | 215 IDR_PROFILE_AVATAR_25, |
216 IDR_PROFILE_AVATAR_26, | |
217 }; | 216 }; |
218 | 217 |
219 // This avatar does not exist on the server, the high res copy is in the build. | |
220 const char* kNoHighResAvatar = "NothingToDownload"; | |
221 | |
222 // File names for the high-res avatar icon resources. In the same order as | 218 // File names for the high-res avatar icon resources. In the same order as |
223 // the avatars in kDefaultAvatarIconResources. | 219 // the avatars in kDefaultAvatarIconResources. |
224 const char* kDefaultAvatarIconResourceFileNames[] = { | 220 const char* kDefaultAvatarIconResourceFileNames[] = { |
225 "avatar_generic.png", | 221 "avatar_generic.png", |
226 "avatar_generic_aqua.png", | 222 "avatar_generic_aqua.png", |
227 "avatar_generic_blue.png", | 223 "avatar_generic_blue.png", |
228 "avatar_generic_green.png", | 224 "avatar_generic_green.png", |
229 "avatar_generic_orange.png", | 225 "avatar_generic_orange.png", |
230 "avatar_generic_purple.png", | 226 "avatar_generic_purple.png", |
231 "avatar_generic_red.png", | 227 "avatar_generic_red.png", |
232 "avatar_generic_yellow.png", | 228 "avatar_generic_yellow.png", |
233 "avatar_secret_agent.png", | 229 "avatar_secret_agent.png", |
234 "avatar_superhero.png", | 230 "avatar_superhero.png", |
235 "avatar_volley_ball.png", | 231 "avatar_volley_ball.png", |
236 "avatar_businessman.png", | 232 "avatar_businessman.png", |
237 "avatar_ninja.png", | 233 "avatar_ninja.png", |
238 "avatar_alien.png", | 234 "avatar_alien.png", |
239 "avatar_smiley.png", | 235 "avatar_smiley.png", |
240 "avatar_flower.png", | 236 "avatar_flower.png", |
241 "avatar_pizza.png", | 237 "avatar_pizza.png", |
242 "avatar_soccer.png", | 238 "avatar_soccer.png", |
243 "avatar_burger.png", | 239 "avatar_burger.png", |
244 "avatar_cat.png", | 240 "avatar_cat.png", |
245 "avatar_cupcake.png", | 241 "avatar_cupcake.png", |
246 "avatar_dog.png", | 242 "avatar_dog.png", |
247 "avatar_horse.png", | 243 "avatar_horse.png", |
248 "avatar_margarita.png", | 244 "avatar_margarita.png", |
249 "avatar_note.png", | 245 "avatar_note.png", |
250 "avatar_sun_cloud.png", | 246 "avatar_sun_cloud.png", |
251 kNoHighResAvatar, | |
252 }; | 247 }; |
253 | 248 |
254 const size_t kDefaultAvatarIconsCount = arraysize(kDefaultAvatarIconResources); | 249 const size_t kDefaultAvatarIconsCount = arraysize(kDefaultAvatarIconResources); |
255 | 250 |
256 // The first 8 icons are generic. | 251 // The first 8 icons are generic. |
257 const size_t kGenericAvatarIconsCount = 8; | 252 const size_t kGenericAvatarIconsCount = 8; |
258 | 253 |
259 // The avatar used as a placeholder (grey silhouette). | |
260 const int kPlaceholderAvatarIcon = 26; | |
261 | |
262 gfx::Image GetSizedAvatarIconWithBorder(const gfx::Image& image, | 254 gfx::Image GetSizedAvatarIconWithBorder(const gfx::Image& image, |
263 bool is_gaia_image, | 255 bool is_rectangle, |
264 int width, int height) { | 256 int width, int height) { |
265 // The image requires no border or resizing. | 257 if (!is_rectangle) |
266 if (!is_gaia_image && image.Height() <= height) | |
267 return image; | 258 return image; |
268 | 259 |
269 gfx::Size size(width, height); | 260 gfx::Size size(width, height); |
270 | 261 |
271 // Source for a centered, sized icon. | 262 // Source for a centered, sized icon with a border. |
272 // GAIA images get a border. | |
273 scoped_ptr<gfx::ImageSkiaSource> source( | 263 scoped_ptr<gfx::ImageSkiaSource> source( |
274 new AvatarImageSource( | 264 new AvatarImageSource( |
275 *image.ToImageSkia(), | 265 *image.ToImageSkia(), |
276 size, | 266 size, |
277 std::min(width, height), | 267 std::min(width, height), |
278 AvatarImageSource::POSITION_CENTER, | 268 AvatarImageSource::POSITION_CENTER, |
279 is_gaia_image ? AvatarImageSource::BORDER_NORMAL : | 269 AvatarImageSource::BORDER_NORMAL)); |
280 AvatarImageSource::BORDER_NONE)); | |
281 | 270 |
282 return gfx::Image(gfx::ImageSkia(source.release(), size)); | 271 return gfx::Image(gfx::ImageSkia(source.release(), size)); |
283 } | 272 } |
284 | 273 |
285 gfx::Image GetAvatarIconForMenu(const gfx::Image& image, | 274 gfx::Image GetAvatarIconForMenu(const gfx::Image& image, |
286 bool is_gaia_image) { | 275 bool is_rectangle) { |
287 return GetSizedAvatarIconWithBorder( | 276 return GetSizedAvatarIconWithBorder( |
288 image, is_gaia_image, kAvatarIconWidth, kAvatarIconHeight); | 277 image, is_rectangle, kAvatarIconWidth, kAvatarIconHeight); |
289 } | 278 } |
290 | 279 |
291 gfx::Image GetAvatarIconForWebUI(const gfx::Image& image, | 280 gfx::Image GetAvatarIconForWebUI(const gfx::Image& image, |
292 bool is_gaia_image) { | 281 bool is_rectangle) { |
293 // The image requires no border or resizing. | 282 if (!is_rectangle) |
294 if (!is_gaia_image && image.Height() <= kAvatarIconHeight) | |
295 return image; | 283 return image; |
296 | 284 |
297 gfx::Size size(kAvatarIconWidth, kAvatarIconHeight); | 285 gfx::Size size(kAvatarIconWidth, kAvatarIconHeight); |
298 | 286 |
299 // Source for a centered, sized icon. | 287 // Source for a centered, sized icon. |
300 scoped_ptr<gfx::ImageSkiaSource> source( | 288 scoped_ptr<gfx::ImageSkiaSource> source( |
301 new AvatarImageSource( | 289 new AvatarImageSource( |
302 *image.ToImageSkia(), | 290 *image.ToImageSkia(), |
303 size, | 291 size, |
304 std::min(kAvatarIconWidth, kAvatarIconHeight), | 292 std::min(kAvatarIconWidth, kAvatarIconHeight), |
305 AvatarImageSource::POSITION_CENTER, | 293 AvatarImageSource::POSITION_CENTER, |
306 AvatarImageSource::BORDER_NONE)); | 294 AvatarImageSource::BORDER_NONE)); |
307 | 295 |
308 return gfx::Image(gfx::ImageSkia(source.release(), size)); | 296 return gfx::Image(gfx::ImageSkia(source.release(), size)); |
309 } | 297 } |
310 | 298 |
311 gfx::Image GetAvatarIconForTitleBar(const gfx::Image& image, | 299 gfx::Image GetAvatarIconForTitleBar(const gfx::Image& image, |
312 bool is_gaia_image, | 300 bool is_rectangle, |
313 int dst_width, | 301 int dst_width, |
314 int dst_height) { | 302 int dst_height) { |
315 // The image requires no border or resizing. | 303 if (!is_rectangle) |
316 if (!is_gaia_image && image.Height() <= kAvatarIconHeight) | |
317 return image; | 304 return image; |
318 | 305 |
319 int size = std::min(std::min(kAvatarIconWidth, kAvatarIconHeight), | 306 int size = std::min(std::min(kAvatarIconWidth, kAvatarIconHeight), |
320 std::min(dst_width, dst_height)); | 307 std::min(dst_width, dst_height)); |
321 gfx::Size dst_size(dst_width, dst_height); | 308 gfx::Size dst_size(dst_width, dst_height); |
322 | 309 |
323 // Source for a sized icon drawn at the bottom center of the canvas, | 310 // Source for a sized icon drawn at the bottom center of the canvas, |
324 // with an etched border (for GAIA images). | 311 // with an etched border. |
325 scoped_ptr<gfx::ImageSkiaSource> source( | 312 scoped_ptr<gfx::ImageSkiaSource> source( |
326 new AvatarImageSource( | 313 new AvatarImageSource( |
327 *image.ToImageSkia(), | 314 *image.ToImageSkia(), |
328 dst_size, | 315 dst_size, |
329 size, | 316 size, |
330 AvatarImageSource::POSITION_BOTTOM_CENTER, | 317 AvatarImageSource::POSITION_BOTTOM_CENTER, |
331 is_gaia_image ? AvatarImageSource::BORDER_ETCHED : | 318 AvatarImageSource::BORDER_ETCHED)); |
332 AvatarImageSource::BORDER_NONE)); | |
333 | 319 |
334 return gfx::Image(gfx::ImageSkia(source.release(), dst_size)); | 320 return gfx::Image(gfx::ImageSkia(source.release(), dst_size)); |
335 } | 321 } |
336 | 322 |
337 // Helper methods for accessing, transforming and drawing avatar icons. | 323 // Helper methods for accessing, transforming and drawing avatar icons. |
338 size_t GetDefaultAvatarIconCount() { | 324 size_t GetDefaultAvatarIconCount() { |
339 return kDefaultAvatarIconsCount; | 325 return kDefaultAvatarIconsCount; |
340 } | 326 } |
341 | 327 |
342 size_t GetGenericAvatarIconCount() { | 328 size_t GetGenericAvatarIconCount() { |
343 return kGenericAvatarIconsCount; | 329 return kGenericAvatarIconsCount; |
344 } | 330 } |
345 | 331 |
346 int GetPlaceholderAvatarIndex() { | |
347 return kPlaceholderAvatarIcon; | |
348 } | |
349 | |
350 int GetPlaceholderAvatarIconResourceID() { | |
351 return IDR_PROFILE_AVATAR_26; | |
352 } | |
353 | |
354 int GetDefaultAvatarIconResourceIDAtIndex(size_t index) { | 332 int GetDefaultAvatarIconResourceIDAtIndex(size_t index) { |
355 DCHECK(IsDefaultAvatarIconIndex(index)); | 333 DCHECK(IsDefaultAvatarIconIndex(index)); |
356 return kDefaultAvatarIconResources[index]; | 334 return kDefaultAvatarIconResources[index]; |
357 } | 335 } |
358 | 336 |
359 const char* GetDefaultAvatarIconFileNameAtIndex(size_t index) { | 337 const char* GetDefaultAvatarIconFileNameAtIndex(size_t index) { |
360 return kDefaultAvatarIconResourceFileNames[index]; | 338 return kDefaultAvatarIconResourceFileNames[index]; |
361 } | 339 } |
362 | 340 |
363 const char* GetNoHighResAvatarFileName() { | |
364 return kNoHighResAvatar; | |
365 } | |
366 | |
367 std::string GetDefaultAvatarIconUrl(size_t index) { | 341 std::string GetDefaultAvatarIconUrl(size_t index) { |
368 DCHECK(IsDefaultAvatarIconIndex(index)); | 342 DCHECK(IsDefaultAvatarIconIndex(index)); |
369 return base::StringPrintf("%s%" PRIuS, kDefaultUrlPrefix, index); | 343 return base::StringPrintf("%s%" PRIuS, kDefaultUrlPrefix, index); |
370 } | 344 } |
371 | 345 |
372 bool IsDefaultAvatarIconIndex(size_t index) { | 346 bool IsDefaultAvatarIconIndex(size_t index) { |
373 return index < kDefaultAvatarIconsCount; | 347 return index < kDefaultAvatarIconsCount; |
374 } | 348 } |
375 | 349 |
376 bool IsDefaultAvatarIconUrl(const std::string& url, | 350 bool IsDefaultAvatarIconUrl(const std::string& url, |
(...skipping 11 matching lines...) Expand all Loading... |
388 int_value >= static_cast<int>(kDefaultAvatarIconsCount)) | 362 int_value >= static_cast<int>(kDefaultAvatarIconsCount)) |
389 return false; | 363 return false; |
390 *icon_index = int_value; | 364 *icon_index = int_value; |
391 return true; | 365 return true; |
392 } | 366 } |
393 | 367 |
394 return false; | 368 return false; |
395 } | 369 } |
396 | 370 |
397 } // namespace profiles | 371 } // namespace profiles |
OLD | NEW |