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
3 // found in the LICENSE file.
5 #include "ui/base/resource/resource_bundle.h"
7 #include "base/command_line.h"
8 #include "base/logging.h"
9 #include "base/path_service.h"
10 #include "ui/base/layout.h"
11 #include "ui/base/resource/material_design/material_design_controller.h"
12 #include "ui/base/resource/resource_handle.h"
13 #include "ui/base/ui_base_paths.h"
14 #include "ui/base/ui_base_switches.h"
15 #include "ui/gfx/display.h"
16 #include "ui/gfx/image/image.h"
20 base::FilePath
GetResourcesPakFilePath(const std::string
& pak_name
) {
22 if (PathService::Get(base::DIR_MODULE
, &path
))
23 return path
.AppendASCII(pak_name
.c_str());
25 // Return just the name of the pack file.
26 return base::FilePath(pak_name
.c_str());
33 // TODO(tdanderson): Refactor cross-platform loading of common resources.
34 void ResourceBundle::LoadCommonResources() {
35 if (MaterialDesignController::IsModeMaterial()) {
36 // The material design data packs contain some of the same asset IDs as in
37 // the non-material design data packs. Add these to the ResourceBundle
38 // first so that they are searched first when a request for an asset is
40 AddMaterialDesignDataPackFromPath(
41 GetResourcesPakFilePath("chrome_material_100_percent.pak"),
44 if (IsScaleFactorSupported(SCALE_FACTOR_200P
)) {
45 AddOptionalMaterialDesignDataPackFromPath(
46 GetResourcesPakFilePath("chrome_material_200_percent.pak"),
51 // Always load the 1x data pack first as the 2x data pack contains both 1x and
52 // 2x images. The 1x data pack only has 1x images, thus passes in an accurate
53 // scale factor to gfx::ImageSkia::AddRepresentation.
54 AddDataPackFromPath(GetResourcesPakFilePath(
55 "chrome_100_percent.pak"), SCALE_FACTOR_100P
);
57 if (IsScaleFactorSupported(SCALE_FACTOR_200P
)) {
58 AddOptionalDataPackFromPath(GetResourcesPakFilePath(
59 "chrome_200_percent.pak"), SCALE_FACTOR_200P
);
63 gfx::Image
& ResourceBundle::GetNativeImageNamed(int resource_id
, ImageRTL rtl
) {
64 // Flipped image is not used on ChromeOS.
65 DCHECK_EQ(rtl
, RTL_DISABLED
);
66 return GetImageNamed(resource_id
);