Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Side by Side Diff: ui/views/controls/label.cc

Issue 2913933002: Move views::Label DisabledColor logic into views::LabelButtonLabel (Closed)
Patch Set: Fix win, linux. Nit. TODO. Fix vector icons Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« ui/views/BUILD.gn ('K') | « ui/views/controls/label.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 102
103 void Label::SetEnabledColor(SkColor color) { 103 void Label::SetEnabledColor(SkColor color) {
104 if (enabled_color_set_ && requested_enabled_color_ == color) 104 if (enabled_color_set_ && requested_enabled_color_ == color)
105 return; 105 return;
106 is_first_paint_text_ = true; 106 is_first_paint_text_ = true;
107 requested_enabled_color_ = color; 107 requested_enabled_color_ = color;
108 enabled_color_set_ = true; 108 enabled_color_set_ = true;
109 RecalculateColors(); 109 RecalculateColors();
110 } 110 }
111 111
112 // TODO(tapted): Move this into a subclass used only by LabelButton.
113 void Label::SetDisabledColorForLabelButton(SkColor color) {
114 if (disabled_color_set_ && requested_disabled_color_ == color)
115 return;
116 is_first_paint_text_ = true;
117 requested_disabled_color_ = color;
118 disabled_color_set_ = true;
119 RecalculateColors();
120 }
121
122 void Label::SetBackgroundColor(SkColor color) { 112 void Label::SetBackgroundColor(SkColor color) {
123 if (background_color_set_ && background_color_ == color) 113 if (background_color_set_ && background_color_ == color)
124 return; 114 return;
125 is_first_paint_text_ = true; 115 is_first_paint_text_ = true;
126 background_color_ = color; 116 background_color_ = color;
127 background_color_set_ = true; 117 background_color_set_ = true;
128 RecalculateColors(); 118 RecalculateColors();
129 } 119 }
130 120
131 void Label::SetSelectionTextColor(SkColor color) { 121 void Label::SetSelectionTextColor(SkColor color) {
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 416
427 if (ShouldShowDefaultTooltip()) { 417 if (ShouldShowDefaultTooltip()) {
428 // Note that |render_text_| is never elided (see the comment in Init() too). 418 // Note that |render_text_| is never elided (see the comment in Init() too).
429 tooltip->assign(render_text_->GetDisplayText()); 419 tooltip->assign(render_text_->GetDisplayText());
430 return true; 420 return true;
431 } 421 }
432 422
433 return false; 423 return false;
434 } 424 }
435 425
436 void Label::OnEnabledChanged() {
437 ApplyTextColors();
438 View::OnEnabledChanged();
439 }
440
441 std::unique_ptr<gfx::RenderText> Label::CreateRenderText( 426 std::unique_ptr<gfx::RenderText> Label::CreateRenderText(
442 const base::string16& text, 427 const base::string16& text,
443 gfx::HorizontalAlignment alignment, 428 gfx::HorizontalAlignment alignment,
444 gfx::DirectionalityMode directionality, 429 gfx::DirectionalityMode directionality,
445 gfx::ElideBehavior elide_behavior) const { 430 gfx::ElideBehavior elide_behavior) const {
446 std::unique_ptr<gfx::RenderText> render_text( 431 std::unique_ptr<gfx::RenderText> render_text(
447 render_text_->CreateInstanceOfSameType()); 432 render_text_->CreateInstanceOfSameType());
448 render_text->SetHorizontalAlignment(alignment); 433 render_text->SetHorizontalAlignment(alignment);
449 render_text->SetDirectionalityMode(directionality); 434 render_text->SetDirectionalityMode(directionality);
450 render_text->SetElideBehavior(elide_behavior); 435 render_text->SetElideBehavior(elide_behavior);
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
822 render_text_->SetDirectionalityMode(gfx::DIRECTIONALITY_FROM_TEXT); 807 render_text_->SetDirectionalityMode(gfx::DIRECTIONALITY_FROM_TEXT);
823 // NOTE: |render_text_| should not be elided at all. This is used to keep some 808 // NOTE: |render_text_| should not be elided at all. This is used to keep some
824 // properties and to compute the size of the string. 809 // properties and to compute the size of the string.
825 render_text_->SetElideBehavior(gfx::NO_ELIDE); 810 render_text_->SetElideBehavior(gfx::NO_ELIDE);
826 render_text_->SetFontList(font_list); 811 render_text_->SetFontList(font_list);
827 render_text_->SetCursorEnabled(false); 812 render_text_->SetCursorEnabled(false);
828 render_text_->SetWordWrapBehavior(gfx::TRUNCATE_LONG_WORDS); 813 render_text_->SetWordWrapBehavior(gfx::TRUNCATE_LONG_WORDS);
829 814
830 elide_behavior_ = gfx::ELIDE_TAIL; 815 elide_behavior_ = gfx::ELIDE_TAIL;
831 stored_selection_range_ = gfx::Range::InvalidRange(); 816 stored_selection_range_ = gfx::Range::InvalidRange();
832 enabled_color_set_ = disabled_color_set_ = background_color_set_ = false; 817 enabled_color_set_ = background_color_set_ = false;
833 selection_text_color_set_ = selection_background_color_set_ = false; 818 selection_text_color_set_ = selection_background_color_set_ = false;
834 subpixel_rendering_enabled_ = true; 819 subpixel_rendering_enabled_ = true;
835 auto_color_readability_ = true; 820 auto_color_readability_ = true;
836 multi_line_ = false; 821 multi_line_ = false;
837 UpdateColorsFromTheme(GetNativeTheme()); 822 UpdateColorsFromTheme(GetNativeTheme());
838 handles_tooltips_ = true; 823 handles_tooltips_ = true;
839 collapse_when_hidden_ = false; 824 collapse_when_hidden_ = false;
840 fixed_width_ = 0; 825 fixed_width_ = 0;
841 max_width_ = 0; 826 max_width_ = 0;
842 is_first_paint_text_ = true; 827 is_first_paint_text_ = true;
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
968 const gfx::Insets shadow_margin = -gfx::ShadowValue::GetMargin(shadows()); 953 const gfx::Insets shadow_margin = -gfx::ShadowValue::GetMargin(shadows());
969 size.Enlarge(shadow_margin.width(), shadow_margin.height()); 954 size.Enlarge(shadow_margin.width(), shadow_margin.height());
970 return size; 955 return size;
971 } 956 }
972 957
973 void Label::RecalculateColors() { 958 void Label::RecalculateColors() {
974 actual_enabled_color_ = auto_color_readability_ ? 959 actual_enabled_color_ = auto_color_readability_ ?
975 color_utils::GetReadableColor(requested_enabled_color_, 960 color_utils::GetReadableColor(requested_enabled_color_,
976 background_color_) : 961 background_color_) :
977 requested_enabled_color_; 962 requested_enabled_color_;
978 actual_disabled_color_ = auto_color_readability_ ?
979 color_utils::GetReadableColor(requested_disabled_color_,
980 background_color_) :
981 requested_disabled_color_;
982 actual_selection_text_color_ = 963 actual_selection_text_color_ =
983 auto_color_readability_ 964 auto_color_readability_
984 ? color_utils::GetReadableColor(requested_selection_text_color_, 965 ? color_utils::GetReadableColor(requested_selection_text_color_,
985 selection_background_color_) 966 selection_background_color_)
986 : requested_selection_text_color_; 967 : requested_selection_text_color_;
987 968
988 ApplyTextColors(); 969 ApplyTextColors();
989 SchedulePaint(); 970 SchedulePaint();
990 } 971 }
991 972
992 void Label::ApplyTextColors() const { 973 void Label::ApplyTextColors() const {
993 SkColor color = enabled() ? actual_enabled_color_ : actual_disabled_color_;
994 bool subpixel_rendering_suppressed = 974 bool subpixel_rendering_suppressed =
995 SkColorGetA(background_color_) != SK_AlphaOPAQUE || 975 SkColorGetA(background_color_) != SK_AlphaOPAQUE ||
996 !subpixel_rendering_enabled_; 976 !subpixel_rendering_enabled_;
997 for (size_t i = 0; i < lines_.size(); ++i) { 977 for (size_t i = 0; i < lines_.size(); ++i) {
998 lines_[i]->SetColor(color); 978 lines_[i]->SetColor(actual_enabled_color_);
999 lines_[i]->set_selection_color(actual_selection_text_color_); 979 lines_[i]->set_selection_color(actual_selection_text_color_);
1000 lines_[i]->set_selection_background_focused_color( 980 lines_[i]->set_selection_background_focused_color(
1001 selection_background_color_); 981 selection_background_color_);
1002 lines_[i]->set_subpixel_rendering_suppressed(subpixel_rendering_suppressed); 982 lines_[i]->set_subpixel_rendering_suppressed(subpixel_rendering_suppressed);
1003 } 983 }
1004 } 984 }
1005 985
1006 void Label::UpdateColorsFromTheme(const ui::NativeTheme* theme) { 986 void Label::UpdateColorsFromTheme(const ui::NativeTheme* theme) {
1007 if (!enabled_color_set_) { 987 if (!enabled_color_set_) {
1008 requested_enabled_color_ = 988 requested_enabled_color_ =
1009 style::GetColor(text_context_, style::STYLE_PRIMARY, theme); 989 style::GetColor(text_context_, style::STYLE_PRIMARY, theme);
1010 } 990 }
1011 if (!disabled_color_set_) {
1012 requested_disabled_color_ =
1013 style::GetColor(text_context_, style::STYLE_DISABLED, theme);
1014 }
1015 if (!background_color_set_) { 991 if (!background_color_set_) {
1016 background_color_ = 992 background_color_ =
1017 theme->GetSystemColor(ui::NativeTheme::kColorId_DialogBackground); 993 theme->GetSystemColor(ui::NativeTheme::kColorId_DialogBackground);
1018 } 994 }
1019 if (!selection_text_color_set_) { 995 if (!selection_text_color_set_) {
1020 requested_selection_text_color_ = theme->GetSystemColor( 996 requested_selection_text_color_ = theme->GetSystemColor(
1021 ui::NativeTheme::kColorId_LabelTextSelectionColor); 997 ui::NativeTheme::kColorId_LabelTextSelectionColor);
1022 } 998 }
1023 if (!selection_background_color_set_) { 999 if (!selection_background_color_set_) {
1024 selection_background_color_ = theme->GetSystemColor( 1000 selection_background_color_ = theme->GetSystemColor(
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1061 .WriteText(GetSelectedText()); 1037 .WriteText(GetSelectedText());
1062 } 1038 }
1063 1039
1064 void Label::BuildContextMenuContents() { 1040 void Label::BuildContextMenuContents() {
1065 context_menu_contents_.AddItemWithStringId(IDS_APP_COPY, IDS_APP_COPY); 1041 context_menu_contents_.AddItemWithStringId(IDS_APP_COPY, IDS_APP_COPY);
1066 context_menu_contents_.AddItemWithStringId(IDS_APP_SELECT_ALL, 1042 context_menu_contents_.AddItemWithStringId(IDS_APP_SELECT_ALL,
1067 IDS_APP_SELECT_ALL); 1043 IDS_APP_SELECT_ALL);
1068 } 1044 }
1069 1045
1070 } // namespace views 1046 } // namespace views
OLDNEW
« ui/views/BUILD.gn ('K') | « ui/views/controls/label.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698