Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(34)

Side by Side Diff: chrome/browser/profiles/profile_avatar_icon_util.cc

Issue 212603011: Newly created profiles should have the grey silhouette as avatar. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase reviewed Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 169
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 struct IconResourceInfo {
180 int resource_id;
181 const char* filename;
182 };
183
179 const int kAvatarIconWidth = 38; 184 const int kAvatarIconWidth = 38;
180 const int kAvatarIconHeight = 31; 185 const int kAvatarIconHeight = 38;
181 const int kAvatarIconPadding = 2; 186 const int kAvatarIconPadding = 2;
182 const SkColor kAvatarTutorialBackgroundColor = SkColorSetRGB(0x42, 0x85, 0xf4); 187 const SkColor kAvatarTutorialBackgroundColor = SkColorSetRGB(0x42, 0x85, 0xf4);
183 const SkColor kAvatarTutorialContentTextColor = SkColorSetRGB(0xc6, 0xda, 0xfc); 188 const SkColor kAvatarTutorialContentTextColor = SkColorSetRGB(0xc6, 0xda, 0xfc);
184 const SkColor kAvatarBubbleAccountsBackgroundColor = 189 const SkColor kAvatarBubbleAccountsBackgroundColor =
185 SkColorSetRGB(0xf3, 0xf3, 0xf3); 190 SkColorSetRGB(0xf3, 0xf3, 0xf3);
186 191
187 const char kDefaultUrlPrefix[] = "chrome://theme/IDR_PROFILE_AVATAR_"; 192 const char kDefaultUrlPrefix[] = "chrome://theme/IDR_PROFILE_AVATAR_";
188 const char kGAIAPictureFileName[] = "Google Profile Picture.png"; 193 const char kGAIAPictureFileName[] = "Google Profile Picture.png";
189 const char kHighResAvatarFolderName[] = "Avatars"; 194 const char kHighResAvatarFolderName[] = "Avatars";
190 195
191 const int kDefaultAvatarIconResources[] = { 196 // This avatar does not exist on the server, the high res copy is in the build.
192 IDR_PROFILE_AVATAR_0, 197 const char kNoHighResAvatar[] = "NothingToDownload";
193 IDR_PROFILE_AVATAR_1,
194 IDR_PROFILE_AVATAR_2,
195 IDR_PROFILE_AVATAR_3,
196 IDR_PROFILE_AVATAR_4,
197 IDR_PROFILE_AVATAR_5,
198 IDR_PROFILE_AVATAR_6,
199 IDR_PROFILE_AVATAR_7,
200 IDR_PROFILE_AVATAR_8,
201 IDR_PROFILE_AVATAR_9,
202 IDR_PROFILE_AVATAR_10,
203 IDR_PROFILE_AVATAR_11,
204 IDR_PROFILE_AVATAR_12,
205 IDR_PROFILE_AVATAR_13,
206 IDR_PROFILE_AVATAR_14,
207 IDR_PROFILE_AVATAR_15,
208 IDR_PROFILE_AVATAR_16,
209 IDR_PROFILE_AVATAR_17,
210 IDR_PROFILE_AVATAR_18,
211 IDR_PROFILE_AVATAR_19,
212 IDR_PROFILE_AVATAR_20,
213 IDR_PROFILE_AVATAR_21,
214 IDR_PROFILE_AVATAR_22,
215 IDR_PROFILE_AVATAR_23,
216 IDR_PROFILE_AVATAR_24,
217 IDR_PROFILE_AVATAR_25,
218 };
219 198
220 // File names for the high-res avatar icon resources. In the same order as 199 // The size of the function-static kDefaultAvatarIconResources array below.
221 // the avatars in kDefaultAvatarIconResources. 200 const size_t kDefaultAvatarIconsCount = 27;
222 const char* kDefaultAvatarIconResourceFileNames[] = {
223 "avatar_generic.png",
224 "avatar_generic_aqua.png",
225 "avatar_generic_blue.png",
226 "avatar_generic_green.png",
227 "avatar_generic_orange.png",
228 "avatar_generic_purple.png",
229 "avatar_generic_red.png",
230 "avatar_generic_yellow.png",
231 "avatar_secret_agent.png",
232 "avatar_superhero.png",
233 "avatar_volley_ball.png",
234 "avatar_businessman.png",
235 "avatar_ninja.png",
236 "avatar_alien.png",
237 "avatar_smiley.png",
238 "avatar_flower.png",
239 "avatar_pizza.png",
240 "avatar_soccer.png",
241 "avatar_burger.png",
242 "avatar_cat.png",
243 "avatar_cupcake.png",
244 "avatar_dog.png",
245 "avatar_horse.png",
246 "avatar_margarita.png",
247 "avatar_note.png",
248 "avatar_sun_cloud.png",
249 };
250
251 const size_t kDefaultAvatarIconsCount = arraysize(kDefaultAvatarIconResources);
252 201
253 // The first 8 icons are generic. 202 // The first 8 icons are generic.
254 const size_t kGenericAvatarIconsCount = 8; 203 const size_t kGenericAvatarIconsCount = 8;
255 204
205 // The avatar used as a placeholder (grey silhouette).
206 const int kPlaceholderAvatarIcon = 26;
207
256 gfx::Image GetSizedAvatarIcon(const gfx::Image& image, 208 gfx::Image GetSizedAvatarIcon(const gfx::Image& image,
257 bool is_rectangle, 209 bool is_rectangle,
258 int width, int height) { 210 int width, int height) {
259 if (!is_rectangle) 211 if (!is_rectangle && image.Height() <= height)
260 return image; 212 return image;
261 213
262 gfx::Size size(width, height); 214 gfx::Size size(width, height);
263 215
264 // Source for a centered, sized icon with a border. 216 // Source for a centered, sized icon. GAIA images get a border.
265 scoped_ptr<gfx::ImageSkiaSource> source( 217 scoped_ptr<gfx::ImageSkiaSource> source(
266 new AvatarImageSource( 218 new AvatarImageSource(
267 *image.ToImageSkia(), 219 *image.ToImageSkia(),
268 size, 220 size,
269 std::min(width, height), 221 std::min(width, height),
270 AvatarImageSource::POSITION_CENTER, 222 AvatarImageSource::POSITION_CENTER,
271 AvatarImageSource::BORDER_NONE)); 223 is_rectangle ? AvatarImageSource::BORDER_NORMAL :
224 AvatarImageSource::BORDER_NONE));
272 225
273 return gfx::Image(gfx::ImageSkia(source.release(), size)); 226 return gfx::Image(gfx::ImageSkia(source.release(), size));
274 } 227 }
275 228
276 gfx::Image GetAvatarIconForMenu(const gfx::Image& image, 229 gfx::Image GetAvatarIconForMenu(const gfx::Image& image,
277 bool is_rectangle) { 230 bool is_rectangle) {
278 return GetSizedAvatarIcon( 231 return GetSizedAvatarIcon(
279 image, is_rectangle, kAvatarIconWidth, kAvatarIconHeight); 232 image, is_rectangle, kAvatarIconWidth, kAvatarIconHeight);
280 } 233 }
281 234
282 gfx::Image GetAvatarIconForWebUI(const gfx::Image& image, 235 gfx::Image GetAvatarIconForWebUI(const gfx::Image& image,
283 bool is_rectangle) { 236 bool is_rectangle) {
284 return GetSizedAvatarIcon(image, is_rectangle, 237 return GetSizedAvatarIcon(image, is_rectangle,
285 kAvatarIconWidth, kAvatarIconHeight); 238 kAvatarIconWidth, kAvatarIconHeight);
286 } 239 }
287 240
288 gfx::Image GetAvatarIconForTitleBar(const gfx::Image& image, 241 gfx::Image GetAvatarIconForTitleBar(const gfx::Image& image,
289 bool is_rectangle, 242 bool is_gaia_image,
290 int dst_width, 243 int dst_width,
291 int dst_height) { 244 int dst_height) {
292 if (!is_rectangle) 245 // The image requires no border or resizing.
246 if (!is_gaia_image && image.Height() <= kAvatarIconHeight)
293 return image; 247 return image;
294 248
295 int size = std::min(std::min(kAvatarIconWidth, kAvatarIconHeight), 249 int size = std::min(std::min(kAvatarIconWidth, kAvatarIconHeight),
296 std::min(dst_width, dst_height)); 250 std::min(dst_width, dst_height));
297 gfx::Size dst_size(dst_width, dst_height); 251 gfx::Size dst_size(dst_width, dst_height);
298 252
299 // Source for a sized icon drawn at the bottom center of the canvas, 253 // Source for a sized icon drawn at the bottom center of the canvas,
300 // with an etched border. 254 // with an etched border (for GAIA images).
301 scoped_ptr<gfx::ImageSkiaSource> source( 255 scoped_ptr<gfx::ImageSkiaSource> source(
302 new AvatarImageSource( 256 new AvatarImageSource(
303 *image.ToImageSkia(), 257 *image.ToImageSkia(),
304 dst_size, 258 dst_size,
305 size, 259 size,
306 AvatarImageSource::POSITION_BOTTOM_CENTER, 260 AvatarImageSource::POSITION_BOTTOM_CENTER,
307 AvatarImageSource::BORDER_ETCHED)); 261 is_gaia_image ? AvatarImageSource::BORDER_ETCHED :
262 AvatarImageSource::BORDER_NONE));
308 263
309 return gfx::Image(gfx::ImageSkia(source.release(), dst_size)); 264 return gfx::Image(gfx::ImageSkia(source.release(), dst_size));
310 } 265 }
311 266
312 // Helper methods for accessing, transforming and drawing avatar icons. 267 // Helper methods for accessing, transforming and drawing avatar icons.
313 size_t GetDefaultAvatarIconCount() { 268 size_t GetDefaultAvatarIconCount() {
314 return kDefaultAvatarIconsCount; 269 return kDefaultAvatarIconsCount;
315 } 270 }
316 271
317 size_t GetGenericAvatarIconCount() { 272 size_t GetGenericAvatarIconCount() {
318 return kGenericAvatarIconsCount; 273 return kGenericAvatarIconsCount;
319 } 274 }
320 275
276 int GetPlaceholderAvatarIndex() {
277 return kPlaceholderAvatarIcon;
278 }
279
280 int GetPlaceholderAvatarIconResourceID() {
281 return IDR_PROFILE_AVATAR_26;
282 }
283
284 const IconResourceInfo* GetDefaultAvatarIconResourceInfo(size_t index) {
285 static const IconResourceInfo resource_info[kDefaultAvatarIconsCount] = {
286 { IDR_PROFILE_AVATAR_0, "avatar_generic.png"},
287 { IDR_PROFILE_AVATAR_1, "avatar_generic_aqua.png"},
288 { IDR_PROFILE_AVATAR_2, "avatar_generic_blue.png"},
289 { IDR_PROFILE_AVATAR_3, "avatar_generic_green.png"},
290 { IDR_PROFILE_AVATAR_4, "avatar_generic_orange.png"},
291 { IDR_PROFILE_AVATAR_5, "avatar_generic_purple.png"},
292 { IDR_PROFILE_AVATAR_6, "avatar_generic_red.png"},
293 { IDR_PROFILE_AVATAR_7, "avatar_generic_yellow.png"},
294 { IDR_PROFILE_AVATAR_8, "avatar_secret_agent.png"},
295 { IDR_PROFILE_AVATAR_9, "avatar_superhero.png"},
296 { IDR_PROFILE_AVATAR_10, "avatar_volley_ball.png"},
297 { IDR_PROFILE_AVATAR_11, "avatar_businessman.png"},
298 { IDR_PROFILE_AVATAR_12, "avatar_ninja.png"},
299 { IDR_PROFILE_AVATAR_13, "avatar_alien.png"},
300 { IDR_PROFILE_AVATAR_14, "avatar_smiley.png"},
301 { IDR_PROFILE_AVATAR_15, "avatar_flower.png"},
302 { IDR_PROFILE_AVATAR_16, "avatar_pizza.png"},
303 { IDR_PROFILE_AVATAR_17, "avatar_soccer.png"},
304 { IDR_PROFILE_AVATAR_18, "avatar_burger.png"},
305 { IDR_PROFILE_AVATAR_19, "avatar_cat.png"},
306 { IDR_PROFILE_AVATAR_20, "avatar_cupcake.png"},
307 { IDR_PROFILE_AVATAR_21, "avatar_dog.png"},
308 { IDR_PROFILE_AVATAR_22, "avatar_horse.png"},
309 { IDR_PROFILE_AVATAR_23, "avatar_margarita.png"},
310 { IDR_PROFILE_AVATAR_24, "avatar_note.png"},
311 { IDR_PROFILE_AVATAR_25, "avatar_sun_cloud.png"},
312 { IDR_PROFILE_AVATAR_26, kNoHighResAvatar},
313 };
314 return &resource_info[index];
315 }
316
321 int GetDefaultAvatarIconResourceIDAtIndex(size_t index) { 317 int GetDefaultAvatarIconResourceIDAtIndex(size_t index) {
322 DCHECK(IsDefaultAvatarIconIndex(index)); 318 DCHECK(IsDefaultAvatarIconIndex(index));
323 return kDefaultAvatarIconResources[index]; 319 return GetDefaultAvatarIconResourceInfo(index)->resource_id;
324 } 320 }
325 321
326 const char* GetDefaultAvatarIconFileNameAtIndex(size_t index) { 322 const char* GetDefaultAvatarIconFileNameAtIndex(size_t index) {
327 return kDefaultAvatarIconResourceFileNames[index]; 323 DCHECK(index < kDefaultAvatarIconsCount);
324 return GetDefaultAvatarIconResourceInfo(index)->filename;
325 }
326
327 const char* GetNoHighResAvatarFileName() {
328 return kNoHighResAvatar;
328 } 329 }
329 330
330 std::string GetDefaultAvatarIconUrl(size_t index) { 331 std::string GetDefaultAvatarIconUrl(size_t index) {
331 DCHECK(IsDefaultAvatarIconIndex(index)); 332 DCHECK(IsDefaultAvatarIconIndex(index));
332 return base::StringPrintf("%s%" PRIuS, kDefaultUrlPrefix, index); 333 return base::StringPrintf("%s%" PRIuS, kDefaultUrlPrefix, index);
333 } 334 }
334 335
335 bool IsDefaultAvatarIconIndex(size_t index) { 336 bool IsDefaultAvatarIconIndex(size_t index) {
336 return index < kDefaultAvatarIconsCount; 337 return index < kDefaultAvatarIconsCount;
337 } 338 }
(...skipping 13 matching lines...) Expand all
351 int_value >= static_cast<int>(kDefaultAvatarIconsCount)) 352 int_value >= static_cast<int>(kDefaultAvatarIconsCount))
352 return false; 353 return false;
353 *icon_index = int_value; 354 *icon_index = int_value;
354 return true; 355 return true;
355 } 356 }
356 357
357 return false; 358 return false;
358 } 359 }
359 360
360 } // namespace profiles 361 } // namespace profiles
OLDNEW
« no previous file with comments | « chrome/browser/profiles/profile_avatar_icon_util.h ('k') | chrome/browser/profiles/profile_info_cache.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698