Commit ac05fa41 authored by minch's avatar minch Committed by Commit Bot

dark_mode: Add kIconButtonSmallOrMedium.

Bug: 1133748
Change-Id: Ie076a61324e6337e0f5f7c559a592a56f33203d7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2441287
Commit-Queue: Min Chen <minch@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#813024}
parent 7cb1bcc8
......@@ -290,6 +290,38 @@ void AshColorProvider::DecorateCloseButton(views::ImageButton* button,
// added separately so its easier to monitor performance.
}
void AshColorProvider::DecorateIconButton(views::ImageButton* button,
ButtonType type,
const gfx::VectorIcon& icon,
bool toggled,
int icon_size) {
DCHECK(!icon.is_empty());
const SkColor normal_color =
GetContentLayerColor(ContentLayerType::kButtonIconColor);
const SkColor toggled_icon_color =
GetContentLayerColor(ContentLayerType::kButtonIconColorPrimary);
const SkColor icon_color = toggled ? toggled_icon_color : normal_color;
// Skip repainting if the incoming icon is the same as the current icon. If
// the icon has been painted before, |gfx::CreateVectorIcon()| will simply
// grab the ImageSkia from a cache, so it will be cheap. Note that this
// assumes that toggled/disabled images changes at the same time as the normal
// image, which it currently does.
const gfx::ImageSkia new_normal_image =
gfx::CreateVectorIcon(icon, icon_size, icon_color);
const gfx::ImageSkia& old_normal_image =
button->GetImage(views::Button::STATE_NORMAL);
if (!new_normal_image.isNull() && !old_normal_image.isNull() &&
new_normal_image.BackedBySameObjectAs(old_normal_image)) {
return;
}
button->SetImage(views::Button::STATE_NORMAL, new_normal_image);
button->SetImage(
views::Button::STATE_DISABLED,
gfx::CreateVectorIcon(icon, icon_size, GetDisabledColor(normal_color)));
}
void AshColorProvider::AddObserver(ColorModeObserver* observer) {
observers_.AddObserver(observer);
}
......
......@@ -121,6 +121,7 @@ class ASH_EXPORT AshColorProvider : public SessionObserver {
enum class ButtonType {
kPillButtonWithIcon,
kCloseButtonWithSmallBase,
kIconButtonSmallOrMedium,
};
// Attributes of ripple, includes the base color, opacity of inkdrop and
......@@ -185,6 +186,11 @@ class ASH_EXPORT AshColorProvider : public SessionObserver {
ButtonType type,
int button_size,
const gfx::VectorIcon& icon);
void DecorateIconButton(views::ImageButton* button,
ButtonType type,
const gfx::VectorIcon& icon,
bool toggled,
int icon_size);
void AddObserver(ColorModeObserver* observer);
void RemoveObserver(ColorModeObserver* observer);
......
......@@ -144,32 +144,9 @@ void FeaturePodIconButton::UpdateVectorIcon() {
if (!icon_)
return;
const auto* color_provider = AshColorProvider::Get();
const SkColor normal_color =
color_provider->GetContentLayerColor(ContentLayerType::kButtonIconColor);
const SkColor toggled_icon_color = color_provider->GetContentLayerColor(
ContentLayerType::kButtonIconColorPrimary);
const SkColor icon_color = toggled_ ? toggled_icon_color : normal_color;
// Skip repainting if the incoming icon is the same as the current icon. If
// the icon has been painted before, |gfx::CreateVectorIcon()| will simply
// grab the ImageSkia from a cache, so it will be cheap. Note that this
// assumes that toggled/disabled images changes at the same time as the normal
// image, which it currently does.
const gfx::ImageSkia new_normal_image = gfx::CreateVectorIcon(
*icon_, kUnifiedFeaturePodVectorIconSize, icon_color);
const gfx::ImageSkia& old_normal_image =
GetImage(views::Button::STATE_NORMAL);
if (!new_normal_image.isNull() && !old_normal_image.isNull() &&
new_normal_image.BackedBySameObjectAs(old_normal_image)) {
return;
}
SetImage(views::Button::STATE_NORMAL, new_normal_image);
SetImage(
views::Button::STATE_DISABLED,
gfx::CreateVectorIcon(*icon_, kUnifiedFeaturePodVectorIconSize,
AshColorProvider::GetDisabledColor(normal_color)));
AshColorProvider::Get()->DecorateIconButton(
this, AshColorProvider::ButtonType::kIconButtonSmallOrMedium, *icon_,
toggled_, kUnifiedFeaturePodVectorIconSize);
}
FeaturePodLabelButton::FeaturePodLabelButton(views::ButtonListener* listener)
......
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