blob: ab3d600a5ffaaca6019972c1cf7f69b11f782fd9 [file] [log] [blame]
[email protected]4b7a2aa2011-12-06 03:46:221// Copyright (c) 2011 The Chromium Authors. All rights reserved.
[email protected]f7be2197b2010-04-23 00:20:442// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
pmonette23c8fb7e2016-06-27 20:45:115#include "chrome/browser/win/app_icon.h"
[email protected]f7be2197b2010-04-23 00:20:446
[email protected]f7be2197b2010-04-23 00:20:447#include "chrome/common/chrome_constants.h"
grt4d6747c2017-02-25 22:16:298#include "chrome/install_static/install_details.h"
[email protected]be74fb52013-01-14 19:45:349#include "third_party/skia/include/core/SkBitmap.h"
mgiuca3e9e69dc2015-11-18 02:02:4210#include "ui/gfx/geometry/size.h"
[email protected]be74fb52013-01-14 19:45:3411#include "ui/gfx/icon_util.h"
mgiuca3e9e69dc2015-11-18 02:02:4212#include "ui/gfx/image/image_family.h"
[email protected]f7be2197b2010-04-23 00:20:4413
[email protected]be74fb52013-01-14 19:45:3414namespace {
15
16// Returns the resource id of the application icon.
17int GetAppIconResourceId() {
grt4d6747c2017-02-25 22:16:2918 return install_static::InstallDetails::Get().app_icon_resource_id();
[email protected]be74fb52013-01-14 19:45:3419}
20
21} // namespace
22
23HICON GetAppIcon() {
mgiuca3e9e69dc2015-11-18 02:02:4224 // TODO(mgiuca): Use GetAppIconImageFamily/CreateExact instead of LoadIcon, to
25 // get correct scaling. (See http://crbug.com/551256)
[email protected]be74fb52013-01-14 19:45:3426 const int icon_id = GetAppIconResourceId();
wfha7baf45d2015-04-22 00:04:2027 // HICON returned from LoadIcon do not leak and do not have to be destroyed.
[email protected]f7be2197b2010-04-23 00:20:4428 return LoadIcon(GetModuleHandle(chrome::kBrowserResourcesDll),
29 MAKEINTRESOURCE(icon_id));
30}
[email protected]4b7a2aa2011-12-06 03:46:2231
tmoniuszkocd5b3ee2014-12-15 08:51:0432HICON GetSmallAppIcon() {
mgiuca3e9e69dc2015-11-18 02:02:4233 // TODO(mgiuca): Use GetAppIconImageFamily/CreateExact instead of LoadIcon, to
34 // get correct scaling. (See http://crbug.com/551256)
tmoniuszkocd5b3ee2014-12-15 08:51:0435 const int icon_id = GetAppIconResourceId();
mgiuca3e9e69dc2015-11-18 02:02:4236 gfx::Size size = GetSmallAppIconSize();
wfha7baf45d2015-04-22 00:04:2037 // HICON returned from LoadImage must be released using DestroyIcon.
tmoniuszkocd5b3ee2014-12-15 08:51:0438 return static_cast<HICON>(LoadImage(
39 GetModuleHandle(chrome::kBrowserResourcesDll), MAKEINTRESOURCE(icon_id),
mgiuca3e9e69dc2015-11-18 02:02:4240 IMAGE_ICON, size.width(), size.height(), LR_DEFAULTCOLOR | LR_SHARED));
tmoniuszkocd5b3ee2014-12-15 08:51:0441}
42
mgiuca3e9e69dc2015-11-18 02:02:4243gfx::Size GetAppIconSize() {
44 return gfx::Size(GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON));
45}
46
47gfx::Size GetSmallAppIconSize() {
48 return gfx::Size(GetSystemMetrics(SM_CXSMICON),
49 GetSystemMetrics(SM_CYSMICON));
50}
51
dcheng4af48582016-04-19 00:29:3552std::unique_ptr<gfx::ImageFamily> GetAppIconImageFamily() {
[email protected]be74fb52013-01-14 19:45:3453 const int icon_id = GetAppIconResourceId();
mgiuca3e9e69dc2015-11-18 02:02:4254 // 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]4b7a2aa2011-12-06 03:46:2264}