| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/app_icon_win.h" | |
| 6 | |
| 7 #include "chrome/app/chrome_dll_resource.h" | |
| 8 #include "chrome/common/chrome_constants.h" | |
| 9 #include "third_party/skia/include/core/SkBitmap.h" | |
| 10 #include "ui/gfx/geometry/size.h" | |
| 11 #include "ui/gfx/icon_util.h" | |
| 12 #include "ui/gfx/image/image_family.h" | |
| 13 | |
| 14 #if defined(GOOGLE_CHROME_BUILD) | |
| 15 #include "chrome/installer/util/install_util.h" | |
| 16 #endif | |
| 17 | |
| 18 namespace { | |
| 19 | |
| 20 // Returns the resource id of the application icon. | |
| 21 int GetAppIconResourceId() { | |
| 22 int icon_id = IDR_MAINFRAME; | |
| 23 #if defined(GOOGLE_CHROME_BUILD) | |
| 24 if (InstallUtil::IsChromeSxSProcess()) | |
| 25 icon_id = IDR_SXS; | |
| 26 #endif | |
| 27 return icon_id; | |
| 28 } | |
| 29 | |
| 30 } // namespace | |
| 31 | |
| 32 HICON GetAppIcon() { | |
| 33 // TODO(mgiuca): Use GetAppIconImageFamily/CreateExact instead of LoadIcon, to | |
| 34 // get correct scaling. (See http://crbug.com/551256) | |
| 35 const int icon_id = GetAppIconResourceId(); | |
| 36 // HICON returned from LoadIcon do not leak and do not have to be destroyed. | |
| 37 return LoadIcon(GetModuleHandle(chrome::kBrowserResourcesDll), | |
| 38 MAKEINTRESOURCE(icon_id)); | |
| 39 } | |
| 40 | |
| 41 HICON GetSmallAppIcon() { | |
| 42 // TODO(mgiuca): Use GetAppIconImageFamily/CreateExact instead of LoadIcon, to | |
| 43 // get correct scaling. (See http://crbug.com/551256) | |
| 44 const int icon_id = GetAppIconResourceId(); | |
| 45 gfx::Size size = GetSmallAppIconSize(); | |
| 46 // HICON returned from LoadImage must be released using DestroyIcon. | |
| 47 return static_cast<HICON>(LoadImage( | |
| 48 GetModuleHandle(chrome::kBrowserResourcesDll), MAKEINTRESOURCE(icon_id), | |
| 49 IMAGE_ICON, size.width(), size.height(), 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 std::unique_ptr<gfx::ImageFamily> GetAppIconImageFamily() { | |
| 62 const int icon_id = GetAppIconResourceId(); | |
| 63 // Get the icon from chrome.dll (not chrome.exe, which has different resource | |
| 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). | |
| 67 HMODULE module = GetModuleHandle(chrome::kBrowserResourcesDll); | |
| 68 if (!module) | |
| 69 module = GetModuleHandle(nullptr); | |
| 70 DCHECK(module); | |
| 71 | |
| 72 return IconUtil::CreateImageFamilyFromIconResource(module, icon_id); | |
| 73 } | |
| OLD | NEW |