Chromium Code Reviews| Index: ui/base/resource/resource_bundle.cc |
| diff --git a/ui/base/resource/resource_bundle.cc b/ui/base/resource/resource_bundle.cc |
| index 8afa15b608988d97be8981edc0f61467667a3c13..c56458ceb42ec9dc8dffb8c4c00a53dd2f697e2f 100644 |
| --- a/ui/base/resource/resource_bundle.cc |
| +++ b/ui/base/resource/resource_bundle.cc |
| @@ -158,6 +158,32 @@ class ResourceBundle::ResourceBundleImageSource : public gfx::ImageSkiaSource { |
| DISALLOW_COPY_AND_ASSIGN(ResourceBundleImageSource); |
| }; |
| +struct ResourceBundle::FontKey { |
| + FontKey(int in_size_delta, |
| + gfx::Font::FontStyle in_style, |
| + gfx::Font::Weight in_weight) |
| + : size_delta(in_size_delta), style(in_style), weight(in_weight) {} |
| + |
| + ~FontKey() {} |
| + |
| + bool operator==(const FontKey& rhs) const { |
| + return size_delta == rhs.size_delta && style == rhs.style && |
| + weight == rhs.weight; |
| + } |
| + |
| + bool operator<(const FontKey& rhs) const { |
| + if (size_delta != rhs.size_delta) |
| + return size_delta < rhs.size_delta; |
| + if (style != rhs.style) |
| + return style < rhs.style; |
| + return weight < rhs.weight; |
| + } |
| + |
| + int size_delta; |
| + gfx::Font::FontStyle style; |
| + gfx::Font::Weight weight; |
| +}; |
| + |
| // static |
| std::string ResourceBundle::InitSharedInstanceWithLocale( |
| const std::string& pref_locale, |
| @@ -533,17 +559,17 @@ base::string16 ResourceBundle::GetLocalizedString(int message_id) { |
| const gfx::FontList& ResourceBundle::GetFontListWithDelta( |
| int size_delta, |
| - gfx::Font::FontStyle style) { |
| + gfx::Font::FontStyle style, |
| + gfx::Font::Weight weight) { |
| base::AutoLock lock_scope(*images_and_fonts_lock_); |
| - typedef std::pair<int, gfx::Font::FontStyle> Key; |
| - const Key styled_key(size_delta, style); |
| + const FontKey styled_key = {size_delta, style, weight}; |
| auto found = font_cache_.find(styled_key); |
| if (found != font_cache_.end()) |
| return found->second; |
| - const Key base_key(0, gfx::Font::NORMAL); |
| + const FontKey base_key = {0, gfx::Font::NORMAL, gfx::Font::Weight::NORMAL}; |
| gfx::FontList& base = font_cache_[base_key]; |
| if (styled_key == base_key) |
| return base; |
| @@ -552,7 +578,8 @@ const gfx::FontList& ResourceBundle::GetFontListWithDelta( |
| // 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); |
| + const FontKey sized_key = {size_delta, gfx::Font::NORMAL, |
| + gfx::Font::Weight::NORMAL}; |
|
tapted
2016/03/22 23:31:32
running `git cl format` should update this to a mo
Mikus
2016/03/23 17:53:21
This is what clang actually does
|
| auto sized = font_cache_.insert(std::make_pair(sized_key, gfx::FontList())); |
| if (sized.second) |
| sized.first->second = base.DeriveWithSizeDelta(size_delta); |
| @@ -561,8 +588,9 @@ const gfx::FontList& ResourceBundle::GetFontListWithDelta( |
| 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); |
| + styled.first->second = sized.first->second.Derive( |
| + 0, sized.first->second.GetFontStyle() | style, weight); |
|
msw
2016/03/22 18:24:10
Isn't the style of the |sized| font gfx::Font::Nor
tapted
2016/03/22 23:31:32
This confused me initially too. There's actually n
Mikus
2016/03/23 17:53:21
Acknowledged.
|
| + |
| return styled.first->second; |
| } |
| @@ -572,10 +600,10 @@ const gfx::Font& ResourceBundle::GetFontWithDelta(int size_delta, |
| } |
| const gfx::FontList& ResourceBundle::GetFontList(FontStyle legacy_style) { |
| - gfx::Font::FontStyle font_style = gfx::Font::NORMAL; |
| + gfx::Font::Weight font_weight = gfx::Font::Weight::NORMAL; |
| if (legacy_style == BoldFont || legacy_style == SmallBoldFont || |
| legacy_style == MediumBoldFont || legacy_style == LargeBoldFont) |
| - font_style = gfx::Font::BOLD; |
| + font_weight = gfx::Font::Weight::BOLD; |
| int size_delta = 0; |
| switch (legacy_style) { |
| @@ -596,7 +624,7 @@ const gfx::FontList& ResourceBundle::GetFontList(FontStyle legacy_style) { |
| break; |
| } |
| - return GetFontListWithDelta(size_delta, font_style); |
| + return GetFontListWithDelta(size_delta, gfx::Font::NORMAL, font_weight); |
| } |
| const gfx::Font& ResourceBundle::GetFont(FontStyle style) { |