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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/views/controls/button/image_button.h" 5 #include "ui/views/controls/button/image_button.h"
6 6
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "ui/accessibility/ax_view_state.h" 8 #include "ui/accessibility/ax_view_state.h"
9 #include "ui/gfx/animation/throb_animation.h" 9 #include "ui/gfx/animation/throb_animation.h"
10 #include "ui/gfx/canvas.h" 10 #include "ui/gfx/canvas.h"
11 #include "ui/gfx/image/image_skia_operations.h" 11 #include "ui/gfx/image/image_skia_operations.h"
12 #include "ui/gfx/scoped_canvas.h" 12 #include "ui/gfx/scoped_canvas.h"
13 #include "ui/views/painter.h" 13 #include "ui/views/painter.h"
14 #include "ui/views/widget/widget.h" 14 #include "ui/views/widget/widget.h"
15 15
16 namespace views { 16 namespace views {
17 17
18 static const int kDefaultWidth = 16; // Default button width if no theme. 18 // Default button size if no image is set. This is ignored if there is an image,
19 static const int kDefaultHeight = 14; // Default button height if no theme. 19 // and exists for historical reasons (any number of clients could depend on this
20 // behaviour).
21 static const int kDefaultWidth = 16;
22 static const int kDefaultHeight = 14;
20 23
21 const char ImageButton::kViewClassName[] = "ImageButton"; 24 const char ImageButton::kViewClassName[] = "ImageButton";
22 25
23 //////////////////////////////////////////////////////////////////////////////// 26 ////////////////////////////////////////////////////////////////////////////////
24 // ImageButton, public: 27 // ImageButton, public:
25 28
26 ImageButton::ImageButton(ButtonListener* listener) 29 ImageButton::ImageButton(ButtonListener* listener)
27 : CustomButton(listener), 30 : CustomButton(listener),
28 h_alignment_(ALIGN_LEFT), 31 h_alignment_(ALIGN_LEFT),
29 v_alignment_(ALIGN_TOP), 32 v_alignment_(ALIGN_TOP),
30 preferred_size_(kDefaultWidth, kDefaultHeight),
31 draw_image_mirrored_(false), 33 draw_image_mirrored_(false),
32 focus_painter_(Painter::CreateDashedFocusPainter()) { 34 focus_painter_(Painter::CreateDashedFocusPainter()) {
33 // By default, we request that the gfx::Canvas passed to our View::OnPaint() 35 // By default, we request that the gfx::Canvas passed to our View::OnPaint()
34 // implementation is flipped horizontally so that the button's images are 36 // implementation is flipped horizontally so that the button's images are
35 // mirrored when the UI directionality is right-to-left. 37 // mirrored when the UI directionality is right-to-left.
36 EnableCanvasFlippingForRTLUI(true); 38 EnableCanvasFlippingForRTLUI(true);
37 } 39 }
38 40
39 ImageButton::~ImageButton() { 41 ImageButton::~ImageButton() {
40 } 42 }
(...skipping 23 matching lines...) Expand all
64 VerticalAlignment v_align) { 66 VerticalAlignment v_align) {
65 h_alignment_ = h_align; 67 h_alignment_ = h_align;
66 v_alignment_ = v_align; 68 v_alignment_ = v_align;
67 SchedulePaint(); 69 SchedulePaint();
68 } 70 }
69 71
70 void ImageButton::SetFocusPainter(scoped_ptr<Painter> focus_painter) { 72 void ImageButton::SetFocusPainter(scoped_ptr<Painter> focus_painter) {
71 focus_painter_ = focus_painter.Pass(); 73 focus_painter_ = focus_painter.Pass();
72 } 74 }
73 75
76 void ImageButton::SetMinimumImageSize(const gfx::Size& size) {
77 if (minimum_image_size_ == size)
78 return;
79
80 minimum_image_size_ = size;
81 PreferredSizeChanged();
82 }
83
74 //////////////////////////////////////////////////////////////////////////////// 84 ////////////////////////////////////////////////////////////////////////////////
75 // ImageButton, View overrides: 85 // ImageButton, View overrides:
76 86
77 gfx::Size ImageButton::GetPreferredSize() const { 87 gfx::Size ImageButton::GetPreferredSize() const {
78 gfx::Size size = preferred_size_; 88 gfx::Size size(kDefaultWidth, kDefaultHeight);
79 if (!images_[STATE_NORMAL].isNull()) { 89 if (!images_[STATE_NORMAL].isNull()) {
80 size = gfx::Size(images_[STATE_NORMAL].width(), 90 size = gfx::Size(images_[STATE_NORMAL].width(),
81 images_[STATE_NORMAL].height()); 91 images_[STATE_NORMAL].height());
82 } 92 }
83 93
94 size.SetToMax(minimum_image_size_);
95
84 gfx::Insets insets = GetInsets(); 96 gfx::Insets insets = GetInsets();
85 size.Enlarge(insets.width(), insets.height()); 97 size.Enlarge(insets.width(), insets.height());
86 return size; 98 return size;
87 } 99 }
88 100
89 const char* ImageButton::GetClassName() const { 101 const char* ImageButton::GetClassName() const {
90 return kViewClassName; 102 return kViewClassName;
91 } 103 }
92 104
93 void ImageButton::OnPaint(gfx::Canvas* canvas) { 105 void ImageButton::OnPaint(gfx::Canvas* canvas) {
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 *tooltip = toggled_tooltip_text_; 257 *tooltip = toggled_tooltip_text_;
246 return true; 258 return true;
247 } 259 }
248 260
249 void ToggleImageButton::GetAccessibleState(ui::AXViewState* state) { 261 void ToggleImageButton::GetAccessibleState(ui::AXViewState* state) {
250 ImageButton::GetAccessibleState(state); 262 ImageButton::GetAccessibleState(state);
251 GetTooltipText(gfx::Point(), &state->name); 263 GetTooltipText(gfx::Point(), &state->name);
252 } 264 }
253 265
254 } // namespace views 266 } // namespace views
OLDNEW
« 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