diff options
Diffstat (limited to 'ui/base')
-rw-r--r-- | ui/base/layout.h | 10 | ||||
-rw-r--r-- | ui/base/resource/data_pack.cc | 9 | ||||
-rw-r--r-- | ui/base/resource/data_pack.h | 10 | ||||
-rw-r--r-- | ui/base/resource/data_pack_literal.cc | 21 | ||||
-rw-r--r-- | ui/base/resource/data_pack_unittest.cc | 9 | ||||
-rw-r--r-- | ui/base/resource/resource_bundle.cc | 58 | ||||
-rw-r--r-- | ui/base/resource/resource_bundle.h | 33 | ||||
-rw-r--r-- | ui/base/resource/resource_bundle_android.cc | 6 | ||||
-rw-r--r-- | ui/base/resource/resource_bundle_aurax11.cc | 10 | ||||
-rw-r--r-- | ui/base/resource/resource_bundle_gtk.cc | 11 | ||||
-rw-r--r-- | ui/base/resource/resource_bundle_mac.mm | 12 | ||||
-rw-r--r-- | ui/base/resource/resource_bundle_unittest.cc | 82 | ||||
-rw-r--r-- | ui/base/resource/resource_bundle_win.cc | 12 | ||||
-rw-r--r-- | ui/base/resource/resource_data_dll_win.cc | 13 | ||||
-rw-r--r-- | ui/base/resource/resource_data_dll_win.h | 3 | ||||
-rw-r--r-- | ui/base/resource/resource_handle.cc | 12 | ||||
-rw-r--r-- | ui/base/resource/resource_handle.h | 10 |
17 files changed, 98 insertions, 223 deletions
diff --git a/ui/base/layout.h b/ui/base/layout.h index b65bfdd..be65e6e 100644 --- a/ui/base/layout.h +++ b/ui/base/layout.h @@ -27,16 +27,6 @@ enum DisplayLayout { // the .pak file of theme resources to load. UI_EXPORT DisplayLayout GetDisplayLayout(); -enum ScaleFactor { - SCALE_FACTOR_100P, - - // The scale factor used for unscaled binary data, the 1x (default) scale - // factor data packs. - SCALE_FACTOR_NONE = SCALE_FACTOR_100P, - - SCALE_FACTOR_200P, -}; - } // namespace ui #endif // UI_BASE_LAYOUT_H_ diff --git a/ui/base/resource/data_pack.cc b/ui/base/resource/data_pack.cc index e1d8c14..0fa97a8 100644 --- a/ui/base/resource/data_pack.cc +++ b/ui/base/resource/data_pack.cc @@ -61,7 +61,7 @@ enum LoadErrors { namespace ui { -DataPack::DataPack(ui::ScaleFactor scale_factor) +DataPack::DataPack(float scale_factor) : resource_count_(0), text_encoding_type_(BINARY), scale_factor_(scale_factor) { @@ -145,11 +145,6 @@ bool DataPack::Load(const FilePath& path) { return true; } -bool DataPack::HasResource(uint16 resource_id) const { - return !!bsearch(&resource_id, mmap_->data() + kHeaderLength, resource_count_, - sizeof(DataPackEntry), DataPackEntry::CompareById); -} - bool DataPack::GetStringPiece(uint16 resource_id, base::StringPiece* data) const { // It won't be hard to make this endian-agnostic, but it's not worth @@ -191,7 +186,7 @@ ResourceHandle::TextEncodingType DataPack::GetTextEncodingType() const { return text_encoding_type_; } -ui::ScaleFactor DataPack::GetScaleFactor() const { +float DataPack::GetScaleFactor() const { return scale_factor_; } diff --git a/ui/base/resource/data_pack.h b/ui/base/resource/data_pack.h index 3c03253..0ac5efe 100644 --- a/ui/base/resource/data_pack.h +++ b/ui/base/resource/data_pack.h @@ -15,9 +15,8 @@ #include "base/basictypes.h" #include "base/memory/scoped_ptr.h" #include "base/string_piece.h" -#include "ui/base/layout.h" -#include "ui/base/resource/resource_handle.h" #include "ui/base/ui_export.h" +#include "ui/base/resource/resource_handle.h" class FilePath; @@ -33,7 +32,7 @@ namespace ui { class UI_EXPORT DataPack : public ResourceHandle { public: - DataPack(ui::ScaleFactor scale_factor); + DataPack(float scale_factor); virtual ~DataPack(); // Load a pack file from |path|, returning false on error. @@ -48,13 +47,12 @@ class UI_EXPORT DataPack : public ResourceHandle { TextEncodingType textEncodingType); // ResourceHandle implementation: - virtual bool HasResource(uint16 resource_id) const OVERRIDE; virtual bool GetStringPiece(uint16 resource_id, base::StringPiece* data) const OVERRIDE; virtual base::RefCountedStaticMemory* GetStaticMemory( uint16 resource_id) const OVERRIDE; virtual TextEncodingType GetTextEncodingType() const OVERRIDE; - virtual ui::ScaleFactor GetScaleFactor() const OVERRIDE; + virtual float GetScaleFactor() const OVERRIDE; private: // The memory-mapped data. @@ -68,7 +66,7 @@ class UI_EXPORT DataPack : public ResourceHandle { // The scale of the image in this resource pack relative to images in the 1x // resource pak. - ui::ScaleFactor scale_factor_; + float scale_factor_; DISALLOW_COPY_AND_ASSIGN(DataPack); }; diff --git a/ui/base/resource/data_pack_literal.cc b/ui/base/resource/data_pack_literal.cc index 05e610b..510d07a 100644 --- a/ui/base/resource/data_pack_literal.cc +++ b/ui/base/resource/data_pack_literal.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 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. @@ -21,23 +21,4 @@ extern const char kSamplePakContents[] = { extern const size_t kSamplePakSize = sizeof(kSamplePakContents); -extern const char kSamplePakContents2x[] = { - 0x04, 0x00, 0x00, 0x00, // header(version - 0x01, 0x00, 0x00, 0x00, // no. entries - 0x01, // encoding) - 0x04, 0x00, 0x15, 0x00, 0x00, 0x00, // index entry 4 - 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, // extra entry for the size of last - 't', 'h', 'i', 's', ' ', 'i', 's', ' ', 'i', 'd', ' ', '4', ' ', '2', 'x' -}; - -extern const size_t kSamplePakSize2x = sizeof(kSamplePakContents2x); - -extern const char kEmptyPakContents[] = { - 0x04, 0x00, 0x00, 0x00, // header(version - 0x00, 0x00, 0x00, 0x00, // no. entries - 0x01 -}; - -extern const size_t kEmptyPakSize = sizeof(kEmptyPakContents); - } // namespace ui diff --git a/ui/base/resource/data_pack_unittest.cc b/ui/base/resource/data_pack_unittest.cc index 1ac2145..36be6fd 100644 --- a/ui/base/resource/data_pack_unittest.cc +++ b/ui/base/resource/data_pack_unittest.cc @@ -31,14 +31,12 @@ TEST(DataPackTest, Load) { static_cast<int>(kSamplePakSize)); // Load the file through the data pack API. - DataPack pack(SCALE_FACTOR_100P); + DataPack pack(ResourceHandle::kScaleFactor100x); ASSERT_TRUE(pack.Load(data_path)); base::StringPiece data; - ASSERT_TRUE(pack.HasResource(4)); ASSERT_TRUE(pack.GetStringPiece(4, &data)); EXPECT_EQ("this is id 4", data); - ASSERT_TRUE(pack.HasResource(6)); ASSERT_TRUE(pack.GetStringPiece(6, &data)); EXPECT_EQ("this is id 6", data); @@ -49,7 +47,6 @@ TEST(DataPackTest, Load) { EXPECT_EQ(0U, data.length()); // Try looking up an invalid key. - ASSERT_FALSE(pack.HasResource(140)); ASSERT_FALSE(pack.GetStringPiece(140, &data)); } @@ -66,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(SCALE_FACTOR_100P); + DataPack pack(ResourceHandle::kScaleFactor100x); ASSERT_FALSE(pack.Load(data_path)); } @@ -90,7 +87,7 @@ TEST_P(DataPackTest, Write) { ASSERT_TRUE(DataPack::WritePack(file, resources, GetParam())); // Now try to read the data back in. - DataPack pack(SCALE_FACTOR_100P); + 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 bc77d53..c5fa973 100644 --- a/ui/base/resource/resource_bundle.cc +++ b/ui/base/resource/resource_bundle.cc @@ -19,7 +19,6 @@ #include "build/build_config.h" #include "third_party/skia/include/core/SkBitmap.h" #include "ui/base/l10n/l10n_util.h" -#include "ui/base/layout.h" #include "ui/base/resource/data_pack.h" #include "ui/base/ui_base_paths.h" #include "ui/base/ui_base_switches.h" @@ -61,7 +60,7 @@ void ResourceBundle::InitSharedInstanceWithPakFile(const FilePath& path) { DCHECK(g_shared_instance_ == NULL) << "ResourceBundle initialized twice"; g_shared_instance_ = new ResourceBundle(NULL); - g_shared_instance_->LoadTestResources(path, path); + g_shared_instance_->LoadTestResources(path); } // static @@ -88,8 +87,7 @@ bool ResourceBundle::LocaleDataPakExists(const std::string& locale) { return !GetLocaleFilePath(locale).empty(); } -void ResourceBundle::AddDataPack(const FilePath& path, - ScaleFactor scale_factor) { +void ResourceBundle::AddDataPack(const FilePath& path, float scale_factor) { // Do not pass an empty |path| value to this method. If the absolute path is // unknown pass just the pack file name. DCHECK(!path.empty()); @@ -103,7 +101,7 @@ void ResourceBundle::AddDataPack(const FilePath& path, return; scoped_ptr<DataPack> data_pack( - new DataPack(scale_factor)); + new DataPack(ResourceHandle::kScaleFactor100x)); if (data_pack->Load(pack_path)) { data_packs_.push_back(data_pack.release()); } else { @@ -166,7 +164,7 @@ std::string ResourceBundle::LoadLocaleResources( } scoped_ptr<DataPack> data_pack( - new DataPack(SCALE_FACTOR_100P)); + new DataPack(ResourceHandle::kScaleFactor100x)); if (!data_pack->Load(locale_file_path)) { UMA_HISTOGRAM_ENUMERATION("ResourceBundle.LoadLocaleResourcesError", logging::GetLastSystemErrorCode(), 16000); @@ -178,21 +176,16 @@ std::string ResourceBundle::LoadLocaleResources( return app_locale; } -void ResourceBundle::LoadTestResources(const FilePath& path, - const FilePath& locale_path) { +void ResourceBundle::LoadTestResources(const FilePath& path) { // Use the given resource pak for both common and localized resources. scoped_ptr<DataPack> data_pack( - new DataPack(SCALE_FACTOR_100P)); - if (!path.empty() && data_pack->Load(path)) + new DataPack(ResourceHandle::kScaleFactor100x)); + if (data_pack->Load(path)) data_packs_.push_back(data_pack.release()); - data_pack.reset(new DataPack(ui::SCALE_FACTOR_NONE)); - if (!locale_path.empty() && data_pack->Load(locale_path)) { + data_pack.reset(new DataPack(ResourceHandle::kScaleFactor100x)); + if (data_pack->Load(path)) locale_resources_data_.reset(data_pack.release()); - } else { - locale_resources_data_.reset( - new DataPack(ui::SCALE_FACTOR_NONE)); - } } void ResourceBundle::UnloadLocaleResources() { @@ -277,45 +270,30 @@ gfx::Image& ResourceBundle::GetNativeImageNamed(int resource_id) { } base::RefCountedStaticMemory* ResourceBundle::LoadDataResourceBytes( - int resource_id, - ScaleFactor scale_factor) const { + int resource_id) const { base::RefCountedStaticMemory* bytes = NULL; if (delegate_) - bytes = delegate_->LoadDataResourceBytes(resource_id, scale_factor); + bytes = delegate_->LoadDataResourceBytes(resource_id); if (!bytes) { - base::StringPiece data = GetRawDataResource(resource_id, scale_factor); - if (!data.empty()) { - bytes = new base::RefCountedStaticMemory( - reinterpret_cast<const unsigned char*>(data.data()), data.length()); - } + for (size_t i = 0; i < data_packs_.size() && !bytes; ++i) + bytes = data_packs_[i]->GetStaticMemory(resource_id); } return bytes; } -base::StringPiece ResourceBundle::GetRawDataResource( - int resource_id, - ScaleFactor scale_factor) const { +base::StringPiece ResourceBundle::GetRawDataResource(int resource_id) const { base::StringPiece data; - if (delegate_ && - delegate_->GetRawDataResource(resource_id, scale_factor, &data)) + if (delegate_ && delegate_->GetRawDataResource(resource_id, &data)) return data; DCHECK(locale_resources_data_.get()); if (locale_resources_data_->GetStringPiece(resource_id, &data)) return data; - if (scale_factor != ui::SCALE_FACTOR_100P) { - for (size_t i = 0; i < data_packs_.size(); i++) { - if (data_packs_[i]->GetScaleFactor() == scale_factor && - data_packs_[i]->GetStringPiece(resource_id, &data)) - return data; - } - } - for (size_t i = 0; i < data_packs_.size(); i++) { - if (data_packs_[i]->GetScaleFactor() == ui::SCALE_FACTOR_100P && - data_packs_[i]->GetStringPiece(resource_id, &data)) + for (size_t i = 0; i < data_packs_.size(); ++i) { + if (data_packs_[i]->GetStringPiece(resource_id, &data)) return data; } @@ -342,7 +320,7 @@ string16 ResourceBundle::GetLocalizedString(int message_id) { if (!locale_resources_data_->GetStringPiece(message_id, &data)) { // Fall back on the main data pack (shouldn't be any strings here except in // unittests). - data = GetRawDataResource(message_id, ui::SCALE_FACTOR_NONE); + data = GetRawDataResource(message_id); if (data.empty()) { NOTREACHED() << "unable to find resource: " << message_id; return string16(); diff --git a/ui/base/resource/resource_bundle.h b/ui/base/resource/resource_bundle.h index 62d8fd6..df25f31 100644 --- a/ui/base/resource/resource_bundle.h +++ b/ui/base/resource/resource_bundle.h @@ -18,7 +18,6 @@ #include "base/memory/scoped_vector.h" #include "base/string16.h" #include "base/string_piece.h" -#include "ui/base/layout.h" #include "ui/base/ui_export.h" #include "ui/gfx/font.h" #include "ui/gfx/image/image.h" @@ -70,7 +69,7 @@ class UI_EXPORT ResourceBundle { // |pack_path| will contain the complete default path for the pack file if // known or just the pack file name otherwise. virtual FilePath GetPathForResourcePack(const FilePath& pack_path, - ScaleFactor scale_factor) = 0; + float scale_factor) = 0; // Called before a locale pack file is loaded. Return the full path for // the pack file to continue loading or an empty value to cancel loading. @@ -90,13 +89,11 @@ class UI_EXPORT ResourceBundle { // Return a static memory resource or NULL to attempt retrieval of the // default resource. virtual base::RefCountedStaticMemory* LoadDataResourceBytes( - int resource_id, - ScaleFactor scale_factor) = 0; + int resource_id) = 0; // Retrieve a raw data resource. Return true if a resource was provided or // false to attempt retrieval of the default resource. virtual bool GetRawDataResource(int resource_id, - ScaleFactor scale_factor, base::StringPiece* value) = 0; // Retrieve a localized string. Return true if a string was provided or @@ -140,7 +137,7 @@ class UI_EXPORT ResourceBundle { // this value). |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, ScaleFactor scale_factor); + 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 @@ -184,19 +181,13 @@ class UI_EXPORT ResourceBundle { // Same as GetNativeImageNamed() except that RTL is not enabled. gfx::Image& GetNativeImageNamed(int resource_id); - // Loads the raw bytes of a data resource nearest the scale factor - // |scale_factor| into |bytes|, without doing any processing or interpretation - // of the resource. Use ResourceHandle::SCALE_FACTOR_NONE for non-image - // resources. Returns NULL if we fail to read the resource. - base::RefCountedStaticMemory* LoadDataResourceBytes( - int resource_id, - ScaleFactor scale_factor) const; + // Loads the raw bytes of a data resource into |bytes|, + // without doing any processing or interpretation of + // the resource. Returns whether we successfully read the resource. + base::RefCountedStaticMemory* LoadDataResourceBytes(int resource_id) const; - // Return the contents of a resource in a StringPiece given the resource id - // nearest the scale factor |scale_factor|. - // Use ResourceHanlde::SCALE_FACTOR_NONE for non-image resources. - base::StringPiece GetRawDataResource(int resource_id, - ScaleFactor scale_factor) const; + // Return the contents of a resource in a StringPiece given the resource id. + base::StringPiece GetRawDataResource(int resource_id) const; // Get a localized string given a message id. Returns an empty // string if the message_id is not found. @@ -222,7 +213,6 @@ class UI_EXPORT ResourceBundle { FRIEND_TEST_ALL_PREFIXES(ResourceBundle, DelegateGetRawDataResource); FRIEND_TEST_ALL_PREFIXES(ResourceBundle, DelegateGetLocalizedString); FRIEND_TEST_ALL_PREFIXES(ResourceBundle, DelegateGetFont); - FRIEND_TEST_ALL_PREFIXES(ResourceBundle, GetRawDataResource); FRIEND_TEST_ALL_PREFIXES(ResourceBundle, LoadDataResourceBytes); FRIEND_TEST_ALL_PREFIXES(ResourceBundle, LocaleDataPakExists); @@ -240,9 +230,8 @@ class UI_EXPORT ResourceBundle { // Returns the locale that is loaded. std::string LoadLocaleResources(const std::string& pref_locale); - // Load test resources in given paths. If either path is empty an empty - // resource pack is loaded. - void LoadTestResources(const FilePath& path, const FilePath& locale_path); + // Load test resources in given path. + void LoadTestResources(const FilePath& path); // Unload the locale specific strings and prepares to load new ones. See // comments for ReloadLocaleResources(). diff --git a/ui/base/resource/resource_bundle_android.cc b/ui/base/resource/resource_bundle_android.cc index b8d30d4..d770d3e 100644 --- a/ui/base/resource/resource_bundle_android.cc +++ b/ui/base/resource/resource_bundle_android.cc @@ -30,11 +30,11 @@ namespace ui { void ResourceBundle::LoadCommonResources() { AddDataPack(GetResourcesPakFilePath("chrome.pak"), - SCALE_FACTOR_100P); + ResourceHandle::kScaleFactor100x); AddDataPack(GetResourcesPakFilePath("theme_resources_standard.pak"), - SCALE_FACTOR_100P); + ResourceHandle::kScaleFactor100x); AddDataPack(GetResourcesPakFilePath("ui_resources_standard.pak"), - SCALE_FACTOR_100P); + 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 535f455..6f63dff 100644 --- a/ui/base/resource/resource_bundle_aurax11.cc +++ b/ui/base/resource/resource_bundle_aurax11.cc @@ -28,18 +28,18 @@ namespace ui { void ResourceBundle::LoadCommonResources() { AddDataPack(GetResourcesPakFilePath("chrome.pak"), - SCALE_FACTOR_100P); + ResourceHandle::kScaleFactor100x); if (ui::GetDisplayLayout() == ui::LAYOUT_TOUCH) { AddDataPack(GetResourcesPakFilePath("theme_resources_touch_1x.pak"), - SCALE_FACTOR_100P); + ResourceHandle::kScaleFactor100x); AddDataPack(GetResourcesPakFilePath("ui_resources_touch.pak"), - SCALE_FACTOR_100P); + ResourceHandle::kScaleFactor100x); } else { AddDataPack(GetResourcesPakFilePath("theme_resources_standard.pak"), - SCALE_FACTOR_100P); + ResourceHandle::kScaleFactor100x); AddDataPack(GetResourcesPakFilePath("ui_resources_standard.pak"), - SCALE_FACTOR_100P); + ResourceHandle::kScaleFactor100x); } } diff --git a/ui/base/resource/resource_bundle_gtk.cc b/ui/base/resource/resource_bundle_gtk.cc index d969bc0..1c64e4d 100644 --- a/ui/base/resource/resource_bundle_gtk.cc +++ b/ui/base/resource/resource_bundle_gtk.cc @@ -8,11 +8,10 @@ #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" -#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" @@ -66,11 +65,11 @@ FilePath GetResourcesPakFilePath(const std::string& pak_name) { void ResourceBundle::LoadCommonResources() { AddDataPack(GetResourcesPakFilePath("chrome.pak"), - SCALE_FACTOR_100P); + ResourceHandle::kScaleFactor100x); AddDataPack(GetResourcesPakFilePath("theme_resources_standard.pak"), - SCALE_FACTOR_100P); + ResourceHandle::kScaleFactor100x); AddDataPack(GetResourcesPakFilePath("ui_resources_standard.pak"), - SCALE_FACTOR_100P); + ResourceHandle::kScaleFactor100x); } gfx::Image& ResourceBundle::GetNativeImageNamed(int resource_id, ImageRTL rtl) { @@ -90,7 +89,7 @@ gfx::Image& ResourceBundle::GetNativeImageNamed(int resource_id, ImageRTL rtl) { if (image.IsEmpty()) { scoped_refptr<base::RefCountedStaticMemory> data( - LoadDataResourceBytes(resource_id, SCALE_FACTOR_100P)); + LoadDataResourceBytes(resource_id)); GdkPixbuf* pixbuf = LoadPixbuf(data.get(), rtl == RTL_ENABLED); if (!pixbuf) { diff --git a/ui/base/resource/resource_bundle_mac.mm b/ui/base/resource/resource_bundle_mac.mm index 07736d8..8a559c4 100644 --- a/ui/base/resource/resource_bundle_mac.mm +++ b/ui/base/resource/resource_bundle_mac.mm @@ -50,22 +50,22 @@ FilePath GetResourcesPakFilePath(NSString* name, NSString* mac_locale) { void ResourceBundle::LoadCommonResources() { AddDataPack(GetResourcesPakFilePath(@"chrome", nil), - SCALE_FACTOR_100P); + ResourceHandle::kScaleFactor100x); AddDataPack(GetResourcesPakFilePath(@"theme_resources_standard", nil), - SCALE_FACTOR_100P); + ResourceHandle::kScaleFactor100x); AddDataPack(GetResourcesPakFilePath(@"ui_resources_standard", nil), - SCALE_FACTOR_100P); + 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), - SCALE_FACTOR_200P); + ResourceHandle::kScaleFactor200x); AddDataPack(GetResourcesPakFilePath(@"theme_resources_standard_2x", nil), - SCALE_FACTOR_200P); + ResourceHandle::kScaleFactor200x); AddDataPack(GetResourcesPakFilePath(@"ui_resources_standard_2x", nil), - SCALE_FACTOR_200P); + ResourceHandle::kScaleFactor200x); } #endif } diff --git a/ui/base/resource/resource_bundle_unittest.cc b/ui/base/resource/resource_bundle_unittest.cc index 79a8ca9..1d72785 100644 --- a/ui/base/resource/resource_bundle_unittest.cc +++ b/ui/base/resource/resource_bundle_unittest.cc @@ -14,7 +14,6 @@ #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/skia/include/core/SkBitmap.h" -#include "ui/base/layout.h" using ::testing::_; using ::testing::Between; @@ -26,10 +25,6 @@ namespace ui { extern const char kSamplePakContents[]; extern const size_t kSamplePakSize; -extern const char kSamplePakContents2x[]; -extern const size_t kSamplePakSize2x; -extern const char kEmptyPakContents[]; -extern const size_t kEmptyPakSize; namespace { @@ -42,23 +37,19 @@ class MockResourceBundleDelegate : public ui::ResourceBundle::Delegate { } MOCK_METHOD2(GetPathForResourcePack, FilePath(const FilePath& pack_path, - ui::ScaleFactor scale_factor)); + float scale_factor)); MOCK_METHOD2(GetPathForLocalePack, FilePath(const FilePath& pack_path, const std::string& locale)); MOCK_METHOD1(GetImageNamed, gfx::Image(int resource_id)); MOCK_METHOD2(GetNativeImageNamed, gfx::Image(int resource_id, ui::ResourceBundle::ImageRTL rtl)); - MOCK_METHOD2(LoadDataResourceBytes, - base::RefCountedStaticMemory*(int resource_id, - ui::ScaleFactor scale_factor)); - MOCK_METHOD2(GetRawDataResourceMock, base::StringPiece( - int resource_id, - ui::ScaleFactor scale_factor)); + MOCK_METHOD1(LoadDataResourceBytes, + base::RefCountedStaticMemory*(int resource_id)); + MOCK_METHOD1(GetRawDataResourceMock, base::StringPiece(int resource_id)); virtual bool GetRawDataResource(int resource_id, - ui::ScaleFactor scale_factor, base::StringPiece* value) OVERRIDE { - *value = GetRawDataResourceMock(resource_id, scale_factor); + *value = GetRawDataResourceMock(resource_id); return true; } MOCK_METHOD1(GetLocalizedStringMock, string16(int message_id)); @@ -80,7 +71,7 @@ TEST(ResourceBundle, DelegateGetPathForResourcePack) { ResourceBundle resource_bundle(&delegate); FilePath pack_path(FILE_PATH_LITERAL("/path/to/test_path.pak")); - ui::ScaleFactor pack_scale_factor = ui::SCALE_FACTOR_200P; + double pack_scale_factor = 2.0; EXPECT_CALL(delegate, GetPathForResourcePack( @@ -161,14 +152,13 @@ TEST(ResourceBundle, DelegateLoadDataResourceBytes) { new base::RefCountedStaticMemory(data, sizeof(data))); int resource_id = 5; - ui::ScaleFactor scale_factor = ui::SCALE_FACTOR_NONE; - EXPECT_CALL(delegate, LoadDataResourceBytes(resource_id, scale_factor)) + EXPECT_CALL(delegate, LoadDataResourceBytes(resource_id)) .Times(1) .WillOnce(Return(static_memory)); scoped_refptr<base::RefCountedStaticMemory> result = - resource_bundle.LoadDataResourceBytes(resource_id, scale_factor); + resource_bundle.LoadDataResourceBytes(resource_id); EXPECT_EQ(static_memory, result); } @@ -182,13 +172,11 @@ TEST(ResourceBundle, DelegateGetRawDataResource) { int resource_id = 5; - EXPECT_CALL(delegate, GetRawDataResourceMock( - resource_id, ui::SCALE_FACTOR_NONE)) + EXPECT_CALL(delegate, GetRawDataResourceMock(resource_id)) .Times(1) .WillOnce(Return(string_piece)); - base::StringPiece result = resource_bundle.GetRawDataResource( - resource_id, ui::SCALE_FACTOR_NONE); + base::StringPiece result = resource_bundle.GetRawDataResource(resource_id); EXPECT_EQ(string_piece.data(), result.data()); } @@ -244,58 +232,16 @@ TEST(ResourceBundle, LoadDataResourceBytes) { static_cast<int>(kSamplePakSize)); // Create a resource bundle from the file. - resource_bundle.LoadTestResources(data_path, data_path); + resource_bundle.LoadTestResources(data_path); const int kUnfoundResourceId = 10000; - EXPECT_EQ(NULL, resource_bundle.LoadDataResourceBytes( - kUnfoundResourceId, ui::SCALE_FACTOR_NONE)); + EXPECT_EQ(NULL, resource_bundle.LoadDataResourceBytes(kUnfoundResourceId)); // 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")), - ui::SCALE_FACTOR_NONE); - EXPECT_EQ(NULL, resource_bundle.LoadDataResourceBytes( - kUnfoundResourceId, ui::SCALE_FACTOR_NONE)); - } -} - -TEST(ResourceBundle, GetRawDataResource) { - - // On Windows, the default data is compiled into the binary so this does - // nothing. - ScopedTempDir dir; - ASSERT_TRUE(dir.CreateUniqueTempDir()); - FilePath locale_path = dir.path().Append(FILE_PATH_LITERAL("empty.pak")); - FilePath data_path = dir.path().Append(FILE_PATH_LITERAL("sample.pak")); - FilePath data_2x_path = dir.path().Append(FILE_PATH_LITERAL("sample_2x.pak")); - - { - ResourceBundle resource_bundle(NULL); - // Dump contents into the pak files. - ASSERT_EQ(file_util::WriteFile(locale_path, kEmptyPakContents, - kEmptyPakSize), static_cast<int>(kEmptyPakSize)); - ASSERT_EQ(file_util::WriteFile(data_path, kSamplePakContents, - kSamplePakSize), static_cast<int>(kSamplePakSize)); - ASSERT_EQ(file_util::WriteFile(data_2x_path, kSamplePakContents2x, - kSamplePakSize2x), static_cast<int>(kSamplePakSize2x)); - - // Load the regular and 2x pak files. - resource_bundle.LoadTestResources(data_path, locale_path); - resource_bundle.AddDataPack(data_2x_path, SCALE_FACTOR_200P); - - // Resource ID 4 exists in both 1x and 2x paks, so we expect a different - // result when requesting the 2x scale. - EXPECT_EQ("this is id 4", resource_bundle.GetRawDataResource(4, - SCALE_FACTOR_100P)); - EXPECT_EQ("this is id 4 2x", resource_bundle.GetRawDataResource(4, - SCALE_FACTOR_200P)); - - // Resource ID 6 only exists in the 1x pak so we expect the same resource - // for both scale factor requests. - EXPECT_EQ("this is id 6", resource_bundle.GetRawDataResource(6, - SCALE_FACTOR_100P)); - EXPECT_EQ("this is id 6", resource_bundle.GetRawDataResource(6, - SCALE_FACTOR_200P)); + 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 4e525e7..e181e7d 100644 --- a/ui/base/resource/resource_bundle_win.cc +++ b/ui/base/resource/resource_bundle_win.cc @@ -49,21 +49,21 @@ void ResourceBundle::LoadCommonResources() { switch (ui::GetDisplayLayout()) { case ui::LAYOUT_TOUCH: AddDataPack(GetResourcesPakFilePath("theme_resources_touch_1x.pak"), - SCALE_FACTOR_100P); + ResourceHandle::kScaleFactor100x); AddDataPack(GetResourcesPakFilePath("ui_resources_standard.pak"), - SCALE_FACTOR_100P); + ResourceHandle::kScaleFactor100x); break; default: if (use_hidpi) { AddDataPack(GetResourcesPakFilePath("theme_resources_2x.pak"), - SCALE_FACTOR_200P); + ResourceHandle::kScaleFactor200x); AddDataPack(GetResourcesPakFilePath("ui_resources_2x.pak"), - SCALE_FACTOR_200P); + ResourceHandle::kScaleFactor200x); } else { AddDataPack(GetResourcesPakFilePath("theme_resources_standard.pak"), - SCALE_FACTOR_100P); + ResourceHandle::kScaleFactor100x); AddDataPack(GetResourcesPakFilePath("ui_resources_standard.pak"), - SCALE_FACTOR_100P); + ResourceHandle::kScaleFactor100x); } break; } diff --git a/ui/base/resource/resource_data_dll_win.cc b/ui/base/resource/resource_data_dll_win.cc index c6c90c71..48e9db1 100644 --- a/ui/base/resource/resource_data_dll_win.cc +++ b/ui/base/resource/resource_data_dll_win.cc @@ -17,15 +17,6 @@ ResourceDataDLL::ResourceDataDLL(HINSTANCE module) : module_(module) { ResourceDataDLL::~ResourceDataDLL() { } -bool ResourceDataDLL::HasResource(uint16 resource_id) const { - void* data_ptr; - size_t data_size; - return base::win::GetDataResourceFromModule(module_, - resource_id, - &data_ptr, - &data_size); -} - bool ResourceDataDLL::GetStringPiece(uint16 resource_id, base::StringPiece* data) const { DCHECK(data); @@ -57,8 +48,8 @@ ResourceHandle::TextEncodingType ResourceDataDLL::GetTextEncodingType() const { return BINARY; } -ScaleFactor ResourceDataDLL::GetScaleFactor() const { - return ui::SCALE_FACTOR_NONE; +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 a38dd54..e21e9aa 100644 --- a/ui/base/resource/resource_data_dll_win.h +++ b/ui/base/resource/resource_data_dll_win.h @@ -19,13 +19,12 @@ class ResourceDataDLL : public ResourceHandle { virtual ~ResourceDataDLL(); // ResourceHandle implementation: - virtual bool HasResource(uint16 resource_id) const OVERRIDE; virtual bool GetStringPiece(uint16 resource_id, base::StringPiece* data) const OVERRIDE; virtual base::RefCountedStaticMemory* GetStaticMemory( uint16 resource_id) const OVERRIDE; virtual TextEncodingType GetTextEncodingType() const OVERRIDE; - virtual ScaleFactor GetScaleFactor() 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 1d26e72..b40741e 100644 --- a/ui/base/resource/resource_handle.h +++ b/ui/base/resource/resource_handle.h @@ -8,7 +8,6 @@ #include "base/basictypes.h" #include "base/string_piece.h" -#include "ui/base/layout.h" #include "ui/base/ui_export.h" namespace base { @@ -26,10 +25,11 @@ class UI_EXPORT ResourceHandle { UTF16 }; - virtual ~ResourceHandle() {} + // The scale factors for image resources. + static const float kScaleFactor100x; + static const float kScaleFactor200x; - // Returns true if the DataPack contains a resource with id |resource_id|. - virtual bool HasResource(uint16 resource_id) const = 0; + virtual ~ResourceHandle() {} // Get resource by id |resource_id|, filling in |data|. // The data is owned by the DataPack object and should not be modified. @@ -47,7 +47,7 @@ class UI_EXPORT ResourceHandle { // The scale of images in this resource pack relative to images in the 1x // resource pak. - virtual ScaleFactor GetScaleFactor() const = 0; + virtual float GetScaleFactor() const = 0; }; } // namespace ui |