Commit 19d351e0 authored by estade's avatar estade Committed by Commit bot

Make LabelButton::SetFontList protected.

The last public use of it is part of the pre-MD profile switcher.

BUG=633986

Review-Url: https://codereview.chromium.org/2556833002
Cr-Commit-Position: refs/heads/master@{#437967}
parent 2db959f2
......@@ -70,7 +70,8 @@ NewAvatarButton::NewAvatarButton(AvatarButtonDelegate* delegate,
// is larger than this, it will be shrunk to match it.
// TODO(noms): Calculate this constant algorithmically from the button's size.
const int kDisplayFontHeight = 16;
SetFontList(GetFontList().DeriveWithHeightUpperBound(kDisplayFontHeight));
SetFontList(
label()->font_list().DeriveWithHeightUpperBound(kDisplayFontHeight));
ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance();
if (button_style == AvatarButtonStyle::THEMED) {
......
......@@ -534,7 +534,7 @@ class EditableProfileName : public views::View,
AddChildView(profile_name_textfield_);
button_ = new RightAlignedIconLabelButton(this, text);
button_->SetFontList(medium_font_list);
button_->SetFontListDeprecated(medium_font_list);
// Show an "edit" pencil icon when hovering over. In the default state,
// we need to create an empty placeholder of the correct size, so that
// the text doesn't jump around when the hovered icon appears.
......
......@@ -159,25 +159,13 @@ void LabelButton::SetTextSubpixelRenderingEnabled(bool enabled) {
label_->SetSubpixelRenderingEnabled(enabled);
}
const gfx::FontList& LabelButton::GetFontList() const {
return label_->font_list();
}
void LabelButton::SetFontList(const gfx::FontList& font_list) {
cached_normal_font_list_ = font_list;
if (PlatformStyle::kDefaultLabelButtonHasBoldFont) {
cached_bold_font_list_ = font_list.DeriveWithWeight(
GetValueBolderThan(font_list.GetFontWeight()));
if (is_default_) {
label_->SetFontList(cached_bold_font_list_);
return;
}
}
label_->SetFontList(cached_normal_font_list_);
void LabelButton::SetFontListDeprecated(const gfx::FontList& font_list) {
SetFontList(font_list);
}
void LabelButton::AdjustFontSize(int font_size_delta) {
LabelButton::SetFontList(GetFontList().DeriveWithSizeDelta(font_size_delta));
LabelButton::SetFontList(
label()->font_list().DeriveWithSizeDelta(font_size_delta));
}
void LabelButton::SetElideBehavior(gfx::ElideBehavior elide_behavior) {
......@@ -393,6 +381,19 @@ gfx::Rect LabelButton::GetChildAreaBounds() {
return GetLocalBounds();
}
void LabelButton::SetFontList(const gfx::FontList& font_list) {
cached_normal_font_list_ = font_list;
if (PlatformStyle::kDefaultLabelButtonHasBoldFont) {
cached_bold_font_list_ = font_list.DeriveWithWeight(
GetValueBolderThan(font_list.GetFontWeight()));
if (is_default_) {
label_->SetFontList(cached_bold_font_list_);
return;
}
}
label_->SetFontList(cached_normal_font_list_);
}
void LabelButton::OnPaint(gfx::Canvas* canvas) {
View::OnPaint(canvas);
Painter::PaintFocusPainter(this, canvas, focus_painter_.get());
......
......@@ -56,10 +56,8 @@ class VIEWS_EXPORT LabelButton : public CustomButton,
// Sets whether subpixel rendering is used on the label.
void SetTextSubpixelRenderingEnabled(bool enabled);
// Gets or sets the font list used by this button.
const gfx::FontList& GetFontList() const;
// TODO(estade): make this function protected.
virtual void SetFontList(const gfx::FontList& font_list);
// TODO(estade): remove. See crbug.com/633986
void SetFontListDeprecated(const gfx::FontList& font_list);
// Adjusts the font size up or down by the given amount.
virtual void AdjustFontSize(int font_size_delta);
......@@ -120,6 +118,9 @@ class VIEWS_EXPORT LabelButton : public CustomButton,
// these bounds if they need room to do manual painting.
virtual gfx::Rect GetChildAreaBounds();
// Sets the font list used by this button.
virtual void SetFontList(const gfx::FontList& font_list);
// View:
void OnPaint(gfx::Canvas* canvas) override;
void OnFocus() override;
......
......@@ -291,24 +291,21 @@ TEST_F(LabelButtonTest, LabelAndImage) {
EXPECT_LT(button_->GetPreferredSize().height(), image_size);
}
TEST_F(LabelButtonTest, FontList) {
TEST_F(LabelButtonTest, AdjustFontSize) {
button_->SetText(base::ASCIIToUTF16("abc"));
const gfx::FontList original_font_list = button_->GetFontList();
const gfx::FontList large_font_list =
original_font_list.DeriveWithSizeDelta(100);
const int original_width = button_->GetPreferredSize().width();
const int original_height = button_->GetPreferredSize().height();
// The button size increases when the font size is increased.
button_->SetFontList(large_font_list);
button_->AdjustFontSize(100);
EXPECT_GT(button_->GetPreferredSize().width(), original_width);
EXPECT_GT(button_->GetPreferredSize().height(), original_height);
// The button returns to its original size when the minimal size is cleared
// and the original font size is restored.
button_->SetMinSize(gfx::Size());
button_->SetFontList(original_font_list);
button_->AdjustFontSize(-100);
EXPECT_EQ(original_width, button_->GetPreferredSize().width());
EXPECT_EQ(original_height, button_->GetPreferredSize().height());
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment