| 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 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <limits> | 9 #include <limits> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 #endif | 50 #endif |
| 51 | 51 |
| 52 #if defined(OS_CHROMEOS) | 52 #if defined(OS_CHROMEOS) |
| 53 #include "ui/gfx/platform_font_linux.h" | 53 #include "ui/gfx/platform_font_linux.h" |
| 54 #endif | 54 #endif |
| 55 | 55 |
| 56 #if defined(OS_WIN) | 56 #if defined(OS_WIN) |
| 57 #include "ui/display/win/dpi.h" | 57 #include "ui/display/win/dpi.h" |
| 58 #endif | 58 #endif |
| 59 | 59 |
| 60 // Helpers -------------------------------------------------------------------- | |
| 61 | |
| 62 namespace ui { | 60 namespace ui { |
| 63 | 61 |
| 64 namespace { | 62 namespace { |
| 65 | 63 |
| 66 // PNG-related constants. | 64 // PNG-related constants. |
| 67 const unsigned char kPngMagic[8] = { 0x89, 'P', 'N', 'G', 13, 10, 26, 10 }; | 65 const unsigned char kPngMagic[8] = { 0x89, 'P', 'N', 'G', 13, 10, 26, 10 }; |
| 68 const size_t kPngChunkMetadataSize = 12; // length, type, crc32 | 66 const size_t kPngChunkMetadataSize = 12; // length, type, crc32 |
| 69 const unsigned char kPngScaleChunkType[4] = { 'c', 's', 'C', 'l' }; | 67 const unsigned char kPngScaleChunkType[4] = { 'c', 's', 'C', 'l' }; |
| 70 const unsigned char kPngDataChunkType[4] = { 'I', 'D', 'A', 'T' }; | 68 const unsigned char kPngDataChunkType[4] = { 'I', 'D', 'A', 'T' }; |
| 71 | 69 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 | 107 |
| 110 SkBitmap CreateEmptyBitmap() { | 108 SkBitmap CreateEmptyBitmap() { |
| 111 SkBitmap bitmap; | 109 SkBitmap bitmap; |
| 112 bitmap.allocN32Pixels(32, 32); | 110 bitmap.allocN32Pixels(32, 32); |
| 113 bitmap.eraseARGB(255, 255, 255, 0); | 111 bitmap.eraseARGB(255, 255, 255, 0); |
| 114 return bitmap; | 112 return bitmap; |
| 115 } | 113 } |
| 116 | 114 |
| 117 } // namespace | 115 } // namespace |
| 118 | 116 |
| 119 | |
| 120 // ResourceBundle::TemporaryLoader -------------------------------------------- | |
| 121 | |
| 122 ResourceBundle::TemporaryLoader::TemporaryLoader() | |
| 123 : already_loaded_(ResourceBundle::HasSharedInstance()) { | |
| 124 if (!already_loaded_) { | |
| 125 std::string locale = l10n_util::GetApplicationLocale(std::string()); | |
| 126 const char kUserDataDirDialogFallbackLocale[] = "en-US"; | |
| 127 if (locale.empty()) | |
| 128 locale = kUserDataDirDialogFallbackLocale; | |
| 129 ui::ResourceBundle::InitSharedInstanceWithLocale( | |
| 130 locale, nullptr, ui::ResourceBundle::DO_NOT_LOAD_COMMON_RESOURCES); | |
| 131 } | |
| 132 } | |
| 133 | |
| 134 ResourceBundle::TemporaryLoader::~TemporaryLoader() { | |
| 135 if (!already_loaded_) | |
| 136 ResourceBundle::CleanupSharedInstance(); | |
| 137 } | |
| 138 | |
| 139 | |
| 140 // ResourceBundle::ResourceBundleImageSource ---------------------------------- | |
| 141 | |
| 142 // An ImageSkiaSource that loads bitmaps for the requested scale factor from | 117 // An ImageSkiaSource that loads bitmaps for the requested scale factor from |
| 143 // ResourceBundle on demand for a given |resource_id|. If the bitmap for the | 118 // ResourceBundle on demand for a given |resource_id|. If the bitmap for the |
| 144 // requested scale factor does not exist, it will return the 1x bitmap scaled | 119 // requested scale factor does not exist, it will return the 1x bitmap scaled |
| 145 // by the scale factor. This may lead to broken UI if the correct size of the | 120 // by the scale factor. This may lead to broken UI if the correct size of the |
| 146 // scaled image is not exactly |scale_factor| * the size of the 1x resource. | 121 // scaled image is not exactly |scale_factor| * the size of the 1x resource. |
| 147 // When --highlight-missing-scaled-resources flag is specified, scaled 1x images | 122 // When --highlight-missing-scaled-resources flag is specified, scaled 1x images |
| 148 // are higlighted by blending them with red. | 123 // are higlighted by blending them with red. |
| 149 class ResourceBundle::ResourceBundleImageSource : public gfx::ImageSkiaSource { | 124 class ResourceBundle::ResourceBundleImageSource : public gfx::ImageSkiaSource { |
| 150 public: | 125 public: |
| 151 ResourceBundleImageSource(ResourceBundle* rb, int resource_id) | 126 ResourceBundleImageSource(ResourceBundle* rb, int resource_id) |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 return gfx::ImageSkiaRep(image, scale); | 164 return gfx::ImageSkiaRep(image, scale); |
| 190 } | 165 } |
| 191 | 166 |
| 192 private: | 167 private: |
| 193 ResourceBundle* rb_; | 168 ResourceBundle* rb_; |
| 194 const int resource_id_; | 169 const int resource_id_; |
| 195 | 170 |
| 196 DISALLOW_COPY_AND_ASSIGN(ResourceBundleImageSource); | 171 DISALLOW_COPY_AND_ASSIGN(ResourceBundleImageSource); |
| 197 }; | 172 }; |
| 198 | 173 |
| 199 | |
| 200 // ResourceBundle ------------------------------------------------------------- | |
| 201 | |
| 202 // static | 174 // static |
| 203 std::string ResourceBundle::InitSharedInstanceWithLocale( | 175 std::string ResourceBundle::InitSharedInstanceWithLocale( |
| 204 const std::string& pref_locale, | 176 const std::string& pref_locale, |
| 205 Delegate* delegate, | 177 Delegate* delegate, |
| 206 LoadResources load_resources) { | 178 LoadResources load_resources) { |
| 207 InitSharedInstance(delegate); | 179 InitSharedInstance(delegate); |
| 208 if (load_resources == LOAD_COMMON_RESOURCES) | 180 if (load_resources == LOAD_COMMON_RESOURCES) |
| 209 g_shared_instance_->LoadCommonResources(); | 181 g_shared_instance_->LoadCommonResources(); |
| 210 std::string result = g_shared_instance_->LoadLocaleResources(pref_locale); | 182 std::string result = g_shared_instance_->LoadLocaleResources(pref_locale); |
| 211 g_shared_instance_->InitDefaultFontList(); | 183 g_shared_instance_->InitDefaultFontList(); |
| (...skipping 712 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 924 // static | 896 // static |
| 925 bool ResourceBundle::DecodePNG(const unsigned char* buf, | 897 bool ResourceBundle::DecodePNG(const unsigned char* buf, |
| 926 size_t size, | 898 size_t size, |
| 927 SkBitmap* bitmap, | 899 SkBitmap* bitmap, |
| 928 bool* fell_back_to_1x) { | 900 bool* fell_back_to_1x) { |
| 929 *fell_back_to_1x = PNGContainsFallbackMarker(buf, size); | 901 *fell_back_to_1x = PNGContainsFallbackMarker(buf, size); |
| 930 return gfx::PNGCodec::Decode(buf, size, bitmap); | 902 return gfx::PNGCodec::Decode(buf, size, bitmap); |
| 931 } | 903 } |
| 932 | 904 |
| 933 } // namespace ui | 905 } // namespace ui |
| OLD | NEW |