Chromium Code Reviews| Index: views/controls/label.cc |
| =================================================================== |
| --- views/controls/label.cc (revision 104769) |
| +++ views/controls/label.cc (working copy) |
| @@ -23,12 +23,17 @@ |
| #include "ui/gfx/insets.h" |
| #include "views/background.h" |
| -namespace views { |
| +namespace { |
| // The colors to use for enabled and disabled labels. |
| -static SkColor kEnabledColor; |
| -static SkColor kDisabledColor; |
| +SkColor kDefaultEnabledColor; |
|
sky
2011/10/11 00:42:35
Having these away from where you initialize them m
Peter Kasting
2011/10/11 01:05:47
Sure. Moved. (Also for link.cc.)
|
| +SkColor kDefaultDisabledColor; |
| +SkColor kDefaultBackgroundColor; |
| +}; |
|
sky
2011/10/11 00:42:35
nit: no ;
|
| + |
| +namespace views { |
| + |
| // static |
| const char Label::kViewClassName[] = "views/Label"; |
| @@ -81,17 +86,19 @@ |
| return url_set_ ? url_ : GURL(UTF16ToUTF8(text_)); |
| } |
| -void Label::SetColor(const SkColor& color) { |
| - color_ = color; |
| +void Label::SetEnabledColor(const SkColor& color) { |
| + requested_enabled_color_ = color; |
| + RecalculateColors(); |
| } |
| -SkColor Label::GetColor() const { |
| - return color_; |
| +void Label::SetDisabledColor(const SkColor& color) { |
| + requested_disabled_color_ = color; |
| + RecalculateColors(); |
| } |
| -void Label::MakeReadableOverBackgroundColor(const SkColor& background_color) { |
| - SetColor(color_utils::GetReadableColor( |
| - IsEnabled() ? kEnabledColor : kDisabledColor, background_color)); |
| +void Label::SetBackgroundColor(const SkColor& color) { |
| + background_color_ = color; |
| + RecalculateColors(); |
| } |
| void Label::SetHorizontalAlignment(Alignment alignment) { |
| @@ -216,11 +223,6 @@ |
| return h + GetInsets().height(); |
| } |
| -void Label::OnEnabledChanged() { |
| - View::OnEnabledChanged(); |
| - SetColor(IsEnabled() ? kEnabledColor : kDisabledColor); |
| -} |
| - |
| std::string Label::GetClassName() const { |
| return kViewClassName; |
| } |
| @@ -269,9 +271,10 @@ |
| const string16& text, |
| const gfx::Rect& text_bounds, |
| int flags) { |
| - canvas->DrawStringInt(text, font_, color_, |
| - text_bounds.x(), text_bounds.y(), |
| - text_bounds.width(), text_bounds.height(), flags); |
| + canvas->DrawStringInt(text, font_, |
| + IsEnabled() ? actual_enabled_color_ : actual_disabled_color_, |
| + text_bounds.x(), text_bounds.y(), text_bounds.width(), |
| + text_bounds.height(), flags); |
| if (HasFocus() || paint_as_focused_) { |
| gfx::Rect focus_bounds = text_bounds; |
| @@ -334,12 +337,14 @@ |
| static bool initialized = false; |
| if (!initialized) { |
| #if defined(OS_WIN) |
| - kEnabledColor = color_utils::GetSysSkColor(COLOR_WINDOWTEXT); |
| - kDisabledColor = color_utils::GetSysSkColor(COLOR_GRAYTEXT); |
| + kDefaultEnabledColor = color_utils::GetSysSkColor(COLOR_WINDOWTEXT); |
| + kDefaultDisabledColor = color_utils::GetSysSkColor(COLOR_GRAYTEXT); |
| + kDefaultBackgroundColor = color_utils::GetSysSkColor(COLOR_WINDOW); |
| #else |
| // TODO(beng): source from theme provider. |
| - kEnabledColor = SK_ColorBLACK; |
| - kDisabledColor = SK_ColorGRAY; |
| + kDefaultEnabledColor = SK_ColorBLACK; |
| + kDefaultDisabledColor = SK_ColorGRAY; |
| + kDefaultBackgroundColor = SK_ColorWHITE; |
| #endif |
| initialized = true; |
| @@ -348,9 +353,12 @@ |
| contains_mouse_ = false; |
| font_ = font; |
| text_size_valid_ = false; |
| - SetText(text); |
| url_set_ = false; |
| - color_ = kEnabledColor; |
| + requested_enabled_color_ = kDefaultEnabledColor; |
| + requested_disabled_color_ = kDefaultDisabledColor; |
| + background_color_ = kDefaultBackgroundColor; |
| + auto_color_readability_ = true; |
| + RecalculateColors(); |
| horiz_alignment_ = ALIGN_CENTER; |
| is_multi_line_ = false; |
| allow_character_break_ = false; |
| @@ -359,8 +367,21 @@ |
| rtl_alignment_mode_ = USE_UI_ALIGNMENT; |
| paint_as_focused_ = false; |
| has_focus_border_ = false; |
| + |
| + SetText(text); |
| } |
| +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_; |
| +} |
| + |
| void Label::UpdateContainsMouse(const MouseEvent& event) { |
| SetContainsMouse(GetTextBounds().Contains(event.x(), event.y())); |
| } |