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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "base/logging.h" 7 #include "base/logging.h"
8 #include "ui/gfx/animation/throb_animation.h" 8 #include "ui/gfx/animation/throb_animation.h"
9 #include "ui/gfx/canvas.h" 9 #include "ui/gfx/canvas.h"
10 #include "ui/gfx/font_list.h" 10 #include "ui/gfx/font_list.h"
(...skipping 12 matching lines...) Expand all
23 23
24 // The default spacing between the icon and text. 24 // The default spacing between the icon and text.
25 const int kSpacing = 5; 25 const int kSpacing = 5;
26 26
27 #if !(defined(OS_LINUX) && !defined(OS_CHROMEOS)) 27 #if !(defined(OS_LINUX) && !defined(OS_CHROMEOS))
28 // Default text and shadow colors for STYLE_BUTTON. 28 // Default text and shadow colors for STYLE_BUTTON.
29 const SkColor kStyleButtonTextColor = SK_ColorBLACK; 29 const SkColor kStyleButtonTextColor = SK_ColorBLACK;
30 const SkColor kStyleButtonShadowColor = SK_ColorWHITE; 30 const SkColor kStyleButtonShadowColor = SK_ColorWHITE;
31 #endif 31 #endif
32 32
33 const gfx::FontList& GetDefaultNormalFontList() {
34 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.
35 return kNormalFontList;
36 }
37
38 const gfx::FontList& GetDefaultBoldFontList() {
39 static const gfx::FontList kBoldFontList = gfx::FontList().
40 DeriveWithStyle(gfx::FontList().GetFontStyle() | gfx::Font::BOLD);
41 return kBoldFontList;
42 }
43
33 } // namespace 44 } // namespace
34 45
35 namespace views { 46 namespace views {
36 47
37 // static 48 // static
38 const int LabelButton::kHoverAnimationDurationMs = 170; 49 const int LabelButton::kHoverAnimationDurationMs = 170;
39 50
40 // static 51 // static
41 const char LabelButton::kViewClassName[] = "LabelButton"; 52 const char LabelButton::kViewClassName[] = "LabelButton";
42 53
43 LabelButton::LabelButton(ButtonListener* listener, const base::string16& text) 54 LabelButton::LabelButton(ButtonListener* listener, const base::string16& text)
44 : CustomButton(listener), 55 : CustomButton(listener),
45 image_(new ImageView()), 56 image_(new ImageView()),
46 label_(new Label()), 57 label_(new Label()),
58 cached_normal_font_list_(GetDefaultNormalFontList()),
59 cached_bold_font_list_(GetDefaultBoldFontList()),
47 button_state_images_(), 60 button_state_images_(),
48 button_state_colors_(), 61 button_state_colors_(),
49 explicitly_set_colors_(), 62 explicitly_set_colors_(),
50 is_default_(false), 63 is_default_(false),
51 style_(STYLE_TEXTBUTTON), 64 style_(STYLE_TEXTBUTTON),
52 border_is_themed_border_(true), 65 border_is_themed_border_(true),
53 image_label_spacing_(kSpacing) { 66 image_label_spacing_(kSpacing) {
54 SetAnimationDuration(kHoverAnimationDurationMs); 67 SetAnimationDuration(kHoverAnimationDurationMs);
55 SetText(text); 68 SetText(text);
56 SetFontList(gfx::FontList());
57 69
58 AddChildView(image_); 70 AddChildView(image_);
59 image_->set_interactive(false); 71 image_->set_interactive(false);
60 72
61 AddChildView(label_); 73 AddChildView(label_);
74 label_->SetFontList(cached_normal_font_list_);
62 label_->SetAutoColorReadabilityEnabled(false); 75 label_->SetAutoColorReadabilityEnabled(false);
63 label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); 76 label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
64 77
65 // Initialize the colors, border, and layout. 78 // Initialize the colors, border, and layout.
66 SetStyle(style_); 79 SetStyle(style_);
67 80
68 SetAccessibleName(text); 81 SetAccessibleName(text);
69 } 82 }
70 83
71 LabelButton::~LabelButton() {} 84 LabelButton::~LabelButton() {}
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 GetExtraParams(params); 502 GetExtraParams(params);
490 return ui::NativeTheme::kHovered; 503 return ui::NativeTheme::kHovered;
491 } 504 }
492 505
493 void LabelButton::ResetCachedPreferredSize() { 506 void LabelButton::ResetCachedPreferredSize() {
494 cached_preferred_size_valid_ = false; 507 cached_preferred_size_valid_ = false;
495 cached_preferred_size_= gfx::Size(); 508 cached_preferred_size_= gfx::Size();
496 } 509 }
497 510
498 } // namespace views 511 } // namespace views
OLDNEW
« 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