Index: ui/views/controls/button/image_button.cc |
diff --git a/ui/views/controls/button/image_button.cc b/ui/views/controls/button/image_button.cc |
index ecbd4a1072443854e379004fe4214be65fd1846b..c0b3735ed1405e2483a61cfca7f09bc6164e3f36 100644 |
--- a/ui/views/controls/button/image_button.cc |
+++ b/ui/views/controls/button/image_button.cc |
@@ -15,8 +15,11 @@ |
namespace views { |
-static const int kDefaultWidth = 16; // Default button width if no theme. |
-static const int kDefaultHeight = 14; // Default button height if no theme. |
+// Default button size if no image is set. This is ignored if there is an image, |
+// and exists for historical reasons (any number of clients could depend on this |
+// behaviour). |
+static const int kDefaultWidth = 16; |
+static const int kDefaultHeight = 14; |
const char ImageButton::kViewClassName[] = "ImageButton"; |
@@ -27,7 +30,7 @@ ImageButton::ImageButton(ButtonListener* listener) |
: CustomButton(listener), |
h_alignment_(ALIGN_LEFT), |
v_alignment_(ALIGN_TOP), |
- preferred_size_(kDefaultWidth, kDefaultHeight), |
+ minimum_image_size_(0, 0), |
sky
2014/09/19 15:31:06
nit: remove this as 0,0 is the default.
Matt Giuca
2014/09/22 00:41:05
Done.
|
draw_image_mirrored_(false), |
focus_painter_(Painter::CreateDashedFocusPainter()) { |
// By default, we request that the gfx::Canvas passed to our View::OnPaint() |
@@ -71,16 +74,24 @@ void ImageButton::SetFocusPainter(scoped_ptr<Painter> focus_painter) { |
focus_painter_ = focus_painter.Pass(); |
} |
+void ImageButton::SetMinimumImageSize(const gfx::Size& size) { |
+ minimum_image_size_ = size; |
sky
2014/09/19 15:31:06
early out if size == minimum_image_size_
Matt Giuca
2014/09/22 00:41:05
Done.
|
+ PreferredSizeChanged(); |
+} |
+ |
//////////////////////////////////////////////////////////////////////////////// |
// ImageButton, View overrides: |
gfx::Size ImageButton::GetPreferredSize() const { |
- gfx::Size size = preferred_size_; |
+ gfx::Size size(kDefaultWidth, kDefaultHeight); |
if (!images_[STATE_NORMAL].isNull()) { |
size = gfx::Size(images_[STATE_NORMAL].width(), |
images_[STATE_NORMAL].height()); |
} |
+ size.set_width(std::max(size.width(), minimum_image_size_.width())); |
sky
2014/09/19 15:31:06
size.SetToMax(minimum_image_size_);
Matt Giuca
2014/09/22 00:41:05
Done.
|
+ size.set_height(std::max(size.height(), minimum_image_size_.height())); |
+ |
gfx::Insets insets = GetInsets(); |
size.Enlarge(insets.width(), insets.height()); |
return size; |