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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: ui/views/controls/button/image_button_factory.cc
diff --git a/ui/views/controls/button/image_button_factory.cc b/ui/views/controls/button/image_button_factory.cc
new file mode 100644
index 0000000000000000000000000000000000000000..6cb9c0beace847c0a86d72081f4071951b0e453e
--- /dev/null
+++ b/ui/views/controls/button/image_button_factory.cc
@@ -0,0 +1,43 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ui/views/controls/button/image_button_factory.h"
+
+#include "ui/gfx/color_utils.h"
+#include "ui/gfx/paint_vector_icon.h"
+#include "ui/gfx/vector_icon_types.h"
+#include "ui/views/border.h"
+#include "ui/views/controls/button/custom_button.h"
+#include "ui/views/controls/button/image_button.h"
+#include "ui/views/painter.h"
+
+namespace views {
+
+ImageButton* CreateVectorImageButton(ButtonListener* listener) {
+ ImageButton* button = new ImageButton(listener);
+ button->SetInkDropMode(CustomButton::InkDropMode::ON);
+ button->set_has_ink_drop_action_on_click(true);
+ button->SetImageAlignment(ImageButton::ALIGN_CENTER,
+ ImageButton::ALIGN_MIDDLE);
+ button->SetFocusPainter(nullptr);
+ // Extra space around the buttons to increase their event target size.
+ constexpr int kButtonExtraTouchSize = 4;
+ button->SetBorder(CreateEmptyBorder(gfx::Insets(kButtonExtraTouchSize)));
+ return button;
+}
+
+void SetImageFromVectorIcon(ImageButton* button,
+ const gfx::VectorIcon& icon,
+ SkColor related_text_color) {
+ const SkColor icon_color =
+ color_utils::DeriveDefaultIconColor(related_text_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);
+}
+
+} // views
« 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