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

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

Issue 268073005: Bring back support for 38x31 avatars. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Refactor crop/squaring code into ProfileAvatarIconUtil Created 6 years, 7 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/file_util.h" 7 #include "base/file_util.h"
8 #include "base/format_macros.h" 8 #include "base/format_macros.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
11 #include "base/strings/string_number_conversions.h" 11 #include "base/strings/string_number_conversions.h"
12 #include "base/strings/stringprintf.h" 12 #include "base/strings/stringprintf.h"
13 #include "chrome/common/chrome_paths.h" 13 #include "chrome/common/chrome_paths.h"
14 #include "grit/generated_resources.h" 14 #include "grit/generated_resources.h"
15 #include "grit/theme_resources.h" 15 #include "grit/theme_resources.h"
16 #include "skia/ext/image_operations.h"
16 #include "third_party/skia/include/core/SkPaint.h" 17 #include "third_party/skia/include/core/SkPaint.h"
17 #include "third_party/skia/include/core/SkPath.h" 18 #include "third_party/skia/include/core/SkPath.h"
18 #include "third_party/skia/include/core/SkScalar.h" 19 #include "third_party/skia/include/core/SkScalar.h"
19 #include "third_party/skia/include/core/SkXfermode.h" 20 #include "third_party/skia/include/core/SkXfermode.h"
20 #include "ui/base/resource/resource_bundle.h" 21 #include "ui/base/resource/resource_bundle.h"
21 #include "ui/gfx/canvas.h" 22 #include "ui/gfx/canvas.h"
22 #include "ui/gfx/image/canvas_image_source.h" 23 #include "ui/gfx/image/canvas_image_source.h"
23 #include "ui/gfx/image/image.h" 24 #include "ui/gfx/image/image.h"
24 #include "ui/gfx/image/image_skia_operations.h" 25 #include "ui/gfx/image/image_skia_operations.h"
26 #include "ui/gfx/rect.h"
27 #include "ui/gfx/skia_util.h"
25 28
26 // Helper methods for transforming and drawing avatar icons. 29 // Helper methods for transforming and drawing avatar icons.
27 namespace { 30 namespace {
28 31
29 // Determine what the scaled height of the avatar icon should be for a 32 // Determine what the scaled height of the avatar icon should be for a
30 // specified width, to preserve the aspect ratio. 33 // specified width, to preserve the aspect ratio.
31 int GetScaledAvatarHeightForWidth(int width, const gfx::ImageSkia& avatar) { 34 int GetScaledAvatarHeightForWidth(int width, const gfx::ImageSkia& avatar) {
32 // Multiply the width by the inverted aspect ratio (height over 35 // Multiply the width by the inverted aspect ratio (height over
33 // width), and then add 0.5 to ensure the int truncation rounds nicely. 36 // width), and then add 0.5 to ensure the int truncation rounds nicely.
34 int scaled_height = width * 37 int scaled_height = width *
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 } // namespace 180 } // namespace
178 181
179 namespace profiles { 182 namespace profiles {
180 183
181 struct IconResourceInfo { 184 struct IconResourceInfo {
182 int resource_id; 185 int resource_id;
183 const char* filename; 186 const char* filename;
184 }; 187 };
185 188
186 const int kAvatarIconWidth = 38; 189 const int kAvatarIconWidth = 38;
187 const int kAvatarIconHeight = 38; 190 const int kAvatarIconHeight = 31;
188 const SkColor kAvatarTutorialBackgroundColor = SkColorSetRGB(0x42, 0x85, 0xf4); 191 const SkColor kAvatarTutorialBackgroundColor = SkColorSetRGB(0x42, 0x85, 0xf4);
189 const SkColor kAvatarTutorialContentTextColor = SkColorSetRGB(0xc6, 0xda, 0xfc); 192 const SkColor kAvatarTutorialContentTextColor = SkColorSetRGB(0xc6, 0xda, 0xfc);
190 const SkColor kAvatarBubbleAccountsBackgroundColor = 193 const SkColor kAvatarBubbleAccountsBackgroundColor =
191 SkColorSetRGB(0xf3, 0xf3, 0xf3); 194 SkColorSetRGB(0xf3, 0xf3, 0xf3);
192 195
193 const char kDefaultUrlPrefix[] = "chrome://theme/IDR_PROFILE_AVATAR_"; 196 const char kDefaultUrlPrefix[] = "chrome://theme/IDR_PROFILE_AVATAR_";
194 const char kGAIAPictureFileName[] = "Google Profile Picture.png"; 197 const char kGAIAPictureFileName[] = "Google Profile Picture.png";
195 const char kHighResAvatarFolderName[] = "Avatars"; 198 const char kHighResAvatarFolderName[] = "Avatars";
196 199
197 // This avatar does not exist on the server, the high res copy is in the build. 200 // This avatar does not exist on the server, the high res copy is in the build.
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 *image.ToImageSkia(), 260 *image.ToImageSkia(),
258 dst_size, 261 dst_size,
259 size, 262 size,
260 AvatarImageSource::POSITION_BOTTOM_CENTER, 263 AvatarImageSource::POSITION_BOTTOM_CENTER,
261 is_gaia_image ? AvatarImageSource::BORDER_ETCHED : 264 is_gaia_image ? AvatarImageSource::BORDER_ETCHED :
262 AvatarImageSource::BORDER_NONE)); 265 AvatarImageSource::BORDER_NONE));
263 266
264 return gfx::Image(gfx::ImageSkia(source.release(), dst_size)); 267 return gfx::Image(gfx::ImageSkia(source.release(), dst_size));
265 } 268 }
266 269
270 SkBitmap GetAvatarIconAsSquare(const SkBitmap& bitmap, int scale_factor) {
271 if ((bitmap.width() == scale_factor * profiles::kAvatarIconWidth) &&
272 (bitmap.height() == scale_factor * profiles::kAvatarIconHeight)) {
273 // Shave a couple of columns so the bitmap is more square. So when
274 // resized to a square aspect ratio it looks pretty.
275 SkBitmap cropped_bitmap;
276 gfx::Rect frame(scale_factor * profiles::kAvatarIconWidth,
277 scale_factor * profiles::kAvatarIconHeight);
278 frame.Inset(scale_factor * 2, 0, scale_factor * 2, 0);
279 bitmap.extractSubset(&cropped_bitmap, gfx::RectToSkIRect(frame));
280 return cropped_bitmap;
281 } else {
282 // If not the avatar icon's aspect ratio, the image should be square.
283 DCHECK(bitmap.width() == bitmap.height());
284 return bitmap;
285 }
286 }
287
267 // Helper methods for accessing, transforming and drawing avatar icons. 288 // Helper methods for accessing, transforming and drawing avatar icons.
268 size_t GetDefaultAvatarIconCount() { 289 size_t GetDefaultAvatarIconCount() {
269 return kDefaultAvatarIconsCount; 290 return kDefaultAvatarIconsCount;
270 } 291 }
271 292
272 size_t GetGenericAvatarIconCount() { 293 size_t GetGenericAvatarIconCount() {
273 return kGenericAvatarIconsCount; 294 return kGenericAvatarIconsCount;
274 } 295 }
275 296
276 int GetPlaceholderAvatarIndex() { 297 int GetPlaceholderAvatarIndex() {
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 int_value >= static_cast<int>(kDefaultAvatarIconsCount)) 380 int_value >= static_cast<int>(kDefaultAvatarIconsCount))
360 return false; 381 return false;
361 *icon_index = int_value; 382 *icon_index = int_value;
362 return true; 383 return true;
363 } 384 }
364 385
365 return false; 386 return false;
366 } 387 }
367 388
368 } // namespace profiles 389 } // namespace profiles
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698