1 // Copyright (c) 2012 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.
5 #include "ui/base/resource/resource_bundle_win.h"
7 #include "base/logging.h"
8 #include "base/path_service.h"
9 #include "base/strings/utf_string_conversions.h"
10 #include "ui/base/layout.h"
11 #include "ui/base/resource/resource_bundle.h"
12 #include "ui/base/resource/resource_data_dll_win.h"
13 #include "ui/gfx/win/dpi.h"
19 HINSTANCE resources_data_dll
;
21 HINSTANCE
GetCurrentResourceDLL() {
22 if (resources_data_dll
)
23 return resources_data_dll
;
24 return GetModuleHandle(NULL
);
27 base::FilePath
GetResourcesPakFilePath(const std::string
& pak_name
) {
29 if (PathService::Get(base::DIR_MODULE
, &path
))
30 return path
.AppendASCII(pak_name
.c_str());
32 // Return just the name of the pack file.
33 return base::FilePath(base::ASCIIToUTF16(pak_name
));
38 void ResourceBundle::LoadCommonResources() {
39 // As a convenience, add the current resource module as a data packs.
40 data_packs_
.push_back(new ResourceDataDLL(GetCurrentResourceDLL()));
41 // Have high-DPI resources for 140% and 180% scaling on Windows based on
42 // default scaling for Metro mode. If high-DPI mode is enabled, load resource
43 // pak closest to the desired scale factor. The high-DPI resources are
44 // scaled up from 100% touch.
45 float scale
= gfx::win::GetDeviceScaleFactor();
46 bool force_touch_resources
= false;
47 switch(ui::GetSupportedScaleFactor(scale
)) {
48 case ui::SCALE_FACTOR_180P
:
49 AddDataPackFromPath(GetResourcesPakFilePath(
50 "chrome_touch_180_percent.pak"),
52 force_touch_resources
= true;
54 case ui::SCALE_FACTOR_140P
:
55 AddDataPackFromPath(GetResourcesPakFilePath(
56 "chrome_touch_140_percent.pak"),
58 force_touch_resources
= true;
60 // TODO(kevers|girard): Remove loading of 1x resources when in high-DPI
61 // mode once all resources are available at 140% and 180%.
62 if (ui::GetDisplayLayout() == ui::LAYOUT_TOUCH
|| force_touch_resources
) {
64 GetResourcesPakFilePath("chrome_touch_100_percent.pak"),
68 GetResourcesPakFilePath("chrome_100_percent.pak"),
73 gfx::Image
& ResourceBundle::GetNativeImageNamed(int resource_id
, ImageRTL rtl
) {
74 // Flipped image is not used on Windows.
75 DCHECK_EQ(rtl
, RTL_DISABLED
);
77 // Windows only uses SkBitmap for gfx::Image, so this is the same as
79 return GetImageNamed(resource_id
);
82 void SetResourcesDataDLL(HINSTANCE handle
) {
83 resources_data_dll
= handle
;
86 HICON
LoadThemeIconFromResourcesDataDLL(int icon_id
) {
87 return ::LoadIcon(GetCurrentResourceDLL(), MAKEINTRESOURCE(icon_id
));