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

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: Add bold styling DCHECK warning against repeated derive calls. 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..300c5a79b28c85bc0c96ff795167a6c1bb506c79 100644
--- a/ui/views/controls/button/label_button.cc
+++ b/ui/views/controls/button/label_button.cc
@@ -4,6 +4,7 @@
#include "ui/views/controls/button/label_button.h"
+#include "base/lazy_instance.h"
#include "base/logging.h"
#include "ui/gfx/animation/throb_animation.h"
#include "ui/gfx/canvas.h"
@@ -30,6 +31,23 @@ const SkColor kStyleButtonTextColor = SK_ColorBLACK;
const SkColor kStyleButtonShadowColor = SK_ColorWHITE;
#endif
+const gfx::FontList& GetDefaultNormalFontList() {
+ static base::LazyInstance<gfx::FontList>::Leaky font_list =
+ LAZY_INSTANCE_INITIALIZER;
+ return font_list.Get();
+}
+
+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);
+ }
+ return font_list.Get();
+}
+
} // namespace
namespace views {
@@ -44,6 +62,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 +73,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