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