| 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 "chrome/browser/ui/views/bar_control_button.h" | 5 #include "ui/views/controls/button/vector_icon_button.h" |
| 6 | 6 |
| 7 #include "ui/base/material_design/material_design_controller.h" | 7 #include "ui/base/material_design/material_design_controller.h" |
| 8 #include "ui/gfx/color_palette.h" |
| 8 #include "ui/gfx/color_utils.h" | 9 #include "ui/gfx/color_utils.h" |
| 9 #include "ui/gfx/paint_vector_icon.h" | 10 #include "ui/gfx/paint_vector_icon.h" |
| 10 #include "ui/gfx/vector_icons_public.h" | 11 #include "ui/gfx/vector_icons_public.h" |
| 11 #include "ui/views/border.h" | 12 #include "ui/views/border.h" |
| 12 #include "ui/views/painter.h" | 13 #include "ui/views/painter.h" |
| 13 | 14 |
| 15 namespace views { |
| 16 |
| 14 namespace { | 17 namespace { |
| 15 | 18 |
| 16 // Extra space around the buttons to increase their event target size. | 19 // Extra space around the buttons to increase their event target size. |
| 17 const int kButtonExtraTouchSize = 4; | 20 const int kButtonExtraTouchSize = 4; |
| 18 | 21 |
| 19 } // namespace | 22 } // namespace |
| 20 | 23 |
| 21 BarControlButton::BarControlButton(views::ButtonListener* listener) | 24 SkColor VectorIconButtonDelegate::GetVectorIconBaseColor() const { |
| 22 : views::ImageButton(listener), id_(gfx::VectorIconId::VECTOR_ICON_NONE) { | 25 return SK_ColorBLACK; |
| 26 } |
| 27 |
| 28 VectorIconButton::VectorIconButton(VectorIconButtonDelegate* delegate) |
| 29 : views::ImageButton(delegate), |
| 30 delegate_(delegate), |
| 31 id_(gfx::VectorIconId::VECTOR_ICON_NONE) { |
| 23 if (ui::MaterialDesignController::IsModeMaterial()) | 32 if (ui::MaterialDesignController::IsModeMaterial()) |
| 24 SetInkDropMode(InkDropMode::ON); | 33 SetInkDropMode(InkDropMode::ON); |
| 25 set_has_ink_drop_action_on_click(true); | 34 set_has_ink_drop_action_on_click(true); |
| 26 SetImageAlignment(views::ImageButton::ALIGN_CENTER, | 35 SetImageAlignment(views::ImageButton::ALIGN_CENTER, |
| 27 views::ImageButton::ALIGN_MIDDLE); | 36 views::ImageButton::ALIGN_MIDDLE); |
| 28 SetFocusPainter(nullptr); | 37 SetFocusPainter(nullptr); |
| 29 } | 38 } |
| 30 | 39 |
| 31 BarControlButton::~BarControlButton() {} | 40 VectorIconButton::~VectorIconButton() {} |
| 32 | 41 |
| 33 void BarControlButton::SetIcon( | 42 void VectorIconButton::SetIcon(gfx::VectorIconId id) { |
| 34 gfx::VectorIconId id, | |
| 35 const base::Callback<SkColor(void)>& get_text_color_callback) { | |
| 36 id_ = id; | 43 id_ = id; |
| 37 get_text_color_callback_ = get_text_color_callback; | |
| 38 | 44 |
| 39 if (!border()) { | 45 if (!border()) { |
| 40 SetBorder(views::Border::CreateEmptyBorder( | 46 SetBorder(views::Border::CreateEmptyBorder( |
| 41 kButtonExtraTouchSize, kButtonExtraTouchSize, kButtonExtraTouchSize, | 47 kButtonExtraTouchSize, kButtonExtraTouchSize, kButtonExtraTouchSize, |
| 42 kButtonExtraTouchSize)); | 48 kButtonExtraTouchSize)); |
| 43 } | 49 } |
| 44 } | 50 } |
| 45 | 51 |
| 46 void BarControlButton::OnThemeChanged() { | 52 void VectorIconButton::OnEnabledChanged() { |
| 53 OnThemeChanged(); |
| 54 } |
| 55 |
| 56 void VectorIconButton::OnThemeChanged() { |
| 47 SkColor icon_color = | 57 SkColor icon_color = |
| 48 color_utils::DeriveDefaultIconColor(get_text_color_callback_.Run()); | 58 color_utils::DeriveDefaultIconColor(delegate_->GetVectorIconBaseColor()); |
| 49 gfx::ImageSkia image = gfx::CreateVectorIcon(id_, icon_color); | 59 gfx::ImageSkia image = gfx::CreateVectorIcon(id_, icon_color); |
| 50 SetImage(views::CustomButton::STATE_NORMAL, &image); | 60 SetImage(views::CustomButton::STATE_NORMAL, &image); |
| 51 image = gfx::CreateVectorIcon(id_, SkColorSetA(icon_color, 0xff / 2)); | 61 image = gfx::CreateVectorIcon(id_, SkColorSetA(icon_color, 0xff / 2)); |
| 52 SetImage(views::CustomButton::STATE_DISABLED, &image); | 62 SetImage(views::CustomButton::STATE_DISABLED, &image); |
| 53 set_ink_drop_base_color(icon_color); | 63 set_ink_drop_base_color(icon_color); |
| 54 } | 64 } |
| 55 | 65 |
| 56 void BarControlButton::OnNativeThemeChanged(const ui::NativeTheme* theme) { | 66 void VectorIconButton::OnNativeThemeChanged(const ui::NativeTheme* theme) { |
| 57 OnThemeChanged(); | 67 OnThemeChanged(); |
| 58 } | 68 } |
| 69 |
| 70 } // namespace views |
| OLD | NEW |