| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/views/controls/label.h" | 5 #include "ui/views/controls/label.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <cmath> | 10 #include <cmath> |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 | 46 |
| 47 const char Label::kViewClassName[] = "Label"; | 47 const char Label::kViewClassName[] = "Label"; |
| 48 | 48 |
| 49 Label::Label() : Label(base::string16()) { | 49 Label::Label() : Label(base::string16()) { |
| 50 } | 50 } |
| 51 | 51 |
| 52 Label::Label(const base::string16& text) | 52 Label::Label(const base::string16& text) |
| 53 : Label(text, style::CONTEXT_LABEL, style::STYLE_PRIMARY) {} | 53 : Label(text, style::CONTEXT_LABEL, style::STYLE_PRIMARY) {} |
| 54 | 54 |
| 55 Label::Label(const base::string16& text, int text_context, int text_style) | 55 Label::Label(const base::string16& text, int text_context, int text_style) |
| 56 : context_menu_contents_(this) { | 56 : text_context_(text_context), context_menu_contents_(this) { |
| 57 Init(text, style::GetFont(text_context, text_style)); | 57 Init(text, style::GetFont(text_context, text_style)); |
| 58 SetLineHeight(style::GetLineHeight(text_context, text_style)); | 58 SetLineHeight(style::GetLineHeight(text_context, text_style)); |
| 59 |
| 60 // If an explicit style is given, ignore color changes due to the NativeTheme. |
| 61 if (text_style != style::STYLE_PRIMARY) { |
| 62 SetEnabledColor( |
| 63 style::GetColor(text_context, text_style, GetNativeTheme())); |
| 64 } |
| 59 } | 65 } |
| 60 | 66 |
| 61 Label::Label(const base::string16& text, const CustomFont& font) | 67 Label::Label(const base::string16& text, const CustomFont& font) |
| 62 : context_menu_contents_(this) { | 68 : text_context_(style::CONTEXT_LABEL), context_menu_contents_(this) { |
| 63 Init(text, font.font_list); | 69 Init(text, font.font_list); |
| 64 } | 70 } |
| 65 | 71 |
| 66 Label::~Label() { | 72 Label::~Label() { |
| 67 } | 73 } |
| 68 | 74 |
| 69 // static | 75 // static |
| 70 const gfx::FontList& Label::GetDefaultFontList() { | 76 const gfx::FontList& Label::GetDefaultFontList() { |
| 71 return style::GetFont(style::CONTEXT_LABEL, style::STYLE_PRIMARY); | 77 return style::GetFont(style::CONTEXT_LABEL, style::STYLE_PRIMARY); |
| 72 } | 78 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 96 | 102 |
| 97 void Label::SetEnabledColor(SkColor color) { | 103 void Label::SetEnabledColor(SkColor color) { |
| 98 if (enabled_color_set_ && requested_enabled_color_ == color) | 104 if (enabled_color_set_ && requested_enabled_color_ == color) |
| 99 return; | 105 return; |
| 100 is_first_paint_text_ = true; | 106 is_first_paint_text_ = true; |
| 101 requested_enabled_color_ = color; | 107 requested_enabled_color_ = color; |
| 102 enabled_color_set_ = true; | 108 enabled_color_set_ = true; |
| 103 RecalculateColors(); | 109 RecalculateColors(); |
| 104 } | 110 } |
| 105 | 111 |
| 106 void Label::SetDisabledColor(SkColor color) { | 112 // TODO(tapted): Move this into a subclass used only by LabelButton. |
| 113 void Label::SetDisabledColorForLabelButton(SkColor color) { |
| 107 if (disabled_color_set_ && requested_disabled_color_ == color) | 114 if (disabled_color_set_ && requested_disabled_color_ == color) |
| 108 return; | 115 return; |
| 109 is_first_paint_text_ = true; | 116 is_first_paint_text_ = true; |
| 110 requested_disabled_color_ = color; | 117 requested_disabled_color_ = color; |
| 111 disabled_color_set_ = true; | 118 disabled_color_set_ = true; |
| 112 RecalculateColors(); | 119 RecalculateColors(); |
| 113 } | 120 } |
| 114 | 121 |
| 115 void Label::SetBackgroundColor(SkColor color) { | 122 void Label::SetBackgroundColor(SkColor color) { |
| 116 if (background_color_set_ && background_color_ == color) | 123 if (background_color_set_ && background_color_ == color) |
| (...skipping 874 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 991 lines_[i]->SetColor(color); | 998 lines_[i]->SetColor(color); |
| 992 lines_[i]->set_selection_color(actual_selection_text_color_); | 999 lines_[i]->set_selection_color(actual_selection_text_color_); |
| 993 lines_[i]->set_selection_background_focused_color( | 1000 lines_[i]->set_selection_background_focused_color( |
| 994 selection_background_color_); | 1001 selection_background_color_); |
| 995 lines_[i]->set_subpixel_rendering_suppressed(subpixel_rendering_suppressed); | 1002 lines_[i]->set_subpixel_rendering_suppressed(subpixel_rendering_suppressed); |
| 996 } | 1003 } |
| 997 } | 1004 } |
| 998 | 1005 |
| 999 void Label::UpdateColorsFromTheme(const ui::NativeTheme* theme) { | 1006 void Label::UpdateColorsFromTheme(const ui::NativeTheme* theme) { |
| 1000 if (!enabled_color_set_) { | 1007 if (!enabled_color_set_) { |
| 1001 requested_enabled_color_ = theme->GetSystemColor( | 1008 requested_enabled_color_ = |
| 1002 ui::NativeTheme::kColorId_LabelEnabledColor); | 1009 style::GetColor(text_context_, style::STYLE_PRIMARY, theme); |
| 1003 } | 1010 } |
| 1004 if (!disabled_color_set_) { | 1011 if (!disabled_color_set_) { |
| 1005 requested_disabled_color_ = theme->GetSystemColor( | 1012 requested_disabled_color_ = |
| 1006 ui::NativeTheme::kColorId_LabelDisabledColor); | 1013 style::GetColor(text_context_, style::STYLE_DISABLED, theme); |
| 1007 } | 1014 } |
| 1008 if (!background_color_set_) { | 1015 if (!background_color_set_) { |
| 1009 background_color_ = | 1016 background_color_ = |
| 1010 theme->GetSystemColor(ui::NativeTheme::kColorId_DialogBackground); | 1017 theme->GetSystemColor(ui::NativeTheme::kColorId_DialogBackground); |
| 1011 } | 1018 } |
| 1012 if (!selection_text_color_set_) { | 1019 if (!selection_text_color_set_) { |
| 1013 requested_selection_text_color_ = theme->GetSystemColor( | 1020 requested_selection_text_color_ = theme->GetSystemColor( |
| 1014 ui::NativeTheme::kColorId_LabelTextSelectionColor); | 1021 ui::NativeTheme::kColorId_LabelTextSelectionColor); |
| 1015 } | 1022 } |
| 1016 if (!selection_background_color_set_) { | 1023 if (!selection_background_color_set_) { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1054 .WriteText(GetSelectedText()); | 1061 .WriteText(GetSelectedText()); |
| 1055 } | 1062 } |
| 1056 | 1063 |
| 1057 void Label::BuildContextMenuContents() { | 1064 void Label::BuildContextMenuContents() { |
| 1058 context_menu_contents_.AddItemWithStringId(IDS_APP_COPY, IDS_APP_COPY); | 1065 context_menu_contents_.AddItemWithStringId(IDS_APP_COPY, IDS_APP_COPY); |
| 1059 context_menu_contents_.AddItemWithStringId(IDS_APP_SELECT_ALL, | 1066 context_menu_contents_.AddItemWithStringId(IDS_APP_SELECT_ALL, |
| 1060 IDS_APP_SELECT_ALL); | 1067 IDS_APP_SELECT_ALL); |
| 1061 } | 1068 } |
| 1062 | 1069 |
| 1063 } // namespace views | 1070 } // namespace views |
| OLD | NEW |