| 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 "base/path_service.h" |
| 9 #include "ui/base/resource/resource_bundle.h" | 9 #include "ui/base/resource/resource_bundle.h" |
| 10 #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" | 11 #include "ui/base/scale.h" |
| 12 | 12 |
| 13 namespace ui { | 13 namespace ui { |
| 14 | 14 |
| 15 namespace { | 15 namespace { |
| 16 | 16 |
| 17 HINSTANCE resources_data_dll; | 17 HINSTANCE resources_data_dll; |
| 18 | 18 |
| 19 HINSTANCE GetCurrentResourceDLL() { | 19 HINSTANCE GetCurrentResourceDLL() { |
| 20 if (resources_data_dll) | 20 if (resources_data_dll) |
| 21 return resources_data_dll; | 21 return resources_data_dll; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 36 return false; | 36 return false; |
| 37 return buffer == std::string("1"); | 37 return buffer == std::string("1"); |
| 38 } | 38 } |
| 39 | 39 |
| 40 } // end anonymous namespace | 40 } // end anonymous namespace |
| 41 | 41 |
| 42 void ResourceBundle::LoadCommonResources() { | 42 void ResourceBundle::LoadCommonResources() { |
| 43 // As a convenience, add the current resource module as a data packs. | 43 // As a convenience, add the current resource module as a data packs. |
| 44 data_packs_.push_back(new ResourceDataDLL(GetCurrentResourceDLL())); | 44 data_packs_.push_back(new ResourceDataDLL(GetCurrentResourceDLL())); |
| 45 | 45 |
| 46 bool use_hidpi_pak = false; | 46 switch (ui::GetDisplayScale()) { |
| 47 #if defined(ENABLE_HIDPI) | 47 case ui::DS_METRO_100: |
| 48 // If we're running in HiDPI mode then use the 2x resource for DPI greater | 48 case ui::DS_METRO_140: |
| 49 // than 1.5. Otherwise use the 1x resource. | 49 case ui::DS_METRO_180: |
| 50 use_hidpi_pak = ui::GetDPIScale() > 1.5; | 50 // TODO(joi): Support the 140 and 180 scales. |
| 51 #endif | 51 AddDataPack(GetResourcesPakFilePath("theme_resources_metro_1x.pak")); |
| 52 | 52 AddDataPack(GetResourcesPakFilePath("ui_resources_standard.pak")); |
| 53 bool use_metro_pak = false; | 53 break; |
| 54 #if defined(ENABLE_METRO) | 54 case ui::DS_DESKTOP_200: |
| 55 use_metro_pak = IsInMetroMode(); | 55 AddDataPack(GetResourcesPakFilePath("theme_resources_2x.pak")); |
| 56 #endif | 56 AddDataPack(GetResourcesPakFilePath("ui_resources_2x.pak")); |
| 57 | 57 break; |
| 58 if (use_metro_pak) { | 58 default: |
| 59 AddDataPack(GetResourcesPakFilePath("theme_resources_metro_1x.pak")); | 59 AddDataPack(GetResourcesPakFilePath("theme_resources_standard.pak")); |
| 60 } else if (use_hidpi_pak) { | 60 AddDataPack(GetResourcesPakFilePath("ui_resources_standard.pak")); |
| 61 AddDataPack(GetResourcesPakFilePath("theme_resources_2x.pak")); | 61 break; |
| 62 } else { | |
| 63 AddDataPack(GetResourcesPakFilePath("theme_resources_standard.pak")); | |
| 64 } | |
| 65 | |
| 66 if (use_hidpi_pak) { | |
| 67 AddDataPack(GetResourcesPakFilePath("ui_resources_2x.pak")); | |
| 68 } else { | |
| 69 AddDataPack(GetResourcesPakFilePath("ui_resources_standard.pak")); | |
| 70 } | 62 } |
| 71 } | 63 } |
| 72 | 64 |
| 73 void ResourceBundle::LoadTestResources(const FilePath& path) { | 65 void ResourceBundle::LoadTestResources(const FilePath& path) { |
| 74 // On Windows, the test resources are normally compiled into the binary | 66 // On Windows, the test resources are normally compiled into the binary |
| 75 // itself. | 67 // itself. |
| 76 } | 68 } |
| 77 | 69 |
| 78 gfx::Image& ResourceBundle::GetNativeImageNamed(int resource_id, ImageRTL rtl) { | 70 gfx::Image& ResourceBundle::GetNativeImageNamed(int resource_id, ImageRTL rtl) { |
| 79 // Flipped image is not used on Windows. | 71 // Flipped image is not used on Windows. |
| 80 DCHECK_EQ(rtl, RTL_DISABLED); | 72 DCHECK_EQ(rtl, RTL_DISABLED); |
| 81 | 73 |
| 82 // Windows only uses SkBitmap for gfx::Image, so this is the same as | 74 // Windows only uses SkBitmap for gfx::Image, so this is the same as |
| 83 // GetImageNamed. | 75 // GetImageNamed. |
| 84 return GetImageNamed(resource_id); | 76 return GetImageNamed(resource_id); |
| 85 } | 77 } |
| 86 | 78 |
| 87 void SetResourcesDataDLL(HINSTANCE handle) { | 79 void SetResourcesDataDLL(HINSTANCE handle) { |
| 88 resources_data_dll = handle; | 80 resources_data_dll = handle; |
| 89 } | 81 } |
| 90 | 82 |
| 91 HICON LoadThemeIconFromResourcesDataDLL(int icon_id) { | 83 HICON LoadThemeIconFromResourcesDataDLL(int icon_id) { |
| 92 return ::LoadIcon(GetCurrentResourceDLL(), MAKEINTRESOURCE(icon_id)); | 84 return ::LoadIcon(GetCurrentResourceDLL(), MAKEINTRESOURCE(icon_id)); |
| 93 } | 85 } |
| 94 | 86 |
| 95 } // namespace ui; | 87 } // namespace ui; |
| OLD | NEW |