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

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

Issue 2744463002: Add VectorIconButton functionality to ImageButton. (Closed)
Patch Set: fix cros build 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "ui/views/controls/button/vector_icon_button.h"
6
7 #include "ui/gfx/color_palette.h"
8 #include "ui/gfx/color_utils.h"
9 #include "ui/gfx/paint_vector_icon.h"
10 #include "ui/gfx/vector_icons_public.h"
11 #include "ui/views/border.h"
12 #include "ui/views/controls/button/vector_icon_button_delegate.h"
13 #include "ui/views/painter.h"
14
15 namespace views {
16
17 namespace {
18
19 // Extra space around the buttons to increase their event target size.
20 const int kButtonExtraTouchSize = 4;
21
22 } // namespace
23
24 VectorIconButton::VectorIconButton(VectorIconButtonDelegate* delegate)
25 : ImageButton(delegate),
26 delegate_(delegate),
27 id_(gfx::VectorIconId::VECTOR_ICON_NONE) {
28 SetInkDropMode(InkDropMode::ON);
29 set_has_ink_drop_action_on_click(true);
30 SetImageAlignment(ImageButton::ALIGN_CENTER, ImageButton::ALIGN_MIDDLE);
31 SetFocusPainter(nullptr);
32 }
33
34 VectorIconButton::~VectorIconButton() {}
35
36 void VectorIconButton::SetIcon(gfx::VectorIconId id) {
37 id_ = id;
38 icon_ = nullptr;
39
40 OnSetIcon();
41 }
42
43 void VectorIconButton::SetIcon(const gfx::VectorIcon& icon) {
44 id_ = gfx::VectorIconId::VECTOR_ICON_NONE;
45 icon_ = &icon;
46
47 OnSetIcon();
48 }
49
50 void VectorIconButton::OnThemeChanged() {
51 UpdateImagesAndColors();
52 }
53
54 void VectorIconButton::OnNativeThemeChanged(const ui::NativeTheme* theme) {
55 UpdateImagesAndColors();
56 }
57
58 void VectorIconButton::OnSetIcon() {
59 if (!border())
60 SetBorder(CreateEmptyBorder(gfx::Insets(kButtonExtraTouchSize)));
61
62 UpdateImagesAndColors();
63 }
64
65 void VectorIconButton::UpdateImagesAndColors() {
66 SkColor icon_color =
67 color_utils::DeriveDefaultIconColor(delegate_->GetVectorIconBaseColor());
68 SkColor disabled_color = SkColorSetA(icon_color, 0xff / 2);
69 if (icon_) {
70 SetImage(CustomButton::STATE_NORMAL,
71 gfx::CreateVectorIcon(*icon_, icon_color));
72 SetImage(CustomButton::STATE_DISABLED,
73 gfx::CreateVectorIcon(*icon_, disabled_color));
74 } else {
75 SetImage(CustomButton::STATE_NORMAL,
76 gfx::CreateVectorIcon(id_, icon_color));
77 SetImage(CustomButton::STATE_DISABLED,
78 gfx::CreateVectorIcon(id_, disabled_color));
79 }
80 set_ink_drop_base_color(icon_color);
81 }
82
83 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698