summaryrefslogtreecommitdiff
path: root/chromium/ui/base/resource
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/ui/base/resource')
-rw-r--r--chromium/ui/base/resource/data_pack.h4
-rw-r--r--chromium/ui/base/resource/data_pack_export.h37
-rw-r--r--chromium/ui/base/resource/material_design/material_design_controller.cc65
-rw-r--r--chromium/ui/base/resource/material_design/material_design_controller.h67
-rw-r--r--chromium/ui/base/resource/material_design/material_design_controller_unittest.cc121
-rw-r--r--chromium/ui/base/resource/resource_bundle.cc194
-rw-r--r--chromium/ui/base/resource/resource_bundle.h79
-rw-r--r--chromium/ui/base/resource/resource_bundle_android.cc4
-rw-r--r--chromium/ui/base/resource/resource_bundle_auralinux.cc4
-rw-r--r--chromium/ui/base/resource/resource_bundle_ios.mm7
-rw-r--r--chromium/ui/base/resource/resource_bundle_mac.mm97
-rw-r--r--chromium/ui/base/resource/resource_bundle_unittest.cc64
-rw-r--r--chromium/ui/base/resource/resource_bundle_win.cc5
-rw-r--r--chromium/ui/base/resource/resource_handle.h6
-rw-r--r--chromium/ui/base/resource/scale_factor.cc24
-rw-r--r--chromium/ui/base/resource/scale_factor.h37
-rw-r--r--chromium/ui/base/resource/scale_factor_unittest.cc23
17 files changed, 307 insertions, 531 deletions
diff --git a/chromium/ui/base/resource/data_pack.h b/chromium/ui/base/resource/data_pack.h
index b2d90684c0f..1292203a6bb 100644
--- a/chromium/ui/base/resource/data_pack.h
+++ b/chromium/ui/base/resource/data_pack.h
@@ -20,8 +20,8 @@
#include "base/memory/scoped_ptr.h"
#include "base/memory/scoped_vector.h"
#include "base/strings/string_piece.h"
+#include "ui/base/resource/data_pack_export.h"
#include "ui/base/resource/resource_handle.h"
-#include "ui/base/ui_base_export.h"
namespace base {
class FilePath;
@@ -31,7 +31,7 @@ class RefCountedStaticMemory;
namespace ui {
enum ScaleFactor : int;
-class UI_BASE_EXPORT DataPack : public ResourceHandle {
+class UI_DATA_PACK_EXPORT DataPack : public ResourceHandle {
public:
explicit DataPack(ui::ScaleFactor scale_factor);
~DataPack() override;
diff --git a/chromium/ui/base/resource/data_pack_export.h b/chromium/ui/base/resource/data_pack_export.h
new file mode 100644
index 00000000000..88e908d5cbe
--- /dev/null
+++ b/chromium/ui/base/resource/data_pack_export.h
@@ -0,0 +1,37 @@
+// Copyright 2016 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.
+
+#ifndef UI_BASE_RESOURCE_DATA_PACK_EXPORT_H_
+#define UI_BASE_RESOURCE_DATA_PACK_EXPORT_H_
+
+// Defines UI_DATA_PACK_EXPORT so that functionality implemented by the data
+// pack loading module can be exported to consumers.
+
+#if defined(COMPONENT_BUILD)
+
+#if defined(WIN32)
+
+#if defined(UI_DATA_PACK_IMPLEMENTATION)
+#define UI_DATA_PACK_EXPORT __declspec(dllexport)
+#else
+#define UI_DATA_PACK_EXPORT __declspec(dllimport)
+#endif
+
+#else // !defined(WIN32)
+
+#if defined(UI_DATA_PACK_IMPLEMENTATION)
+#define UI_DATA_PACK_EXPORT __attribute__((visibility("default")))
+#else
+#define UI_DATA_PACK_EXPORT
+#endif
+
+#endif
+
+#else // !defined(COMPONENT_BUILD)
+
+#define UI_DATA_PACK_EXPORT
+
+#endif
+
+#endif // UI_BASE_RESOURCE_DATA_PACK_EXPORT_H_
diff --git a/chromium/ui/base/resource/material_design/material_design_controller.cc b/chromium/ui/base/resource/material_design/material_design_controller.cc
deleted file mode 100644
index b19935e4962..00000000000
--- a/chromium/ui/base/resource/material_design/material_design_controller.cc
+++ /dev/null
@@ -1,65 +0,0 @@
-// Copyright 2015 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 <string>
-
-#include "base/command_line.h"
-#include "base/logging.h"
-#include "ui/base/resource/material_design/material_design_controller.h"
-#include "ui/base/ui_base_switches.h"
-
-namespace ui {
-
-bool MaterialDesignController::is_mode_initialized_ = false;
-
-MaterialDesignController::Mode MaterialDesignController::mode_ =
- MaterialDesignController::Mode::NON_MATERIAL;
-
-MaterialDesignController::Mode MaterialDesignController::GetMode() {
- if (!is_mode_initialized_)
- InitializeMode();
- CHECK(is_mode_initialized_);
- return mode_;
-}
-
-bool MaterialDesignController::IsModeMaterial() {
- return GetMode() == Mode::MATERIAL_NORMAL ||
- GetMode() == Mode::MATERIAL_HYBRID;
-}
-
-void MaterialDesignController::InitializeMode() {
-#if !defined(ENABLE_TOPCHROME_MD)
- SetMode(Mode::NON_MATERIAL);
-#else
- const std::string switch_value =
- base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
- switches::kTopChromeMD);
-
- if (switch_value == switches::kTopChromeMDMaterial) {
- SetMode(Mode::MATERIAL_NORMAL);
- } else if (switch_value == switches::kTopChromeMDMaterialHybrid) {
- SetMode(Mode::MATERIAL_HYBRID);
- } else if (switch_value == switches::kTopChromeMDNonMaterial) {
- SetMode(Mode::NON_MATERIAL);
- } else {
- LOG(ERROR) << "Invalid value='" << switch_value
- << "' for command line switch '" << switches::kTopChromeMD
- << "'.";
- SetMode(Mode::NON_MATERIAL);
- }
-#endif // !defined(ENABLE_TOPCHROME_MD)
-}
-
-void MaterialDesignController::UninitializeMode() {
- MaterialDesignController::SetMode(
- MaterialDesignController::Mode::NON_MATERIAL);
- is_mode_initialized_ = false;
-}
-
-void MaterialDesignController::SetMode(MaterialDesignController::Mode mode) {
- mode_ = mode;
- is_mode_initialized_ = true;
-}
-
-} // namespace ui
diff --git a/chromium/ui/base/resource/material_design/material_design_controller.h b/chromium/ui/base/resource/material_design/material_design_controller.h
deleted file mode 100644
index af92f4d62bc..00000000000
--- a/chromium/ui/base/resource/material_design/material_design_controller.h
+++ /dev/null
@@ -1,67 +0,0 @@
-// Copyright 2015 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.
-
-#ifndef UI_BASE_RESOURCE_MATERIAL_DESIGN_MATERIAL_DESIGN_CONTROLLER_H_
-#define UI_BASE_RESOURCE_MATERIAL_DESIGN_MATERIAL_DESIGN_CONTROLLER_H_
-
-#include "base/macros.h"
-#include "ui/base/ui_base_export.h"
-
-namespace ui {
-
-namespace test {
-class MaterialDesignControllerTestAPI;
-} // namespace test
-
-// Central controller to handle material design modes.
-class UI_BASE_EXPORT MaterialDesignController {
- public:
- // The different material design modes. The order cannot be changed without
- // updating references as these are used as array indices.
- enum Mode {
- // Classic, non-material design.
- NON_MATERIAL = 0,
- // Basic material design.
- MATERIAL_NORMAL = 1,
- // Material design targeted at mouse/touch hybrid devices.
- MATERIAL_HYBRID = 2
- };
-
- // Get the current Mode that should be used by the system.
- static Mode GetMode();
-
- // Returns true if the current mode is a material design variant.
- static bool IsModeMaterial();
-
- private:
- friend class test::MaterialDesignControllerTestAPI;
-
- // Tracks whether |mode_| has been initialized. This is necessary so tests can
- // reset the state back to a clean state during tear down.
- static bool is_mode_initialized_;
-
- // The current Mode to be used by the system.
- static Mode mode_;
-
- // Declarations only. Do not allow construction of an object.
- MaterialDesignController();
- ~MaterialDesignController();
-
- // Initializes |mode_|.
- static void InitializeMode();
-
- // Resets the Mode state to uninitialized. To be used by tests to cleanup
- // global state.
- static void UninitializeMode();
-
- // Set |mode_| to |mode| and updates |is_mode_initialized_| to true. Can be
- // used by tests to directly set the mode.
- static void SetMode(Mode mode);
-
- DISALLOW_COPY_AND_ASSIGN(MaterialDesignController);
-};
-
-} // namespace ui
-
-#endif // UI_BASE_RESOURCE_MATERIAL_DESIGN_MATERIAL_DESIGN_CONTROLLER_H_
diff --git a/chromium/ui/base/resource/material_design/material_design_controller_unittest.cc b/chromium/ui/base/resource/material_design/material_design_controller_unittest.cc
deleted file mode 100644
index cfc76b59493..00000000000
--- a/chromium/ui/base/resource/material_design/material_design_controller_unittest.cc
+++ /dev/null
@@ -1,121 +0,0 @@
-// Copyright 2015 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 <string>
-
-#include "base/command_line.h"
-#include "base/macros.h"
-#include "testing/gtest/include/gtest/gtest.h"
-#include "ui/base/resource/material_design/material_design_controller.h"
-#include "ui/base/test/material_design_controller_test_api.h"
-#include "ui/base/ui_base_switches.h"
-
-namespace ui {
-namespace {
-
-// Test fixture for the MaterialDesignController class.
-class MaterialDesignControllerTest : public testing::Test {
- public:
- MaterialDesignControllerTest();
- ~MaterialDesignControllerTest() override;
-
- // testing::Test:
- void SetUp() override;
-
- private:
- DISALLOW_COPY_AND_ASSIGN(MaterialDesignControllerTest);
-};
-
-MaterialDesignControllerTest::MaterialDesignControllerTest() {
-}
-
-MaterialDesignControllerTest::~MaterialDesignControllerTest() {
-}
-
-void MaterialDesignControllerTest::SetUp() {
- testing::Test::SetUp();
-
- // Ensure other tests aren't polluted by a Mode set in these tests. The Mode
- // has to be cleared in SetUp and not in TearDown because when the test suite
- // starts up it triggers a call to ResourceBundle::LoadCommonResources()
- // which calls MaterialDesignController::IsModeMaterial(), thereby
- // initializing the mode and potentially causing the first test to fail.
- test::MaterialDesignControllerTestAPI::UninitializeMode();
-}
-
-#if !defined(ENABLE_TOPCHROME_MD)
-
-// Verify the Mode maps to Mode::NON_MATERIAL when the compile time flag is not
-// defined.
-TEST_F(MaterialDesignControllerTest,
- NonMaterialModeWhenCompileTimeFlagDisabled) {
- EXPECT_EQ(MaterialDesignController::Mode::NON_MATERIAL,
- MaterialDesignController::GetMode());
-}
-
-#else
-
-// Verify command line value "material" maps to Mode::MATERIAL when the compile
-// time flag is defined.
-TEST_F(MaterialDesignControllerTest,
- EnabledCommandLineValueMapsToMaterialModeWhenCompileTimeFlagEnabled) {
- base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
- switches::kTopChromeMD, "material");
- EXPECT_EQ(MaterialDesignController::Mode::MATERIAL_NORMAL,
- MaterialDesignController::GetMode());
-}
-
-// Verify command line value "material-hybrid" maps to Mode::MATERIAL_HYBRID
-// when the compile time flag is defined.
-TEST_F(
- MaterialDesignControllerTest,
- EnabledHybridCommandLineValueMapsToMaterialHybridModeWhenCompileTimeFlagEnabled) {
- base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
- switches::kTopChromeMD, "material-hybrid");
- EXPECT_EQ(MaterialDesignController::Mode::MATERIAL_HYBRID,
- MaterialDesignController::GetMode());
-}
-
-// Verify command line value "" maps to Mode::NON_MATERIAL when the compile time
-// flag is defined.
-TEST_F(
- MaterialDesignControllerTest,
- DisabledCommandLineValueMapsToNonMaterialModeWhenCompileTimeFlagEnabled) {
- base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
- switches::kTopChromeMD, "");
- EXPECT_EQ(MaterialDesignController::Mode::NON_MATERIAL,
- MaterialDesignController::GetMode());
-}
-
-// Verify no command line value maps to Mode::NON_MATERIAL when the compile time
-// flag is defined.
-TEST_F(MaterialDesignControllerTest,
- NoCommandLineValueMapsToNonMaterialModeWhenCompileTimeFlagEnabled) {
- ASSERT_FALSE(base::CommandLine::ForCurrentProcess()->HasSwitch(
- switches::kTopChromeMD));
- EXPECT_EQ(MaterialDesignController::Mode::NON_MATERIAL,
- MaterialDesignController::GetMode());
-}
-
-// Verify an invalid command line value uses the default NON_MATERIAL mode.
-TEST_F(MaterialDesignControllerTest, InvalidCommandLineValue) {
- const std::string kInvalidValue = "1nvalid-valu3";
- base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
- switches::kTopChromeMD, kInvalidValue);
- EXPECT_EQ(MaterialDesignController::Mode::NON_MATERIAL,
- MaterialDesignController::GetMode());
-}
-
-// Verify that MaterialDesignController::IsModeMaterial() will initialize the
-// mode if it hasn't been initialized yet.
-TEST_F(MaterialDesignControllerTest, IsModeMaterialInitializesMode) {
- base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
- switches::kTopChromeMD, "material");
- EXPECT_TRUE(MaterialDesignController::IsModeMaterial());
-}
-
-#endif // !defined(ENABLE_TOPCHROME_MD)
-
-} // namespace
-} // namespace ui
diff --git a/chromium/ui/base/resource/resource_bundle.cc b/chromium/ui/base/resource/resource_bundle.cc
index a2aa5824a19..93230b42da4 100644
--- a/chromium/ui/base/resource/resource_bundle.cc
+++ b/chromium/ui/base/resource/resource_bundle.cc
@@ -28,10 +28,11 @@
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/layout.h"
+#include "ui/base/material_design/material_design_controller.h"
#include "ui/base/resource/data_pack.h"
-#include "ui/base/resource/material_design/material_design_controller.h"
#include "ui/base/ui_base_paths.h"
#include "ui/base/ui_base_switches.h"
+#include "ui/base/ui_features.h"
#include "ui/gfx/codec/jpeg_codec.h"
#include "ui/gfx/codec/png_codec.h"
#include "ui/gfx/geometry/safe_integer_conversions.h"
@@ -62,11 +63,6 @@ namespace ui {
namespace {
-// Font sizes relative to base font.
-const int kSmallFontSizeDelta = -1;
-const int kMediumFontSizeDelta = 3;
-const int kLargeFontSizeDelta = 8;
-
// PNG-related constants.
const unsigned char kPngMagic[8] = { 0x89, 'P', 'N', 'G', 13, 10, 26, 10 };
const size_t kPngChunkMetadataSize = 12; // length, type, crc32
@@ -394,12 +390,14 @@ gfx::Image& ResourceBundle::GetImageNamed(int resource_id) {
DCHECK(!data_packs_.empty()) <<
"Missing call to SetResourcesDataDLL?";
-#if defined(OS_CHROMEOS) || defined(OS_WIN)
- ui::ScaleFactor scale_factor_to_load = GetMaxScaleFactor();
+#if defined(OS_CHROMEOS)
+ ui::ScaleFactor scale_factor_to_load = GetMaxScaleFactor();
+#elif defined(OS_WIN)
+ ui::ScaleFactor scale_factor_to_load =
+ gfx::GetDPIScale() > 1.25 ? GetMaxScaleFactor() : ui::SCALE_FACTOR_100P;
#else
- ui::ScaleFactor scale_factor_to_load = ui::SCALE_FACTOR_100P;
+ ui::ScaleFactor scale_factor_to_load = ui::SCALE_FACTOR_100P;
#endif
-
// TODO(oshima): Consider reading the image size from png IHDR chunk and
// skip decoding here and remove #ifdef below.
// ResourceBundle::GetSharedInstance() is destroyed after the
@@ -428,10 +426,6 @@ gfx::Image& ResourceBundle::GetImageNamed(int resource_id) {
return images_[resource_id];
}
-gfx::Image& ResourceBundle::GetNativeImageNamed(int resource_id) {
- return GetNativeImageNamed(resource_id, RTL_DISABLED);
-}
-
base::RefCountedStaticMemory* ResourceBundle::LoadDataResourceBytes(
int resource_id) const {
return LoadDataResourceBytesForScale(resource_id, ui::SCALE_FACTOR_NONE);
@@ -539,29 +533,72 @@ base::string16 ResourceBundle::GetLocalizedString(int message_id) {
return msg;
}
-const gfx::FontList& ResourceBundle::GetFontList(FontStyle style) {
- {
- base::AutoLock lock_scope(*images_and_fonts_lock_);
- LoadFontsIfNecessary();
- }
- switch (style) {
- case BoldFont:
- return *bold_font_list_;
+const gfx::FontList& ResourceBundle::GetFontListWithDelta(
+ int size_delta,
+ gfx::Font::FontStyle style) {
+ base::AutoLock lock_scope(*images_and_fonts_lock_);
+
+ typedef std::pair<int, gfx::Font::FontStyle> Key;
+ const Key styled_key(size_delta, style);
+
+ auto found = font_cache_.find(styled_key);
+ if (found != font_cache_.end())
+ return found->second;
+
+ const Key base_key(0, gfx::Font::NORMAL);
+ gfx::FontList& base = font_cache_[base_key];
+ if (styled_key == base_key)
+ return base;
+
+ // Fonts of a given style are derived from the unstyled font of the same size.
+ // Cache the unstyled font by first inserting a default-constructed font list.
+ // Then, derive it for the initial insertion, or use the iterator that points
+ // to the existing entry that the insertion collided with.
+ const Key sized_key(size_delta, gfx::Font::NORMAL);
+ auto sized = font_cache_.insert(std::make_pair(sized_key, gfx::FontList()));
+ if (sized.second)
+ sized.first->second = base.DeriveWithSizeDelta(size_delta);
+ if (styled_key == sized_key)
+ return sized.first->second;
+
+ auto styled = font_cache_.insert(std::make_pair(styled_key, gfx::FontList()));
+ DCHECK(styled.second); // Otherwise font_cache_.find(..) would have found it.
+ styled.first->second = sized.first->second.DeriveWithStyle(
+ sized.first->second.GetFontStyle() | style);
+ return styled.first->second;
+}
+
+const gfx::Font& ResourceBundle::GetFontWithDelta(int size_delta,
+ gfx::Font::FontStyle style) {
+ return GetFontListWithDelta(size_delta, style).GetPrimaryFont();
+}
+
+const gfx::FontList& ResourceBundle::GetFontList(FontStyle legacy_style) {
+ gfx::Font::FontStyle font_style = gfx::Font::NORMAL;
+ if (legacy_style == BoldFont || legacy_style == SmallBoldFont ||
+ legacy_style == MediumBoldFont || legacy_style == LargeBoldFont)
+ font_style = gfx::Font::BOLD;
+
+ int size_delta = 0;
+ switch (legacy_style) {
case SmallFont:
- return *small_font_list_;
- case MediumFont:
- return *medium_font_list_;
case SmallBoldFont:
- return *small_bold_font_list_;
+ size_delta = kSmallFontDelta;
+ break;
+ case MediumFont:
case MediumBoldFont:
- return *medium_bold_font_list_;
+ size_delta = kMediumFontDelta;
+ break;
case LargeFont:
- return *large_font_list_;
case LargeBoldFont:
- return *large_bold_font_list_;
- default:
- return *base_font_list_;
+ size_delta = kLargeFontDelta;
+ break;
+ case BaseFont:
+ case BoldFont:
+ break;
}
+
+ return GetFontListWithDelta(size_delta, font_style);
}
const gfx::Font& ResourceBundle::GetFont(FontStyle style) {
@@ -571,12 +608,11 @@ const gfx::Font& ResourceBundle::GetFont(FontStyle style) {
void ResourceBundle::ReloadFonts() {
base::AutoLock lock_scope(*images_and_fonts_lock_);
InitDefaultFontList();
- base_font_list_.reset();
- LoadFontsIfNecessary();
+ font_cache_.clear();
}
ScaleFactor ResourceBundle::GetMaxScaleFactor() const {
-#if defined(OS_CHROMEOS) || defined(OS_WIN)
+#if defined(OS_CHROMEOS) || defined(OS_WIN) || defined(OS_LINUX)
return max_scale_factor_;
#else
return GetSupportedScaleFactors().back();
@@ -608,7 +644,7 @@ void ResourceBundle::InitSharedInstance(Delegate* delegate) {
DCHECK(g_shared_instance_ == NULL) << "ResourceBundle initialized twice";
g_shared_instance_ = new ResourceBundle(delegate);
static std::vector<ScaleFactor> supported_scale_factors;
-#if !defined(OS_IOS) && !defined(OS_WIN)
+#if !defined(OS_IOS)
// On platforms other than iOS, 100P is always a supported scale factor.
// For Windows we have a separate case in this function.
supported_scale_factors.push_back(SCALE_FACTOR_100P);
@@ -625,7 +661,7 @@ void ResourceBundle::InitSharedInstance(Delegate* delegate) {
if (closest != SCALE_FACTOR_100P)
supported_scale_factors.push_back(closest);
#elif defined(OS_IOS)
- gfx::Display display = gfx::Screen::GetNativeScreen()->GetPrimaryDisplay();
+ gfx::Display display = gfx::Screen::GetScreen()->GetPrimaryDisplay();
if (display.device_scale_factor() > 2.0) {
DCHECK_EQ(3.0, display.device_scale_factor());
supported_scale_factors.push_back(SCALE_FACTOR_300P);
@@ -638,22 +674,8 @@ void ResourceBundle::InitSharedInstance(Delegate* delegate) {
#elif defined(OS_MACOSX)
if (base::mac::IsOSLionOrLater())
supported_scale_factors.push_back(SCALE_FACTOR_200P);
-#elif defined(OS_CHROMEOS)
- // TODO(oshima): Include 200P only if the device support 200P
+#elif defined(OS_CHROMEOS) || defined(OS_LINUX) || defined(OS_WIN)
supported_scale_factors.push_back(SCALE_FACTOR_200P);
-#elif defined(OS_LINUX) && defined(ENABLE_HIDPI)
- supported_scale_factors.push_back(SCALE_FACTOR_200P);
-#elif defined(OS_WIN)
- bool default_to_100P = true;
- // On Windows if the dpi scale is greater than 1.25 on high dpi machines
- // downscaling from 200 percent looks better than scaling up from 100
- // percent.
- if (gfx::GetDPIScale() > 1.25) {
- supported_scale_factors.push_back(SCALE_FACTOR_200P);
- default_to_100P = false;
- }
- if (default_to_100P)
- supported_scale_factors.push_back(SCALE_FACTOR_100P);
#endif
ui::SetSupportedScaleFactors(supported_scale_factors);
}
@@ -749,76 +771,6 @@ void ResourceBundle::InitDefaultFontList() {
#endif
}
-void ResourceBundle::LoadFontsIfNecessary() {
- images_and_fonts_lock_->AssertAcquired();
- if (!base_font_list_.get()) {
- if (delegate_) {
- base_font_list_ = GetFontListFromDelegate(BaseFont);
- bold_font_list_ = GetFontListFromDelegate(BoldFont);
- small_font_list_ = GetFontListFromDelegate(SmallFont);
- small_bold_font_list_ = GetFontListFromDelegate(SmallBoldFont);
- medium_font_list_ = GetFontListFromDelegate(MediumFont);
- medium_bold_font_list_ = GetFontListFromDelegate(MediumBoldFont);
- large_font_list_ = GetFontListFromDelegate(LargeFont);
- large_bold_font_list_ = GetFontListFromDelegate(LargeBoldFont);
- }
-
- if (!base_font_list_.get())
- base_font_list_.reset(new gfx::FontList());
-
- if (!bold_font_list_.get()) {
- bold_font_list_.reset(new gfx::FontList());
- *bold_font_list_ = base_font_list_->DeriveWithStyle(
- base_font_list_->GetFontStyle() | gfx::Font::BOLD);
- }
-
- if (!small_font_list_.get()) {
- small_font_list_.reset(new gfx::FontList());
- *small_font_list_ =
- base_font_list_->DeriveWithSizeDelta(kSmallFontSizeDelta);
- }
-
- if (!small_bold_font_list_.get()) {
- small_bold_font_list_.reset(new gfx::FontList());
- *small_bold_font_list_ = small_font_list_->DeriveWithStyle(
- small_font_list_->GetFontStyle() | gfx::Font::BOLD);
- }
-
- if (!medium_font_list_.get()) {
- medium_font_list_.reset(new gfx::FontList());
- *medium_font_list_ =
- base_font_list_->DeriveWithSizeDelta(kMediumFontSizeDelta);
- }
-
- if (!medium_bold_font_list_.get()) {
- medium_bold_font_list_.reset(new gfx::FontList());
- *medium_bold_font_list_ = medium_font_list_->DeriveWithStyle(
- medium_font_list_->GetFontStyle() | gfx::Font::BOLD);
- }
-
- if (!large_font_list_.get()) {
- large_font_list_.reset(new gfx::FontList());
- *large_font_list_ =
- base_font_list_->DeriveWithSizeDelta(kLargeFontSizeDelta);
- }
-
- if (!large_bold_font_list_.get()) {
- large_bold_font_list_.reset(new gfx::FontList());
- *large_bold_font_list_ = large_font_list_->DeriveWithStyle(
- large_font_list_->GetFontStyle() | gfx::Font::BOLD);
- }
- }
-}
-
-scoped_ptr<gfx::FontList> ResourceBundle::GetFontListFromDelegate(
- FontStyle style) {
- DCHECK(delegate_);
- scoped_ptr<gfx::Font> font = delegate_->GetFont(style);
- if (font.get())
- return make_scoped_ptr(new gfx::FontList(*font));
- return nullptr;
-}
-
bool ResourceBundle::LoadBitmap(const ResourceHandle& data_handle,
int resource_id,
SkBitmap* bitmap,
diff --git a/chromium/ui/base/resource/resource_bundle.h b/chromium/ui/base/resource/resource_bundle.h
index 3e169a469bd..61f2861b1e9 100644
--- a/chromium/ui/base/resource/resource_bundle.h
+++ b/chromium/ui/base/resource/resource_bundle.h
@@ -43,12 +43,16 @@ class ResourceHandle;
// such as theme graphics. Every resource is loaded only once.
class UI_BASE_EXPORT ResourceBundle {
public:
- // An enumeration of the various font styles used throughout Chrome.
- // The following holds true for the font sizes:
- // Small <= SmallBold <= Base <= Bold <= Medium <= MediumBold <= Large.
+ // Legacy font size deltas. Consider these to be magic numbers. New code
+ // should declare their own size delta constant using an identifier that
+ // imparts some semantic meaning.
+ static const int kSmallFontDelta = -1;
+ static const int kMediumFontDelta = 3;
+ static const int kLargeFontDelta = 8;
+
+ // Legacy font style mappings. TODO(tapted): Phase these out in favour of
+ // client code providing their own constant with the desired font size delta.
enum FontStyle {
- // NOTE: depending upon the locale, using one of the *BoldFont below
- // may *not* actually result in a bold font.
SmallFont,
SmallBoldFont,
BaseFont,
@@ -59,13 +63,6 @@ class UI_BASE_EXPORT ResourceBundle {
LargeBoldFont,
};
- enum ImageRTL {
- // Images are flipped in RTL locales.
- RTL_ENABLED,
- // Images are never flipped.
- RTL_DISABLED,
- };
-
enum LoadResources {
LOAD_COMMON_RESOURCES,
DO_NOT_LOAD_COMMON_RESOURCES
@@ -97,7 +94,7 @@ class UI_BASE_EXPORT ResourceBundle {
// Return an image resource or an empty value to attempt retrieval of the
// default resource.
- virtual gfx::Image GetNativeImageNamed(int resource_id, ImageRTL rtl) = 0;
+ virtual gfx::Image GetNativeImageNamed(int resource_id) = 0;
// Return a static memory resource or NULL to attempt retrieval of the
// default resource.
@@ -115,9 +112,6 @@ class UI_BASE_EXPORT ResourceBundle {
// false to attempt retrieval of the default string.
virtual bool GetLocalizedString(int message_id, base::string16* value) = 0;
- // Returns a font or NULL to attempt retrieval of the default resource.
- virtual scoped_ptr<gfx::Font> GetFont(FontStyle style) = 0;
-
protected:
virtual ~Delegate() {}
};
@@ -219,11 +213,6 @@ class UI_BASE_EXPORT ResourceBundle {
// Note that if the same resource has already been loaded in GetImageNamed(),
// gfx::Image will perform a conversion, rather than using the native image
// loading code of ResourceBundle.
- //
- // If |rtl| is RTL_ENABLED then the image is flipped in RTL locales.
- gfx::Image& GetNativeImageNamed(int resource_id, ImageRTL rtl);
-
- // Same as GetNativeImageNamed() except that RTL is not enabled.
gfx::Image& GetNativeImageNamed(int resource_id);
// Loads the raw bytes of a scale independent data resource.
@@ -253,10 +242,19 @@ class UI_BASE_EXPORT ResourceBundle {
// string if the message_id is not found.
base::string16 GetLocalizedString(int message_id);
- // Returns the font list for the specified style.
- const gfx::FontList& GetFontList(FontStyle style);
+ // Returns a font list derived from the platform-specific "Base" font list.
+ // The result is always cached and exists for the lifetime of the process.
+ const gfx::FontList& GetFontListWithDelta(
+ int size_delta,
+ gfx::Font::FontStyle style = gfx::Font::NORMAL);
- // Returns the font for the specified style.
+ // Returns the primary font from the FontList given by GetFontListWithDelta().
+ const gfx::Font& GetFontWithDelta(
+ int size_delta,
+ gfx::Font::FontStyle style = gfx::Font::NORMAL);
+
+ // Deprecated. Returns fonts using hard-coded size deltas implied by |style|.
+ const gfx::FontList& GetFontList(FontStyle style);
const gfx::Font& GetFont(FontStyle style);
// Resets and reloads the cached fonts. This is useful when the fonts of the
@@ -287,6 +285,12 @@ class UI_BASE_EXPORT ResourceBundle {
// Returns SCALE_FACTOR_100P if no resource is loaded.
ScaleFactor GetMaxScaleFactor() const;
+#if defined(OS_MACOSX)
+ // Loads Material Design data packs and makes them the first items in
+ // |data_packs_|.
+ void LoadMaterialDesignResources();
+#endif
+
protected:
// Returns true if |scale_factor| is supported by this platform.
static bool IsScaleFactorSupported(ScaleFactor scale_factor);
@@ -299,10 +303,13 @@ class UI_BASE_EXPORT ResourceBundle {
CountMaterialDesignDataPacksInResourceBundle);
FRIEND_TEST_ALL_PREFIXES(ResourceBundleMacImageTest,
CheckImageFromMaterialDesign);
+ FRIEND_TEST_ALL_PREFIXES(ChromeBrowserMainMacBrowserTest,
+ MDResourceAccess);
friend class ResourceBundleMacImageTest;
friend class ResourceBundleImageTest;
friend class ResourceBundleTest;
+ friend class ChromeBrowserMainMacBrowserTest;
class ResourceBundleImageSource;
friend class ResourceBundleImageSource;
@@ -356,14 +363,6 @@ class UI_BASE_EXPORT ResourceBundle {
// Initializes the font description of default gfx::FontList.
void InitDefaultFontList();
- // Initializes all the gfx::FontList members if they haven't yet been
- // initialized.
- void LoadFontsIfNecessary();
-
- // Returns a FontList or NULL by calling Delegate::GetFont and converting
- // scoped_ptr<gfx::Font> to scoped_ptr<gfx::FontList>.
- scoped_ptr<gfx::FontList> GetFontListFromDelegate(FontStyle style);
-
// Fills the |bitmap| given the data file to look in and the |resource_id|.
// Returns false if the resource does not exist.
//
@@ -430,17 +429,11 @@ class UI_BASE_EXPORT ResourceBundle {
gfx::Image empty_image_;
- // The various font lists used. Cached to avoid repeated GDI
- // creation/destruction.
- scoped_ptr<gfx::FontList> base_font_list_;
- scoped_ptr<gfx::FontList> bold_font_list_;
- scoped_ptr<gfx::FontList> small_font_list_;
- scoped_ptr<gfx::FontList> small_bold_font_list_;
- scoped_ptr<gfx::FontList> medium_font_list_;
- scoped_ptr<gfx::FontList> medium_bold_font_list_;
- scoped_ptr<gfx::FontList> large_font_list_;
- scoped_ptr<gfx::FontList> large_bold_font_list_;
- scoped_ptr<gfx::FontList> web_font_list_;
+ // The various font lists used, as a map from a signed size delta from the
+ // platform base font size, plus style, to the FontList. Cached to avoid
+ // repeated GDI creation/destruction and font derivation.
+ // Must be accessed only while holding |images_and_fonts_lock_|.
+ std::map<std::pair<int, gfx::Font::FontStyle>, gfx::FontList> font_cache_;
base::FilePath overridden_pak_path_;
diff --git a/chromium/ui/base/resource/resource_bundle_android.cc b/chromium/ui/base/resource/resource_bundle_android.cc
index ae731d680cb..e19a8b8301d 100644
--- a/chromium/ui/base/resource/resource_bundle_android.cc
+++ b/chromium/ui/base/resource/resource_bundle_android.cc
@@ -120,9 +120,7 @@ std::string ResourceBundle::LoadLocaleResources(
return app_locale;
}
-gfx::Image& ResourceBundle::GetNativeImageNamed(int resource_id, ImageRTL rtl) {
- // Flipped image is not used on Android.
- DCHECK_EQ(rtl, RTL_DISABLED);
+gfx::Image& ResourceBundle::GetNativeImageNamed(int resource_id) {
return GetImageNamed(resource_id);
}
diff --git a/chromium/ui/base/resource/resource_bundle_auralinux.cc b/chromium/ui/base/resource/resource_bundle_auralinux.cc
index 7365b1df3d1..8989a9e49c4 100644
--- a/chromium/ui/base/resource/resource_bundle_auralinux.cc
+++ b/chromium/ui/base/resource/resource_bundle_auralinux.cc
@@ -20,9 +20,7 @@ void ResourceBundle::LoadCommonResources() {
LoadChromeResources();
}
-gfx::Image& ResourceBundle::GetNativeImageNamed(int resource_id, ImageRTL rtl) {
- // Flipped image is not used on ChromeOS.
- DCHECK_EQ(rtl, RTL_DISABLED);
+gfx::Image& ResourceBundle::GetNativeImageNamed(int resource_id) {
return GetImageNamed(resource_id);
}
diff --git a/chromium/ui/base/resource/resource_bundle_ios.mm b/chromium/ui/base/resource/resource_bundle_ios.mm
index 88cf829c6dd..17f1c79ac07 100644
--- a/chromium/ui/base/resource/resource_bundle_ios.mm
+++ b/chromium/ui/base/resource/resource_bundle_ios.mm
@@ -89,10 +89,7 @@ base::FilePath ResourceBundle::GetLocaleFilePath(const std::string& app_locale,
return locale_file_path;
}
-gfx::Image& ResourceBundle::GetNativeImageNamed(int resource_id, ImageRTL rtl) {
- // Flipped images are not used on iOS.
- DCHECK_EQ(rtl, RTL_DISABLED);
-
+gfx::Image& ResourceBundle::GetNativeImageNamed(int resource_id) {
// Check to see if the image is already in the cache.
{
base::AutoLock lock(*images_and_fonts_lock_);
@@ -104,7 +101,7 @@ gfx::Image& ResourceBundle::GetNativeImageNamed(int resource_id, ImageRTL rtl) {
gfx::Image image;
if (delegate_)
- image = delegate_->GetNativeImageNamed(resource_id, rtl);
+ image = delegate_->GetNativeImageNamed(resource_id);
if (image.IsEmpty()) {
// Load the raw data from the resource pack at the current supported scale
diff --git a/chromium/ui/base/resource/resource_bundle_mac.mm b/chromium/ui/base/resource/resource_bundle_mac.mm
index 74d82615606..0b8d526c9a6 100644
--- a/chromium/ui/base/resource/resource_bundle_mac.mm
+++ b/chromium/ui/base/resource/resource_bundle_mac.mm
@@ -14,7 +14,7 @@
#include "base/memory/ref_counted_memory.h"
#include "base/strings/sys_string_conversions.h"
#include "base/synchronization/lock.h"
-#include "ui/base/resource/material_design/material_design_controller.h"
+#include "ui/base/material_design/material_design_controller.h"
#include "ui/base/resource/resource_handle.h"
#include "ui/gfx/image/image.h"
@@ -49,20 +49,6 @@ base::FilePath GetResourcesPakFilePath(NSString* name, NSString* mac_locale) {
} // namespace
void ResourceBundle::LoadCommonResources() {
- // The material design data packs contain some of the same asset IDs as in
- // the non-material design data packs. Add these to the ResourceBundle
- // first so that they are searched first when a request for an asset is
- // made.
- if (MaterialDesignController::IsModeMaterial()) {
- AddMaterialDesignDataPackFromPath(
- GetResourcesPakFilePath(@"chrome_material_100_percent", nil),
- SCALE_FACTOR_100P);
-
- AddOptionalMaterialDesignDataPackFromPath(
- GetResourcesPakFilePath(@"chrome_material_200_percent", nil),
- SCALE_FACTOR_200P);
- }
-
AddDataPackFromPath(GetResourcesPakFilePath(@"chrome_100_percent",
nil), SCALE_FACTOR_100P);
@@ -74,6 +60,40 @@ void ResourceBundle::LoadCommonResources() {
}
}
+void ResourceBundle::LoadMaterialDesignResources() {
+ if (!MaterialDesignController::IsModeMaterial()) {
+ return;
+ }
+
+ // The Material Design data packs contain some of the same asset IDs as in
+ // the non-Material Design data packs. Set aside the current packs and add the
+ // Material Design packs so that they are searched first when a request for an
+ // asset is made. The Material Design packs cannot be loaded in
+ // LoadCommonResources() because the MaterialDesignController is not always
+ // initialized at the time it is called.
+ // TODO(shrike) - remove this method and restore loading of Material Design
+ // packs to LoadCommonResources() when the MaterialDesignController goes away.
+ std::vector<scoped_ptr<ResourceHandle>> tmp_packs;
+ for (auto it = data_packs_.begin(); it != data_packs_.end(); ++it) {
+ scoped_ptr<ResourceHandle> next_pack(*it);
+ tmp_packs.push_back(std::move(next_pack));
+ }
+ data_packs_.weak_clear();
+
+ AddMaterialDesignDataPackFromPath(
+ GetResourcesPakFilePath(@"chrome_material_100_percent", nil),
+ SCALE_FACTOR_100P);
+
+ AddOptionalMaterialDesignDataPackFromPath(
+ GetResourcesPakFilePath(@"chrome_material_200_percent", nil),
+ SCALE_FACTOR_200P);
+
+ // Add back the non-Material Design packs so that they serve as a fallback.
+ for (auto it = tmp_packs.begin(); it != tmp_packs.end(); ++it) {
+ data_packs_.push_back(std::move(*it));
+ }
+}
+
base::FilePath ResourceBundle::GetLocaleFilePath(const std::string& app_locale,
bool test_file_exists) {
NSString* mac_locale = base::SysUTF8ToNSString(app_locale);
@@ -104,10 +124,7 @@ base::FilePath ResourceBundle::GetLocaleFilePath(const std::string& app_locale,
return locale_file_path;
}
-gfx::Image& ResourceBundle::GetNativeImageNamed(int resource_id, ImageRTL rtl) {
- // Flipped images are not used on Mac.
- DCHECK_EQ(rtl, RTL_DISABLED);
-
+gfx::Image& ResourceBundle::GetNativeImageNamed(int resource_id) {
// Check to see if the image is already in the cache.
{
base::AutoLock lock(*images_and_fonts_lock_);
@@ -124,29 +141,45 @@ gfx::Image& ResourceBundle::GetNativeImageNamed(int resource_id, ImageRTL rtl) {
gfx::Image image;
if (delegate_)
- image = delegate_->GetNativeImageNamed(resource_id, rtl);
-
- bool found_in_a_material_design_pack = false;
+ image = delegate_->GetNativeImageNamed(resource_id);
if (image.IsEmpty()) {
base::scoped_nsobject<NSImage> ns_image;
+ // Material Design packs are meant to override the standard packs, so
+ // search for the image in those packs first.
for (size_t i = 0; i < data_packs_.size(); ++i) {
+ if (!data_packs_[i]->HasOnlyMaterialDesignAssets())
+ continue;
scoped_refptr<base::RefCountedStaticMemory> data(
data_packs_[i]->GetStaticMemory(resource_id));
if (!data.get())
continue;
- // This loop adds the image resource from each available pack, if it's
- // present. When Material Design packs are available, however, their
- // images are meant to override the same image in the standard packs. The
- // Material Design packs exist at the start of the data_packs_ vector,
- // so make a note that the image was pulled from a Material Design pack,
- // and ignore the same image in the standard packs.
- if (found_in_a_material_design_pack) {
- break;
+ base::scoped_nsobject<NSData> ns_data(
+ [[NSData alloc] initWithBytes:data->front() length:data->size()]);
+ if (!ns_image.get()) {
+ ns_image.reset([[NSImage alloc] initWithData:ns_data]);
+ } else {
+ NSImageRep* image_rep = [NSBitmapImageRep imageRepWithData:ns_data];
+ if (image_rep)
+ [ns_image addRepresentation:image_rep];
}
- found_in_a_material_design_pack =
- data_packs_[i]->HasOnlyMaterialDesignAssets();
+ }
+
+ if (ns_image.get()) {
+ image = gfx::Image(ns_image.release());
+ }
+ }
+
+ if (image.IsEmpty()) {
+ base::scoped_nsobject<NSImage> ns_image;
+ for (size_t i = 0; i < data_packs_.size(); ++i) {
+ if (data_packs_[i]->HasOnlyMaterialDesignAssets())
+ continue;
+ scoped_refptr<base::RefCountedStaticMemory> data(
+ data_packs_[i]->GetStaticMemory(resource_id));
+ if (!data.get())
+ continue;
base::scoped_nsobject<NSData> ns_data(
[[NSData alloc] initWithBytes:data->front() length:data->size()]);
diff --git a/chromium/ui/base/resource/resource_bundle_unittest.cc b/chromium/ui/base/resource/resource_bundle_unittest.cc
index eac9ef37306..0ada42e28be 100644
--- a/chromium/ui/base/resource/resource_bundle_unittest.cc
+++ b/chromium/ui/base/resource/resource_bundle_unittest.cc
@@ -72,9 +72,7 @@ class MockResourceBundleDelegate : public ui::ResourceBundle::Delegate {
MOCK_METHOD2(GetPathForLocalePack, base::FilePath(
const base::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_METHOD1(GetNativeImageNamed, gfx::Image(int resource_id));
MOCK_METHOD2(LoadDataResourceBytes,
base::RefCountedStaticMemory*(int resource_id,
ui::ScaleFactor scale_factor));
@@ -93,11 +91,6 @@ class MockResourceBundleDelegate : public ui::ResourceBundle::Delegate {
*value = GetLocalizedStringMock(message_id);
return true;
}
- MOCK_METHOD1(GetFontMock,
- gfx::Font*(ui::ResourceBundle::FontStyle style));
- scoped_ptr<gfx::Font> GetFont(ui::ResourceBundle::FontStyle style) override {
- return make_scoped_ptr(GetFontMock(style));
- }
};
// Returns |bitmap_data| with |custom_chunk| inserted after the IHDR chunk.
@@ -250,7 +243,7 @@ TEST_F(ResourceBundleTest, DelegateGetNativeImageNamed) {
.Times(Between(0, 1))
.WillOnce(Return(empty_image));
EXPECT_CALL(delegate,
- GetNativeImageNamed(resource_id, ui::ResourceBundle::RTL_DISABLED))
+ GetNativeImageNamed(resource_id))
.Times(Between(0, 1))
.WillOnce(Return(empty_image));
@@ -344,59 +337,6 @@ TEST_F(ResourceBundleTest, DelegateGetLocalizedStringWithOverride) {
EXPECT_EQ(delegate_data, result);
}
-#if (defined(USE_OZONE) && !defined(USE_PANGO)) || defined(OS_ANDROID)
-#define MAYBE_DelegateGetFontList DISABLED_DelegateGetFontList
-#else
-#define MAYBE_DelegateGetFontList DelegateGetFontList
-#endif
-
-TEST_F(ResourceBundleTest, MAYBE_DelegateGetFontList) {
- MockResourceBundleDelegate delegate;
- ResourceBundle* resource_bundle = CreateResourceBundle(&delegate);
-
- // Should be called once for each font type. When we return NULL the default
- // font will be created.
- gfx::Font* test_font = NULL;
- EXPECT_CALL(delegate, GetFontMock(_))
- .Times(8)
- .WillRepeatedly(Return(test_font));
-
- const gfx::FontList* font_list =
- &resource_bundle->GetFontList(ui::ResourceBundle::BaseFont);
- EXPECT_TRUE(font_list);
-
- const gfx::Font* font =
- &resource_bundle->GetFont(ui::ResourceBundle::BaseFont);
- EXPECT_TRUE(font);
-}
-
-#if defined(OS_CHROMEOS) && defined(USE_PANGO)
-TEST_F(ResourceBundleTest, FontListReload) {
- MockResourceBundleDelegate delegate;
- ResourceBundle* resource_bundle = CreateResourceBundle(&delegate);
-
- // Should be called once for each font type. When we return NULL the default
- // font will be created.
- gfx::Font* test_font = nullptr;
- EXPECT_CALL(delegate, GetFontMock(_))
- .Times(16)
- .WillRepeatedly(Return(test_font));
-
- EXPECT_CALL(delegate, GetLocalizedStringMock(IDS_UI_FONT_FAMILY_CROS))
- .WillOnce(Return(base::UTF8ToUTF16("test font, 12px")));
- resource_bundle->ReloadFonts();
- // Don't test the font name; it'll get mapped to something else by Fontconfig.
- EXPECT_EQ(12, gfx::FontList().GetPrimaryFont().GetFontSize());
- EXPECT_EQ(gfx::Font::NORMAL, gfx::FontList().GetPrimaryFont().GetStyle());
-
- EXPECT_CALL(delegate, GetLocalizedStringMock(IDS_UI_FONT_FAMILY_CROS))
- .WillOnce(Return(base::UTF8ToUTF16("test font 2, Bold 10px")));
- resource_bundle->ReloadFonts();
- EXPECT_EQ(10, gfx::FontList().GetPrimaryFont().GetFontSize());
- EXPECT_EQ(gfx::Font::BOLD, gfx::FontList().GetPrimaryFont().GetStyle());
-}
-#endif
-
TEST_F(ResourceBundleTest, LocaleDataPakExists) {
ResourceBundle* resource_bundle = CreateResourceBundle(NULL);
diff --git a/chromium/ui/base/resource/resource_bundle_win.cc b/chromium/ui/base/resource/resource_bundle_win.cc
index 6792870be96..4546b66fcd7 100644
--- a/chromium/ui/base/resource/resource_bundle_win.cc
+++ b/chromium/ui/base/resource/resource_bundle_win.cc
@@ -37,10 +37,7 @@ void ResourceBundle::LoadCommonResources() {
LoadChromeResources();
}
-gfx::Image& ResourceBundle::GetNativeImageNamed(int resource_id, ImageRTL rtl) {
- // Flipped image is not used on Windows.
- DCHECK_EQ(rtl, RTL_DISABLED);
-
+gfx::Image& ResourceBundle::GetNativeImageNamed(int resource_id) {
// Windows only uses SkBitmap for gfx::Image, so this is the same as
// GetImageNamed.
return GetImageNamed(resource_id);
diff --git a/chromium/ui/base/resource/resource_handle.h b/chromium/ui/base/resource/resource_handle.h
index 138c739134c..9632c536713 100644
--- a/chromium/ui/base/resource/resource_handle.h
+++ b/chromium/ui/base/resource/resource_handle.h
@@ -8,8 +8,8 @@
#include <stdint.h>
#include "base/strings/string_piece.h"
-#include "ui/base/layout.h"
-#include "ui/base/ui_base_export.h"
+#include "ui/base/resource/data_pack_export.h"
+#include "ui/base/resource/scale_factor.h"
namespace base {
class RefCountedStaticMemory;
@@ -17,7 +17,7 @@ class RefCountedStaticMemory;
namespace ui {
-class UI_BASE_EXPORT ResourceHandle {
+class UI_DATA_PACK_EXPORT ResourceHandle {
public:
// What type of encoding the text resources use.
enum TextEncodingType {
diff --git a/chromium/ui/base/resource/scale_factor.cc b/chromium/ui/base/resource/scale_factor.cc
new file mode 100644
index 00000000000..dceffaec424
--- /dev/null
+++ b/chromium/ui/base/resource/scale_factor.cc
@@ -0,0 +1,24 @@
+// Copyright 2016 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/scale_factor.h"
+
+#include "base/macros.h"
+
+namespace ui {
+
+namespace {
+
+const float kScaleFactorScales[] = {1.0f, 1.0f, 1.25f, 1.33f, 1.4f, 1.5f, 1.8f,
+ 2.0f, 2.5f, 3.0f};
+static_assert(NUM_SCALE_FACTORS == arraysize(kScaleFactorScales),
+ "kScaleFactorScales has incorrect size");
+
+} // namespace
+
+float GetScaleForScaleFactor(ScaleFactor scale_factor) {
+ return kScaleFactorScales[scale_factor];
+}
+
+} // namespace ui
diff --git a/chromium/ui/base/resource/scale_factor.h b/chromium/ui/base/resource/scale_factor.h
new file mode 100644
index 00000000000..06205851715
--- /dev/null
+++ b/chromium/ui/base/resource/scale_factor.h
@@ -0,0 +1,37 @@
+// Copyright 2016 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.
+
+#ifndef UI_BASE_RESOURCE_SCALE_FACTOR_H_
+#define UI_BASE_RESOURCE_SCALE_FACTOR_H_
+
+#include "ui/base/resource/data_pack_export.h"
+
+namespace ui {
+
+// Supported UI scale factors for the platform. This is used as an index
+// into the array |kScaleFactorScales| which maps the enum value to a float.
+// SCALE_FACTOR_NONE is used for density independent resources such as
+// string, html/js files or an image that can be used for any scale factors
+// (such as wallpapers).
+enum ScaleFactor : int {
+ SCALE_FACTOR_NONE = 0,
+ SCALE_FACTOR_100P,
+ SCALE_FACTOR_125P,
+ SCALE_FACTOR_133P,
+ SCALE_FACTOR_140P,
+ SCALE_FACTOR_150P,
+ SCALE_FACTOR_180P,
+ SCALE_FACTOR_200P,
+ SCALE_FACTOR_250P,
+ SCALE_FACTOR_300P,
+
+ NUM_SCALE_FACTORS // This always appears last.
+};
+
+// Returns the image scale for the scale factor passed in.
+UI_DATA_PACK_EXPORT float GetScaleForScaleFactor(ScaleFactor scale_factor);
+
+} // namespace ui
+
+#endif // UI_BASE_RESOURCE_SCALE_FACTOR_H_
diff --git a/chromium/ui/base/resource/scale_factor_unittest.cc b/chromium/ui/base/resource/scale_factor_unittest.cc
new file mode 100644
index 00000000000..52bf39b2ab8
--- /dev/null
+++ b/chromium/ui/base/resource/scale_factor_unittest.cc
@@ -0,0 +1,23 @@
+// Copyright 2016 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/scale_factor.h"
+
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace ui {
+
+TEST(ScaleFactorTest, GetScaleFactorScale) {
+ EXPECT_FLOAT_EQ(1.0f, GetScaleForScaleFactor(SCALE_FACTOR_100P));
+ EXPECT_FLOAT_EQ(1.25f, GetScaleForScaleFactor(SCALE_FACTOR_125P));
+ EXPECT_FLOAT_EQ(1.33f, GetScaleForScaleFactor(SCALE_FACTOR_133P));
+ EXPECT_FLOAT_EQ(1.4f, GetScaleForScaleFactor(SCALE_FACTOR_140P));
+ EXPECT_FLOAT_EQ(1.5f, GetScaleForScaleFactor(SCALE_FACTOR_150P));
+ EXPECT_FLOAT_EQ(1.8f, GetScaleForScaleFactor(SCALE_FACTOR_180P));
+ EXPECT_FLOAT_EQ(2.0f, GetScaleForScaleFactor(SCALE_FACTOR_200P));
+ EXPECT_FLOAT_EQ(2.5f, GetScaleForScaleFactor(SCALE_FACTOR_250P));
+ EXPECT_FLOAT_EQ(3.0f, GetScaleForScaleFactor(SCALE_FACTOR_300P));
+}
+
+} // namespace ui