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.h" | 5 #include "ui/base/resource/resource_bundle.h" |
6 | 6 |
7 #import <AppKit/AppKit.h> | 7 #import <AppKit/AppKit.h> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 // Return just the name of the pack file. | 42 // Return just the name of the pack file. |
43 return FilePath(base::SysNSStringToUTF8(name) + ".pak"); | 43 return FilePath(base::SysNSStringToUTF8(name) + ".pak"); |
44 } | 44 } |
45 | 45 |
46 return FilePath([resource_path fileSystemRepresentation]); | 46 return FilePath([resource_path fileSystemRepresentation]); |
47 } | 47 } |
48 | 48 |
49 } // namespace | 49 } // namespace |
50 | 50 |
51 void ResourceBundle::LoadCommonResources() { | 51 void ResourceBundle::LoadCommonResources() { |
52 AddDataPack(GetResourcesPakFilePath(@"chrome", nil), | 52 AddDataPackFromPath(GetResourcesPakFilePath(@"chrome", nil), |
53 SCALE_FACTOR_100P); | 53 SCALE_FACTOR_100P); |
54 AddDataPack(GetResourcesPakFilePath(@"theme_resources_standard", nil), | 54 AddDataPackFromPath(GetResourcesPakFilePath(@"theme_resources_standard", nil), |
55 SCALE_FACTOR_100P); | 55 SCALE_FACTOR_100P); |
56 AddDataPack(GetResourcesPakFilePath(@"ui_resources_standard", nil), | 56 AddDataPackFromPath(GetResourcesPakFilePath(@"ui_resources_standard", nil), |
57 SCALE_FACTOR_100P); | 57 SCALE_FACTOR_100P); |
58 | 58 |
59 // On Windows and ChromeOS we load either the 1x resource or the 2x resource. | 59 // On Windows and ChromeOS we load either the 1x resource or the 2x resource. |
60 // On Mac we load both and let the UI framework decide which one to use. | 60 // On Mac we load both and let the UI framework decide which one to use. |
61 #if defined(ENABLE_HIDPI) | 61 #if defined(ENABLE_HIDPI) |
62 if (base::mac::IsOSLionOrLater()) { | 62 if (base::mac::IsOSLionOrLater()) { |
63 AddDataPack(GetResourcesPakFilePath(@"theme_resources_2x", nil), | 63 AddDataPackFromPath(GetResourcesPakFilePath(@"theme_resources_2x", nil), |
64 SCALE_FACTOR_200P); | 64 SCALE_FACTOR_200P); |
65 AddDataPack(GetResourcesPakFilePath(@"ui_resources_2x", nil), | 65 AddDataPackFromPath(GetResourcesPakFilePath(@"ui_resources_2x", nil), |
66 SCALE_FACTOR_200P); | 66 SCALE_FACTOR_200P); |
67 } | 67 } |
68 #endif | 68 #endif |
69 } | 69 } |
70 | 70 |
71 FilePath ResourceBundle::GetLocaleFilePath(const std::string& app_locale) { | 71 FilePath ResourceBundle::GetLocaleFilePath(const std::string& app_locale, |
| 72 bool test_file_exists) { |
72 NSString* mac_locale = base::SysUTF8ToNSString(app_locale); | 73 NSString* mac_locale = base::SysUTF8ToNSString(app_locale); |
73 | 74 |
74 // Mac OS X uses "_" instead of "-", so swap to get a Mac-style value. | 75 // Mac OS X uses "_" instead of "-", so swap to get a Mac-style value. |
75 mac_locale = [mac_locale stringByReplacingOccurrencesOfString:@"-" | 76 mac_locale = [mac_locale stringByReplacingOccurrencesOfString:@"-" |
76 withString:@"_"]; | 77 withString:@"_"]; |
77 | 78 |
78 // On disk, the "en_US" resources are just "en" (http://crbug.com/25578). | 79 // On disk, the "en_US" resources are just "en" (http://crbug.com/25578). |
79 if ([mac_locale isEqual:@"en_US"]) | 80 if ([mac_locale isEqual:@"en_US"]) |
80 mac_locale = @"en"; | 81 mac_locale = @"en"; |
81 | 82 |
82 FilePath locale_file_path = GetResourcesPakFilePath(@"locale", mac_locale); | 83 FilePath locale_file_path = GetResourcesPakFilePath(@"locale", mac_locale); |
83 | 84 |
84 if (delegate_) { | 85 if (delegate_) { |
85 locale_file_path = | 86 locale_file_path = |
86 delegate_->GetPathForLocalePack(locale_file_path, app_locale); | 87 delegate_->GetPathForLocalePack(locale_file_path, app_locale); |
87 } | 88 } |
88 | 89 |
89 // Don't try to load empty values or values that are not absolute paths. | 90 // Don't try to load empty values or values that are not absolute paths. |
90 if (locale_file_path.empty() || !locale_file_path.IsAbsolute()) | 91 if (locale_file_path.empty() || !locale_file_path.IsAbsolute()) |
91 return FilePath(); | 92 return FilePath(); |
92 | 93 |
93 if (!file_util::PathExists(locale_file_path)) | 94 if (test_file_exists && !file_util::PathExists(locale_file_path)) |
94 return FilePath(); | 95 return FilePath(); |
95 | 96 |
96 return locale_file_path; | 97 return locale_file_path; |
97 } | 98 } |
98 | 99 |
99 gfx::Image& ResourceBundle::GetNativeImageNamed(int resource_id, ImageRTL rtl) { | 100 gfx::Image& ResourceBundle::GetNativeImageNamed(int resource_id, ImageRTL rtl) { |
100 // Flipped images are not used on Mac. | 101 // Flipped images are not used on Mac. |
101 DCHECK_EQ(rtl, RTL_DISABLED); | 102 DCHECK_EQ(rtl, RTL_DISABLED); |
102 | 103 |
103 // Check to see if the image is already in the cache. | 104 // Check to see if the image is already in the cache. |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 | 152 |
152 // Another thread raced the load and has already cached the image. | 153 // Another thread raced the load and has already cached the image. |
153 if (images_.count(resource_id)) | 154 if (images_.count(resource_id)) |
154 return images_[resource_id]; | 155 return images_[resource_id]; |
155 | 156 |
156 images_[resource_id] = image; | 157 images_[resource_id] = image; |
157 return images_[resource_id]; | 158 return images_[resource_id]; |
158 } | 159 } |
159 | 160 |
160 } // namespace ui | 161 } // namespace ui |
OLD | NEW |