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

Side by Side 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: Fixes for review issues. 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/views/controls/button/label_button.h" 5 #include "ui/views/controls/button/label_button.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
(...skipping 18 matching lines...) Expand all
29 29
30 // The default spacing between the icon and text. 30 // The default spacing between the icon and text.
31 const int kSpacing = 5; 31 const int kSpacing = 5;
32 32
33 #if !(defined(OS_LINUX) && !defined(OS_CHROMEOS)) 33 #if !(defined(OS_LINUX) && !defined(OS_CHROMEOS))
34 // Default text and shadow colors for STYLE_BUTTON. 34 // Default text and shadow colors for STYLE_BUTTON.
35 const SkColor kStyleButtonTextColor = SK_ColorBLACK; 35 const SkColor kStyleButtonTextColor = SK_ColorBLACK;
36 const SkColor kStyleButtonShadowColor = SK_ColorWHITE; 36 const SkColor kStyleButtonShadowColor = SK_ColorWHITE;
37 #endif 37 #endif
38 38
39 gfx::Font::Weight GetValueBolderThan(gfx::Font::Weight weight) {
40 if (weight < gfx::Font::Weight::BOLD)
41 return gfx::Font::Weight::BOLD;
42 switch (weight) {
43 case gfx::Font::Weight::BOLD:
44 return gfx::Font::Weight::EXTRA_BOLD;
45 case gfx::Font::Weight::EXTRA_BOLD:
46 case gfx::Font::Weight::BLACK:
47 return gfx::Font::Weight::BLACK;
48 default:
49 NOTREACHED();
50 }
51 return gfx::Font::Weight::INVALID;
52 }
53
39 const gfx::FontList& GetDefaultNormalFontList() { 54 const gfx::FontList& GetDefaultNormalFontList() {
40 static base::LazyInstance<gfx::FontList>::Leaky font_list = 55 static base::LazyInstance<gfx::FontList>::Leaky font_list =
41 LAZY_INSTANCE_INITIALIZER; 56 LAZY_INSTANCE_INITIALIZER;
42 return font_list.Get(); 57 return font_list.Get();
43 } 58 }
44 59
45 const gfx::FontList& GetDefaultBoldFontList() { 60 const gfx::FontList& GetDefaultBoldFontList() {
46 static base::LazyInstance<gfx::FontList>::Leaky font_list = 61 static base::LazyInstance<gfx::FontList>::Leaky font_list =
47 LAZY_INSTANCE_INITIALIZER; 62 LAZY_INSTANCE_INITIALIZER;
48 if ((font_list.Get().GetFontStyle() & gfx::Font::BOLD) == 0) { 63
49 font_list.Get() = font_list.Get(). 64 if (font_list.Get().GetFontWeight() < gfx::Font::Weight::BOLD) {
msw 2016/03/22 18:24:11 Remove this conditional now, it should handle any
Mikus 2016/03/23 17:53:22 Done.
50 DeriveWithStyle(font_list.Get().GetFontStyle() | gfx::Font::BOLD); 65 font_list.Get() = font_list.Get().DeriveWithWeight(
51 DCHECK_NE(font_list.Get().GetFontStyle() & gfx::Font::BOLD, 0); 66 GetValueBolderThan(font_list.Get().GetFontWeight()));
67 DCHECK_GE(font_list.Get().GetFontWeight(), gfx::Font::Weight::BOLD);
52 } 68 }
69
53 return font_list.Get(); 70 return font_list.Get();
54 } 71 }
55 72
56 // Ink drop container view that does not capture any events. 73 // Ink drop container view that does not capture any events.
57 class InkDropContainerView : public views::View { 74 class InkDropContainerView : public views::View {
58 public: 75 public:
59 InkDropContainerView() {} 76 InkDropContainerView() {}
60 77
61 // View: 78 // View:
62 bool CanProcessEventsWithinSubtree() const override { 79 bool CanProcessEventsWithinSubtree() const override {
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 void LabelButton::SetTextSubpixelRenderingEnabled(bool enabled) { 174 void LabelButton::SetTextSubpixelRenderingEnabled(bool enabled) {
158 label_->SetSubpixelRenderingEnabled(enabled); 175 label_->SetSubpixelRenderingEnabled(enabled);
159 } 176 }
160 177
161 const gfx::FontList& LabelButton::GetFontList() const { 178 const gfx::FontList& LabelButton::GetFontList() const {
162 return label_->font_list(); 179 return label_->font_list();
163 } 180 }
164 181
165 void LabelButton::SetFontList(const gfx::FontList& font_list) { 182 void LabelButton::SetFontList(const gfx::FontList& font_list) {
166 cached_normal_font_list_ = font_list; 183 cached_normal_font_list_ = font_list;
167 cached_bold_font_list_ = font_list.DeriveWithStyle( 184 cached_bold_font_list_ = font_list.DeriveWithWeight(gfx::Font::Weight::BOLD);
msw 2016/03/22 18:24:11 Use GetValueBolderThan here too.
168 font_list.GetFontStyle() | gfx::Font::BOLD);
169 185
170 // STYLE_BUTTON uses bold text to indicate default buttons. 186 // STYLE_BUTTON uses bold text to indicate default buttons.
171 label_->SetFontList( 187 label_->SetFontList(
172 style_ == STYLE_BUTTON && is_default_ ? 188 style_ == STYLE_BUTTON && is_default_ ?
173 cached_bold_font_list_ : cached_normal_font_list_); 189 cached_bold_font_list_ : cached_normal_font_list_);
174 } 190 }
175 191
176 void LabelButton::SetElideBehavior(gfx::ElideBehavior elide_behavior) { 192 void LabelButton::SetElideBehavior(gfx::ElideBehavior elide_behavior) {
177 label_->SetElideBehavior(elide_behavior); 193 label_->SetElideBehavior(elide_behavior);
178 } 194 }
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 GetExtraParams(params); 578 GetExtraParams(params);
563 return ui::NativeTheme::kHovered; 579 return ui::NativeTheme::kHovered;
564 } 580 }
565 581
566 void LabelButton::ResetCachedPreferredSize() { 582 void LabelButton::ResetCachedPreferredSize() {
567 cached_preferred_size_valid_ = false; 583 cached_preferred_size_valid_ = false;
568 cached_preferred_size_ = gfx::Size(); 584 cached_preferred_size_ = gfx::Size();
569 } 585 }
570 586
571 } // namespace views 587 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698