Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "ui/views/controls/button/vector_icon_image_button_observer.h" | |
| 6 | |
| 7 #include "ui/gfx/color_utils.h" | |
| 8 #include "ui/gfx/paint_vector_icon.h" | |
| 9 #include "ui/views/animation/ink_drop_host_view.h" | |
| 10 #include "ui/views/controls/button/button.h" | |
| 11 #include "ui/views/controls/button/custom_button.h" | |
| 12 #include "ui/views/controls/button/image_button.h" | |
| 13 #include "ui/views/painter.h" | |
| 14 #include "ui/views/view.h" | |
| 15 #include "ui/views/views_delegate.h" | |
| 16 | |
| 17 namespace views { | |
| 18 | |
| 19 ImageButton* CreateDefaultVectorIconButton( | |
| 20 const gfx::VectorIcon& icon, | |
|
bruthig
2017/03/13 15:19:49
nit: |icon| doesn't appear to be required/used.
| |
| 21 VectorIconImageButtonObserver* observer, | |
| 22 ButtonListener* listener) { | |
| 23 ImageButton* button = new ImageButton(listener); | |
| 24 button->AddObserver(observer); | |
| 25 button->SetInkDropMode(InkDropHostView::InkDropMode::ON); | |
| 26 button->set_has_ink_drop_action_on_click(true); | |
| 27 button->SetImageAlignment(ImageButton::ALIGN_CENTER, | |
| 28 ImageButton::ALIGN_MIDDLE); | |
| 29 button->SetFocusPainter(nullptr); | |
| 30 button->SetPadding(ViewsDelegate::GetInstance()->GetButtonMargins()); | |
| 31 return button; | |
| 32 }; | |
| 33 | |
| 34 void VectorIconImageButtonObserver::OnThemeChanged(View* view) { | |
| 35 UpdateButtonImages(view); | |
| 36 } | |
| 37 | |
| 38 void VectorIconImageButtonObserver::OnNativeThemeChanged( | |
| 39 View* view, | |
| 40 const ui::NativeTheme* theme) { | |
| 41 UpdateButtonImages(view); | |
| 42 } | |
| 43 | |
| 44 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
| |
| 45 const gfx::VectorIcon& icon = GetVectorIcon(view); | |
| 46 SkColor icon_color = | |
| 47 color_utils::DeriveDefaultIconColor(GetVectorIconColor()); | |
| 48 ImageButton* button = static_cast<ImageButton*>(view); | |
| 49 SkColor disabled_color = SkColorSetA(icon_color, 0xff / 2); | |
| 50 button->SetImage(CustomButton::STATE_NORMAL, | |
| 51 gfx::CreateVectorIcon(icon, icon_color)); | |
| 52 button->SetImage(CustomButton::STATE_DISABLED, | |
| 53 gfx::CreateVectorIcon(icon, disabled_color)); | |
| 54 button->set_ink_drop_base_color(icon_color); | |
| 55 } | |
| 56 | |
| 57 SkColor VectorIconImageButtonObserver::GetVectorIconColor() const { | |
| 58 return SK_ColorBLACK; | |
| 59 } | |
| 60 } | |
| OLD | NEW |