| OLD | NEW |
| (Empty) |
| 1 // Copyright 2015 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/vector_icon_button.h" | |
| 6 | |
| 7 #include "ui/gfx/color_palette.h" | |
| 8 #include "ui/gfx/color_utils.h" | |
| 9 #include "ui/gfx/paint_vector_icon.h" | |
| 10 #include "ui/views/border.h" | |
| 11 #include "ui/views/controls/button/vector_icon_button_delegate.h" | |
| 12 #include "ui/views/painter.h" | |
| 13 | |
| 14 namespace views { | |
| 15 | |
| 16 namespace { | |
| 17 | |
| 18 // Extra space around the buttons to increase their event target size. | |
| 19 const int kButtonExtraTouchSize = 4; | |
| 20 | |
| 21 } // namespace | |
| 22 | |
| 23 VectorIconButton::VectorIconButton(VectorIconButtonDelegate* delegate) | |
| 24 : ImageButton(delegate), delegate_(delegate), icon_(&gfx::kNoneIcon) { | |
| 25 SetInkDropMode(InkDropMode::ON); | |
| 26 set_has_ink_drop_action_on_click(true); | |
| 27 SetImageAlignment(ImageButton::ALIGN_CENTER, ImageButton::ALIGN_MIDDLE); | |
| 28 SetFocusPainter(nullptr); | |
| 29 } | |
| 30 | |
| 31 VectorIconButton::~VectorIconButton() {} | |
| 32 | |
| 33 void VectorIconButton::SetIcon(const gfx::VectorIcon& icon) { | |
| 34 icon_ = &icon; | |
| 35 OnSetIcon(); | |
| 36 } | |
| 37 | |
| 38 void VectorIconButton::OnThemeChanged() { | |
| 39 UpdateImagesAndColors(); | |
| 40 } | |
| 41 | |
| 42 void VectorIconButton::OnNativeThemeChanged(const ui::NativeTheme* theme) { | |
| 43 UpdateImagesAndColors(); | |
| 44 } | |
| 45 | |
| 46 void VectorIconButton::OnSetIcon() { | |
| 47 if (!border()) | |
| 48 SetBorder(CreateEmptyBorder(gfx::Insets(kButtonExtraTouchSize))); | |
| 49 | |
| 50 UpdateImagesAndColors(); | |
| 51 } | |
| 52 | |
| 53 void VectorIconButton::UpdateImagesAndColors() { | |
| 54 SkColor icon_color = | |
| 55 color_utils::DeriveDefaultIconColor(delegate_->GetVectorIconBaseColor()); | |
| 56 SkColor disabled_color = SkColorSetA(icon_color, 0xff / 2); | |
| 57 SetImage(CustomButton::STATE_NORMAL, | |
| 58 gfx::CreateVectorIcon(*icon_, icon_color)); | |
| 59 SetImage(CustomButton::STATE_DISABLED, | |
| 60 gfx::CreateVectorIcon(*icon_, disabled_color)); | |
| 61 set_ink_drop_base_color(icon_color); | |
| 62 } | |
| 63 | |
| 64 } // namespace views | |
| OLD | NEW |