Chromium Code Reviews| Index: ui/views/controls/button/image_button_util.cc |
| diff --git a/ui/views/controls/button/image_button_util.cc b/ui/views/controls/button/image_button_util.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..cab574e9ac66d905e963cc055ba24318462bf4e8 |
| --- /dev/null |
| +++ b/ui/views/controls/button/image_button_util.cc |
| @@ -0,0 +1,42 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "ui/views/controls/button/image_button_util.h" |
| + |
| +#include "ui/gfx/color_utils.h" |
| +#include "ui/gfx/paint_vector_icon.h" |
| +#include "ui/gfx/vector_icon_types.h" |
| +#include "ui/views/border.h" |
| +#include "ui/views/controls/button/custom_button.h" |
| +#include "ui/views/controls/button/image_button.h" |
| +#include "ui/views/painter.h" |
| + |
| +namespace views { |
| + |
| +ImageButton* CreateImageButtonWithVectorIconStyling(ButtonListener* listener) { |
| + ImageButton* button = new ImageButton(listener); |
| + button->SetInkDropMode(CustomButton::InkDropMode::ON); |
| + button->set_has_ink_drop_action_on_click(true); |
| + button->SetImageAlignment(ImageButton::ALIGN_CENTER, |
| + ImageButton::ALIGN_MIDDLE); |
| + button->SetFocusPainter(nullptr); |
| + // Extra space around the buttons to increase their event target size. |
| + constexpr int kButtonExtraTouchSize = 4; |
| + button->SetBorder(CreateEmptyBorder(gfx::Insets(kButtonExtraTouchSize))); |
|
Evan Stade
2017/03/17 13:54:44
VectorIconButton checks if a different border has
Bret
2017/03/17 23:41:41
It's doing that because its SetBorder call is in S
|
| + return button; |
| +} |
| + |
| +void SetImageFromVectorIcon(ImageButton* button, |
| + const gfx::VectorIcon& icon, |
| + SkColor base_color) { |
| + const SkColor icon_color = color_utils::DeriveDefaultIconColor(base_color); |
| + const SkColor disabled_color = SkColorSetA(icon_color, 0xff / 2); |
| + button->SetImage(CustomButton::STATE_NORMAL, |
| + gfx::CreateVectorIcon(icon, icon_color)); |
| + button->SetImage(CustomButton::STATE_DISABLED, |
| + gfx::CreateVectorIcon(icon, disabled_color)); |
| + button->set_ink_drop_base_color(icon_color); |
| +} |
| + |
| +} // views |