Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(463)

Unified Diff: ui/views/controls/button/label_button.cc

Issue 1819753003: Allow various font weights in gfx. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Further Mac and Linux fixes. Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ui/views/controls/button/label_button.cc
diff --git a/ui/views/controls/button/label_button.cc b/ui/views/controls/button/label_button.cc
index f5b07e474368a2d8484444a0ed37887ddf5a3ff0..5a3414d8960fc5b83eeb80bcf9b801dc0c27cb13 100644
--- a/ui/views/controls/button/label_button.cc
+++ b/ui/views/controls/button/label_button.cc
@@ -36,6 +36,21 @@ const SkColor kStyleButtonTextColor = SK_ColorBLACK;
const SkColor kStyleButtonShadowColor = SK_ColorWHITE;
#endif
+gfx::Font::Weight GetValueBolderThan(gfx::Font::Weight weight) {
+ if (weight < gfx::Font::Weight::BOLD)
+ return gfx::Font::Weight::BOLD;
+ switch (weight) {
+ case gfx::Font::Weight::BOLD:
+ return gfx::Font::Weight::EXTRA_BOLD;
+ case gfx::Font::Weight::EXTRA_BOLD:
+ case gfx::Font::Weight::BLACK:
+ return gfx::Font::Weight::BLACK;
+ default:
+ NOTREACHED();
+ }
+ return gfx::Font::Weight::INVALID;
+}
+
const gfx::FontList& GetDefaultNormalFontList() {
static base::LazyInstance<gfx::FontList>::Leaky font_list =
LAZY_INSTANCE_INITIALIZER;
@@ -45,11 +60,11 @@ const gfx::FontList& GetDefaultNormalFontList() {
const gfx::FontList& GetDefaultBoldFontList() {
static base::LazyInstance<gfx::FontList>::Leaky font_list =
LAZY_INSTANCE_INITIALIZER;
- if ((font_list.Get().GetFontStyle() & gfx::Font::BOLD) == 0) {
- font_list.Get() = font_list.Get().
- DeriveWithStyle(font_list.Get().GetFontStyle() | gfx::Font::BOLD);
- DCHECK_NE(font_list.Get().GetFontStyle() & gfx::Font::BOLD, 0);
- }
+
+ font_list.Get() = font_list.Get().DeriveWithWeight(
+ GetValueBolderThan(font_list.Get().GetFontWeight()));
+ DCHECK_GE(font_list.Get().GetFontWeight(), gfx::Font::Weight::BOLD);
+
return font_list.Get();
}
@@ -163,10 +178,10 @@ const gfx::FontList& LabelButton::GetFontList() const {
void LabelButton::SetFontList(const gfx::FontList& font_list) {
cached_normal_font_list_ = font_list;
- cached_bold_font_list_ = font_list.DeriveWithStyle(
- font_list.GetFontStyle() | gfx::Font::BOLD);
- label_->SetFontList(is_default_ ?
- cached_bold_font_list_ : cached_normal_font_list_);
+ cached_bold_font_list_ =
+ font_list.DeriveWithWeight(GetValueBolderThan(font_list.GetFontWeight()));
+ label_->SetFontList(is_default_ ? cached_bold_font_list_
+ : cached_normal_font_list_);
}
void LabelButton::SetElideBehavior(gfx::ElideBehavior elide_behavior) {

Powered by Google App Engine
This is Rietveld 408576698