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

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

Issue 1955773002: Enable MD by default on Windows for Canary/Dev and local builds. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: DISALLOW_IMPLICIT_CONSTRUCTORS Created 4 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
« no previous file with comments | « ui/base/resource/resource_bundle.h ('k') | ui/base/test/material_design_controller_test_api.h » ('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.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
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
60 namespace ui { 62 namespace ui {
61 63
62 namespace { 64 namespace {
63 65
64 // PNG-related constants. 66 // PNG-related constants.
65 const unsigned char kPngMagic[8] = { 0x89, 'P', 'N', 'G', 13, 10, 26, 10 }; 67 const unsigned char kPngMagic[8] = { 0x89, 'P', 'N', 'G', 13, 10, 26, 10 };
66 const size_t kPngChunkMetadataSize = 12; // length, type, crc32 68 const size_t kPngChunkMetadataSize = 12; // length, type, crc32
67 const unsigned char kPngScaleChunkType[4] = { 'c', 's', 'C', 'l' }; 69 const unsigned char kPngScaleChunkType[4] = { 'c', 's', 'C', 'l' };
68 const unsigned char kPngDataChunkType[4] = { 'I', 'D', 'A', 'T' }; 70 const unsigned char kPngDataChunkType[4] = { 'I', 'D', 'A', 'T' };
69 71
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 109
108 SkBitmap CreateEmptyBitmap() { 110 SkBitmap CreateEmptyBitmap() {
109 SkBitmap bitmap; 111 SkBitmap bitmap;
110 bitmap.allocN32Pixels(32, 32); 112 bitmap.allocN32Pixels(32, 32);
111 bitmap.eraseARGB(255, 255, 255, 0); 113 bitmap.eraseARGB(255, 255, 255, 0);
112 return bitmap; 114 return bitmap;
113 } 115 }
114 116
115 } // namespace 117 } // namespace
116 118
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
117 // An ImageSkiaSource that loads bitmaps for the requested scale factor from 142 // An ImageSkiaSource that loads bitmaps for the requested scale factor from
118 // ResourceBundle on demand for a given |resource_id|. If the bitmap for the 143 // ResourceBundle on demand for a given |resource_id|. If the bitmap for the
119 // requested scale factor does not exist, it will return the 1x bitmap scaled 144 // requested scale factor does not exist, it will return the 1x bitmap scaled
120 // by the scale factor. This may lead to broken UI if the correct size of the 145 // by the scale factor. This may lead to broken UI if the correct size of the
121 // scaled image is not exactly |scale_factor| * the size of the 1x resource. 146 // scaled image is not exactly |scale_factor| * the size of the 1x resource.
122 // When --highlight-missing-scaled-resources flag is specified, scaled 1x images 147 // When --highlight-missing-scaled-resources flag is specified, scaled 1x images
123 // are higlighted by blending them with red. 148 // are higlighted by blending them with red.
124 class ResourceBundle::ResourceBundleImageSource : public gfx::ImageSkiaSource { 149 class ResourceBundle::ResourceBundleImageSource : public gfx::ImageSkiaSource {
125 public: 150 public:
126 ResourceBundleImageSource(ResourceBundle* rb, int resource_id) 151 ResourceBundleImageSource(ResourceBundle* rb, int resource_id)
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 return gfx::ImageSkiaRep(image, scale); 189 return gfx::ImageSkiaRep(image, scale);
165 } 190 }
166 191
167 private: 192 private:
168 ResourceBundle* rb_; 193 ResourceBundle* rb_;
169 const int resource_id_; 194 const int resource_id_;
170 195
171 DISALLOW_COPY_AND_ASSIGN(ResourceBundleImageSource); 196 DISALLOW_COPY_AND_ASSIGN(ResourceBundleImageSource);
172 }; 197 };
173 198
199
200 // ResourceBundle -------------------------------------------------------------
201
174 // static 202 // static
175 std::string ResourceBundle::InitSharedInstanceWithLocale( 203 std::string ResourceBundle::InitSharedInstanceWithLocale(
176 const std::string& pref_locale, 204 const std::string& pref_locale,
177 Delegate* delegate, 205 Delegate* delegate,
178 LoadResources load_resources) { 206 LoadResources load_resources) {
179 InitSharedInstance(delegate); 207 InitSharedInstance(delegate);
180 if (load_resources == LOAD_COMMON_RESOURCES) 208 if (load_resources == LOAD_COMMON_RESOURCES)
181 g_shared_instance_->LoadCommonResources(); 209 g_shared_instance_->LoadCommonResources();
182 std::string result = g_shared_instance_->LoadLocaleResources(pref_locale); 210 std::string result = g_shared_instance_->LoadLocaleResources(pref_locale);
183 g_shared_instance_->InitDefaultFontList(); 211 g_shared_instance_->InitDefaultFontList();
(...skipping 712 matching lines...) Expand 10 before | Expand all | Expand 10 after
896 // static 924 // static
897 bool ResourceBundle::DecodePNG(const unsigned char* buf, 925 bool ResourceBundle::DecodePNG(const unsigned char* buf,
898 size_t size, 926 size_t size,
899 SkBitmap* bitmap, 927 SkBitmap* bitmap,
900 bool* fell_back_to_1x) { 928 bool* fell_back_to_1x) {
901 *fell_back_to_1x = PNGContainsFallbackMarker(buf, size); 929 *fell_back_to_1x = PNGContainsFallbackMarker(buf, size);
902 return gfx::PNGCodec::Decode(buf, size, bitmap); 930 return gfx::PNGCodec::Decode(buf, size, bitmap);
903 } 931 }
904 932
905 } // namespace ui 933 } // namespace ui
OLDNEW
« no previous file with comments | « ui/base/resource/resource_bundle.h ('k') | ui/base/test/material_design_controller_test_api.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698