diff options
author | sail@chromium.org <sail@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-01 06:11:52 +0000 |
---|---|---|
committer | sail@chromium.org <sail@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-01 06:11:52 +0000 |
commit | 63942f254fe21a93e8a0183e2107ea428f7cd7a1 (patch) | |
tree | 7a0299e8b66b6c088337e5cd483bd7701bba3e01 | |
parent | c7d2eb3f7ea80d42722e64fe319d090a199d0a04 (diff) | |
download | chromium_src-63942f254fe21a93e8a0183e2107ea428f7cd7a1.zip chromium_src-63942f254fe21a93e8a0183e2107ea428f7cd7a1.tar.gz chromium_src-63942f254fe21a93e8a0183e2107ea428f7cd7a1.tar.bz2 |
Add scale factor tag to data packs
This CL sets the image scale factor for data packs.
This will be used by the DOM UI code to look up encoded PNG data for images with a specific scale factor.
BUG=114311
TEST=
Review URL: http://codereview.chromium.org/10151025
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@134682 0039d316-1c4b-4281-b951-d872f2087c98
27 files changed, 131 insertions, 51 deletions
diff --git a/chrome/browser/chrome_browser_main.cc b/chrome/browser/chrome_browser_main.cc index 9905d8a..b497dcf 100644 --- a/chrome/browser/chrome_browser_main.cc +++ b/chrome/browser/chrome_browser_main.cc @@ -123,6 +123,7 @@ #include "net/websockets/websocket_job.h" #include "ui/base/l10n/l10n_util.h" #include "ui/base/resource/resource_bundle.h" +#include "ui/base/resource/resource_handle.h" #if defined(OS_LINUX) && !defined(OS_CHROMEOS) #include "chrome/browser/first_run/upgrade_util_linux.h" @@ -1305,7 +1306,8 @@ int ChromeBrowserMainParts::PreCreateThreadsImpl() { FilePath resources_pack_path; PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path); - ResourceBundle::GetSharedInstance().AddDataPack(resources_pack_path); + ResourceBundle::GetSharedInstance().AddDataPack( + resources_pack_path, ui::ResourceHandle::kScaleFactor100x); #endif // defined(OS_MACOSX) } diff --git a/chrome/browser/chrome_browser_main_mac.mm b/chrome/browser/chrome_browser_main_mac.mm index c0ac4ac..cb09c85 100644 --- a/chrome/browser/chrome_browser_main_mac.mm +++ b/chrome/browser/chrome_browser_main_mac.mm @@ -25,6 +25,7 @@ #include "content/public/common/result_codes.h" #include "ui/base/l10n/l10n_util_mac.h" #include "ui/base/resource/resource_bundle.h" +#include "ui/base/resource/resource_handle.h" void RecordBreakpadStatusUMA(MetricsService* metrics) { metrics->RecordBreakpadRegistration(IsCrashReporterEnabled()); @@ -92,7 +93,8 @@ void ChromeBrowserMainPartsMac::PreMainMessageLoopStart() { FilePath resources_pack_path; PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path); - ResourceBundle::GetSharedInstance().AddDataPack(resources_pack_path); + ResourceBundle::GetSharedInstance().AddDataPack( + resources_pack_path, ui::ResourceHandle::kScaleFactor100x); } // This is a no-op if the KeystoneRegistration framework is not present. diff --git a/chrome/browser/themes/browser_theme_pack.cc b/chrome/browser/themes/browser_theme_pack.cc index 5d8fd73..42797d4 100644 --- a/chrome/browser/themes/browser_theme_pack.cc +++ b/chrome/browser/themes/browser_theme_pack.cc @@ -380,7 +380,8 @@ scoped_refptr<BrowserThemePack> BrowserThemePack::BuildFromDataPack( // (see http://crbug.com/80206) base::ThreadRestrictions::ScopedAllowIO allow_io; scoped_refptr<BrowserThemePack> pack(new BrowserThemePack); - pack->data_pack_.reset(new ui::DataPack); + pack->data_pack_.reset( + new ui::DataPack(ui::ResourceHandle::kScaleFactor100x)); if (!pack->data_pack_->Load(path)) { LOG(ERROR) << "Failed to load theme data pack."; diff --git a/chrome/browser/ui/webui/web_ui_browsertest.cc b/chrome/browser/ui/webui/web_ui_browsertest.cc index 96d211b..c7061f1 100644 --- a/chrome/browser/ui/webui/web_ui_browsertest.cc +++ b/chrome/browser/ui/webui/web_ui_browsertest.cc @@ -32,6 +32,7 @@ #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest-spi.h" #include "ui/base/resource/resource_bundle.h" +#include "ui/base/resource/resource_handle.h" using content::NavigationController; using content::RenderViewHost; @@ -320,7 +321,8 @@ void WebUIBrowserTest::SetUpInProcessBrowserTestFixture() { // TODO(dtseng): should this be part of every BrowserTest or just WebUI test. FilePath resources_pack_path; PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path); - ResourceBundle::GetSharedInstance().AddDataPack(resources_pack_path); + ResourceBundle::GetSharedInstance().AddDataPack( + resources_pack_path, ui::ResourceHandle::kScaleFactor100x); FilePath mockPath; ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &mockPath)); diff --git a/chrome/test/base/chrome_test_suite.cc b/chrome/test/base/chrome_test_suite.cc index 0efafbc..b0dd7e2 100644 --- a/chrome/test/base/chrome_test_suite.cc +++ b/chrome/test/base/chrome_test_suite.cc @@ -25,6 +25,7 @@ #include "net/base/net_util.h" #include "testing/gtest/include/gtest/gtest.h" #include "ui/base/resource/resource_bundle.h" +#include "ui/base/resource/resource_handle.h" #include "ui/base/ui_base_paths.h" #if defined(OS_MACOSX) @@ -199,7 +200,8 @@ void ChromeTestSuite::Initialize() { PathService::Get(base::DIR_MODULE, &resources_pack_path); resources_pack_path = resources_pack_path.Append(FILE_PATH_LITERAL("resources.pak")); - ResourceBundle::GetSharedInstance().AddDataPack(resources_pack_path); + ResourceBundle::GetSharedInstance().AddDataPack( + resources_pack_path, ui::ResourceHandle::kScaleFactor100x); // Mock out the compositor on platforms that use it. ui::SetupTestCompositor(); diff --git a/chrome/tools/mac_helpers/infoplist_strings_util.mm b/chrome/tools/mac_helpers/infoplist_strings_util.mm index 935b531..270e07f 100644 --- a/chrome/tools/mac_helpers/infoplist_strings_util.mm +++ b/chrome/tools/mac_helpers/infoplist_strings_util.mm @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -60,7 +60,7 @@ ui::DataPack* LoadResourceDataPack(const char* dir_path, dir_path, branding_strings_name, locale_name]; if (resource_path) { FilePath resources_pak_path([resource_path fileSystemRepresentation]); - resource_pack = new ui::DataPack; + resource_pack = new ui::DataPack(ui::ResourceHandle::kScaleFactor100x); bool success = resource_pack->Load(resources_pak_path); if (!success) { delete resource_pack; diff --git a/chrome_frame/simple_resource_loader.cc b/chrome_frame/simple_resource_loader.cc index 36c5e01..8d1524f 100644 --- a/chrome_frame/simple_resource_loader.cc +++ b/chrome_frame/simple_resource_loader.cc @@ -205,7 +205,8 @@ bool SimpleResourceLoader::LoadLocalePack( if (file_util::PathExists(resource_pack_path) && file_util::PathExists(dll_path)) { - scoped_ptr<ui::DataPack> cur_data_pack(new ui::DataPack()); + scoped_ptr<ui::DataPack> cur_data_pack( + new ui::DataPack(ui::ResourceHandle::kScaleFactor100x)); if (!cur_data_pack->Load(resource_pack_path)) continue; diff --git a/content/test/test_content_client.cc b/content/test/test_content_client.cc index b59e962..4f7bce9 100644 --- a/content/test/test_content_client.cc +++ b/content/test/test_content_client.cc @@ -10,7 +10,8 @@ #include "base/path_service.h" #include "base/string_piece.h" -TestContentClient::TestContentClient() { +TestContentClient::TestContentClient() + : data_pack_(ui::ResourceHandle::kScaleFactor100x) { FilePath content_resources_pack_path; PathService::Get(base::DIR_MODULE, &content_resources_pack_path); content_resources_pack_path = content_resources_pack_path.Append( diff --git a/ui/base/resource/data_pack.cc b/ui/base/resource/data_pack.cc index 6a8490c..0fa97a8 100644 --- a/ui/base/resource/data_pack.cc +++ b/ui/base/resource/data_pack.cc @@ -61,9 +61,12 @@ enum LoadErrors { namespace ui { -// In .cc for MemoryMappedFile dtor. -DataPack::DataPack() : resource_count_(0), text_encoding_type_(BINARY) { +DataPack::DataPack(float scale_factor) + : resource_count_(0), + text_encoding_type_(BINARY), + scale_factor_(scale_factor) { } + DataPack::~DataPack() { } @@ -183,6 +186,10 @@ ResourceHandle::TextEncodingType DataPack::GetTextEncodingType() const { return text_encoding_type_; } +float DataPack::GetScaleFactor() const { + return scale_factor_; +} + // static bool DataPack::WritePack(const FilePath& path, const std::map<uint16, base::StringPiece>& resources, diff --git a/ui/base/resource/data_pack.h b/ui/base/resource/data_pack.h index 5e3426f..0ac5efe 100644 --- a/ui/base/resource/data_pack.h +++ b/ui/base/resource/data_pack.h @@ -32,7 +32,7 @@ namespace ui { class UI_EXPORT DataPack : public ResourceHandle { public: - DataPack(); + DataPack(float scale_factor); virtual ~DataPack(); // Load a pack file from |path|, returning false on error. @@ -52,6 +52,7 @@ class UI_EXPORT DataPack : public ResourceHandle { virtual base::RefCountedStaticMemory* GetStaticMemory( uint16 resource_id) const OVERRIDE; virtual TextEncodingType GetTextEncodingType() const OVERRIDE; + virtual float GetScaleFactor() const OVERRIDE; private: // The memory-mapped data. @@ -63,6 +64,10 @@ class UI_EXPORT DataPack : public ResourceHandle { // Type of encoding for text resources. TextEncodingType text_encoding_type_; + // The scale of the image in this resource pack relative to images in the 1x + // resource pak. + float scale_factor_; + DISALLOW_COPY_AND_ASSIGN(DataPack); }; diff --git a/ui/base/resource/data_pack_unittest.cc b/ui/base/resource/data_pack_unittest.cc index 1c0bd7a..36be6fd 100644 --- a/ui/base/resource/data_pack_unittest.cc +++ b/ui/base/resource/data_pack_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -31,7 +31,7 @@ TEST(DataPackTest, Load) { static_cast<int>(kSamplePakSize)); // Load the file through the data pack API. - DataPack pack; + DataPack pack(ResourceHandle::kScaleFactor100x); ASSERT_TRUE(pack.Load(data_path)); base::StringPiece data; @@ -63,7 +63,7 @@ TEST(DataPackTest, LoadFileWithTruncatedHeader) { data_path = data_path.Append(FILE_PATH_LITERAL( "ui/base/test/data/data_pack_unittest/truncated-header.pak")); - DataPack pack; + DataPack pack(ResourceHandle::kScaleFactor100x); ASSERT_FALSE(pack.Load(data_path)); } @@ -87,7 +87,7 @@ TEST_P(DataPackTest, Write) { ASSERT_TRUE(DataPack::WritePack(file, resources, GetParam())); // Now try to read the data back in. - DataPack pack; + DataPack pack(ResourceHandle::kScaleFactor100x); ASSERT_TRUE(pack.Load(file)); EXPECT_EQ(pack.GetTextEncodingType(), GetParam()); diff --git a/ui/base/resource/resource_bundle.cc b/ui/base/resource/resource_bundle.cc index 13aaacf..4c5a50b 100644 --- a/ui/base/resource/resource_bundle.cc +++ b/ui/base/resource/resource_bundle.cc @@ -89,8 +89,9 @@ bool ResourceBundle::LocaleDataPakExists(const std::string& locale) { return !GetLocaleFilePath(locale).empty(); } -void ResourceBundle::AddDataPack(const FilePath& path) { - scoped_ptr<DataPack> data_pack(new DataPack()); +void ResourceBundle::AddDataPack(const FilePath& path, float scale_factor) { + scoped_ptr<DataPack> data_pack( + new DataPack(ResourceHandle::kScaleFactor100x)); if (data_pack->Load(path)) { data_packs_.push_back(data_pack.release()); } else { @@ -141,7 +142,8 @@ std::string ResourceBundle::LoadLocaleResources( return std::string(); } - scoped_ptr<DataPack> data_pack(new DataPack()); + scoped_ptr<DataPack> data_pack( + new DataPack(ResourceHandle::kScaleFactor100x)); if (!data_pack->Load(locale_file_path)) { UMA_HISTOGRAM_ENUMERATION("ResourceBundle.LoadLocaleResourcesError", logging::GetLastSystemErrorCode(), 16000); @@ -155,11 +157,12 @@ std::string ResourceBundle::LoadLocaleResources( void ResourceBundle::LoadTestResources(const FilePath& path) { // Use the given resource pak for both common and localized resources. - scoped_ptr<DataPack> data_pack(new DataPack()); + scoped_ptr<DataPack> data_pack( + new DataPack(ResourceHandle::kScaleFactor100x)); if (data_pack->Load(path)) data_packs_.push_back(data_pack.release()); - data_pack.reset(new DataPack()); + data_pack.reset(new DataPack(ResourceHandle::kScaleFactor100x)); if (data_pack->Load(path)) locale_resources_data_.reset(data_pack.release()); } diff --git a/ui/base/resource/resource_bundle.h b/ui/base/resource/resource_bundle.h index 974e5d3..7b06e5e9 100644 --- a/ui/base/resource/resource_bundle.h +++ b/ui/base/resource/resource_bundle.h @@ -87,9 +87,10 @@ class UI_EXPORT ResourceBundle { // Registers additional data pack files with the global ResourceBundle. When // looking for a DataResource, we will search these files after searching the - // main module. This method is not thread safe! You should call it - // immediately after calling InitSharedInstance. - void AddDataPack(const FilePath& path); + // main module. |scale_factor| is the scale of images in this resource pak + // relative to the images in the 1x resource pak. This method is not thread + // safe! You should call it immediately after calling InitSharedInstance. + void AddDataPack(const FilePath& path, float scale_factor); // Changes the locale for an already-initialized ResourceBundle, returning the // name of the newly-loaded locale. Future calls to get strings will return diff --git a/ui/base/resource/resource_bundle_android.cc b/ui/base/resource/resource_bundle_android.cc index 62a53c6..6825c40 100644 --- a/ui/base/resource/resource_bundle_android.cc +++ b/ui/base/resource/resource_bundle_android.cc @@ -11,6 +11,7 @@ #include "base/logging.h" #include "base/path_service.h" #include "base/stringprintf.h" +#include "ui/base/resource/resource_handle.h" namespace { @@ -26,9 +27,12 @@ FilePath GetResourcesPakFilePath(const std::string& pak_name) { namespace ui { void ResourceBundle::LoadCommonResources() { - AddDataPack(GetResourcesPakFilePath("chrome.pak")); - AddDataPack(GetResourcesPakFilePath("theme_resources_standard.pak")); - AddDataPack(GetResourcesPakFilePath("ui_resources_standard.pak")); + AddDataPack(GetResourcesPakFilePath("chrome.pak"), + ResourceHandle::kScaleFactor100x); + AddDataPack(GetResourcesPakFilePath("theme_resources_standard.pak"), + ResourceHandle::kScaleFactor100x); + AddDataPack(GetResourcesPakFilePath("ui_resources_standard.pak"), + ResourceHandle::kScaleFactor100x); } gfx::Image& ResourceBundle::GetNativeImageNamed(int resource_id, ImageRTL rtl) { diff --git a/ui/base/resource/resource_bundle_aurax11.cc b/ui/base/resource/resource_bundle_aurax11.cc index 3c1f824..76152ea 100644 --- a/ui/base/resource/resource_bundle_aurax11.cc +++ b/ui/base/resource/resource_bundle_aurax11.cc @@ -7,6 +7,7 @@ #include "base/logging.h" #include "base/path_service.h" #include "ui/base/layout.h" +#include "ui/base/resource/resource_handle.h" #include "ui/base/ui_base_paths.h" #include "ui/gfx/image/image.h" @@ -24,13 +25,17 @@ FilePath GetResourcesPakFilePath(const std::string& pak_name) { namespace ui { void ResourceBundle::LoadCommonResources() { - AddDataPack(GetResourcesPakFilePath("chrome.pak")); - AddDataPack(GetResourcesPakFilePath("theme_resources_standard.pak")); + AddDataPack(GetResourcesPakFilePath("chrome.pak"), + ResourceHandle::kScaleFactor100x); + AddDataPack(GetResourcesPakFilePath("theme_resources_standard.pak"), + ResourceHandle::kScaleFactor100x); if (ui::GetDisplayLayout() == ui::LAYOUT_TOUCH) { - AddDataPack(GetResourcesPakFilePath("ui_resources_touch.pak")); + AddDataPack(GetResourcesPakFilePath("ui_resources_touch.pak"), + ResourceHandle::kScaleFactor100x); } else { - AddDataPack(GetResourcesPakFilePath("ui_resources_standard.pak")); + AddDataPack(GetResourcesPakFilePath("ui_resources_standard.pak"), + ResourceHandle::kScaleFactor100x); } } diff --git a/ui/base/resource/resource_bundle_gtk.cc b/ui/base/resource/resource_bundle_gtk.cc index bc4a5cc..6125dd7 100644 --- a/ui/base/resource/resource_bundle_gtk.cc +++ b/ui/base/resource/resource_bundle_gtk.cc @@ -8,6 +8,7 @@ #include "base/logging.h" #include "base/memory/ref_counted_memory.h" #include "base/path_service.h" +#include "ui/base/resource/resource_handle.h" #include "base/synchronization/lock.h" #include "third_party/skia/include/core/SkBitmap.h" #include "ui/base/gtk/scoped_gobject.h" @@ -61,9 +62,12 @@ FilePath GetResourcesPakFilePath(const std::string& pak_name) { } // namespace void ResourceBundle::LoadCommonResources() { - AddDataPack(GetResourcesPakFilePath("chrome.pak")); - AddDataPack(GetResourcesPakFilePath("theme_resources_standard.pak")); - AddDataPack(GetResourcesPakFilePath("ui_resources_standard.pak")); + AddDataPack(GetResourcesPakFilePath("chrome.pak"), + ResourceHandle::kScaleFactor100x); + AddDataPack(GetResourcesPakFilePath("theme_resources_standard.pak"), + ResourceHandle::kScaleFactor100x); + AddDataPack(GetResourcesPakFilePath("ui_resources_standard.pak"), + ResourceHandle::kScaleFactor100x); } gfx::Image& ResourceBundle::GetNativeImageNamed(int resource_id, ImageRTL rtl) { diff --git a/ui/base/resource/resource_bundle_mac.mm b/ui/base/resource/resource_bundle_mac.mm index ee2a6ef..cd89433 100644 --- a/ui/base/resource/resource_bundle_mac.mm +++ b/ui/base/resource/resource_bundle_mac.mm @@ -44,17 +44,23 @@ FilePath GetResourcesPakFilePath(NSString* name, NSString* mac_locale) { } // namespace void ResourceBundle::LoadCommonResources() { - AddDataPack(GetResourcesPakFilePath(@"chrome", nil)); - AddDataPack(GetResourcesPakFilePath(@"theme_resources_standard", nil)); - AddDataPack(GetResourcesPakFilePath(@"ui_resources_standard", nil)); + AddDataPack(GetResourcesPakFilePath(@"chrome", nil), + ResourceHandle::kScaleFactor100x); + AddDataPack(GetResourcesPakFilePath(@"theme_resources_standard", nil), + ResourceHandle::kScaleFactor100x); + AddDataPack(GetResourcesPakFilePath(@"ui_resources_standard", nil), + ResourceHandle::kScaleFactor100x); // On Windows and ChromeOS we load either the 1x resource or the 2x resource. // On Mac we load both and let the UI framework decide which one to use. #if defined(ENABLE_HIDPI) if (base::mac::IsOSLionOrLater()) { - AddDataPack(GetResourcesPakFilePath(@"theme_resources_2x", nil)); - AddDataPack(GetResourcesPakFilePath(@"theme_resources_standard_2x", nil)); - AddDataPack(GetResourcesPakFilePath(@"ui_resources_standard_2x", nil)); + AddDataPack(GetResourcesPakFilePath(@"theme_resources_2x", nil), + ResourceHandle::kScaleFactor200x); + AddDataPack(GetResourcesPakFilePath(@"theme_resources_standard_2x", nil), + ResourceHandle::kScaleFactor200x); + AddDataPack(GetResourcesPakFilePath(@"ui_resources_standard_2x", nil), + ResourceHandle::kScaleFactor200x); } #endif } diff --git a/ui/base/resource/resource_bundle_unittest.cc b/ui/base/resource/resource_bundle_unittest.cc index f98d8a7..5e2598ed 100644 --- a/ui/base/resource/resource_bundle_unittest.cc +++ b/ui/base/resource/resource_bundle_unittest.cc @@ -40,7 +40,7 @@ TEST(ResourceBundle, LoadDataResourceBytes) { // Give a .pak file that doesn't exist so we will fail to load it. resource_bundle.AddDataPack(FilePath( - FILE_PATH_LITERAL("non-existant-file.pak"))); + FILE_PATH_LITERAL("non-existant-file.pak")), 1.0); EXPECT_EQ(NULL, resource_bundle.LoadDataResourceBytes(kUnfoundResourceId)); } diff --git a/ui/base/resource/resource_bundle_win.cc b/ui/base/resource/resource_bundle_win.cc index 7890002..c28cf12 100644 --- a/ui/base/resource/resource_bundle_win.cc +++ b/ui/base/resource/resource_bundle_win.cc @@ -45,16 +45,22 @@ void ResourceBundle::LoadCommonResources() { switch (ui::GetDisplayLayout()) { case ui::LAYOUT_TOUCH: - AddDataPack(GetResourcesPakFilePath("theme_resources_metro_1x.pak")); - AddDataPack(GetResourcesPakFilePath("ui_resources_standard.pak")); + AddDataPack(GetResourcesPakFilePath("theme_resources_metro_1x.pak"), + ResourceHandle::kScaleFactor100x); + AddDataPack(GetResourcesPakFilePath("ui_resources_standard.pak"), + ResourceHandle::kScaleFactor100x); break; default: if (use_hidpi) { - AddDataPack(GetResourcesPakFilePath("theme_resources_2x.pak")); - AddDataPack(GetResourcesPakFilePath("ui_resources_2x.pak")); + AddDataPack(GetResourcesPakFilePath("theme_resources_2x.pak"), + ResourceHandle::kScaleFactor200x); + AddDataPack(GetResourcesPakFilePath("ui_resources_2x.pak"), + ResourceHandle::kScaleFactor200x); } else { - AddDataPack(GetResourcesPakFilePath("theme_resources_standard.pak")); - AddDataPack(GetResourcesPakFilePath("ui_resources_standard.pak")); + AddDataPack(GetResourcesPakFilePath("theme_resources_standard.pak"), + ResourceHandle::kScaleFactor100x); + AddDataPack(GetResourcesPakFilePath("ui_resources_standard.pak"), + ResourceHandle::kScaleFactor100x); } break; } diff --git a/ui/base/resource/resource_data_dll_win.cc b/ui/base/resource/resource_data_dll_win.cc index 4c7e052..48e9db1 100644 --- a/ui/base/resource/resource_data_dll_win.cc +++ b/ui/base/resource/resource_data_dll_win.cc @@ -48,4 +48,8 @@ ResourceHandle::TextEncodingType ResourceDataDLL::GetTextEncodingType() const { return BINARY; } +float ResourceDataDLL::GetScaleFactor() const { + return 1.0; +} + } // namespace ui diff --git a/ui/base/resource/resource_data_dll_win.h b/ui/base/resource/resource_data_dll_win.h index 9b9a6a0..e21e9aa 100644 --- a/ui/base/resource/resource_data_dll_win.h +++ b/ui/base/resource/resource_data_dll_win.h @@ -24,6 +24,7 @@ class ResourceDataDLL : public ResourceHandle { virtual base::RefCountedStaticMemory* GetStaticMemory( uint16 resource_id) const OVERRIDE; virtual TextEncodingType GetTextEncodingType() const OVERRIDE; + virtual float GetScaleFactor() const OVERRIDE; private: const HINSTANCE module_; diff --git a/ui/base/resource/resource_handle.cc b/ui/base/resource/resource_handle.cc new file mode 100644 index 0000000..947ff80 --- /dev/null +++ b/ui/base/resource/resource_handle.cc @@ -0,0 +1,12 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ui/base/resource/resource_handle.h" + +namespace ui { + +const float ResourceHandle::kScaleFactor100x = 1.0; +const float ResourceHandle::kScaleFactor200x = 2.0; + +} // namespace ui diff --git a/ui/base/resource/resource_handle.h b/ui/base/resource/resource_handle.h index ce3a23b..b40741e 100644 --- a/ui/base/resource/resource_handle.h +++ b/ui/base/resource/resource_handle.h @@ -25,6 +25,10 @@ class UI_EXPORT ResourceHandle { UTF16 }; + // The scale factors for image resources. + static const float kScaleFactor100x; + static const float kScaleFactor200x; + virtual ~ResourceHandle() {} // Get resource by id |resource_id|, filling in |data|. @@ -40,6 +44,10 @@ class UI_EXPORT ResourceHandle { // Get the encoding type of text resources. virtual TextEncodingType GetTextEncodingType() const = 0; + + // The scale of images in this resource pack relative to images in the 1x + // resource pak. + virtual float GetScaleFactor() const = 0; }; } // namespace ui diff --git a/ui/test/test_suite.cc b/ui/test/test_suite.cc index 024543e..538b5d7 100644 --- a/ui/test/test_suite.cc +++ b/ui/test/test_suite.cc @@ -8,6 +8,7 @@ #include "base/path_service.h" #include "build/build_config.h" #include "ui/base/resource/resource_bundle.h" +#include "ui/base/resource/resource_handle.h" #include "ui/base/ui_base_paths.h" #include "ui/gfx/gfx_paths.h" @@ -54,7 +55,8 @@ void UITestSuite::Initialize() { #if !defined(OS_MACOSX) && defined(OS_POSIX) ui::ResourceBundle::GetSharedInstance().AddDataPack( - pak_dir.AppendASCII("ui_resources.pak")); + pak_dir.AppendASCII("ui_resources.pak"), + ResourceHandle::kScaleFactor100x); #endif } @@ -226,6 +226,7 @@ 'base/resource/resource_bundle_win.h', 'base/resource/resource_data_dll_win.cc', 'base/resource/resource_data_dll_win.h', + 'base/resource/resource_handle.cc', 'base/resource/resource_handle.h', 'base/text/bytes_formatting.cc', 'base/text/bytes_formatting.h', diff --git a/webkit/support/platform_support_mac.mm b/webkit/support/platform_support_mac.mm index 88a32a3..487d521 100644 --- a/webkit/support/platform_support_mac.mm +++ b/webkit/support/platform_support_mac.mm @@ -103,7 +103,7 @@ void AfterInitialize(bool unit_test_mode) { return; // We don't have a resource pack when running the unit-tests. // Load a data pack. - g_resource_data_pack = new ui::DataPack; + g_resource_data_pack = new ui::DataPack(ui::ResourceHandle::kScaleFactor100x); NSString* resource_path = [base::mac::FrameworkBundle() pathForResource:@"DumpRenderTree" ofType:@"pak"]; diff --git a/webkit/tools/test_shell/test_shell_mac.mm b/webkit/tools/test_shell/test_shell_mac.mm index 835ff4f..a5a556c 100644 --- a/webkit/tools/test_shell/test_shell_mac.mm +++ b/webkit/tools/test_shell/test_shell_mac.mm @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -212,7 +212,7 @@ void TestShell::InitializeTestShell(bool layout_test_mode, // mmap the data pack which holds strings used by WebCore. This is only // a fatal error if we're bundled, which means we might be running layout // tests. This is a harmless failure for test_shell_tests. - g_resource_data_pack = new ui::DataPack; + g_resource_data_pack = new ui::DataPack(ui::ResourceHandle::kScaleFactor100x); NSString *resource_path = [base::mac::FrameworkBundle() pathForResource:@"test_shell" ofType:@"pak"]; |