Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/app_icon_win.h" | 5 #include "chrome/browser/app_icon_win.h" |
| 6 | 6 |
| 7 #include "chrome/app/chrome_dll_resource.h" | 7 #include "chrome/app/chrome_dll_resource.h" |
| 8 #include "chrome/common/chrome_constants.h" | 8 #include "chrome/common/chrome_constants.h" |
| 9 #include "third_party/skia/include/core/SkBitmap.h" | 9 #include "third_party/skia/include/core/SkBitmap.h" |
| 10 #include "ui/gfx/geometry/size.h" | |
| 10 #include "ui/gfx/icon_util.h" | 11 #include "ui/gfx/icon_util.h" |
| 12 #include "ui/gfx/image/image_family.h" | |
| 11 | 13 |
| 12 #if defined(GOOGLE_CHROME_BUILD) | 14 #if defined(GOOGLE_CHROME_BUILD) |
| 13 #include "chrome/installer/util/install_util.h" | 15 #include "chrome/installer/util/install_util.h" |
| 14 #endif | 16 #endif |
| 15 | 17 |
| 16 namespace { | 18 namespace { |
| 17 | 19 |
| 18 // Returns the resource id of the application icon. | 20 // Returns the resource id of the application icon. |
| 19 int GetAppIconResourceId() { | 21 int GetAppIconResourceId() { |
| 20 int icon_id = IDR_MAINFRAME; | 22 int icon_id = IDR_MAINFRAME; |
| 21 #if defined(GOOGLE_CHROME_BUILD) | 23 #if defined(GOOGLE_CHROME_BUILD) |
| 22 if (InstallUtil::IsChromeSxSProcess()) | 24 if (InstallUtil::IsChromeSxSProcess()) |
| 23 icon_id = IDR_SXS; | 25 icon_id = IDR_SXS; |
| 24 #endif | 26 #endif |
| 25 return icon_id; | 27 return icon_id; |
| 26 } | 28 } |
| 27 | 29 |
| 28 } // namespace | 30 } // namespace |
| 29 | 31 |
| 30 HICON GetAppIcon() { | 32 HICON GetAppIcon() { |
| 33 // TODO(mgiuca): Use GetAppIconForSize instead of LoadIcon, to get correct | |
| 34 // scaling. (See http://crbug.com/551256) | |
| 31 const int icon_id = GetAppIconResourceId(); | 35 const int icon_id = GetAppIconResourceId(); |
| 32 // HICON returned from LoadIcon do not leak and do not have to be destroyed. | 36 // HICON returned from LoadIcon do not leak and do not have to be destroyed. |
| 33 return LoadIcon(GetModuleHandle(chrome::kBrowserResourcesDll), | 37 return LoadIcon(GetModuleHandle(chrome::kBrowserResourcesDll), |
| 34 MAKEINTRESOURCE(icon_id)); | 38 MAKEINTRESOURCE(icon_id)); |
| 35 } | 39 } |
| 36 | 40 |
| 37 HICON GetSmallAppIcon() { | 41 HICON GetSmallAppIcon() { |
| 42 // TODO(mgiuca): Use GetAppIconForSize instead of LoadImage, to get correct | |
| 43 // scaling. (See http://crbug.com/551256) | |
| 38 const int icon_id = GetAppIconResourceId(); | 44 const int icon_id = GetAppIconResourceId(); |
| 45 gfx::Size size = GetSmallAppIconSize(); | |
| 39 // HICON returned from LoadImage must be released using DestroyIcon. | 46 // HICON returned from LoadImage must be released using DestroyIcon. |
| 40 return static_cast<HICON>(LoadImage( | 47 return static_cast<HICON>(LoadImage( |
| 41 GetModuleHandle(chrome::kBrowserResourcesDll), MAKEINTRESOURCE(icon_id), | 48 GetModuleHandle(chrome::kBrowserResourcesDll), MAKEINTRESOURCE(icon_id), |
| 42 IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), | 49 IMAGE_ICON, size.width(), size.height(), LR_DEFAULTCOLOR | LR_SHARED)); |
| 43 LR_DEFAULTCOLOR | LR_SHARED)); | 50 } |
| 51 | |
| 52 gfx::Size GetAppIconSize() { | |
| 53 return gfx::Size(GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON)); | |
| 54 } | |
| 55 | |
| 56 gfx::Size GetSmallAppIconSize() { | |
| 57 return gfx::Size(GetSystemMetrics(SM_CXSMICON), | |
| 58 GetSystemMetrics(SM_CYSMICON)); | |
| 59 } | |
| 60 | |
| 61 scoped_ptr<gfx::ImageFamily> GetAppIconImageFamily() { | |
| 62 const int icon_id = GetAppIconResourceId(); | |
| 63 return IconUtil::CreateImageFamilyFromIconResource( | |
| 64 GetModuleHandle(chrome::kBrowserResourcesDll), icon_id); | |
| 65 } | |
| 66 | |
| 67 scoped_ptr<SkBitmap> GetAppIconForSize(const gfx::Size& size) { | |
| 68 scoped_ptr<gfx::ImageFamily> family = GetAppIconImageFamily(); | |
| 69 if (!family) | |
| 70 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.
| |
| 71 | |
| 72 // Note: We could just use the LoadImage function from the Windows API, but | |
| 73 // that does a *terrible* job scaling images. Therefore, we fetch the original | |
| 74 // images and do our own high-quality scaling. | |
| 75 gfx::Image image = family->CreateExact(size); | |
| 76 return make_scoped_ptr(new SkBitmap(image.AsBitmap())); | |
| 44 } | 77 } |
| 45 | 78 |
| 46 scoped_ptr<SkBitmap> GetAppIconForSize(int size) { | 79 scoped_ptr<SkBitmap> GetAppIconForSize(int size) { |
| 47 const int icon_id = GetAppIconResourceId(); | 80 return GetAppIconForSize(gfx::Size(size, size)); |
| 48 return IconUtil::CreateSkBitmapFromIconResource( | |
| 49 GetModuleHandle(chrome::kBrowserResourcesDll), icon_id, size); | |
| 50 } | 81 } |
| OLD | NEW |