Chromium Code Reviews| OLD | NEW |
|---|---|
| 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), | 33 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.
| |
| 31 draw_image_mirrored_(false), | 34 draw_image_mirrored_(false), |
| 32 focus_painter_(Painter::CreateDashedFocusPainter()) { | 35 focus_painter_(Painter::CreateDashedFocusPainter()) { |
| 33 // By default, we request that the gfx::Canvas passed to our View::OnPaint() | 36 // 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 | 37 // implementation is flipped horizontally so that the button's images are |
| 35 // mirrored when the UI directionality is right-to-left. | 38 // mirrored when the UI directionality is right-to-left. |
| 36 EnableCanvasFlippingForRTLUI(true); | 39 EnableCanvasFlippingForRTLUI(true); |
| 37 } | 40 } |
| 38 | 41 |
| 39 ImageButton::~ImageButton() { | 42 ImageButton::~ImageButton() { |
| 40 } | 43 } |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 64 VerticalAlignment v_align) { | 67 VerticalAlignment v_align) { |
| 65 h_alignment_ = h_align; | 68 h_alignment_ = h_align; |
| 66 v_alignment_ = v_align; | 69 v_alignment_ = v_align; |
| 67 SchedulePaint(); | 70 SchedulePaint(); |
| 68 } | 71 } |
| 69 | 72 |
| 70 void ImageButton::SetFocusPainter(scoped_ptr<Painter> focus_painter) { | 73 void ImageButton::SetFocusPainter(scoped_ptr<Painter> focus_painter) { |
| 71 focus_painter_ = focus_painter.Pass(); | 74 focus_painter_ = focus_painter.Pass(); |
| 72 } | 75 } |
| 73 | 76 |
| 77 void ImageButton::SetMinimumImageSize(const gfx::Size& size) { | |
| 78 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.
| |
| 79 PreferredSizeChanged(); | |
| 80 } | |
| 81 | |
| 74 //////////////////////////////////////////////////////////////////////////////// | 82 //////////////////////////////////////////////////////////////////////////////// |
| 75 // ImageButton, View overrides: | 83 // ImageButton, View overrides: |
| 76 | 84 |
| 77 gfx::Size ImageButton::GetPreferredSize() const { | 85 gfx::Size ImageButton::GetPreferredSize() const { |
| 78 gfx::Size size = preferred_size_; | 86 gfx::Size size(kDefaultWidth, kDefaultHeight); |
| 79 if (!images_[STATE_NORMAL].isNull()) { | 87 if (!images_[STATE_NORMAL].isNull()) { |
| 80 size = gfx::Size(images_[STATE_NORMAL].width(), | 88 size = gfx::Size(images_[STATE_NORMAL].width(), |
| 81 images_[STATE_NORMAL].height()); | 89 images_[STATE_NORMAL].height()); |
| 82 } | 90 } |
| 83 | 91 |
| 92 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.
| |
| 93 size.set_height(std::max(size.height(), minimum_image_size_.height())); | |
| 94 | |
| 84 gfx::Insets insets = GetInsets(); | 95 gfx::Insets insets = GetInsets(); |
| 85 size.Enlarge(insets.width(), insets.height()); | 96 size.Enlarge(insets.width(), insets.height()); |
| 86 return size; | 97 return size; |
| 87 } | 98 } |
| 88 | 99 |
| 89 const char* ImageButton::GetClassName() const { | 100 const char* ImageButton::GetClassName() const { |
| 90 return kViewClassName; | 101 return kViewClassName; |
| 91 } | 102 } |
| 92 | 103 |
| 93 void ImageButton::OnPaint(gfx::Canvas* canvas) { | 104 void ImageButton::OnPaint(gfx::Canvas* canvas) { |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 245 *tooltip = toggled_tooltip_text_; | 256 *tooltip = toggled_tooltip_text_; |
| 246 return true; | 257 return true; |
| 247 } | 258 } |
| 248 | 259 |
| 249 void ToggleImageButton::GetAccessibleState(ui::AXViewState* state) { | 260 void ToggleImageButton::GetAccessibleState(ui::AXViewState* state) { |
| 250 ImageButton::GetAccessibleState(state); | 261 ImageButton::GetAccessibleState(state); |
| 251 GetTooltipText(gfx::Point(), &state->name); | 262 GetTooltipText(gfx::Point(), &state->name); |
| 252 } | 263 } |
| 253 | 264 |
| 254 } // namespace views | 265 } // namespace views |
| OLD | NEW |