Chromium Code Reviews| Index: ui/views/controls/button/vector_icon_image_button_observer.cc |
| diff --git a/ui/views/controls/button/vector_icon_image_button_observer.cc b/ui/views/controls/button/vector_icon_image_button_observer.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..19ad45bda78acd11abc652547e8a05a3051e6e09 |
| --- /dev/null |
| +++ b/ui/views/controls/button/vector_icon_image_button_observer.cc |
| @@ -0,0 +1,60 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "ui/views/controls/button/vector_icon_image_button_observer.h" |
| + |
| +#include "ui/gfx/color_utils.h" |
| +#include "ui/gfx/paint_vector_icon.h" |
| +#include "ui/views/animation/ink_drop_host_view.h" |
| +#include "ui/views/controls/button/button.h" |
| +#include "ui/views/controls/button/custom_button.h" |
| +#include "ui/views/controls/button/image_button.h" |
| +#include "ui/views/painter.h" |
| +#include "ui/views/view.h" |
| +#include "ui/views/views_delegate.h" |
| + |
| +namespace views { |
| + |
| +ImageButton* CreateDefaultVectorIconButton( |
| + const gfx::VectorIcon& icon, |
|
bruthig
2017/03/13 15:19:49
nit: |icon| doesn't appear to be required/used.
|
| + VectorIconImageButtonObserver* observer, |
| + ButtonListener* listener) { |
| + ImageButton* button = new ImageButton(listener); |
| + button->AddObserver(observer); |
| + button->SetInkDropMode(InkDropHostView::InkDropMode::ON); |
| + button->set_has_ink_drop_action_on_click(true); |
| + button->SetImageAlignment(ImageButton::ALIGN_CENTER, |
| + ImageButton::ALIGN_MIDDLE); |
| + button->SetFocusPainter(nullptr); |
| + button->SetPadding(ViewsDelegate::GetInstance()->GetButtonMargins()); |
| + return button; |
| +}; |
| + |
| +void VectorIconImageButtonObserver::OnThemeChanged(View* view) { |
| + UpdateButtonImages(view); |
| +} |
| + |
| +void VectorIconImageButtonObserver::OnNativeThemeChanged( |
| + View* view, |
| + const ui::NativeTheme* theme) { |
| + UpdateButtonImages(view); |
| +} |
| + |
| +void VectorIconImageButtonObserver::UpdateButtonImages(View* view) { |
|
bruthig
2017/03/13 15:19:49
I'm not sure if this is already on your radar or n
Bret
2017/03/15 00:07:13
I fixed this by giving the observer an Attach meth
sky
2017/03/15 15:05:11
You shouldn't need this. OnNativeThemeChanged() is
bruthig
2017/03/15 15:53:20
What if the View is parented to a Widget before th
sky
2017/03/15 17:01:54
You're suggesting the function take a View? In tha
bruthig
2017/03/15 21:41:21
disclaimer: I'm not clear on what 'function' you m
Bret
2017/03/15 23:39:19
I think bruthig@ is right, that you could hypothet
sky
2017/03/15 23:48:04
You could make that argument for any observer. I t
|
| + const gfx::VectorIcon& icon = GetVectorIcon(view); |
| + SkColor icon_color = |
| + color_utils::DeriveDefaultIconColor(GetVectorIconColor()); |
| + ImageButton* button = static_cast<ImageButton*>(view); |
| + SkColor disabled_color = SkColorSetA(icon_color, 0xff / 2); |
| + button->SetImage(CustomButton::STATE_NORMAL, |
| + gfx::CreateVectorIcon(icon, icon_color)); |
| + button->SetImage(CustomButton::STATE_DISABLED, |
| + gfx::CreateVectorIcon(icon, disabled_color)); |
| + button->set_ink_drop_base_color(icon_color); |
| +} |
| + |
| +SkColor VectorIconImageButtonObserver::GetVectorIconColor() const { |
| + return SK_ColorBLACK; |
| +} |
| +} |