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

Unified Diff: ui/views/controls/button/image_button.cc

Issue 583843003: views::ImageButton: Added SetMinimumImageSize; removed SetPreferredSize. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Respond to sky's comments. 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/views/controls/button/image_button.h ('k') | ui/views/controls/button/image_button_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..1079d5e209b3effa2f44cad0eab34d03e717b6c6 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,6 @@ ImageButton::ImageButton(ButtonListener* listener)
: CustomButton(listener),
h_alignment_(ALIGN_LEFT),
v_alignment_(ALIGN_TOP),
- preferred_size_(kDefaultWidth, kDefaultHeight),
draw_image_mirrored_(false),
focus_painter_(Painter::CreateDashedFocusPainter()) {
// By default, we request that the gfx::Canvas passed to our View::OnPaint()
@@ -71,16 +73,26 @@ void ImageButton::SetFocusPainter(scoped_ptr<Painter> focus_painter) {
focus_painter_ = focus_painter.Pass();
}
+void ImageButton::SetMinimumImageSize(const gfx::Size& size) {
+ if (minimum_image_size_ == size)
+ return;
+
+ minimum_image_size_ = size;
+ 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.SetToMax(minimum_image_size_);
+
gfx::Insets insets = GetInsets();
size.Enlarge(insets.width(), insets.height());
return size;
« no previous file with comments | « ui/views/controls/button/image_button.h ('k') | ui/views/controls/button/image_button_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698