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

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: 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 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 font_list.Get() = font_list.Get().DeriveWithWeight(
50 DeriveWithStyle(font_list.Get().GetFontStyle() | gfx::Font::BOLD); 65 GetValueBolderThan(font_list.Get().GetFontWeight()));
51 DCHECK_NE(font_list.Get().GetFontStyle() & gfx::Font::BOLD, 0); 66 DCHECK_GE(font_list.Get().GetFontWeight(), gfx::Font::Weight::BOLD);
52 } 67
53 return font_list.Get(); 68 return font_list.Get();
54 } 69 }
55 70
56 // Ink drop container view that does not capture any events. 71 // Ink drop container view that does not capture any events.
57 class InkDropContainerView : public views::View { 72 class InkDropContainerView : public views::View {
58 public: 73 public:
59 InkDropContainerView() {} 74 InkDropContainerView() {}
60 75
61 // View: 76 // View:
62 bool CanProcessEventsWithinSubtree() const override { 77 bool CanProcessEventsWithinSubtree() const override {
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 void LabelButton::SetTextSubpixelRenderingEnabled(bool enabled) { 171 void LabelButton::SetTextSubpixelRenderingEnabled(bool enabled) {
157 label_->SetSubpixelRenderingEnabled(enabled); 172 label_->SetSubpixelRenderingEnabled(enabled);
158 } 173 }
159 174
160 const gfx::FontList& LabelButton::GetFontList() const { 175 const gfx::FontList& LabelButton::GetFontList() const {
161 return label_->font_list(); 176 return label_->font_list();
162 } 177 }
163 178
164 void LabelButton::SetFontList(const gfx::FontList& font_list) { 179 void LabelButton::SetFontList(const gfx::FontList& font_list) {
165 cached_normal_font_list_ = font_list; 180 cached_normal_font_list_ = font_list;
166 cached_bold_font_list_ = font_list.DeriveWithStyle( 181 cached_bold_font_list_ =
167 font_list.GetFontStyle() | gfx::Font::BOLD); 182 font_list.DeriveWithWeight(GetValueBolderThan(font_list.GetFontWeight()));
168 label_->SetFontList(is_default_ ? 183 label_->SetFontList(is_default_ ? cached_bold_font_list_
169 cached_bold_font_list_ : cached_normal_font_list_); 184 : cached_normal_font_list_);
170 } 185 }
171 186
172 void LabelButton::SetElideBehavior(gfx::ElideBehavior elide_behavior) { 187 void LabelButton::SetElideBehavior(gfx::ElideBehavior elide_behavior) {
173 label_->SetElideBehavior(elide_behavior); 188 label_->SetElideBehavior(elide_behavior);
174 } 189 }
175 190
176 void LabelButton::SetHorizontalAlignment(gfx::HorizontalAlignment alignment) { 191 void LabelButton::SetHorizontalAlignment(gfx::HorizontalAlignment alignment) {
177 DCHECK_NE(gfx::ALIGN_TO_HEAD, alignment); 192 DCHECK_NE(gfx::ALIGN_TO_HEAD, alignment);
178 horizontal_alignment_ = alignment; 193 horizontal_alignment_ = alignment;
179 InvalidateLayout(); 194 InvalidateLayout();
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 GetExtraParams(params); 582 GetExtraParams(params);
568 return ui::NativeTheme::kHovered; 583 return ui::NativeTheme::kHovered;
569 } 584 }
570 585
571 void LabelButton::ResetCachedPreferredSize() { 586 void LabelButton::ResetCachedPreferredSize() {
572 cached_preferred_size_valid_ = false; 587 cached_preferred_size_valid_ = false;
573 cached_preferred_size_ = gfx::Size(); 588 cached_preferred_size_ = gfx::Size();
574 } 589 }
575 590
576 } // namespace views 591 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698