[email protected] | 4b7a2aa | 2011-12-06 03:46:22 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
[email protected] | f7be2197b | 2010-04-23 00:20:44 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
pmonette | 23c8fb7e | 2016-06-27 20:45:11 | [diff] [blame] | 5 | #include "chrome/browser/win/app_icon.h" |
[email protected] | f7be2197b | 2010-04-23 00:20:44 | [diff] [blame] | 6 | |
[email protected] | f7be2197b | 2010-04-23 00:20:44 | [diff] [blame] | 7 | #include "chrome/common/chrome_constants.h" |
grt | 4d6747c | 2017-02-25 22:16:29 | [diff] [blame] | 8 | #include "chrome/install_static/install_details.h" |
[email protected] | be74fb5 | 2013-01-14 19:45:34 | [diff] [blame] | 9 | #include "third_party/skia/include/core/SkBitmap.h" |
mgiuca | 3e9e69dc | 2015-11-18 02:02:42 | [diff] [blame] | 10 | #include "ui/gfx/geometry/size.h" |
[email protected] | be74fb5 | 2013-01-14 19:45:34 | [diff] [blame] | 11 | #include "ui/gfx/icon_util.h" |
mgiuca | 3e9e69dc | 2015-11-18 02:02:42 | [diff] [blame] | 12 | #include "ui/gfx/image/image_family.h" |
[email protected] | f7be2197b | 2010-04-23 00:20:44 | [diff] [blame] | 13 | |
[email protected] | be74fb5 | 2013-01-14 19:45:34 | [diff] [blame] | 14 | namespace { |
| 15 | |
| 16 | // Returns the resource id of the application icon. |
| 17 | int GetAppIconResourceId() { |
grt | 4d6747c | 2017-02-25 22:16:29 | [diff] [blame] | 18 | return install_static::InstallDetails::Get().app_icon_resource_id(); |
[email protected] | be74fb5 | 2013-01-14 19:45:34 | [diff] [blame] | 19 | } |
| 20 | |
| 21 | } // namespace |
| 22 | |
| 23 | HICON GetAppIcon() { |
mgiuca | 3e9e69dc | 2015-11-18 02:02:42 | [diff] [blame] | 24 | // TODO(mgiuca): Use GetAppIconImageFamily/CreateExact instead of LoadIcon, to |
| 25 | // get correct scaling. (See http://crbug.com/551256) |
[email protected] | be74fb5 | 2013-01-14 19:45:34 | [diff] [blame] | 26 | const int icon_id = GetAppIconResourceId(); |
wfh | a7baf45d | 2015-04-22 00:04:20 | [diff] [blame] | 27 | // HICON returned from LoadIcon do not leak and do not have to be destroyed. |
[email protected] | f7be2197b | 2010-04-23 00:20:44 | [diff] [blame] | 28 | return LoadIcon(GetModuleHandle(chrome::kBrowserResourcesDll), |
| 29 | MAKEINTRESOURCE(icon_id)); |
| 30 | } |
[email protected] | 4b7a2aa | 2011-12-06 03:46:22 | [diff] [blame] | 31 | |
tmoniuszko | cd5b3ee | 2014-12-15 08:51:04 | [diff] [blame] | 32 | HICON GetSmallAppIcon() { |
mgiuca | 3e9e69dc | 2015-11-18 02:02:42 | [diff] [blame] | 33 | // TODO(mgiuca): Use GetAppIconImageFamily/CreateExact instead of LoadIcon, to |
| 34 | // get correct scaling. (See http://crbug.com/551256) |
tmoniuszko | cd5b3ee | 2014-12-15 08:51:04 | [diff] [blame] | 35 | const int icon_id = GetAppIconResourceId(); |
mgiuca | 3e9e69dc | 2015-11-18 02:02:42 | [diff] [blame] | 36 | gfx::Size size = GetSmallAppIconSize(); |
wfh | a7baf45d | 2015-04-22 00:04:20 | [diff] [blame] | 37 | // HICON returned from LoadImage must be released using DestroyIcon. |
tmoniuszko | cd5b3ee | 2014-12-15 08:51:04 | [diff] [blame] | 38 | return static_cast<HICON>(LoadImage( |
| 39 | GetModuleHandle(chrome::kBrowserResourcesDll), MAKEINTRESOURCE(icon_id), |
mgiuca | 3e9e69dc | 2015-11-18 02:02:42 | [diff] [blame] | 40 | IMAGE_ICON, size.width(), size.height(), LR_DEFAULTCOLOR | LR_SHARED)); |
tmoniuszko | cd5b3ee | 2014-12-15 08:51:04 | [diff] [blame] | 41 | } |
| 42 | |
mgiuca | 3e9e69dc | 2015-11-18 02:02:42 | [diff] [blame] | 43 | gfx::Size GetAppIconSize() { |
| 44 | return gfx::Size(GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON)); |
| 45 | } |
| 46 | |
| 47 | gfx::Size GetSmallAppIconSize() { |
| 48 | return gfx::Size(GetSystemMetrics(SM_CXSMICON), |
| 49 | GetSystemMetrics(SM_CYSMICON)); |
| 50 | } |
| 51 | |
dcheng | 4af4858 | 2016-04-19 00:29:35 | [diff] [blame] | 52 | std::unique_ptr<gfx::ImageFamily> GetAppIconImageFamily() { |
[email protected] | be74fb5 | 2013-01-14 19:45:34 | [diff] [blame] | 53 | const int icon_id = GetAppIconResourceId(); |
mgiuca | 3e9e69dc | 2015-11-18 02:02:42 | [diff] [blame] | 54 | // Get the icon from chrome.dll (not chrome.exe, which has different resource |
| 55 | // IDs). If chrome.dll is not loaded, we are probably in a unit test, so fall |
| 56 | // back to getting the icon from the current module (assuming it is |
| 57 | // unit_tests.exe, that has the same resource IDs as chrome.dll). |
| 58 | HMODULE module = GetModuleHandle(chrome::kBrowserResourcesDll); |
| 59 | if (!module) |
| 60 | module = GetModuleHandle(nullptr); |
| 61 | DCHECK(module); |
| 62 | |
| 63 | return IconUtil::CreateImageFamilyFromIconResource(module, icon_id); |
[email protected] | 4b7a2aa | 2011-12-06 03:46:22 | [diff] [blame] | 64 | } |