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

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

Issue 544173007: Avoid repeatedly deriving fonts in the LabelButton ctor. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Set Label FontList in LabelButton ctor. Created 6 years, 3 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 8768c31e1fd398fdc0f9dabe79acdfe15328b746..c4e6e2e39a49521863d1722ff380b89fbd070c97 100644
--- a/ui/views/controls/button/label_button.cc
+++ b/ui/views/controls/button/label_button.cc
@@ -30,6 +30,17 @@ const SkColor kStyleButtonTextColor = SK_ColorBLACK;
const SkColor kStyleButtonShadowColor = SK_ColorWHITE;
#endif
+const gfx::FontList& GetDefaultNormalFontList() {
+ static const gfx::FontList kNormalFontList = gfx::FontList();
sky 2014/09/15 19:15:34 Style guide says no statics like this. I think the
msw 2014/09/15 20:51:42 Done.
+ return kNormalFontList;
+}
+
+const gfx::FontList& GetDefaultBoldFontList() {
+ static const gfx::FontList kBoldFontList = gfx::FontList().
+ DeriveWithStyle(gfx::FontList().GetFontStyle() | gfx::Font::BOLD);
+ return kBoldFontList;
+}
+
} // namespace
namespace views {
@@ -44,6 +55,8 @@ LabelButton::LabelButton(ButtonListener* listener, const base::string16& text)
: CustomButton(listener),
image_(new ImageView()),
label_(new Label()),
+ cached_normal_font_list_(GetDefaultNormalFontList()),
+ cached_bold_font_list_(GetDefaultBoldFontList()),
button_state_images_(),
button_state_colors_(),
explicitly_set_colors_(),
@@ -53,12 +66,12 @@ LabelButton::LabelButton(ButtonListener* listener, const base::string16& text)
image_label_spacing_(kSpacing) {
SetAnimationDuration(kHoverAnimationDurationMs);
SetText(text);
- SetFontList(gfx::FontList());
AddChildView(image_);
image_->set_interactive(false);
AddChildView(label_);
+ label_->SetFontList(cached_normal_font_list_);
label_->SetAutoColorReadabilityEnabled(false);
label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698