Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 <QuartzCore/QuartzCore.h> | 7 #import <QuartzCore/QuartzCore.h> |
| 8 #import <UIKit/UIKit.h> | 8 #import <UIKit/UIKit.h> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 49 | 49 |
| 50 if (IsScaleFactorSupported(SCALE_FACTOR_100P)) { | 50 if (IsScaleFactorSupported(SCALE_FACTOR_100P)) { |
| 51 AddDataPackFromPath(GetResourcesPakFilePath(@"chrome_100_percent", nil), | 51 AddDataPackFromPath(GetResourcesPakFilePath(@"chrome_100_percent", nil), |
| 52 SCALE_FACTOR_100P); | 52 SCALE_FACTOR_100P); |
| 53 } | 53 } |
| 54 | 54 |
| 55 if (IsScaleFactorSupported(SCALE_FACTOR_200P)) { | 55 if (IsScaleFactorSupported(SCALE_FACTOR_200P)) { |
| 56 AddDataPackFromPath(GetResourcesPakFilePath(@"chrome_200_percent", nil), | 56 AddDataPackFromPath(GetResourcesPakFilePath(@"chrome_200_percent", nil), |
| 57 SCALE_FACTOR_200P); | 57 SCALE_FACTOR_200P); |
| 58 } | 58 } |
| 59 | |
| 60 // TODO(rohitrao): Add a chrome_300_percent pak file and load it here. For | |
| 61 // now, we are simply falling back to the 200P resources. | |
|
lliabraa
2014/09/16 14:13:36
add "crbug.com/413300"
lliabraa
2014/09/16 14:13:36
add "crbug.com/413300"
rohitrao (ping after 24h)
2014/09/16 14:16:47
Done.
| |
| 62 if (IsScaleFactorSupported(SCALE_FACTOR_200P)) { | |
|
lliabraa
2014/09/16 14:13:36
this should be 300P, right?
rohitrao (ping after 24h)
2014/09/16 14:16:47
Yup, bad copy/paste. Good catch!
| |
| 63 AddDataPackFromPath(GetResourcesPakFilePath(@"chrome_200_percent", nil), | |
| 64 SCALE_FACTOR_200P); | |
| 65 } | |
| 59 } | 66 } |
| 60 | 67 |
| 61 base::FilePath ResourceBundle::GetLocaleFilePath(const std::string& app_locale, | 68 base::FilePath ResourceBundle::GetLocaleFilePath(const std::string& app_locale, |
| 62 bool test_file_exists) { | 69 bool test_file_exists) { |
| 63 NSString* mac_locale = base::SysUTF8ToNSString(app_locale); | 70 NSString* mac_locale = base::SysUTF8ToNSString(app_locale); |
| 64 | 71 |
| 65 // iOS uses "_" instead of "-", so swap to get a iOS-style value. | 72 // iOS uses "_" instead of "-", so swap to get a iOS-style value. |
| 66 mac_locale = [mac_locale stringByReplacingOccurrencesOfString:@"-" | 73 mac_locale = [mac_locale stringByReplacingOccurrencesOfString:@"-" |
| 67 withString:@"_"]; | 74 withString:@"_"]; |
| 68 | 75 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 120 } | 127 } |
| 121 | 128 |
| 122 // Create a data object from the raw bytes. | 129 // Create a data object from the raw bytes. |
| 123 base::scoped_nsobject<NSData> ns_data( | 130 base::scoped_nsobject<NSData> ns_data( |
| 124 [[NSData alloc] initWithBytes:data->front() length:data->size()]); | 131 [[NSData alloc] initWithBytes:data->front() length:data->size()]); |
| 125 | 132 |
| 126 bool is_fallback = PNGContainsFallbackMarker(data->front(), data->size()); | 133 bool is_fallback = PNGContainsFallbackMarker(data->front(), data->size()); |
| 127 // Create the image from the data. | 134 // Create the image from the data. |
| 128 CGFloat target_scale = ui::GetScaleForScaleFactor(scale_factor); | 135 CGFloat target_scale = ui::GetScaleForScaleFactor(scale_factor); |
| 129 CGFloat source_scale = is_fallback ? 1.0 : target_scale; | 136 CGFloat source_scale = is_fallback ? 1.0 : target_scale; |
| 137 // Hack: The 200P pak file is the only pak file loaded on iOS devices with | |
| 138 // an @3x scale factor. Force |source_scale| to be 2.0 to handle this case, | |
| 139 // since it cannot be anything else. | |
| 140 // TODO(rohitrao): Support proper fallback by using the actual scale factor | |
| 141 // of the source image, rather than assuming it is 1.0 or 2.0. | |
| 142 if (scale_factor == SCALE_FACTOR_300P) { | |
| 143 source_scale = 2.0; | |
| 144 } | |
| 130 base::scoped_nsobject<UIImage> ui_image( | 145 base::scoped_nsobject<UIImage> ui_image( |
| 131 [[UIImage alloc] initWithData:ns_data scale:source_scale]); | 146 [[UIImage alloc] initWithData:ns_data scale:source_scale]); |
| 132 | 147 |
| 133 // If the image is a 1x fallback, scale it up to a full-size representation. | 148 // If the image is a 1x fallback, scale it up to a full-size representation. |
| 134 if (is_fallback) { | 149 if (is_fallback) { |
| 135 CGSize source_size = [ui_image size]; | 150 CGSize source_size = [ui_image size]; |
| 136 CGSize target_size = CGSizeMake(source_size.width * target_scale, | 151 CGSize target_size = CGSizeMake(source_size.width * target_scale, |
| 137 source_size.height * target_scale); | 152 source_size.height * target_scale); |
| 138 base::ScopedCFTypeRef<CGColorSpaceRef> color_space( | 153 base::ScopedCFTypeRef<CGColorSpaceRef> color_space( |
| 139 CGColorSpaceCreateDeviceRGB()); | 154 CGColorSpaceCreateDeviceRGB()); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 172 | 187 |
| 173 // Another thread raced the load and has already cached the image. | 188 // Another thread raced the load and has already cached the image. |
| 174 if (images_.count(resource_id)) | 189 if (images_.count(resource_id)) |
| 175 return images_[resource_id]; | 190 return images_[resource_id]; |
| 176 | 191 |
| 177 images_[resource_id] = image; | 192 images_[resource_id] = image; |
| 178 return images_[resource_id]; | 193 return images_[resource_id]; |
| 179 } | 194 } |
| 180 | 195 |
| 181 } // namespace ui | 196 } // namespace ui |
| OLD | NEW |