Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "ui/views/controls/button/image_button_util.h" | |
| 6 | |
| 7 #include "ui/gfx/color_utils.h" | |
| 8 #include "ui/gfx/paint_vector_icon.h" | |
| 9 #include "ui/gfx/vector_icon_types.h" | |
| 10 #include "ui/views/border.h" | |
| 11 #include "ui/views/controls/button/custom_button.h" | |
| 12 #include "ui/views/controls/button/image_button.h" | |
| 13 #include "ui/views/painter.h" | |
| 14 | |
| 15 namespace views { | |
| 16 | |
| 17 ImageButton* CreateImageButtonWithVectorIconStyling(ButtonListener* listener) { | |
| 18 ImageButton* button = new ImageButton(listener); | |
| 19 button->SetInkDropMode(CustomButton::InkDropMode::ON); | |
| 20 button->set_has_ink_drop_action_on_click(true); | |
| 21 button->SetImageAlignment(ImageButton::ALIGN_CENTER, | |
| 22 ImageButton::ALIGN_MIDDLE); | |
| 23 button->SetFocusPainter(nullptr); | |
| 24 // Extra space around the buttons to increase their event target size. | |
| 25 constexpr int kButtonExtraTouchSize = 4; | |
| 26 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
| |
| 27 return button; | |
| 28 } | |
| 29 | |
| 30 void SetImageFromVectorIcon(ImageButton* button, | |
| 31 const gfx::VectorIcon& icon, | |
| 32 SkColor base_color) { | |
| 33 const SkColor icon_color = color_utils::DeriveDefaultIconColor(base_color); | |
| 34 const SkColor disabled_color = SkColorSetA(icon_color, 0xff / 2); | |
| 35 button->SetImage(CustomButton::STATE_NORMAL, | |
| 36 gfx::CreateVectorIcon(icon, icon_color)); | |
| 37 button->SetImage(CustomButton::STATE_DISABLED, | |
| 38 gfx::CreateVectorIcon(icon, disabled_color)); | |
| 39 button->set_ink_drop_base_color(icon_color); | |
| 40 } | |
| 41 | |
| 42 } // views | |
| OLD | NEW |