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

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

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 side-by-side diff with in-line comments
Download patch
Index: ui/views/controls/button/image_button.h
diff --git a/ui/views/controls/button/image_button.h b/ui/views/controls/button/image_button.h
index eba2a835a40eff5f07a628558b2fe1fd5ad48b16..00af163f2f9f73d8289f6b052933fee2fd17f884 100644
--- a/ui/views/controls/button/image_button.h
+++ b/ui/views/controls/button/image_button.h
@@ -13,10 +13,24 @@
#include "ui/gfx/image/image_skia.h"
#include "ui/views/controls/button/custom_button.h"
+namespace gfx {
+struct VectorIcon;
+}
+
namespace views {
class Painter;
+// A ButtonListener that also provides padding around the image and a color if
+// the image is a vector icon.
+class VIEWS_EXPORT ImageButtonDelegate : public ButtonListener {
bruthig 2017/03/09 05:04:42 IMO I don't think coupling the click listener to t
Bret 2017/03/09 22:32:37 In practice I haven't seen any cases where it seem
bruthig 2017/03/10 14:35:25 As noted below, this is partly because we have man
+ public:
+ virtual SkColor GetVectorIconColor() const;
sky 2017/03/09 04:05:02 Specifying the color should not be a requirement f
Bret 2017/03/09 22:32:37 Subclasses aren't required to override GetVectorIc
bruthig 2017/03/10 14:35:25 It's different because it decouples the button sta
+
+ protected:
+ ~ImageButtonDelegate() override {}
+};
+
// An image button.
// Note that this type of button is not focusable by default and will not be
// part of the focus chain, unless in accessibility mode. Call
@@ -37,7 +51,11 @@ class VIEWS_EXPORT ImageButton : public CustomButton {
ALIGN_BOTTOM
};
- explicit ImageButton(ButtonListener* listener);
+ static ImageButton* CreateDefaultVectorIconButton(
+ const gfx::VectorIcon& icon,
+ ImageButtonDelegate* delegate);
+
+ explicit ImageButton(ImageButtonDelegate* delegate);
~ImageButton() override;
// Returns the image for a given |state|.
@@ -51,6 +69,11 @@ class VIEWS_EXPORT ImageButton : public CustomButton {
// consolidated.
virtual void SetImage(ButtonState state, const gfx::ImageSkia& image);
+ // Sets a vector icon to use for the button images. Generates images for
+ // STATE_NORMAL and STATE_DISALBED based on
+ // ImageButtonDelegate::GetVectorIconColor.
+ void SetVectorIcon(const gfx::VectorIcon& icon);
+
// Set the background details.
void SetBackground(SkColor color,
const gfx::ImageSkia* image,
@@ -73,10 +96,14 @@ class VIEWS_EXPORT ImageButton : public CustomButton {
draw_image_mirrored_ = mirrored;
}
+ void SetPadding(const gfx::Insets& padding);
+
// Overridden from View:
gfx::Size GetPreferredSize() const override;
const char* GetClassName() const override;
void OnPaint(gfx::Canvas* canvas) override;
+ void OnThemeChanged() override;
+ void OnNativeThemeChanged(const ui::NativeTheme* theme) override;
protected:
// Overridden from View:
@@ -106,6 +133,12 @@ class VIEWS_EXPORT ImageButton : public CustomButton {
// Returns the correct position of the image for painting.
gfx::Point ComputeImagePaintPosition(const gfx::ImageSkia& image);
+ void UpdateImagesFromVectorIcon();
+
+ ImageButtonDelegate* delegate_;
+
+ const gfx::VectorIcon* vector_icon_;
+
// Image alignment.
HorizontalAlignment h_alignment_;
VerticalAlignment v_alignment_;
@@ -131,7 +164,7 @@ class VIEWS_EXPORT ImageButton : public CustomButton {
////////////////////////////////////////////////////////////////////////////////
class VIEWS_EXPORT ToggleImageButton : public ImageButton {
public:
- explicit ToggleImageButton(ButtonListener* listener);
+ explicit ToggleImageButton(ImageButtonDelegate* delegate);
~ToggleImageButton() override;
// Change the toggled state.
@@ -145,11 +178,11 @@ class VIEWS_EXPORT ToggleImageButton : public ImageButton {
// Set the tooltip text displayed when the button is toggled.
void SetToggledTooltipText(const base::string16& tooltip);
- // Overridden from ImageButton:
+ // ImageButton:
const gfx::ImageSkia& GetImage(ButtonState state) const override;
void SetImage(ButtonState state, const gfx::ImageSkia& image) override;
- // Overridden from View:
+ // View:
bool GetTooltipText(const gfx::Point& p,
base::string16* tooltip) const override;
void GetAccessibleNodeData(ui::AXNodeData* node_data) override;

Powered by Google App Engine
This is Rietveld 408576698