Skip to content

Commit

Permalink
Make LabelButton::SetFontList protected.
Browse files Browse the repository at this point in the history
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}
  • Loading branch information
estade authored and Commit bot committed Dec 13, 2016
1 parent 2db959f commit 19d351e
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 28 deletions.
3 changes: 2 additions & 1 deletion chrome/browser/ui/views/profiles/new_avatar_button.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/ui/views/profiles/profile_chooser_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
33 changes: 17 additions & 16 deletions ui/views/controls/button/label_button.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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());
Expand Down
9 changes: 5 additions & 4 deletions ui/views/controls/button/label_button.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
9 changes: 3 additions & 6 deletions ui/views/controls/button/label_button_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down

0 comments on commit 19d351e

Please sign in to comment.