Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(357)

Side by Side Diff: ui/views/controls/button/vector_icon_button.cc

Issue 2744463002: Add VectorIconButton functionality to ImageButton. (Closed)
Patch Set: wip: address high-level comments Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "ui/views/controls/button/vector_icon_button.h" 5 #include "ui/views/controls/button/vector_icon_button.h"
6 6
7 #include "ui/gfx/color_palette.h" 7 #include "ui/gfx/color_palette.h"
8 #include "ui/gfx/color_utils.h" 8 #include "ui/gfx/color_utils.h"
9 #include "ui/gfx/paint_vector_icon.h" 9 #include "ui/gfx/paint_vector_icon.h"
10 #include "ui/views/border.h"
11 #include "ui/views/controls/button/vector_icon_button_delegate.h" 10 #include "ui/views/controls/button/vector_icon_button_delegate.h"
12 #include "ui/views/painter.h" 11 #include "ui/views/painter.h"
12 #include "ui/views/views_delegate.h"
13 13
14 namespace views { 14 namespace views {
15 15
16 namespace {
17
18 // Extra space around the buttons to increase their event target size.
19 const int kButtonExtraTouchSize = 4;
20
21 } // namespace
22
23 VectorIconButton::VectorIconButton(VectorIconButtonDelegate* delegate) 16 VectorIconButton::VectorIconButton(VectorIconButtonDelegate* delegate)
24 : ImageButton(delegate), delegate_(delegate), icon_(&gfx::kNoneIcon) { 17 : ImageButton(delegate), delegate_(delegate), icon_(&gfx::kNoneIcon) {
25 SetInkDropMode(InkDropMode::ON); 18 SetInkDropMode(InkDropMode::ON);
26 set_has_ink_drop_action_on_click(true); 19 set_has_ink_drop_action_on_click(true);
27 SetImageAlignment(ImageButton::ALIGN_CENTER, ImageButton::ALIGN_MIDDLE); 20 SetImageAlignment(ImageButton::ALIGN_CENTER, ImageButton::ALIGN_MIDDLE);
28 SetFocusPainter(nullptr); 21 SetFocusPainter(nullptr);
22 SetPadding(ViewsDelegate::GetInstance()->GetButtonMargins());
29 } 23 }
30 24
31 VectorIconButton::~VectorIconButton() {} 25 VectorIconButton::~VectorIconButton() {}
32 26
33 void VectorIconButton::SetIcon(const gfx::VectorIcon& icon) { 27 void VectorIconButton::SetIcon(const gfx::VectorIcon& icon) {
34 icon_ = &icon; 28 icon_ = &icon;
35 OnSetIcon(); 29 UpdateImagesAndColors();
36 } 30 }
37 31
38 void VectorIconButton::OnThemeChanged() { 32 void VectorIconButton::OnThemeChanged() {
39 UpdateImagesAndColors(); 33 UpdateImagesAndColors();
40 } 34 }
41 35
42 void VectorIconButton::OnNativeThemeChanged(const ui::NativeTheme* theme) { 36 void VectorIconButton::OnNativeThemeChanged(const ui::NativeTheme* theme) {
43 UpdateImagesAndColors(); 37 UpdateImagesAndColors();
44 } 38 }
45 39
46 void VectorIconButton::OnSetIcon() {
47 if (!border())
48 SetBorder(CreateEmptyBorder(gfx::Insets(kButtonExtraTouchSize)));
49
50 UpdateImagesAndColors();
51 }
52
53 void VectorIconButton::UpdateImagesAndColors() { 40 void VectorIconButton::UpdateImagesAndColors() {
41 if (!icon_)
42 return;
43
54 SkColor icon_color = 44 SkColor icon_color =
55 color_utils::DeriveDefaultIconColor(delegate_->GetVectorIconBaseColor()); 45 color_utils::DeriveDefaultIconColor(delegate_->GetVectorIconBaseColor());
56 SkColor disabled_color = SkColorSetA(icon_color, 0xff / 2); 46 SkColor disabled_color = SkColorSetA(icon_color, 0xff / 2);
57 SetImage(CustomButton::STATE_NORMAL, 47 SetImage(CustomButton::STATE_NORMAL,
58 gfx::CreateVectorIcon(*icon_, icon_color)); 48 gfx::CreateVectorIcon(*icon_, icon_color));
59 SetImage(CustomButton::STATE_DISABLED, 49 SetImage(CustomButton::STATE_DISABLED,
60 gfx::CreateVectorIcon(*icon_, disabled_color)); 50 gfx::CreateVectorIcon(*icon_, disabled_color));
61 set_ink_drop_base_color(icon_color); 51 set_ink_drop_base_color(icon_color);
62 } 52 }
63 53
64 } // namespace views 54 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698