diff options
author | noms@chromium.org <noms@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-08-15 15:13:09 +0000 |
---|---|---|
committer | noms@chromium.org <noms@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-08-15 15:14:40 +0000 |
commit | 12fc877059b124f2f5d8cc7947d6338ce15f3745 (patch) | |
tree | a6906f035f121135696a0f958bf4a39304ed3014 /ui/views | |
parent | 16a388b35afe297f3f7bbe93bd464250b168985d (diff) | |
download | chromium_src-12fc877059b124f2f5d8cc7947d6338ce15f3745.zip chromium_src-12fc877059b124f2f5d8cc7947d6338ce15f3745.tar.gz chromium_src-12fc877059b124f2f5d8cc7947d6338ce15f3745.tar.bz2 |
[Win] Increase the spacing between icons and labels in the new avatar bubble.
This involves adding a configurable member to views::LabelButton.
BUG=403859
Review URL: https://codereview.chromium.org/471173002
Cr-Commit-Position: refs/heads/master@{#289861}
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@289861 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/views')
-rw-r--r-- | ui/views/controls/button/label_button.cc | 32 | ||||
-rw-r--r-- | ui/views/controls/button/label_button.h | 8 | ||||
-rw-r--r-- | ui/views/controls/button/label_button_unittest.cc | 18 |
3 files changed, 48 insertions, 10 deletions
diff --git a/ui/views/controls/button/label_button.cc b/ui/views/controls/button/label_button.cc index 042acaf..bb550bd 100644 --- a/ui/views/controls/button/label_button.cc +++ b/ui/views/controls/button/label_button.cc @@ -21,7 +21,7 @@ namespace { -// The spacing between the icon and text. +// The default spacing between the icon and text. const int kSpacing = 5; #if !(defined(OS_LINUX) && !defined(OS_CHROMEOS)) @@ -49,7 +49,8 @@ LabelButton::LabelButton(ButtonListener* listener, const base::string16& text) explicitly_set_colors_(), is_default_(false), style_(STYLE_TEXTBUTTON), - border_is_themed_border_(true) { + border_is_themed_border_(true), + image_label_spacing_(kSpacing) { SetAnimationDuration(kHoverAnimationDurationMs); SetText(text); SetFontList(gfx::FontList()); @@ -185,6 +186,14 @@ void LabelButton::SetStyle(ButtonStyle style) { ResetCachedPreferredSize(); } +void LabelButton::SetImageLabelSpacing(int spacing) { + if (spacing == image_label_spacing_) + return; + image_label_spacing_ = spacing; + ResetCachedPreferredSize(); + InvalidateLayout(); +} + void LabelButton::SetFocusPainter(scoped_ptr<Painter> focus_painter) { focus_painter_ = focus_painter.Pass(); } @@ -211,7 +220,7 @@ gfx::Size LabelButton::GetPreferredSize() const { const gfx::Size image_size(image_->GetPreferredSize()); gfx::Size size(label.GetPreferredSize()); if (image_size.width() > 0 && size.width() > 0) - size.Enlarge(kSpacing, 0); + size.Enlarge(image_label_spacing_, 0); size.SetToMax(gfx::Size(0, image_size.height())); const gfx::Insets insets(GetInsets()); size.Enlarge(image_size.width() + insets.width(), insets.height()); @@ -240,7 +249,7 @@ int LabelButton::GetHeightForWidth(int w) const { const gfx::Size image_size(image_->GetPreferredSize()); w -= image_size.width(); if (image_size.width() > 0 && !GetText().empty()) - w -= kSpacing; + w -= image_label_spacing_; int height = std::max(image_size.height(), label_->GetHeightForWidth(w)); if (border()) @@ -269,9 +278,10 @@ void LabelButton::Layout() { // avoids wasted space within the label that would look like awkward padding. // Labels can paint over the full button height, including the border height. gfx::Size label_size(child_area.width(), height()); - if (!image_size.IsEmpty() && !label_size.IsEmpty()) { - label_size.set_width( - std::max(child_area.width() - image_size.width() - kSpacing, 0)); + const bool image_and_label = !image_size.IsEmpty() && !label_size.IsEmpty(); + if (image_and_label) { + label_size.set_width(std::max(child_area.width() - + image_size.width() - image_label_spacing_, 0)); if (adjusted_alignment == gfx::ALIGN_CENTER) { // Ensure multi-line labels paired with images use their available width. label_size.set_width( @@ -283,15 +293,17 @@ void LabelButton::Layout() { image_origin.Offset(0, (child_area.height() - image_size.height()) / 2); if (adjusted_alignment == gfx::ALIGN_CENTER) { const int total_width = image_size.width() + label_size.width() + - ((image_size.width() > 0 && label_size.width() > 0) ? kSpacing : 0); + (image_and_label ? image_label_spacing_ : 0); image_origin.Offset((child_area.width() - total_width) / 2, 0); } else if (adjusted_alignment == gfx::ALIGN_RIGHT) { image_origin.Offset(child_area.width() - image_size.width(), 0); } gfx::Point label_origin(child_area.x(), 0); - if (!image_size.IsEmpty() && adjusted_alignment != gfx::ALIGN_RIGHT) - label_origin.set_x(image_origin.x() + image_size.width() + kSpacing); + if (!image_size.IsEmpty() && adjusted_alignment != gfx::ALIGN_RIGHT) { + label_origin.set_x(image_origin.x() + image_size.width() + + image_label_spacing_); + } image_->SetBoundsRect(gfx::Rect(image_origin, image_size)); label_->SetBoundsRect(gfx::Rect(label_origin, label_size)); diff --git a/ui/views/controls/button/label_button.h b/ui/views/controls/button/label_button.h index 5e730ca..b614fe2a 100644 --- a/ui/views/controls/button/label_button.h +++ b/ui/views/controls/button/label_button.h @@ -77,6 +77,11 @@ class VIEWS_EXPORT LabelButton : public CustomButton, ButtonStyle style() const { return style_; } void SetStyle(ButtonStyle style); + // Set the spacing between the image and the text. Shrinking the spacing + // will not shrink the overall button size, as it is monotonically increasing. + // Call SetMinSize(gfx::Size()) to clear the size if needed. + void SetImageLabelSpacing(int spacing); + void SetFocusPainter(scoped_ptr<Painter> focus_painter); Painter* focus_painter() { return focus_painter_.get(); } @@ -183,6 +188,9 @@ class VIEWS_EXPORT LabelButton : public CustomButton, // True if current border was set by UpdateThemedBorder. Defaults to true. bool border_is_themed_border_; + // Spacing between the image and the text. + int image_label_spacing_; + scoped_ptr<Painter> focus_painter_; DISALLOW_COPY_AND_ASSIGN(LabelButton); diff --git a/ui/views/controls/button/label_button_unittest.cc b/ui/views/controls/button/label_button_unittest.cc index d622370..f295173 100644 --- a/ui/views/controls/button/label_button_unittest.cc +++ b/ui/views/controls/button/label_button_unittest.cc @@ -207,4 +207,22 @@ TEST_F(LabelButtonTest, ChangeTextSize) { EXPECT_EQ(original_width, button.GetPreferredSize().width()); } +TEST_F(LabelButtonTest, ChangeLabelImageSpacing) { + LabelButton button(NULL, ASCIIToUTF16("abc")); + button.SetImage(Button::STATE_NORMAL, CreateTestImage(50, 50)); + + const int kOriginalSpacing = 5; + button.SetImageLabelSpacing(kOriginalSpacing); + const int original_width = button.GetPreferredSize().width(); + + // Increasing the spacing between the text and label should increase the size. + button.SetImageLabelSpacing(2 * kOriginalSpacing); + EXPECT_GT(button.GetPreferredSize().width(), original_width); + + // The button shrinks if the original spacing is restored. + button.SetMinSize(gfx::Size()); + button.SetImageLabelSpacing(kOriginalSpacing); + EXPECT_EQ(original_width, button.GetPreferredSize().width()); +} + } // namespace views |