Chromium Code Reviews| Index: chrome/browser/app_icon_win.cc |
| diff --git a/chrome/browser/app_icon_win.cc b/chrome/browser/app_icon_win.cc |
| index 6f1424e4977b5c54e3ad1045be78dc010264c421..1fbd70726b60b3129ec1307379adc921409aaddf 100644 |
| --- a/chrome/browser/app_icon_win.cc |
| +++ b/chrome/browser/app_icon_win.cc |
| @@ -7,7 +7,9 @@ |
| #include "chrome/app/chrome_dll_resource.h" |
| #include "chrome/common/chrome_constants.h" |
| #include "third_party/skia/include/core/SkBitmap.h" |
| +#include "ui/gfx/geometry/size.h" |
| #include "ui/gfx/icon_util.h" |
| +#include "ui/gfx/image/image_family.h" |
| #if defined(GOOGLE_CHROME_BUILD) |
| #include "chrome/installer/util/install_util.h" |
| @@ -28,6 +30,8 @@ int GetAppIconResourceId() { |
| } // namespace |
| HICON GetAppIcon() { |
| + // TODO(mgiuca): Use GetAppIconForSize instead of LoadIcon, to get correct |
| + // scaling. (See http://crbug.com/551256) |
| const int icon_id = GetAppIconResourceId(); |
| // HICON returned from LoadIcon do not leak and do not have to be destroyed. |
| return LoadIcon(GetModuleHandle(chrome::kBrowserResourcesDll), |
| @@ -35,16 +39,43 @@ HICON GetAppIcon() { |
| } |
| HICON GetSmallAppIcon() { |
| + // TODO(mgiuca): Use GetAppIconForSize instead of LoadImage, to get correct |
| + // scaling. (See http://crbug.com/551256) |
| const int icon_id = GetAppIconResourceId(); |
| + gfx::Size size = GetSmallAppIconSize(); |
| // HICON returned from LoadImage must be released using DestroyIcon. |
| return static_cast<HICON>(LoadImage( |
| GetModuleHandle(chrome::kBrowserResourcesDll), MAKEINTRESOURCE(icon_id), |
| - IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), |
| - LR_DEFAULTCOLOR | LR_SHARED)); |
| + IMAGE_ICON, size.width(), size.height(), LR_DEFAULTCOLOR | LR_SHARED)); |
| } |
| -scoped_ptr<SkBitmap> GetAppIconForSize(int size) { |
| +gfx::Size GetAppIconSize() { |
| + return gfx::Size(GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON)); |
| +} |
| + |
| +gfx::Size GetSmallAppIconSize() { |
| + return gfx::Size(GetSystemMetrics(SM_CXSMICON), |
| + GetSystemMetrics(SM_CYSMICON)); |
| +} |
| + |
| +scoped_ptr<gfx::ImageFamily> GetAppIconImageFamily() { |
| const int icon_id = GetAppIconResourceId(); |
| - return IconUtil::CreateSkBitmapFromIconResource( |
| - GetModuleHandle(chrome::kBrowserResourcesDll), icon_id, size); |
| + return IconUtil::CreateImageFamilyFromIconResource( |
| + GetModuleHandle(chrome::kBrowserResourcesDll), icon_id); |
| +} |
| + |
| +scoped_ptr<SkBitmap> GetAppIconForSize(const gfx::Size& size) { |
| + scoped_ptr<gfx::ImageFamily> family = GetAppIconImageFamily(); |
| + if (!family) |
| + return make_scoped_ptr(new SkBitmap); |
|
calamity
2015/11/09 02:12:11
nit: Why not just return an empty scoped_ptr?
Matt Giuca
2015/11/10 06:56:53
Done.
|
| + |
| + // Note: We could just use the LoadImage function from the Windows API, but |
| + // that does a *terrible* job scaling images. Therefore, we fetch the original |
| + // images and do our own high-quality scaling. |
| + gfx::Image image = family->CreateExact(size); |
| + return make_scoped_ptr(new SkBitmap(image.AsBitmap())); |
| +} |
| + |
| +scoped_ptr<SkBitmap> GetAppIconForSize(int size) { |
| + return GetAppIconForSize(gfx::Size(size, size)); |
| } |