Chromium Code Reviews| 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 #include "ui/views/painter.h" | |
| 12 | 13 |
| 13 namespace { | 14 namespace { |
| 14 | 15 |
| 15 // Extra space around the buttons to increase their event target size. | 16 // Extra space around the buttons to increase their event target size. |
| 16 const int kButtonExtraTouchSize = 4; | 17 const int kButtonExtraTouchSize = 4; |
| 17 | 18 |
| 18 } // namespace | 19 } // namespace |
| 19 | 20 |
| 20 BarControlButton::BarControlButton(views::ButtonListener* listener) | 21 BarControlButton::BarControlButton(views::ButtonListener* listener) |
| 21 : views::ImageButton(listener), | 22 : views::ImageButton(listener), |
| 22 id_(gfx::VectorIconId::VECTOR_ICON_NONE), | 23 id_(gfx::VectorIconId::VECTOR_ICON_NONE), |
| 23 ink_drop_delegate_(new views::ButtonInkDropDelegate(this, this)) { | 24 ink_drop_delegate_(new views::ButtonInkDropDelegate(this, this)) { |
| 24 set_ink_drop_delegate(ink_drop_delegate_.get()); | 25 set_ink_drop_delegate(ink_drop_delegate_.get()); |
| 25 set_has_ink_drop_action_on_click(true); | 26 set_has_ink_drop_action_on_click(true); |
| 26 SetImageAlignment(views::ImageButton::ALIGN_CENTER, | 27 SetImageAlignment(views::ImageButton::ALIGN_CENTER, |
| 27 views::ImageButton::ALIGN_MIDDLE); | 28 views::ImageButton::ALIGN_MIDDLE); |
| 29 SetFocusPainter(nullptr); | |
| 30 UseMdFocusRing(); | |
| 28 } | 31 } |
| 29 | 32 |
| 30 BarControlButton::~BarControlButton() {} | 33 BarControlButton::~BarControlButton() {} |
| 31 | 34 |
| 32 void BarControlButton::SetIcon( | 35 void BarControlButton::SetIcon( |
| 33 gfx::VectorIconId id, | 36 gfx::VectorIconId id, |
| 34 const base::Callback<SkColor(void)>& get_text_color_callback) { | 37 const base::Callback<SkColor(void)>& get_text_color_callback) { |
| 35 id_ = id; | 38 id_ = id; |
| 36 get_text_color_callback_ = get_text_color_callback; | 39 get_text_color_callback_ = get_text_color_callback; |
| 37 | 40 |
| 38 if (!border()) { | 41 if (!border()) { |
| 39 SetBorder(views::Border::CreateEmptyBorder( | 42 SetBorder(views::Border::CreateEmptyBorder( |
| 40 kButtonExtraTouchSize, kButtonExtraTouchSize, kButtonExtraTouchSize, | 43 kButtonExtraTouchSize, kButtonExtraTouchSize, kButtonExtraTouchSize, |
| 41 kButtonExtraTouchSize)); | 44 kButtonExtraTouchSize)); |
| 42 } | 45 } |
| 43 } | 46 } |
| 44 | 47 |
| 45 void BarControlButton::OnThemeChanged() { | 48 void BarControlButton::OnThemeChanged() { |
| 46 SkColor icon_color = | 49 SkColor icon_color = |
| 47 color_utils::DeriveDefaultIconColor(get_text_color_callback_.Run()); | 50 color_utils::DeriveDefaultIconColor(get_text_color_callback_.Run()); |
| 48 gfx::ImageSkia image = gfx::CreateVectorIcon(id_, 16, icon_color); | 51 gfx::ImageSkia image = gfx::CreateVectorIcon(id_, 16, icon_color); |
| 49 SetImage(views::CustomButton::STATE_NORMAL, &image); | 52 SetImage(views::CustomButton::STATE_NORMAL, &image); |
| 50 image = gfx::CreateVectorIcon(id_, 16, SkColorSetA(icon_color, 0xff / 2)); | 53 image = gfx::CreateVectorIcon(id_, 16, SkColorSetA(icon_color, 0xff / 2)); |
| 51 SetImage(views::CustomButton::STATE_DISABLED, &image); | 54 SetImage(views::CustomButton::STATE_DISABLED, &image); |
| 52 set_ink_drop_base_color(icon_color); | 55 set_ink_drop_base_color(icon_color); |
| 56 SizeToPreferredSize(); | |
|
sky
2016/03/22 15:31:40
What view has BarControlButton in it? I get nervou
Evan Stade
2016/03/22 17:35:44
infobarview, find bar, download shelf. The alterna
sky
2016/03/22 18:02:27
Doesn't find bar and the like need to relayout in
Evan Stade
2016/03/22 18:16:11
This code path gets hit as soon as BarControlButto
| |
| 53 } | 57 } |
| 54 | 58 |
| 55 void BarControlButton::OnNativeThemeChanged(const ui::NativeTheme* theme) { | 59 void BarControlButton::OnNativeThemeChanged(const ui::NativeTheme* theme) { |
| 56 OnThemeChanged(); | 60 OnThemeChanged(); |
| 57 } | 61 } |
| OLD | NEW |