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 GetAppIconImageFamily/CreateExact instead of LoadIcon, to | |
| 34 // get correct 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 GetAppIconImageFamily/CreateExact instead of LoadIcon, to | |
| 43 // get correct 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)); | |
| 44 } | 50 } |
| 45 | 51 |
| 46 scoped_ptr<SkBitmap> GetAppIconForSize(int size) { | 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() { | |
| 47 const int icon_id = GetAppIconResourceId(); | 62 const int icon_id = GetAppIconResourceId(); |
| 48 return IconUtil::CreateSkBitmapFromIconResource( | 63 // Get the icon from chrome.dll (not chrome.exe, which has different resource |
| 49 GetModuleHandle(chrome::kBrowserResourcesDll), icon_id, size); | 64 // IDs). If chrome.dll is not loaded, we are probably in a unit test, so fall |
| 65 // back to getting the icon from the current module (assuming it is | |
| 66 // unit_tests.exe, that has the same resource IDs as chrome.dll). | |
|
Nico
2015/11/16 19:04:28
why wasn't this needed previously? or am i just mi
Matt Giuca
2015/11/17 07:11:45
That's a great question. It took me some time to f
| |
| 67 HMODULE module = GetModuleHandle(chrome::kBrowserResourcesDll); | |
| 68 if (!module) | |
| 69 module = GetModuleHandle(nullptr); | |
| 70 DCHECK(module); | |
| 71 | |
| 72 return IconUtil::CreateImageFamilyFromIconResource(module, icon_id); | |
| 50 } | 73 } |
| OLD | NEW |