Chromium Code Reviews| 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_shortcut_manager_win.h" | 5 #include "chrome/browser/profiles/profile_shortcut_manager_win.h" |
| 6 | 6 |
| 7 #include <shlobj.h> // For SHChangeNotify(). | 7 #include <shlobj.h> // For SHChangeNotify(). |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 65 // differently than it was when a shortcut was originally created. | 65 // differently than it was when a shortcut was originally created. |
| 66 const int kMaxProfileShortcutFileNameLength = 64; | 66 const int kMaxProfileShortcutFileNameLength = 64; |
| 67 | 67 |
| 68 // The avatar badge size needs to be half of the shortcut icon size because | 68 // The avatar badge size needs to be half of the shortcut icon size because |
| 69 // the Windows taskbar icon is 32x32 and the avatar icon overlay is 16x16. So to | 69 // the Windows taskbar icon is 32x32 and the avatar icon overlay is 16x16. So to |
| 70 // get the shortcut avatar badge and the avatar icon overlay to match up, we | 70 // get the shortcut avatar badge and the avatar icon overlay to match up, we |
| 71 // need to preserve those ratios when creating the shortcut icon. | 71 // need to preserve those ratios when creating the shortcut icon. |
| 72 const int kShortcutIconSize = 48; | 72 const int kShortcutIconSize = 48; |
| 73 const int kProfileAvatarBadgeSize = kShortcutIconSize / 2; | 73 const int kProfileAvatarBadgeSize = kShortcutIconSize / 2; |
| 74 | 74 |
| 75 const int kCurrentProfileIconVersion = 2; | 75 const int kCurrentProfileIconVersion = 2; |
|
gab
2014/05/05 22:58:09
As calamity@ mentioned on issue 369495, you should
noms (inactive)
2014/05/06 00:30:03
Gab: Mike is actually reverting to the status quo
gab
2014/05/06 18:34:59
Ah ok, ignore me then :)! Thanks!
| |
| 76 | 76 |
| 77 // 2x sized profile avatar icons. Mirrors |kDefaultAvatarIconResources| in | 77 // 2x sized profile avatar icons. Mirrors |kDefaultAvatarIconResources| in |
| 78 // profile_info_cache.cc. | 78 // profile_info_cache.cc. |
| 79 const int kProfileAvatarIconResources2x[] = { | 79 const int kProfileAvatarIconResources2x[] = { |
| 80 IDR_PROFILE_AVATAR_2X_0, | 80 IDR_PROFILE_AVATAR_2X_0, |
| 81 IDR_PROFILE_AVATAR_2X_1, | 81 IDR_PROFILE_AVATAR_2X_1, |
| 82 IDR_PROFILE_AVATAR_2X_2, | 82 IDR_PROFILE_AVATAR_2X_2, |
| 83 IDR_PROFILE_AVATAR_2X_3, | 83 IDR_PROFILE_AVATAR_2X_3, |
| 84 IDR_PROFILE_AVATAR_2X_4, | 84 IDR_PROFILE_AVATAR_2X_4, |
| 85 IDR_PROFILE_AVATAR_2X_5, | 85 IDR_PROFILE_AVATAR_2X_5, |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 104 IDR_PROFILE_AVATAR_2X_24, | 104 IDR_PROFILE_AVATAR_2X_24, |
| 105 IDR_PROFILE_AVATAR_2X_25, | 105 IDR_PROFILE_AVATAR_2X_25, |
| 106 IDR_PROFILE_AVATAR_2X_26, | 106 IDR_PROFILE_AVATAR_2X_26, |
| 107 }; | 107 }; |
| 108 | 108 |
| 109 // Badges |app_icon_bitmap| with |avatar_bitmap| at the bottom right corner and | 109 // Badges |app_icon_bitmap| with |avatar_bitmap| at the bottom right corner and |
| 110 // returns the resulting SkBitmap. | 110 // returns the resulting SkBitmap. |
| 111 SkBitmap BadgeIcon(const SkBitmap& app_icon_bitmap, | 111 SkBitmap BadgeIcon(const SkBitmap& app_icon_bitmap, |
| 112 const SkBitmap& avatar_bitmap, | 112 const SkBitmap& avatar_bitmap, |
| 113 int scale_factor) { | 113 int scale_factor) { |
| 114 // All icons, whether cartoon, GAIA or placeholder, should be square. | 114 // TODO(rlp): Share this chunk of code with |
| 115 // TODO(mlerman) - uncomment the ASSERT once noms@ lands the square images. | 115 // avatar_menu_button::DrawTaskBarDecoration. |
|
noms (inactive)
2014/05/05 16:10:53
Can we address this TODO? Maybe move the function
Mike Lerman
2014/05/06 12:43:15
Done, refactored the code into profile_avatar_icon
| |
| 116 // DCHECK(avatar_bitmap.width() == avatar_bitmap.height()); | 116 SkBitmap source_bitmap = avatar_bitmap; |
| 117 if ((avatar_bitmap.width() == scale_factor * profiles::kAvatarIconWidth) && | |
| 118 (avatar_bitmap.height() == scale_factor * profiles::kAvatarIconHeight)) { | |
| 119 // Shave a couple of columns so the bitmap is more square. So when | |
| 120 // resized to a square aspect ratio it looks pretty. | |
| 121 gfx::Rect frame(scale_factor * profiles::kAvatarIconWidth, | |
| 122 scale_factor * profiles::kAvatarIconHeight); | |
| 123 frame.Inset(scale_factor * 2, 0, scale_factor * 2, 0); | |
| 124 avatar_bitmap.extractSubset(&source_bitmap, gfx::RectToSkIRect(frame)); | |
| 125 } else { | |
| 126 // If not the icon's aspect ratio, the image should be square. | |
| 127 DCHECK(avatar_bitmap.width() == avatar_bitmap.height()); | |
| 128 } | |
| 117 | 129 |
| 118 int avatar_badge_size = kProfileAvatarBadgeSize; | 130 int avatar_badge_size = kProfileAvatarBadgeSize; |
| 119 if (app_icon_bitmap.width() != kShortcutIconSize) { | 131 if (app_icon_bitmap.width() != kShortcutIconSize) { |
| 120 avatar_badge_size = | 132 avatar_badge_size = |
| 121 app_icon_bitmap.width() * kProfileAvatarBadgeSize / kShortcutIconSize; | 133 app_icon_bitmap.width() * kProfileAvatarBadgeSize / kShortcutIconSize; |
| 122 } | 134 } |
| 123 SkBitmap sk_icon = skia::ImageOperations::Resize( | 135 SkBitmap sk_icon = skia::ImageOperations::Resize( |
| 124 avatar_bitmap, skia::ImageOperations::RESIZE_LANCZOS3, avatar_badge_size, | 136 source_bitmap, skia::ImageOperations::RESIZE_LANCZOS3, avatar_badge_size, |
| 125 avatar_bitmap.height() * avatar_badge_size / avatar_bitmap.width()); | 137 source_bitmap.height() * avatar_badge_size / source_bitmap.width()); |
| 126 | 138 |
| 127 // Overlay the avatar on the icon, anchoring it to the bottom-right of the | 139 // Overlay the avatar on the icon, anchoring it to the bottom-right of the |
| 128 // icon. | 140 // icon. |
| 129 SkBitmap badged_bitmap; | 141 SkBitmap badged_bitmap; |
| 130 badged_bitmap.allocN32Pixels(app_icon_bitmap.width(), | 142 badged_bitmap.allocN32Pixels(app_icon_bitmap.width(), |
| 131 app_icon_bitmap.height()); | 143 app_icon_bitmap.height()); |
| 132 SkCanvas offscreen_canvas(badged_bitmap); | 144 SkCanvas offscreen_canvas(badged_bitmap); |
| 133 offscreen_canvas.clear(SK_ColorTRANSPARENT); | 145 offscreen_canvas.clear(SK_ColorTRANSPARENT); |
| 134 | 146 |
| 135 offscreen_canvas.drawBitmap(app_icon_bitmap, 0, 0); | 147 offscreen_canvas.drawBitmap(app_icon_bitmap, 0, 0); |
| (...skipping 707 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 843 // Ensure the profile's icon file has been created. | 855 // Ensure the profile's icon file has been created. |
| 844 CreateOrUpdateProfileIcon(profile->GetPath()); | 856 CreateOrUpdateProfileIcon(profile->GetPath()); |
| 845 } | 857 } |
| 846 break; | 858 break; |
| 847 } | 859 } |
| 848 default: | 860 default: |
| 849 NOTREACHED(); | 861 NOTREACHED(); |
| 850 break; | 862 break; |
| 851 } | 863 } |
| 852 } | 864 } |
| OLD | NEW |