| 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 "chrome/browser/ui/views/bar_control_button.h" |
| 6 | 6 |
| 7 #include "ui/gfx/color_utils.h" | 7 #include "ui/gfx/color_utils.h" |
| 8 #include "ui/gfx/paint_vector_icon.h" | 8 #include "ui/gfx/paint_vector_icon.h" |
| 9 #include "ui/gfx/vector_icons_public.h" | 9 #include "ui/gfx/vector_icons_public.h" |
| 10 #include "ui/views/animation/button_ink_drop_delegate.h" | 10 #include "ui/views/animation/button_ink_drop_delegate.h" |
| 11 #include "ui/views/border.h" | 11 #include "ui/views/border.h" |
| 12 | 12 |
| 13 namespace { | 13 namespace { |
| 14 | 14 |
| 15 // Extra space around the buttons to increase their event target size. | 15 // Extra space around the buttons to increase their event target size. |
| 16 const int kButtonExtraTouchSize = 4; | 16 const int kButtonExtraTouchSize = 4; |
| 17 | 17 |
| 18 } // namespace | 18 } // namespace |
| 19 | 19 |
| 20 BarControlButton::BarControlButton(views::ButtonListener* listener) | 20 BarControlButton::BarControlButton(views::ButtonListener* listener) |
| 21 : views::ImageButton(listener), | 21 : views::ImageButton(listener), |
| 22 id_(gfx::VectorIconId::VECTOR_ICON_NONE), | 22 id_(gfx::VectorIconId::VECTOR_ICON_NONE), |
| 23 ink_drop_delegate_(new views::ButtonInkDropDelegate(this, this)) { | 23 ink_drop_delegate_(new views::ButtonInkDropDelegate(this, this)) { |
| 24 set_ink_drop_delegate(ink_drop_delegate_.get()); | 24 set_ink_drop_delegate(ink_drop_delegate_.get()); |
| 25 set_has_ink_drop_action_on_click(true); | 25 set_has_ink_drop_action_on_click(true); |
| 26 SetImageAlignment(views::ImageButton::ALIGN_CENTER, |
| 27 views::ImageButton::ALIGN_MIDDLE); |
| 26 } | 28 } |
| 27 | 29 |
| 28 BarControlButton::~BarControlButton() {} | 30 BarControlButton::~BarControlButton() {} |
| 29 | 31 |
| 30 void BarControlButton::SetIcon( | 32 void BarControlButton::SetIcon( |
| 31 gfx::VectorIconId id, | 33 gfx::VectorIconId id, |
| 32 const base::Callback<SkColor(void)>& get_text_color_callback) { | 34 const base::Callback<SkColor(void)>& get_text_color_callback) { |
| 33 id_ = id; | 35 id_ = id; |
| 34 get_text_color_callback_ = get_text_color_callback; | 36 get_text_color_callback_ = get_text_color_callback; |
| 35 | 37 |
| 36 SetBorder(views::Border::CreateEmptyBorder( | 38 if (!border()) { |
| 37 kButtonExtraTouchSize, kButtonExtraTouchSize, kButtonExtraTouchSize, | 39 SetBorder(views::Border::CreateEmptyBorder( |
| 38 kButtonExtraTouchSize)); | 40 kButtonExtraTouchSize, kButtonExtraTouchSize, kButtonExtraTouchSize, |
| 39 SetImageAlignment(views::ImageButton::ALIGN_CENTER, | 41 kButtonExtraTouchSize)); |
| 40 views::ImageButton::ALIGN_MIDDLE); | 42 } |
| 41 } | 43 } |
| 42 | 44 |
| 43 void BarControlButton::OnThemeChanged() { | 45 void BarControlButton::OnThemeChanged() { |
| 44 SkColor icon_color = | 46 SkColor icon_color = |
| 45 color_utils::DeriveDefaultIconColor(get_text_color_callback_.Run()); | 47 color_utils::DeriveDefaultIconColor(get_text_color_callback_.Run()); |
| 46 gfx::ImageSkia image = gfx::CreateVectorIcon(id_, 16, icon_color); | 48 gfx::ImageSkia image = gfx::CreateVectorIcon(id_, 16, icon_color); |
| 47 SetImage(views::CustomButton::STATE_NORMAL, &image); | 49 SetImage(views::CustomButton::STATE_NORMAL, &image); |
| 48 image = gfx::CreateVectorIcon(id_, 16, SkColorSetA(icon_color, 0xff / 2)); | 50 image = gfx::CreateVectorIcon(id_, 16, SkColorSetA(icon_color, 0xff / 2)); |
| 49 SetImage(views::CustomButton::STATE_DISABLED, &image); | 51 SetImage(views::CustomButton::STATE_DISABLED, &image); |
| 50 set_ink_drop_base_color(icon_color); | 52 set_ink_drop_base_color(icon_color); |
| 51 } | 53 } |
| 52 | 54 |
| 53 void BarControlButton::OnNativeThemeChanged(const ui::NativeTheme* theme) { | 55 void BarControlButton::OnNativeThemeChanged(const ui::NativeTheme* theme) { |
| 54 OnThemeChanged(); | 56 OnThemeChanged(); |
| 55 } | 57 } |
| OLD | NEW |