Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(37)

Side by Side Diff: ui/base/resource/resource_bundle_win.cc

Issue 10270023: Add new ResourceBundle::Delegate interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/base/resource/resource_bundle_unittest.cc ('k') | ui/test/test_suite.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "base/utf_string_conversions.h"
9 #include "ui/base/layout.h" 10 #include "ui/base/layout.h"
10 #include "ui/base/resource/resource_bundle.h" 11 #include "ui/base/resource/resource_bundle.h"
11 #include "ui/base/resource/resource_data_dll_win.h" 12 #include "ui/base/resource/resource_data_dll_win.h"
12 #include "ui/base/win/dpi.h" 13 #include "ui/base/win/dpi.h"
13 14
14 namespace ui { 15 namespace ui {
15 16
16 namespace { 17 namespace {
17 18
18 HINSTANCE resources_data_dll; 19 HINSTANCE resources_data_dll;
19 20
20 HINSTANCE GetCurrentResourceDLL() { 21 HINSTANCE GetCurrentResourceDLL() {
21 if (resources_data_dll) 22 if (resources_data_dll)
22 return resources_data_dll; 23 return resources_data_dll;
23 return GetModuleHandle(NULL); 24 return GetModuleHandle(NULL);
24 } 25 }
25 26
26 FilePath GetResourcesPakFilePath(const std::string& pak_name) { 27 FilePath GetResourcesPakFilePath(const std::string& pak_name) {
27 FilePath path; 28 FilePath path;
28 if (PathService::Get(base::DIR_MODULE, &path)) 29 if (PathService::Get(base::DIR_MODULE, &path))
29 return path.AppendASCII(pak_name.c_str()); 30 return path.AppendASCII(pak_name.c_str());
30 return FilePath(); 31
32 // Return just the name of the pack file.
33 return FilePath(ASCIIToUTF16(pak_name));
31 } 34 }
32 35
33 } // end anonymous namespace 36 } // end anonymous namespace
34 37
35 void ResourceBundle::LoadCommonResources() { 38 void ResourceBundle::LoadCommonResources() {
36 // As a convenience, add the current resource module as a data packs. 39 // As a convenience, add the current resource module as a data packs.
37 data_packs_.push_back(new ResourceDataDLL(GetCurrentResourceDLL())); 40 data_packs_.push_back(new ResourceDataDLL(GetCurrentResourceDLL()));
38 41
39 bool use_hidpi = false; 42 bool use_hidpi = false;
40 #if defined(ENABLE_HIDPI) 43 #if defined(ENABLE_HIDPI)
41 // If we're running in HiDPI mode at a scale larger than 150%, we switch 44 // If we're running in HiDPI mode at a scale larger than 150%, we switch
42 // to 2x resources for desktop layouts. 45 // to 2x resources for desktop layouts.
43 use_hidpi = ui::GetDPIScale() > 1.5; 46 use_hidpi = ui::GetDPIScale() > 1.5;
44 #endif 47 #endif
45 48
46 switch (ui::GetDisplayLayout()) { 49 switch (ui::GetDisplayLayout()) {
47 case ui::LAYOUT_TOUCH: 50 case ui::LAYOUT_TOUCH:
48 AddDataPack(GetResourcesPakFilePath("theme_resources_touch_1x.pak"), 51 AddDataPack(GetResourcesPakFilePath("theme_resources_touch_1x.pak"),
49 ResourceHandle::kScaleFactor100x); 52 ResourceHandle::kScaleFactor100x);
50 AddDataPack(GetResourcesPakFilePath("ui_resources_standard.pak"), 53 AddDataPack(GetResourcesPakFilePath("ui_resources_standard.pak"),
51 ResourceHandle::kScaleFactor100x); 54 ResourceHandle::kScaleFactor100x);
52 break; 55 break;
53 default: 56 default:
54 if (use_hidpi) { 57 if (use_hidpi) {
55 AddDataPack(GetResourcesPakFilePath("theme_resources_2x.pak"), 58 AddDataPack(GetResourcesPakFilePath("theme_resources_2x.pak"),
56 ResourceHandle::kScaleFactor200x); 59 ResourceHandle::kScaleFactor200x);
57 AddDataPack(GetResourcesPakFilePath("ui_resources_2x.pak"), 60 AddDataPack(GetResourcesPakFilePath("ui_resources_2x.pak"),
58 ResourceHandle::kScaleFactor200x); 61 ResourceHandle::kScaleFactor200x);
59 } else { 62 } else {
60 AddDataPack(GetResourcesPakFilePath("theme_resources_standard.pak"), 63 AddDataPack(GetResourcesPakFilePath("theme_resources_standard.pak"),
61 ResourceHandle::kScaleFactor100x); 64 ResourceHandle::kScaleFactor100x);
62 AddDataPack(GetResourcesPakFilePath("ui_resources_standard.pak"), 65 AddDataPack(GetResourcesPakFilePath("ui_resources_standard.pak"),
63 ResourceHandle::kScaleFactor100x); 66 ResourceHandle::kScaleFactor100x);
64 } 67 }
65 break; 68 break;
66 } 69 }
67 } 70 }
68 71
69 gfx::Image& ResourceBundle::GetNativeImageNamed(int resource_id, ImageRTL rtl) { 72 gfx::Image& ResourceBundle::GetNativeImageNamed(int resource_id, ImageRTL rtl) {
70 // Flipped image is not used on Windows. 73 // Flipped image is not used on Windows.
71 DCHECK_EQ(rtl, RTL_DISABLED); 74 DCHECK_EQ(rtl, RTL_DISABLED);
72 75
73 // Windows only uses SkBitmap for gfx::Image, so this is the same as 76 // Windows only uses SkBitmap for gfx::Image, so this is the same as
74 // GetImageNamed. 77 // GetImageNamed.
75 return GetImageNamed(resource_id); 78 return GetImageNamed(resource_id);
76 } 79 }
77 80
78 void SetResourcesDataDLL(HINSTANCE handle) { 81 void SetResourcesDataDLL(HINSTANCE handle) {
79 resources_data_dll = handle; 82 resources_data_dll = handle;
80 } 83 }
81 84
82 HICON LoadThemeIconFromResourcesDataDLL(int icon_id) { 85 HICON LoadThemeIconFromResourcesDataDLL(int icon_id) {
83 return ::LoadIcon(GetCurrentResourceDLL(), MAKEINTRESOURCE(icon_id)); 86 return ::LoadIcon(GetCurrentResourceDLL(), MAKEINTRESOURCE(icon_id));
84 } 87 }
85 88
86 } // namespace ui; 89 } // namespace ui;
OLDNEW
« no previous file with comments | « ui/base/resource/resource_bundle_unittest.cc ('k') | ui/test/test_suite.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698