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 "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
10 #include "ui/base/layout.h" | 10 #include "ui/base/layout.h" |
11 #include "ui/base/resource/resource_handle.h" | 11 #include "ui/base/resource/resource_handle.h" |
12 #include "ui/base/ui_base_paths.h" | 12 #include "ui/base/ui_base_paths.h" |
13 #include "ui/base/ui_base_switches.h" | 13 #include "ui/base/ui_base_switches.h" |
14 #include "ui/gfx/display.h" | 14 #include "ui/gfx/display.h" |
15 #include "ui/gfx/image/image.h" | 15 #include "ui/gfx/image/image.h" |
16 | 16 |
17 namespace { | 17 namespace { |
18 | 18 |
19 FilePath GetResourcesPakFilePath(const std::string& pak_name) { | 19 FilePath GetResourcesPakFilePath(const std::string& pak_name) { |
20 FilePath path; | 20 FilePath path; |
21 if (PathService::Get(base::DIR_MODULE, &path)) | 21 if (PathService::Get(base::DIR_MODULE, &path)) |
22 return path.AppendASCII(pak_name.c_str()); | 22 return path.AppendASCII(pak_name.c_str()); |
23 | 23 |
24 // Return just the name of the pack file. | 24 // Return just the name of the pack file. |
25 return FilePath(pak_name.c_str()); | 25 return FilePath(pak_name.c_str()); |
26 } | 26 } |
27 | 27 |
28 bool ShouldLoad2xResources() { | |
29 return gfx::Display::GetForcedDeviceScaleFactor() > 1.0f || | |
30 CommandLine::ForCurrentProcess()->HasSwitch(switches::kLoad2xResources); | |
31 } | |
32 | |
33 } // namespace | 28 } // namespace |
34 | 29 |
35 namespace ui { | 30 namespace ui { |
36 | 31 |
37 void ResourceBundle::LoadCommonResources() { | 32 void ResourceBundle::LoadCommonResources() { |
38 // Always load the 1x data pack first as the 2x data pack contains both 1x and | 33 // Always load the 1x data pack first as the 2x data pack contains both 1x and |
39 // 2x images. The 1x data pack only has 1x images, thus passes in an accurate | 34 // 2x images. The 1x data pack only has 1x images, thus passes in an accurate |
40 // scale factor to gfx::ImageSkia::AddRepresentation. | 35 // scale factor to gfx::ImageSkia::AddRepresentation. |
41 | 36 |
42 AddDataPackFromPath(GetResourcesPakFilePath("chrome.pak"), | 37 AddDataPackFromPath(GetResourcesPakFilePath("chrome.pak"), |
43 SCALE_FACTOR_100P); | 38 SCALE_FACTOR_100P); |
44 | 39 |
45 if (ui::GetDisplayLayout() == ui::LAYOUT_TOUCH) { | 40 if (ui::GetDisplayLayout() == ui::LAYOUT_TOUCH) { |
46 // 1x touch | 41 // 1x touch |
47 AddDataPackFromPath(GetResourcesPakFilePath( | 42 AddDataPackFromPath(GetResourcesPakFilePath( |
48 "chrome_touch_100_percent.pak"), | 43 "chrome_touch_100_percent.pak"), |
49 SCALE_FACTOR_100P); | 44 SCALE_FACTOR_100P); |
50 if (ShouldLoad2xResources()) { | 45 |
51 // 2x touch | 46 // 2x touch |
52 AddDataPackFromPath(GetResourcesPakFilePath( | 47 // TODO(flackr): Don't log an error message if these are not found as this |
53 "chrome_touch_200_percent.pak"), | 48 // is an expected case in ChromeOS. |
54 SCALE_FACTOR_200P); | 49 AddDataPackFromPath(GetResourcesPakFilePath( |
55 } | 50 "chrome_touch_200_percent.pak"), |
| 51 SCALE_FACTOR_200P); |
56 } else { | 52 } else { |
57 // 1x non touch | 53 // 1x non touch |
58 AddDataPackFromPath(GetResourcesPakFilePath( | 54 AddDataPackFromPath(GetResourcesPakFilePath( |
59 "chrome_100_percent.pak"), | 55 "chrome_100_percent.pak"), |
60 SCALE_FACTOR_100P); | 56 SCALE_FACTOR_100P); |
61 if (ShouldLoad2xResources()) { | 57 |
62 // 2x non touch | 58 // 2x non touch |
63 AddDataPackFromPath(GetResourcesPakFilePath( | 59 // TODO(flackr): Don't log an error message if these are not found as this |
64 "chrome_200_percent.pak"), | 60 // is an expected case in ChromeOS. |
65 SCALE_FACTOR_200P); | 61 AddDataPackFromPath(GetResourcesPakFilePath( |
66 } | 62 "chrome_200_percent.pak"), |
| 63 SCALE_FACTOR_200P); |
67 } | 64 } |
68 } | 65 } |
69 | 66 |
70 gfx::Image& ResourceBundle::GetNativeImageNamed(int resource_id, ImageRTL rtl) { | 67 gfx::Image& ResourceBundle::GetNativeImageNamed(int resource_id, ImageRTL rtl) { |
71 // Flipped image is not used on ChromeOS. | 68 // Flipped image is not used on ChromeOS. |
72 DCHECK_EQ(rtl, RTL_DISABLED); | 69 DCHECK_EQ(rtl, RTL_DISABLED); |
73 return GetImageNamed(resource_id); | 70 return GetImageNamed(resource_id); |
74 } | 71 } |
75 | 72 |
76 } // namespace ui | 73 } // namespace ui |
OLD | NEW |