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

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

Issue 2744463002: Add VectorIconButton functionality to ImageButton. (Closed)
Patch Set: check details 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 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/image_button_factory.h"
6
7 #include "ui/gfx/color_utils.h"
8 #include "ui/gfx/paint_vector_icon.h"
9 #include "ui/gfx/vector_icon_types.h"
10 #include "ui/views/border.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
15 namespace views {
16
17 ImageButton* CreateVectorImageButton(ButtonListener* listener) {
18 ImageButton* button = new ImageButton(listener);
19 button->SetInkDropMode(CustomButton::InkDropMode::ON);
20 button->set_has_ink_drop_action_on_click(true);
21 button->SetImageAlignment(ImageButton::ALIGN_CENTER,
22 ImageButton::ALIGN_MIDDLE);
23 button->SetFocusPainter(nullptr);
24 // Extra space around the buttons to increase their event target size.
25 constexpr int kButtonExtraTouchSize = 4;
26 button->SetBorder(CreateEmptyBorder(gfx::Insets(kButtonExtraTouchSize)));
27 return button;
28 }
29
30 void SetImageFromVectorIcon(ImageButton* button,
31 const gfx::VectorIcon& icon,
32 SkColor related_text_color) {
33 const SkColor icon_color =
34 color_utils::DeriveDefaultIconColor(related_text_color);
35 const SkColor disabled_color = SkColorSetA(icon_color, 0xff / 2);
36 button->SetImage(CustomButton::STATE_NORMAL,
37 gfx::CreateVectorIcon(icon, icon_color));
38 button->SetImage(CustomButton::STATE_DISABLED,
39 gfx::CreateVectorIcon(icon, disabled_color));
40 button->set_ink_drop_base_color(icon_color);
41 }
42
43 } // views
OLDNEW
« no previous file with comments | « ui/views/controls/button/image_button_factory.h ('k') | ui/views/controls/button/image_button_factory_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698