| Index: chrome/browser/profiles/profile_avatar_icon_util.cc
|
| diff --git a/chrome/browser/profiles/profile_avatar_icon_util.cc b/chrome/browser/profiles/profile_avatar_icon_util.cc
|
| index 30c0661c8eb32883ca27a1e4ce5c0b060651a606..88c3d7a6c5f828defdcf4e4a797f0a57c986fad4 100644
|
| --- a/chrome/browser/profiles/profile_avatar_icon_util.cc
|
| +++ b/chrome/browser/profiles/profile_avatar_icon_util.cc
|
| @@ -4,10 +4,13 @@
|
|
|
| #include "chrome/browser/profiles/profile_avatar_icon_util.h"
|
|
|
| +#include "base/file_util.h"
|
| #include "base/format_macros.h"
|
| #include "base/memory/scoped_ptr.h"
|
| +#include "base/path_service.h"
|
| #include "base/strings/string_number_conversions.h"
|
| #include "base/strings/stringprintf.h"
|
| +#include "chrome/common/chrome_paths.h"
|
| #include "grit/generated_resources.h"
|
| #include "grit/theme_resources.h"
|
| #include "third_party/skia/include/core/SkPaint.h"
|
| @@ -17,15 +20,80 @@
|
| #include "ui/base/resource/resource_bundle.h"
|
| #include "ui/gfx/canvas.h"
|
| #include "ui/gfx/image/canvas_image_source.h"
|
| +#include "ui/gfx/image/image.h"
|
| #include "ui/gfx/image/image_skia_operations.h"
|
|
|
| // Helper methods for transforming and drawing avatar icons.
|
| namespace {
|
|
|
| +const int kDefaultAvatarIconResources[] = {
|
| + IDR_PROFILE_AVATAR_0,
|
| + IDR_PROFILE_AVATAR_1,
|
| + IDR_PROFILE_AVATAR_2,
|
| + IDR_PROFILE_AVATAR_3,
|
| + IDR_PROFILE_AVATAR_4,
|
| + IDR_PROFILE_AVATAR_5,
|
| + IDR_PROFILE_AVATAR_6,
|
| + IDR_PROFILE_AVATAR_7,
|
| + IDR_PROFILE_AVATAR_8,
|
| + IDR_PROFILE_AVATAR_9,
|
| + IDR_PROFILE_AVATAR_10,
|
| + IDR_PROFILE_AVATAR_11,
|
| + IDR_PROFILE_AVATAR_12,
|
| + IDR_PROFILE_AVATAR_13,
|
| + IDR_PROFILE_AVATAR_14,
|
| + IDR_PROFILE_AVATAR_15,
|
| + IDR_PROFILE_AVATAR_16,
|
| + IDR_PROFILE_AVATAR_17,
|
| + IDR_PROFILE_AVATAR_18,
|
| + IDR_PROFILE_AVATAR_19,
|
| + IDR_PROFILE_AVATAR_20,
|
| + IDR_PROFILE_AVATAR_21,
|
| + IDR_PROFILE_AVATAR_22,
|
| + IDR_PROFILE_AVATAR_23,
|
| + IDR_PROFILE_AVATAR_24,
|
| + IDR_PROFILE_AVATAR_25,
|
| +};
|
| +
|
| +// File names for the high-res avatar icon resources. In the same order as
|
| +// the avatars in kDefaultAvatarIconResources.
|
| +const char* kDefaultAvatarIconResourceFileNames[] = {
|
| + "avatar_generic.png",
|
| + "avatar_generic_aqua.png",
|
| + "avatar_generic_blue.png",
|
| + "avatar_generic_green.png",
|
| + "avatar_generic_orange.png",
|
| + "avatar_generic_purple.png",
|
| + "avatar_generic_red.png",
|
| + "avatar_generic_yellow.png",
|
| + "avatar_secret_agent.png",
|
| + "avatar_superhero.png",
|
| + "avatar_volley_ball.png",
|
| + "avatar_businessman.png",
|
| + "avatar_ninja.png",
|
| + "avatar_alien.png",
|
| + "avatar_smiley.png",
|
| + "avatar_flower.png",
|
| + "avatar_pizza.png",
|
| + "avatar_soccer.png",
|
| + "avatar_burger.png",
|
| + "avatar_cat.png",
|
| + "avatar_cupcake.png",
|
| + "avatar_dog.png",
|
| + "avatar_horse.png",
|
| + "avatar_margarita.png",
|
| + "avatar_note.png",
|
| + "avatar_sun_cloud.png",
|
| +};
|
| +
|
| +const size_t kDefaultAvatarIconsCount = arraysize(kDefaultAvatarIconResources);
|
| +
|
| +// The first 8 icons are generic.
|
| +const size_t kGenericAvatarIconsCount = 8;
|
| +
|
| // Determine what the scaled height of the avatar icon should be for a
|
| // specified width, to preserve the aspect ratio.
|
| int GetScaledAvatarHeightForWidth(int width, const gfx::ImageSkia& avatar) {
|
| -
|
| // Multiply the width by the inverted aspect ratio (height over
|
| // width), and then add 0.5 to ensure the int truncation rounds nicely.
|
| int scaled_height = width *
|
| @@ -186,71 +254,6 @@ const char kDefaultUrlPrefix[] = "chrome://theme/IDR_PROFILE_AVATAR_";
|
| const char kGAIAPictureFileName[] = "Google Profile Picture.png";
|
| const char kHighResAvatarFolderName[] = "Avatars";
|
|
|
| -const int kDefaultAvatarIconResources[] = {
|
| - IDR_PROFILE_AVATAR_0,
|
| - IDR_PROFILE_AVATAR_1,
|
| - IDR_PROFILE_AVATAR_2,
|
| - IDR_PROFILE_AVATAR_3,
|
| - IDR_PROFILE_AVATAR_4,
|
| - IDR_PROFILE_AVATAR_5,
|
| - IDR_PROFILE_AVATAR_6,
|
| - IDR_PROFILE_AVATAR_7,
|
| - IDR_PROFILE_AVATAR_8,
|
| - IDR_PROFILE_AVATAR_9,
|
| - IDR_PROFILE_AVATAR_10,
|
| - IDR_PROFILE_AVATAR_11,
|
| - IDR_PROFILE_AVATAR_12,
|
| - IDR_PROFILE_AVATAR_13,
|
| - IDR_PROFILE_AVATAR_14,
|
| - IDR_PROFILE_AVATAR_15,
|
| - IDR_PROFILE_AVATAR_16,
|
| - IDR_PROFILE_AVATAR_17,
|
| - IDR_PROFILE_AVATAR_18,
|
| - IDR_PROFILE_AVATAR_19,
|
| - IDR_PROFILE_AVATAR_20,
|
| - IDR_PROFILE_AVATAR_21,
|
| - IDR_PROFILE_AVATAR_22,
|
| - IDR_PROFILE_AVATAR_23,
|
| - IDR_PROFILE_AVATAR_24,
|
| - IDR_PROFILE_AVATAR_25,
|
| -};
|
| -
|
| -// File names for the high-res avatar icon resources. In the same order as
|
| -// the avatars in kDefaultAvatarIconResources.
|
| -const char* kDefaultAvatarIconResourceFileNames[] = {
|
| - "avatar_generic.png",
|
| - "avatar_generic_aqua.png",
|
| - "avatar_generic_blue.png",
|
| - "avatar_generic_green.png",
|
| - "avatar_generic_orange.png",
|
| - "avatar_generic_purple.png",
|
| - "avatar_generic_red.png",
|
| - "avatar_generic_yellow.png",
|
| - "avatar_secret_agent.png",
|
| - "avatar_superhero.png",
|
| - "avatar_volley_ball.png",
|
| - "avatar_businessman.png",
|
| - "avatar_ninja.png",
|
| - "avatar_alien.png",
|
| - "avatar_smiley.png",
|
| - "avatar_flower.png",
|
| - "avatar_pizza.png",
|
| - "avatar_soccer.png",
|
| - "avatar_burger.png",
|
| - "avatar_cat.png",
|
| - "avatar_cupcake.png",
|
| - "avatar_dog.png",
|
| - "avatar_horse.png",
|
| - "avatar_margarita.png",
|
| - "avatar_note.png",
|
| - "avatar_sun_cloud.png",
|
| -};
|
| -
|
| -const size_t kDefaultAvatarIconsCount = arraysize(kDefaultAvatarIconResources);
|
| -
|
| -// The first 8 icons are generic.
|
| -const size_t kGenericAvatarIconsCount = 8;
|
| -
|
| gfx::Image GetSizedAvatarIconWithBorder(const gfx::Image& image,
|
| bool is_rectangle,
|
| int width, int height) {
|
| @@ -338,6 +341,15 @@ const char* GetDefaultAvatarIconFileNameAtIndex(size_t index) {
|
| return kDefaultAvatarIconResourceFileNames[index];
|
| }
|
|
|
| +base::FilePath GetPathOfHighResAvatarAtIndex(size_t index) {
|
| + std::string file_name = kDefaultAvatarIconResourceFileNames[index];
|
| + base::FilePath user_data_dir;
|
| + PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
|
| + base::FilePath image_path = user_data_dir.AppendASCII(
|
| + kHighResAvatarFolderName).AppendASCII(file_name);
|
| + return image_path;
|
| +}
|
| +
|
| std::string GetDefaultAvatarIconUrl(size_t index) {
|
| DCHECK(IsDefaultAvatarIconIndex(index));
|
| return base::StringPrintf("%s%" PRIuS, kDefaultUrlPrefix, index);
|
|
|