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

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

Issue 2209363002: Remove material design resource pak infrastructure (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove another mac test file Created 4 years, 4 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/resource/resource_bundle_mac.mm » ('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 13 matching lines...) Expand all
24 #include "base/strings/utf_string_conversions.h" 24 #include "base/strings/utf_string_conversions.h"
25 #include "base/synchronization/lock.h" 25 #include "base/synchronization/lock.h"
26 #include "base/sys_byteorder.h" 26 #include "base/sys_byteorder.h"
27 #include "build/build_config.h" 27 #include "build/build_config.h"
28 #include "skia/ext/image_operations.h" 28 #include "skia/ext/image_operations.h"
29 #include "third_party/skia/include/core/SkBitmap.h" 29 #include "third_party/skia/include/core/SkBitmap.h"
30 #include "third_party/skia/include/core/SkColor.h" 30 #include "third_party/skia/include/core/SkColor.h"
31 #include "third_party/zlib/zlib.h" 31 #include "third_party/zlib/zlib.h"
32 #include "ui/base/l10n/l10n_util.h" 32 #include "ui/base/l10n/l10n_util.h"
33 #include "ui/base/layout.h" 33 #include "ui/base/layout.h"
34 #include "ui/base/material_design/material_design_controller.h"
35 #include "ui/base/resource/data_pack.h" 34 #include "ui/base/resource/data_pack.h"
36 #include "ui/base/ui_base_paths.h" 35 #include "ui/base/ui_base_paths.h"
37 #include "ui/base/ui_base_switches.h" 36 #include "ui/base/ui_base_switches.h"
38 #include "ui/base/ui_features.h" 37 #include "ui/base/ui_features.h"
39 #include "ui/display/display.h" 38 #include "ui/display/display.h"
40 #include "ui/display/screen.h" 39 #include "ui/display/screen.h"
41 #include "ui/gfx/codec/jpeg_codec.h" 40 #include "ui/gfx/codec/jpeg_codec.h"
42 #include "ui/gfx/codec/png_codec.h" 41 #include "ui/gfx/codec/png_codec.h"
43 #include "ui/gfx/geometry/safe_integer_conversions.h" 42 #include "ui/gfx/geometry/safe_integer_conversions.h"
44 #include "ui/gfx/geometry/size_conversions.h" 43 #include "ui/gfx/geometry/size_conversions.h"
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 } 284 }
286 285
287 #if !defined(OS_ANDROID) 286 #if !defined(OS_ANDROID)
288 bool ResourceBundle::LocaleDataPakExists(const std::string& locale) { 287 bool ResourceBundle::LocaleDataPakExists(const std::string& locale) {
289 return !GetLocaleFilePath(locale, true).empty(); 288 return !GetLocaleFilePath(locale, true).empty();
290 } 289 }
291 #endif // !defined(OS_ANDROID) 290 #endif // !defined(OS_ANDROID)
292 291
293 void ResourceBundle::AddDataPackFromPath(const base::FilePath& path, 292 void ResourceBundle::AddDataPackFromPath(const base::FilePath& path,
294 ScaleFactor scale_factor) { 293 ScaleFactor scale_factor) {
295 AddDataPackFromPathInternal(path, scale_factor, false, false); 294 AddDataPackFromPathInternal(path, scale_factor, false);
296 } 295 }
297 296
298 void ResourceBundle::AddOptionalDataPackFromPath(const base::FilePath& path, 297 void ResourceBundle::AddOptionalDataPackFromPath(const base::FilePath& path,
299 ScaleFactor scale_factor) { 298 ScaleFactor scale_factor) {
300 AddDataPackFromPathInternal(path, scale_factor, true, false); 299 AddDataPackFromPathInternal(path, scale_factor, true);
301 }
302
303 void ResourceBundle::AddMaterialDesignDataPackFromPath(
304 const base::FilePath& path,
305 ScaleFactor scale_factor) {
306 AddDataPackFromPathInternal(path, scale_factor, false, true);
307 }
308
309 void ResourceBundle::AddOptionalMaterialDesignDataPackFromPath(
310 const base::FilePath& path,
311 ScaleFactor scale_factor) {
312 AddDataPackFromPathInternal(path, scale_factor, true, true);
313 } 300 }
314 301
315 void ResourceBundle::AddDataPackFromFile(base::File file, 302 void ResourceBundle::AddDataPackFromFile(base::File file,
316 ScaleFactor scale_factor) { 303 ScaleFactor scale_factor) {
317 AddDataPackFromFileRegion(std::move(file), 304 AddDataPackFromFileRegion(std::move(file),
318 base::MemoryMappedFile::Region::kWholeFile, 305 base::MemoryMappedFile::Region::kWholeFile,
319 scale_factor); 306 scale_factor);
320 } 307 }
321 308
322 void ResourceBundle::AddDataPackFromFileRegion( 309 void ResourceBundle::AddDataPackFromFileRegion(
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after
743 supported_scale_factors.push_back(SCALE_FACTOR_200P); 730 supported_scale_factors.push_back(SCALE_FACTOR_200P);
744 #endif 731 #endif
745 ui::SetSupportedScaleFactors(supported_scale_factors); 732 ui::SetSupportedScaleFactors(supported_scale_factors);
746 } 733 }
747 734
748 void ResourceBundle::FreeImages() { 735 void ResourceBundle::FreeImages() {
749 images_.clear(); 736 images_.clear();
750 } 737 }
751 738
752 void ResourceBundle::LoadChromeResources() { 739 void ResourceBundle::LoadChromeResources() {
753 // TODO(estade): remove material design specific resources.
754 // See crbug.com/613593
755 #if defined(OS_MACOSX)
756 // The material design data packs contain some of the same asset IDs as in
757 // the non-material design data packs. Add these to the ResourceBundle
758 // first so that they are searched first when a request for an asset is
759 // made.
760 if (MaterialDesignController::IsModeMaterial()) {
761 if (IsScaleFactorSupported(SCALE_FACTOR_100P)) {
762 AddMaterialDesignDataPackFromPath(
763 GetResourcesPakFilePath("chrome_material_100_percent.pak"),
764 SCALE_FACTOR_100P);
765 }
766
767 if (IsScaleFactorSupported(SCALE_FACTOR_200P)) {
768 AddOptionalMaterialDesignDataPackFromPath(
769 GetResourcesPakFilePath("chrome_material_200_percent.pak"),
770 SCALE_FACTOR_200P);
771 }
772 }
773 #endif
774
775 // Always load the 1x data pack first as the 2x data pack contains both 1x and 740 // Always load the 1x data pack first as the 2x data pack contains both 1x and
776 // 2x images. The 1x data pack only has 1x images, thus passes in an accurate 741 // 2x images. The 1x data pack only has 1x images, thus passes in an accurate
777 // scale factor to gfx::ImageSkia::AddRepresentation. 742 // scale factor to gfx::ImageSkia::AddRepresentation.
778 if (IsScaleFactorSupported(SCALE_FACTOR_100P)) { 743 if (IsScaleFactorSupported(SCALE_FACTOR_100P)) {
779 AddDataPackFromPath(GetResourcesPakFilePath( 744 AddDataPackFromPath(GetResourcesPakFilePath(
780 "chrome_100_percent.pak"), SCALE_FACTOR_100P); 745 "chrome_100_percent.pak"), SCALE_FACTOR_100P);
781 } 746 }
782 747
783 if (IsScaleFactorSupported(SCALE_FACTOR_200P)) { 748 if (IsScaleFactorSupported(SCALE_FACTOR_200P)) {
784 AddOptionalDataPackFromPath(GetResourcesPakFilePath( 749 AddOptionalDataPackFromPath(GetResourcesPakFilePath(
785 "chrome_200_percent.pak"), SCALE_FACTOR_200P); 750 "chrome_200_percent.pak"), SCALE_FACTOR_200P);
786 } 751 }
787 } 752 }
788 753
789 void ResourceBundle::AddDataPackFromPathInternal( 754 void ResourceBundle::AddDataPackFromPathInternal(
790 const base::FilePath& path, 755 const base::FilePath& path,
791 ScaleFactor scale_factor, 756 ScaleFactor scale_factor,
792 bool optional, 757 bool optional) {
793 bool has_only_material_assets) {
794 // Do not pass an empty |path| value to this method. If the absolute path is 758 // Do not pass an empty |path| value to this method. If the absolute path is
795 // unknown pass just the pack file name. 759 // unknown pass just the pack file name.
796 DCHECK(!path.empty()); 760 DCHECK(!path.empty());
797 761
798 base::FilePath pack_path = path; 762 base::FilePath pack_path = path;
799 if (delegate_) 763 if (delegate_)
800 pack_path = delegate_->GetPathForResourcePack(pack_path, scale_factor); 764 pack_path = delegate_->GetPathForResourcePack(pack_path, scale_factor);
801 765
802 // Don't try to load empty values or values that are not absolute paths. 766 // Don't try to load empty values or values that are not absolute paths.
803 if (pack_path.empty() || !pack_path.IsAbsolute()) 767 if (pack_path.empty() || !pack_path.IsAbsolute())
804 return; 768 return;
805 769
806 std::unique_ptr<DataPack> data_pack(new DataPack(scale_factor)); 770 std::unique_ptr<DataPack> data_pack(new DataPack(scale_factor));
807 data_pack->set_has_only_material_design_assets(has_only_material_assets);
808 if (data_pack->LoadFromPath(pack_path)) { 771 if (data_pack->LoadFromPath(pack_path)) {
809 AddDataPack(data_pack.release()); 772 AddDataPack(data_pack.release());
810 } else if (!optional) { 773 } else if (!optional) {
811 LOG(ERROR) << "Failed to load " << pack_path.value() 774 LOG(ERROR) << "Failed to load " << pack_path.value()
812 << "\nSome features may not be available."; 775 << "\nSome features may not be available.";
813 } 776 }
814 } 777 }
815 778
816 void ResourceBundle::AddDataPack(DataPack* data_pack) { 779 void ResourceBundle::AddDataPack(DataPack* data_pack) {
817 #if DCHECK_IS_ON() 780 #if DCHECK_IS_ON()
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
983 // static 946 // static
984 bool ResourceBundle::DecodePNG(const unsigned char* buf, 947 bool ResourceBundle::DecodePNG(const unsigned char* buf,
985 size_t size, 948 size_t size,
986 SkBitmap* bitmap, 949 SkBitmap* bitmap,
987 bool* fell_back_to_1x) { 950 bool* fell_back_to_1x) {
988 *fell_back_to_1x = PNGContainsFallbackMarker(buf, size); 951 *fell_back_to_1x = PNGContainsFallbackMarker(buf, size);
989 return gfx::PNGCodec::Decode(buf, size, bitmap); 952 return gfx::PNGCodec::Decode(buf, size, bitmap);
990 } 953 }
991 954
992 } // namespace ui 955 } // namespace ui
OLDNEW
« no previous file with comments | « ui/base/resource/resource_bundle.h ('k') | ui/base/resource/resource_bundle_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698