| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "ui/base/resource/resource_bundle_win.h" | 5 #include "ui/base/resource/resource_bundle_win.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/path_service.h" |
| 8 #include "ui/base/resource/resource_bundle.h" | 9 #include "ui/base/resource/resource_bundle.h" |
| 9 #include "ui/base/resource/resource_data_dll_win.h" | 10 #include "ui/base/resource/resource_data_dll_win.h" |
| 11 #include "ui/base/win/dpi.h" |
| 10 | 12 |
| 11 namespace ui { | 13 namespace ui { |
| 12 | 14 |
| 13 namespace { | 15 namespace { |
| 14 | 16 |
| 15 HINSTANCE resources_data_dll; | 17 HINSTANCE resources_data_dll; |
| 16 | 18 |
| 17 HINSTANCE GetCurrentResourceDLL() { | 19 HINSTANCE GetCurrentResourceDLL() { |
| 18 if (resources_data_dll) | 20 if (resources_data_dll) |
| 19 return resources_data_dll; | 21 return resources_data_dll; |
| 20 return GetModuleHandle(NULL); | 22 return GetModuleHandle(NULL); |
| 21 } | 23 } |
| 22 | 24 |
| 25 FilePath GetResourcesPakFilePath(const std::string& pak_name) { |
| 26 FilePath path; |
| 27 if (PathService::Get(base::DIR_MODULE, &path)) |
| 28 return path.AppendASCII(pak_name.c_str()); |
| 29 return FilePath(); |
| 30 } |
| 31 |
| 23 } // end anonymous namespace | 32 } // end anonymous namespace |
| 24 | 33 |
| 25 void ResourceBundle::LoadCommonResources() { | 34 void ResourceBundle::LoadCommonResources() { |
| 26 // As a convenience, add the current resource module as a data packs. | 35 // As a convenience, add the current resource module as a data packs. |
| 27 data_packs_.push_back(new ResourceDataDLL(GetCurrentResourceDLL())); | 36 data_packs_.push_back(new ResourceDataDLL(GetCurrentResourceDLL())); |
| 37 |
| 38 bool use_hidpi_pak = false; |
| 39 #if defined(ENABLE_HIDPI) |
| 40 // If we're running in HiDPI mode then use the 2x resource for DPI greater |
| 41 // than 1.5. Otherwise use the 1x resource. |
| 42 use_hidpi_pak = ui::GetDPIScale() > 1.5; |
| 43 #endif |
| 44 |
| 45 if (!use_hidpi_pak) { |
| 46 AddDataPack(GetResourcesPakFilePath("theme_resources_standard.pak")); |
| 47 AddDataPack(GetResourcesPakFilePath("ui_resources_standard.pak")); |
| 48 } else { |
| 49 AddDataPack(GetResourcesPakFilePath("theme_resources_2x.pak")); |
| 50 AddDataPack(GetResourcesPakFilePath("ui_resources_2x.pak")); |
| 51 } |
| 28 } | 52 } |
| 29 | 53 |
| 30 gfx::Image& ResourceBundle::GetNativeImageNamed(int resource_id, ImageRTL rtl) { | 54 gfx::Image& ResourceBundle::GetNativeImageNamed(int resource_id, ImageRTL rtl) { |
| 31 // Flipped image is not used on Windows. | 55 // Flipped image is not used on Windows. |
| 32 DCHECK_EQ(rtl, RTL_DISABLED); | 56 DCHECK_EQ(rtl, RTL_DISABLED); |
| 33 | 57 |
| 34 // Windows only uses SkBitmap for gfx::Image, so this is the same as | 58 // Windows only uses SkBitmap for gfx::Image, so this is the same as |
| 35 // GetImageNamed. | 59 // GetImageNamed. |
| 36 return GetImageNamed(resource_id); | 60 return GetImageNamed(resource_id); |
| 37 } | 61 } |
| 38 | 62 |
| 39 void SetResourcesDataDLL(HINSTANCE handle) { | 63 void SetResourcesDataDLL(HINSTANCE handle) { |
| 40 resources_data_dll = handle; | 64 resources_data_dll = handle; |
| 41 } | 65 } |
| 42 | 66 |
| 43 HICON LoadThemeIconFromResourcesDataDLL(int icon_id) { | 67 HICON LoadThemeIconFromResourcesDataDLL(int icon_id) { |
| 44 return ::LoadIcon(GetCurrentResourceDLL(), MAKEINTRESOURCE(icon_id)); | 68 return ::LoadIcon(GetCurrentResourceDLL(), MAKEINTRESOURCE(icon_id)); |
| 45 } | 69 } |
| 46 | 70 |
| 47 } // namespace ui; | 71 } // namespace ui; |
| OLD | NEW |