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

Unified Diff: ui/views/controls/button/image_button.cc

Issue 2753833003: Create utility function for configuring an ImageButton to use a vector (Closed)
Patch Set: . 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/views/controls/button/image_button.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/controls/button/image_button.cc
diff --git a/ui/views/controls/button/image_button.cc b/ui/views/controls/button/image_button.cc
index fd2151e2a1aab73c6ad529ec5a909ffd9ea309ab..9f601378a81842721d9755f371d226d36149c463 100644
--- a/ui/views/controls/button/image_button.cc
+++ b/ui/views/controls/button/image_button.cc
@@ -11,7 +11,10 @@
#include "ui/gfx/animation/throb_animation.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/image/image_skia_operations.h"
+#include "ui/gfx/paint_vector_icon.h"
#include "ui/gfx/scoped_canvas.h"
+#include "ui/gfx/vector_icon_types.h"
+#include "ui/views/border.h"
#include "ui/views/painter.h"
#include "ui/views/widget/widget.h"
@@ -293,4 +296,27 @@ void ToggleImageButton::GetAccessibleNodeData(ui::AXNodeData* node_data) {
}
}
+////////////////////////////////////////////////////////////////////////////////
+// ImageButton, utilities:
+
+void SetImageFromVectorIcon(ImageButton* button,
+ const gfx::VectorIcon& icon,
+ SkColor base_color) {
+ button->SetInkDropMode(CustomButton::InkDropMode::ON);
bruthig 2017/03/16 18:26:07 I'm not sure I would couple the ink drop behavior
Evan Stade 2017/03/16 18:49:13 for now, all call sites want it. To me that sugges
bruthig 2017/03/16 19:11:23 I'm not sure I would agree that all call sites wan
+ button->set_has_ink_drop_action_on_click(true);
+ button->SetImageAlignment(ImageButton::ALIGN_CENTER,
+ ImageButton::ALIGN_MIDDLE);
+ button->SetFocusPainter(nullptr);
+ if (!button->border())
+ button->SetBorder(CreateEmptyBorder(gfx::Insets(4)));
+
+ const SkColor icon_color = color_utils::DeriveDefaultIconColor(base_color);
+ const 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);
+}
+
} // namespace views
« no previous file with comments | « ui/views/controls/button/image_button.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698