| 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 fd2151e2a1aab73c6ad529ec5a909ffd9ea309ab..66e721525393b8b45439179a143b8a84acb0bb5a 100644
|
| --- a/ui/views/controls/button/image_button.cc
|
| +++ b/ui/views/controls/button/image_button.cc
|
| @@ -11,8 +11,13 @@
|
| #include "ui/gfx/animation/throb_animation.h"
|
| #include "ui/gfx/canvas.h"
|
| #include "ui/gfx/image/image_skia_operations.h"
|
| +#include "ui/gfx/paint_vector_icon.h"
|
| #include "ui/gfx/scoped_canvas.h"
|
| +#include "ui/gfx/vector_icon_types.h"
|
| +#include "ui/views/animation/ink_drop_host_view.h"
|
| +#include "ui/views/border.h"
|
| #include "ui/views/painter.h"
|
| +#include "ui/views/views_delegate.h"
|
| #include "ui/views/widget/widget.h"
|
|
|
| namespace views {
|
| @@ -25,15 +30,36 @@ static const int kDefaultHeight = 14;
|
|
|
| const char ImageButton::kViewClassName[] = "ImageButton";
|
|
|
| +SkColor ImageButtonDelegate::GetVectorIconColor() const {
|
| + return SK_ColorBLACK;
|
| +}
|
| +
|
| +// static
|
| +ImageButton* ImageButton::CreateDefaultVectorIconButton(
|
| + const gfx::VectorIcon& icon,
|
| + ImageButtonDelegate* delegate) {
|
| + ImageButton* button = new ImageButton(delegate);
|
| + button->SetVectorIcon(icon);
|
| + button->SetInkDropMode(InkDropHostView::InkDropMode::ON);
|
| + button->set_has_ink_drop_action_on_click(true);
|
| + button->SetImageAlignment(ImageButton::ALIGN_CENTER,
|
| + ImageButton::ALIGN_MIDDLE);
|
| + button->SetFocusPainter(nullptr);
|
| + button->SetPadding(ViewsDelegate::GetInstance()->GetButtonMargins());
|
| + return button;
|
| +}
|
| +
|
| ////////////////////////////////////////////////////////////////////////////////
|
| // ImageButton, public:
|
|
|
| -ImageButton::ImageButton(ButtonListener* listener)
|
| - : CustomButton(listener),
|
| +ImageButton::ImageButton(ImageButtonDelegate* delegate)
|
| + : CustomButton(delegate),
|
| + vector_icon_(nullptr),
|
| h_alignment_(ALIGN_LEFT),
|
| v_alignment_(ALIGN_TOP),
|
| draw_image_mirrored_(false),
|
| focus_painter_(Painter::CreateDashedFocusPainter()) {
|
| + delegate_ = delegate;
|
| // By default, we request that the gfx::Canvas passed to our View::OnPaint()
|
| // implementation is flipped horizontally so that the button's images are
|
| // mirrored when the UI directionality is right-to-left.
|
| @@ -64,6 +90,11 @@ void ImageButton::SetImage(ButtonState for_state, const gfx::ImageSkia& image) {
|
| SchedulePaint();
|
| }
|
|
|
| +void ImageButton::SetVectorIcon(const gfx::VectorIcon& icon) {
|
| + vector_icon_ = &icon;
|
| + UpdateImagesFromVectorIcon();
|
| +}
|
| +
|
| void ImageButton::SetBackground(SkColor color,
|
| const gfx::ImageSkia* image,
|
| const gfx::ImageSkia* mask) {
|
| @@ -95,6 +126,13 @@ void ImageButton::SetMinimumImageSize(const gfx::Size& size) {
|
| PreferredSizeChanged();
|
| }
|
|
|
| +void ImageButton::SetPadding(const gfx::Insets& padding) {
|
| + if (padding.IsEmpty())
|
| + SetBorder(nullptr);
|
| + else
|
| + SetBorder(CreateEmptyBorder(padding));
|
| +}
|
| +
|
| ////////////////////////////////////////////////////////////////////////////////
|
| // ImageButton, View overrides:
|
|
|
| @@ -142,6 +180,14 @@ void ImageButton::OnPaint(gfx::Canvas* canvas) {
|
| Painter::PaintFocusPainter(this, canvas, focus_painter());
|
| }
|
|
|
| +void ImageButton::OnThemeChanged() {
|
| + UpdateImagesFromVectorIcon();
|
| +}
|
| +
|
| +void ImageButton::OnNativeThemeChanged(const ui::NativeTheme* theme) {
|
| + UpdateImagesFromVectorIcon();
|
| +}
|
| +
|
| ////////////////////////////////////////////////////////////////////////////////
|
| // ImageButton, protected:
|
|
|
| @@ -202,13 +248,25 @@ gfx::Point ImageButton::ComputeImagePaintPosition(const gfx::ImageSkia& image) {
|
| return gfx::Point(x, y);
|
| }
|
|
|
| +void ImageButton::UpdateImagesFromVectorIcon() {
|
| + if (!vector_icon_)
|
| + return;
|
| +
|
| + SkColor icon_color =
|
| + color_utils::DeriveDefaultIconColor(delegate_->GetVectorIconColor());
|
| + SkColor disabled_color = SkColorSetA(icon_color, 0xff / 2);
|
| + SetImage(CustomButton::STATE_NORMAL,
|
| + gfx::CreateVectorIcon(*vector_icon_, icon_color));
|
| + SetImage(CustomButton::STATE_DISABLED,
|
| + gfx::CreateVectorIcon(*vector_icon_, disabled_color));
|
| + set_ink_drop_base_color(icon_color);
|
| +}
|
| +
|
| ////////////////////////////////////////////////////////////////////////////////
|
| // ToggleImageButton, public:
|
|
|
| -ToggleImageButton::ToggleImageButton(ButtonListener* listener)
|
| - : ImageButton(listener),
|
| - toggled_(false) {
|
| -}
|
| +ToggleImageButton::ToggleImageButton(ImageButtonDelegate* delegate)
|
| + : ImageButton(delegate), toggled_(false) {}
|
|
|
| ToggleImageButton::~ToggleImageButton() {
|
| }
|
|
|