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

dark_mode: Remove unnecessary colors.

Remove kSystemMenuIconColor and kSystemMenuIconColorToggled. Feature pod
button use kButtonIconColor and kButtonIconColorPrimary in the spec.

Make FeaturePodIconButton as ImageButton only. Since it already has
|toggled_| to control the toggle state. Update the icon color on
|toggled_| is enough for it.

Bug: 1133063
Change-Id: I46e498e967e0065cfd4ce6451adf60275e1864bc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2439432Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Commit-Queue: Min Chen <minch@chromium.org>
Cr-Commit-Position: refs/heads/master@{#812802}
parent efe9d1fb
......@@ -18,7 +18,7 @@ CaptureModeCloseButton::CaptureModeCloseButton(views::ButtonListener* listener)
SetBorder(views::CreateEmptyBorder(capture_mode::kButtonPadding));
auto* color_provider = AshColorProvider::Get();
const SkColor normal_color = color_provider->GetContentLayerColor(
AshColorProvider::ContentLayerType::kSystemMenuIconColor);
AshColorProvider::ContentLayerType::kButtonIconColor);
SetImage(views::Button::STATE_NORMAL,
gfx::CreateVectorIcon(kCloseButtonIcon, normal_color));
SetImageHorizontalAlignment(ALIGN_CENTER);
......
......@@ -69,9 +69,9 @@ void CaptureModeToggleButton::GetAccessibleNodeData(ui::AXNodeData* node_data) {
void CaptureModeToggleButton::SetIcon(const gfx::VectorIcon& icon) {
auto* color_provider = AshColorProvider::Get();
const SkColor normal_color = color_provider->GetContentLayerColor(
AshColorProvider::ContentLayerType::kSystemMenuIconColor);
AshColorProvider::ContentLayerType::kButtonIconColor);
const SkColor toggled_color = color_provider->GetContentLayerColor(
AshColorProvider::ContentLayerType::kSystemMenuIconColorToggled);
AshColorProvider::ContentLayerType::kButtonIconColorPrimary);
SetImage(views::Button::STATE_NORMAL,
gfx::CreateVectorIcon(icon, normal_color));
......
......@@ -213,10 +213,6 @@ SkColor AshColorProvider::GetContentLayerColor(ContentLayerType type) const {
return is_dark_mode ? gfx::kGoogleGrey900 : gfx::kGoogleGrey200;
case ContentLayerType::kSliderThumbColorDisabled:
return is_dark_mode ? gfx::kGoogleGrey600 : gfx::kGoogleGrey600;
case ContentLayerType::kSystemMenuIconColor:
return is_dark_mode ? gfx::kGoogleGrey200 : gfx::kGoogleGrey700;
case ContentLayerType::kSystemMenuIconColorToggled:
return is_dark_mode ? gfx::kGoogleGrey900 : gfx::kGoogleGrey200;
case ContentLayerType::kAppStateIndicatorColor:
return is_dark_mode ? gfx::kGoogleGrey200 : gfx::kGoogleGrey700;
case ContentLayerType::kAppStateIndicatorColorInactive:
......
......@@ -105,11 +105,6 @@ class ASH_EXPORT AshColorProvider : public SessionObserver {
kButtonIconColor,
kButtonIconColorPrimary,
// Color for system menu icon buttons with inverted dark mode colors, e.g,
// FeaturePodIconButton
kSystemMenuIconColor,
kSystemMenuIconColorToggled,
// Color for sliders (volume, brightness etc.)
kSliderThumbColorEnabled,
kSliderThumbColorDisabled,
......
......@@ -208,7 +208,7 @@ void HoldingSpaceItemView::AddPin(views::View* parent) {
pin_->SetVisible(false);
const SkColor icon_color = AshColorProvider::Get()->GetContentLayerColor(
AshColorProvider::ContentLayerType::kSystemMenuIconColor);
AshColorProvider::ContentLayerType::kButtonIconColor);
const gfx::ImageSkia unpinned_icon = gfx::CreateVectorIcon(
views::kUnpinIcon, kHoldingSpacePinIconSize, icon_color);
......
......@@ -141,42 +141,32 @@ const char* NetworkFeaturePodButton::GetClassName() const {
}
void NetworkFeaturePodButton::Update() {
bool image_animating = false;
bool toggled_image_animating = false;
TrayNetworkStateModel* model =
Shell::Get()->system_tray_model()->network_state_model();
const NetworkStateProperties* network = model->default_network();
const bool toggled = network || model->GetDeviceState(NetworkType::kWiFi) ==
DeviceStateType::kEnabled;
network_icon::IconType icon_type =
toggled ? network_icon::ICON_TYPE_FEATURE_POD_TOGGLED
: network_icon::ICON_TYPE_FEATURE_POD;
bool image_animating = false;
gfx::ImageSkia image =
Shell::Get()->system_tray_model()->active_network_icon()->GetImage(
ActiveNetworkIcon::Type::kSingle, network_icon::ICON_TYPE_FEATURE_POD,
&image_animating);
gfx::ImageSkia image_toggled =
Shell::Get()->system_tray_model()->active_network_icon()->GetImage(
ActiveNetworkIcon::Type::kSingle,
network_icon::ICON_TYPE_FEATURE_POD_TOGGLED,
&toggled_image_animating);
ActiveNetworkIcon::Type::kSingle, icon_type, &image_animating);
gfx::ImageSkia image_disabled =
Shell::Get()->system_tray_model()->active_network_icon()->GetImage(
ActiveNetworkIcon::Type::kSingle,
network_icon::ICON_TYPE_FEATURE_POD_DISABLED, &image_animating);
if (image_animating || toggled_image_animating)
if (image_animating)
network_icon::NetworkIconAnimation::GetInstance()->AddObserver(this);
else
network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this);
TrayNetworkStateModel* model =
Shell::Get()->system_tray_model()->network_state_model();
const NetworkStateProperties* network = model->default_network();
bool toggled = network || model->GetDeviceState(NetworkType::kWiFi) ==
DeviceStateType::kEnabled;
SetToggled(toggled);
icon_button()->SetImage(views::Button::STATE_NORMAL, image);
icon_button()->SetImage(views::Button::STATE_DISABLED, image_disabled);
icon_button()->SetToggledImage(views::Button::STATE_NORMAL, &image_toggled);
icon_button()->SetToggledImage(views::Button::STATE_DISABLED,
&image_disabled);
SetToggled(toggled);
base::string16 network_name;
if (network) {
......
......@@ -438,10 +438,10 @@ SkColor GetDefaultColorForIconType(IconType icon_type) {
return kIconColorInOobe;
case ICON_TYPE_FEATURE_POD:
return AshColorProvider::Get()->GetContentLayerColor(
AshColorProvider::ContentLayerType::kSystemMenuIconColor);
AshColorProvider::ContentLayerType::kButtonIconColor);
case ICON_TYPE_FEATURE_POD_TOGGLED:
return AshColorProvider::Get()->GetContentLayerColor(
AshColorProvider::ContentLayerType::kSystemMenuIconColorToggled);
AshColorProvider::ContentLayerType::kButtonIconColorPrimary);
case ICON_TYPE_FEATURE_POD_DISABLED:
return AshColorProvider::GetDisabledColor(
GetDefaultColorForIconType(ICON_TYPE_FEATURE_POD));
......
......@@ -75,7 +75,7 @@ void CommonPaletteTool::OnViewClicked(views::View* sender) {
views::View* CommonPaletteTool::CreateDefaultView(const base::string16& name) {
SkColor icon_color = AshColorProvider::Get()->GetContentLayerColor(
AshColorProvider::ContentLayerType::kSystemMenuIconColor);
AshColorProvider::ContentLayerType::kButtonIconColor);
gfx::ImageSkia icon =
CreateVectorIcon(GetPaletteIcon(), kMenuIconSize, icon_color);
highlight_view_ = new HoverHighlightView(this, true /* use_unified_theme */);
......
......@@ -52,7 +52,7 @@ void ConfigureFeaturePodLabel(views::Label* label,
FeaturePodIconButton::FeaturePodIconButton(views::ButtonListener* listener,
bool is_togglable)
: views::ToggleImageButton(listener), is_togglable_(is_togglable) {
: views::ImageButton(listener), is_togglable_(is_togglable) {
SetPreferredSize(kUnifiedFeaturePodIconSize);
SetBorder(views::CreateEmptyBorder(kUnifiedFeaturePodIconPadding));
SetImageHorizontalAlignment(ALIGN_CENTER);
......@@ -76,43 +76,12 @@ void FeaturePodIconButton::SetToggled(bool toggled) {
return;
toggled_ = toggled;
views::ToggleImageButton::SetToggled(toggled);
UpdateVectorIcon();
}
void FeaturePodIconButton::SetVectorIcon(const gfx::VectorIcon& icon) {
const SkColor icon_color = AshColorProvider::Get()->GetContentLayerColor(
ContentLayerType::kSystemMenuIconColor);
const SkColor toggled_color = AshColorProvider::Get()->GetContentLayerColor(
ContentLayerType::kSystemMenuIconColorToggled);
// 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);
SetToggledImage(views::Button::STATE_NORMAL,
new gfx::ImageSkia(gfx::CreateVectorIcon(
icon, kUnifiedFeaturePodVectorIconSize, toggled_color)));
SetImage(
views::Button::STATE_DISABLED,
gfx::CreateVectorIcon(icon, kUnifiedFeaturePodVectorIconSize,
AshColorProvider::GetDisabledColor(icon_color)));
SetToggledImage(views::Button::STATE_DISABLED,
new gfx::ImageSkia(gfx::CreateVectorIcon(
icon, kUnifiedFeaturePodVectorIconSize,
AshColorProvider::GetDisabledColor(icon_color))));
icon_ = &icon;
UpdateVectorIcon();
}
void FeaturePodIconButton::PaintButtonContents(gfx::Canvas* canvas) {
......@@ -171,6 +140,38 @@ const char* FeaturePodIconButton::GetClassName() const {
return "FeaturePodIconButton";
}
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)));
}
FeaturePodLabelButton::FeaturePodLabelButton(views::ButtonListener* listener)
: Button(listener),
label_(new views::Label),
......
......@@ -21,7 +21,7 @@ namespace ash {
class FeaturePodControllerBase;
// A toggle button with an icon used by feature pods and in other places.
class FeaturePodIconButton : public views::ToggleImageButton {
class FeaturePodIconButton : public views::ImageButton {
public:
FeaturePodIconButton(views::ButtonListener* listener, bool is_togglable);
~FeaturePodIconButton() override;
......@@ -44,12 +44,18 @@ class FeaturePodIconButton : public views::ToggleImageButton {
bool toggled() const { return toggled_; }
private:
// Updates vector icon. Called by SetToggled to update the icon's color on
// toggle state.
void UpdateVectorIcon();
// True if this button is a togglable.
const bool is_togglable_;
// True if the button is currently toggled.
bool toggled_ = false;
const gfx::VectorIcon* icon_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(FeaturePodIconButton);
};
......
......@@ -106,9 +106,9 @@ const char* UnifiedSliderButton::GetClassName() const {
void UnifiedSliderButton::SetVectorIcon(const gfx::VectorIcon& icon) {
const SkColor toggled_color = AshColorProvider::Get()->GetContentLayerColor(
ContentLayerType::kSystemMenuIconColorToggled);
ContentLayerType::kButtonIconColorPrimary);
const SkColor icon_color = AshColorProvider::Get()->GetContentLayerColor(
ContentLayerType::kSystemMenuIconColor);
ContentLayerType::kButtonIconColor);
SetImage(views::Button::STATE_NORMAL,
gfx::CreateVectorIcon(icon, icon_color));
......
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