| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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_factory.h" | 5 #include "ui/views/controls/button/image_button_factory.h" |
| 6 | 6 |
| 7 #include "ui/gfx/color_utils.h" | 7 #include "ui/gfx/color_utils.h" |
| 8 #include "ui/gfx/paint_vector_icon.h" | 8 #include "ui/gfx/paint_vector_icon.h" |
| 9 #include "ui/gfx/vector_icon_types.h" | 9 #include "ui/gfx/vector_icon_types.h" |
| 10 #include "ui/views/border.h" | 10 #include "ui/views/border.h" |
| 11 #include "ui/views/controls/button/custom_button.h" | 11 #include "ui/views/controls/button/custom_button.h" |
| 12 #include "ui/views/controls/button/image_button.h" | 12 #include "ui/views/controls/button/image_button.h" |
| 13 #include "ui/views/painter.h" | 13 #include "ui/views/painter.h" |
| 14 #include "ui/views/views_delegate.h" |
| 14 | 15 |
| 15 namespace views { | 16 namespace views { |
| 16 | 17 |
| 17 ImageButton* CreateVectorImageButton(ButtonListener* listener) { | 18 ImageButton* CreateVectorImageButton(ButtonListener* listener) { |
| 18 ImageButton* button = new ImageButton(listener); | 19 ImageButton* button = new ImageButton(listener); |
| 19 button->SetInkDropMode(CustomButton::InkDropMode::ON); | 20 button->SetInkDropMode(CustomButton::InkDropMode::ON); |
| 20 button->set_has_ink_drop_action_on_click(true); | 21 button->set_has_ink_drop_action_on_click(true); |
| 21 button->SetImageAlignment(ImageButton::ALIGN_CENTER, | 22 button->SetImageAlignment(ImageButton::ALIGN_CENTER, |
| 22 ImageButton::ALIGN_MIDDLE); | 23 ImageButton::ALIGN_MIDDLE); |
| 23 button->SetFocusPainter(nullptr); | 24 button->SetFocusPainter(nullptr); |
| 24 // Extra space around the buttons to increase their event target size. | 25 button->SetBorder( |
| 25 constexpr int kButtonExtraTouchSize = 4; | 26 CreateEmptyBorder(ViewsDelegate::GetInstance()->GetInsetsMetric( |
| 26 button->SetBorder(CreateEmptyBorder(gfx::Insets(kButtonExtraTouchSize))); | 27 InsetsMetric::VECTOR_IMAGE_BUTTON_PADDING))); |
| 27 return button; | 28 return button; |
| 28 } | 29 } |
| 29 | 30 |
| 30 void SetImageFromVectorIcon(ImageButton* button, | 31 void SetImageFromVectorIcon(ImageButton* button, |
| 31 const gfx::VectorIcon& icon, | 32 const gfx::VectorIcon& icon, |
| 32 SkColor related_text_color) { | 33 SkColor related_text_color) { |
| 33 const SkColor icon_color = | 34 const SkColor icon_color = |
| 34 color_utils::DeriveDefaultIconColor(related_text_color); | 35 color_utils::DeriveDefaultIconColor(related_text_color); |
| 35 const SkColor disabled_color = SkColorSetA(icon_color, 0xff / 2); | 36 const SkColor disabled_color = SkColorSetA(icon_color, 0xff / 2); |
| 36 button->SetImage(CustomButton::STATE_NORMAL, | 37 button->SetImage(CustomButton::STATE_NORMAL, |
| 37 gfx::CreateVectorIcon(icon, icon_color)); | 38 gfx::CreateVectorIcon(icon, icon_color)); |
| 38 button->SetImage(CustomButton::STATE_DISABLED, | 39 button->SetImage(CustomButton::STATE_DISABLED, |
| 39 gfx::CreateVectorIcon(icon, disabled_color)); | 40 gfx::CreateVectorIcon(icon, disabled_color)); |
| 40 button->set_ink_drop_base_color(icon_color); | 41 button->set_ink_drop_base_color(icon_color); |
| 41 } | 42 } |
| 42 | 43 |
| 43 } // views | 44 } // views |
| OLD | NEW |