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