Commit 0fbae61f authored by Sangwoo Ko's avatar Sangwoo Ko Committed by Commit Bot

Use LabelButton::SetImageModel() instead of SetImage().

ui::ImageModel should be preferred to ui::Image or ui::ImageSkia.
There's no intended behavior change.

Bug: 1100034
Change-Id: Iaf12012c2da76503a04062e29527118b3f730f3f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2385035Reviewed-by: default avatarScott Violet <sky@chromium.org>
Commit-Queue: Sang Woo Ko <sangwoo108@chromium.org>
Cr-Commit-Position: refs/heads/master@{#803713}
parent 05355f4a
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include <tuple> #include <tuple>
#include "ui/base/models/image_model.h" #include "ui/base/models/image_model.h"
#include "ui/base/resource/resource_bundle.h"
namespace ui { namespace ui {
...@@ -83,6 +84,12 @@ ImageModel ImageModel::FromImageSkia(const gfx::ImageSkia& image_skia) { ...@@ -83,6 +84,12 @@ ImageModel ImageModel::FromImageSkia(const gfx::ImageSkia& image_skia) {
return ImageModel(image_skia); return ImageModel(image_skia);
} }
// static
ImageModel ImageModel::FromResourceId(int resource_id) {
return ImageModel::FromImage(
ResourceBundle::GetSharedInstance().GetImageNamed(resource_id));
}
bool ImageModel::IsEmpty() const { bool ImageModel::IsEmpty() const {
return !IsVectorIcon() && !IsImage(); return !IsVectorIcon() && !IsImage();
} }
......
...@@ -88,6 +88,7 @@ class COMPONENT_EXPORT(UI_BASE) ImageModel { ...@@ -88,6 +88,7 @@ class COMPONENT_EXPORT(UI_BASE) ImageModel {
int icon_size = 0); int icon_size = 0);
static ImageModel FromImage(const gfx::Image& image); static ImageModel FromImage(const gfx::Image& image);
static ImageModel FromImageSkia(const gfx::ImageSkia& image_skia); static ImageModel FromImageSkia(const gfx::ImageSkia& image_skia);
static ImageModel FromResourceId(int resource_id);
bool IsEmpty() const; bool IsEmpty() const;
bool IsVectorIcon() const; bool IsVectorIcon() const;
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "ui/base/dragdrop/os_exchange_data.h" #include "ui/base/dragdrop/os_exchange_data.h"
#include "ui/base/models/image_model.h"
#include "ui/base/resource/resource_bundle.h" #include "ui/base/resource/resource_bundle.h"
#include "ui/compositor/canvas_painter.h" #include "ui/compositor/canvas_painter.h"
#include "ui/gfx/canvas.h" #include "ui/gfx/canvas.h"
...@@ -65,12 +66,11 @@ void SetDragImage(const GURL& url, ...@@ -65,12 +66,11 @@ void SetDragImage(const GURL& url,
} }
button.SetMaxSize(gfx::Size(kLinkDragImageMaxWidth, 0)); button.SetMaxSize(gfx::Size(kLinkDragImageMaxWidth, 0));
if (icon.isNull()) { if (icon.isNull()) {
button.SetImage(views::Button::STATE_NORMAL, button.SetImageModel(views::Button::STATE_NORMAL,
*ui::ResourceBundle::GetSharedInstance() ui::ImageModel::FromResourceId(IDR_DEFAULT_FAVICON));
.GetImageNamed(IDR_DEFAULT_FAVICON)
.ToImageSkia());
} else { } else {
button.SetImage(views::Button::STATE_NORMAL, icon); button.SetImageModel(views::Button::STATE_NORMAL,
ui::ImageModel::FromImageSkia(icon));
} }
gfx::Size size(button.GetPreferredSize()); gfx::Size size(button.GetPreferredSize());
......
...@@ -89,11 +89,11 @@ void ButtonExample::LabelButtonPressed(LabelButton* label_button, ...@@ -89,11 +89,11 @@ void ButtonExample::LabelButtonPressed(LabelButton* label_button,
? kLongText ? kLongText
: label_button->GetText().length() > 50 ? kLabelButton : "")); : label_button->GetText().length() > 50 ? kLabelButton : ""));
} else if (event.IsAltDown()) { } else if (event.IsAltDown()) {
label_button->SetImage( label_button->SetImageModel(
Button::STATE_NORMAL, Button::STATE_NORMAL,
label_button->GetImage(Button::STATE_NORMAL).isNull() label_button->GetImage(Button::STATE_NORMAL).isNull()
? *icon_ ? ui::ImageModel::FromImageSkia(*icon_)
: gfx::ImageSkia()); : ui::ImageModel());
} else { } else {
static int alignment = 0; static int alignment = 0;
label_button->SetHorizontalAlignment( label_button->SetHorizontalAlignment(
......
...@@ -64,8 +64,9 @@ class TextVectorImageButton : public views::MdTextButton { ...@@ -64,8 +64,9 @@ class TextVectorImageButton : public views::MdTextButton {
views::MdTextButton::OnThemeChanged(); views::MdTextButton::OnThemeChanged();
// Use the text color for the associated vector image. // Use the text color for the associated vector image.
SetImage(views::Button::ButtonState::STATE_NORMAL, SetImageModel(
gfx::CreateVectorIcon(icon_, label()->GetEnabledColor())); views::Button::ButtonState::STATE_NORMAL,
ui::ImageModel::FromVectorIcon(icon_, label()->GetEnabledColor()));
} }
private: private:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment