Chromium Code Reviews| Index: ui/views/controls/label.cc |
| diff --git a/ui/views/controls/label.cc b/ui/views/controls/label.cc |
| index 1db98e38acece6a602712d7867780a6365489096..50e35b95feec905895c9bf5d3c39e8a81360e2d2 100644 |
| --- a/ui/views/controls/label.cc |
| +++ b/ui/views/controls/label.cc |
| @@ -109,22 +109,13 @@ void Label::SetEnabledColor(SkColor color) { |
| RecalculateColors(); |
| } |
| -// TODO(tapted): Move this into a subclass used only by LabelButton. |
| -void Label::SetDisabledColorForLabelButton(SkColor color) { |
| - if (disabled_color_set_ && requested_disabled_color_ == color) |
| - return; |
| - is_first_paint_text_ = true; |
| - requested_disabled_color_ = color; |
| - disabled_color_set_ = true; |
| - RecalculateColors(); |
| -} |
| - |
| void Label::SetBackgroundColor(SkColor color) { |
| if (background_color_set_ && background_color_ == color) |
| return; |
| is_first_paint_text_ = true; |
| background_color_ = color; |
| background_color_set_ = true; |
| + OnBackgroundColorChanged(); |
| RecalculateColors(); |
| } |
| @@ -433,11 +424,6 @@ bool Label::GetTooltipText(const gfx::Point& p, base::string16* tooltip) const { |
| return false; |
| } |
| -void Label::OnEnabledChanged() { |
| - ApplyTextColors(); |
|
tapted
2017/06/06 12:30:24
I tested and ran jobs in earlier patchsets with th
|
| - View::OnEnabledChanged(); |
| -} |
| - |
| std::unique_ptr<gfx::RenderText> Label::CreateRenderText( |
| const base::string16& text, |
| gfx::HorizontalAlignment alignment, |
| @@ -507,6 +493,31 @@ void Label::PaintText(gfx::Canvas* canvas) { |
| #endif |
| } |
| +SkColor Label::EnsureTextColorReadable(SkColor requested) const { |
| + return auto_color_readability_ |
| + ? color_utils::GetReadableColor(requested, background_color_) |
| + : requested; |
| +} |
| + |
| +SkColor Label::GetForegroundColor() const { |
| + return enabled_color(); |
| +} |
| + |
| +void Label::OnBackgroundColorChanged() {} |
| + |
| +void Label::ApplyTextColors() const { |
| + bool subpixel_rendering_suppressed = |
| + SkColorGetA(background_color_) != SK_AlphaOPAQUE || |
| + !subpixel_rendering_enabled_; |
| + for (size_t i = 0; i < lines_.size(); ++i) { |
| + lines_[i]->SetColor(GetForegroundColor()); |
| + lines_[i]->set_selection_color(actual_selection_text_color_); |
| + lines_[i]->set_selection_background_focused_color( |
| + selection_background_color_); |
| + lines_[i]->set_subpixel_rendering_suppressed(subpixel_rendering_suppressed); |
| + } |
| +} |
| + |
| void Label::OnBoundsChanged(const gfx::Rect& previous_bounds) { |
| if (previous_bounds.size() != size()) |
| InvalidateLayout(); |
| @@ -829,7 +840,7 @@ void Label::Init(const base::string16& text, const gfx::FontList& font_list) { |
| elide_behavior_ = gfx::ELIDE_TAIL; |
| stored_selection_range_ = gfx::Range::InvalidRange(); |
| - enabled_color_set_ = disabled_color_set_ = background_color_set_ = false; |
| + enabled_color_set_ = background_color_set_ = false; |
| selection_text_color_set_ = selection_background_color_set_ = false; |
| subpixel_rendering_enabled_ = true; |
| auto_color_readability_ = true; |
| @@ -971,14 +982,7 @@ gfx::Size Label::GetTextSize() const { |
| } |
| void Label::RecalculateColors() { |
| - actual_enabled_color_ = auto_color_readability_ ? |
| - color_utils::GetReadableColor(requested_enabled_color_, |
| - background_color_) : |
| - requested_enabled_color_; |
| - actual_disabled_color_ = auto_color_readability_ ? |
| - color_utils::GetReadableColor(requested_disabled_color_, |
| - background_color_) : |
| - requested_disabled_color_; |
| + actual_enabled_color_ = EnsureTextColorReadable(requested_enabled_color_); |
| actual_selection_text_color_ = |
| auto_color_readability_ |
| ? color_utils::GetReadableColor(requested_selection_text_color_, |
| @@ -989,29 +993,11 @@ void Label::RecalculateColors() { |
| SchedulePaint(); |
| } |
| -void Label::ApplyTextColors() const { |
| - SkColor color = enabled() ? actual_enabled_color_ : actual_disabled_color_; |
| - bool subpixel_rendering_suppressed = |
| - SkColorGetA(background_color_) != SK_AlphaOPAQUE || |
| - !subpixel_rendering_enabled_; |
| - for (size_t i = 0; i < lines_.size(); ++i) { |
| - lines_[i]->SetColor(color); |
| - lines_[i]->set_selection_color(actual_selection_text_color_); |
| - lines_[i]->set_selection_background_focused_color( |
| - selection_background_color_); |
| - lines_[i]->set_subpixel_rendering_suppressed(subpixel_rendering_suppressed); |
| - } |
| -} |
| - |
| void Label::UpdateColorsFromTheme(const ui::NativeTheme* theme) { |
| if (!enabled_color_set_) { |
| requested_enabled_color_ = |
| style::GetColor(text_context_, style::STYLE_PRIMARY, theme); |
| } |
| - if (!disabled_color_set_) { |
| - requested_disabled_color_ = |
| - style::GetColor(text_context_, style::STYLE_DISABLED, theme); |
| - } |
| if (!background_color_set_) { |
| background_color_ = |
| theme->GetSystemColor(ui::NativeTheme::kColorId_DialogBackground); |