Commit 8f70ae5c authored by Bret Sepulveda's avatar Bret Sepulveda Committed by Commit Bot

Harmony: add disabled colors for checkbox/radio button icons.

Previously the icons would use the active colors, which is confusing.
See screenshot in the associated bug.

Bug: 812920
Change-Id: I35e11e1b5ec8e1fc95b40ef27e5819b9dd9db008
Reviewed-on: https://chromium-review.googlesource.com/923209Reviewed-by: default avatarScott Violet <sky@chromium.org>
Commit-Queue: Bret Sepulveda <bsep@chromium.org>
Cr-Commit-Position: refs/heads/master@{#537532}
parent 54994c6a
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "ui/base/material_design/material_design_controller.h" #include "ui/base/material_design/material_design_controller.h"
#include "ui/base/resource/resource_bundle.h" #include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/canvas.h" #include "ui/gfx/canvas.h"
#include "ui/gfx/color_palette.h"
#include "ui/gfx/color_utils.h" #include "ui/gfx/color_utils.h"
#include "ui/gfx/paint_vector_icon.h" #include "ui/gfx/paint_vector_icon.h"
#include "ui/native_theme/native_theme.h" #include "ui/native_theme/native_theme.h"
...@@ -215,14 +216,16 @@ std::unique_ptr<InkDropRipple> Checkbox::CreateInkDropRipple() const { ...@@ -215,14 +216,16 @@ std::unique_ptr<InkDropRipple> Checkbox::CreateInkDropRipple() const {
SkColor Checkbox::GetInkDropBaseColor() const { SkColor Checkbox::GetInkDropBaseColor() const {
// Usually ink drop ripples match the text color. Checkboxes use the color of // Usually ink drop ripples match the text color. Checkboxes use the color of
// the unchecked icon. // the unchecked, enabled icon.
return GetIconImageColor(false); return GetIconImageColor(IconState::ENABLED);
} }
gfx::ImageSkia Checkbox::GetImage(ButtonState for_state) const { gfx::ImageSkia Checkbox::GetImage(ButtonState for_state) const {
if (UseMd()) { if (UseMd()) {
const int checked = checked_ ? IconState::CHECKED : 0;
const int enabled = for_state != STATE_DISABLED ? IconState::ENABLED : 0;
return gfx::CreateVectorIcon(GetVectorIcon(), 16, return gfx::CreateVectorIcon(GetVectorIcon(), 16,
GetIconImageColor(checked_)); GetIconImageColor(checked | enabled));
} }
const size_t checked_index = checked_ ? 1 : 0; const size_t checked_index = checked_ ? 1 : 0;
...@@ -263,14 +266,19 @@ const gfx::VectorIcon& Checkbox::GetVectorIcon() const { ...@@ -263,14 +266,19 @@ const gfx::VectorIcon& Checkbox::GetVectorIcon() const {
return checked() ? kCheckboxActiveIcon : kCheckboxNormalIcon; return checked() ? kCheckboxActiveIcon : kCheckboxNormalIcon;
} }
SkColor Checkbox::GetIconImageColor(bool checked) const { SkColor Checkbox::GetIconImageColor(int icon_state) const {
DCHECK(UseMd()); DCHECK(UseMd());
return checked const SkColor active_color =
? GetNativeTheme()->GetSystemColor( (icon_state & IconState::CHECKED)
ui::NativeTheme::kColorId_FocusedBorderColor) ? GetNativeTheme()->GetSystemColor(
// When unchecked, the icon color matches push button text color. ui::NativeTheme::kColorId_FocusedBorderColor)
: style::GetColor(*this, style::CONTEXT_BUTTON_MD, // When unchecked, the icon color matches push button text color.
style::STYLE_PRIMARY); : style::GetColor(*this, style::CONTEXT_BUTTON_MD,
style::STYLE_PRIMARY);
return (icon_state & IconState::ENABLED)
? active_color
: color_utils::BlendTowardOppositeLuma(active_color,
gfx::kDisabledControlAlpha);
} }
void Checkbox::NotifyClick(const ui::Event& event) { void Checkbox::NotifyClick(const ui::Event& event) {
......
...@@ -74,7 +74,11 @@ class VIEWS_EXPORT Checkbox : public LabelButton { ...@@ -74,7 +74,11 @@ class VIEWS_EXPORT Checkbox : public LabelButton {
private: private:
friend class IconFocusRing; friend class IconFocusRing;
SkColor GetIconImageColor(bool checked) const; // Bitmask constants for GetIconImageColor.
enum IconState { CHECKED = 0b1, ENABLED = 0b10 };
// |icon_state| is a bitmask using the IconState enum.
SkColor GetIconImageColor(int icon_state) const;
// Button: // Button:
void NotifyClick(const ui::Event& event) override; void NotifyClick(const ui::Event& event) override;
......
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