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 <algorithm> | 7 #include <algorithm> |
8 #include <cmath> | 8 #include <cmath> |
9 #include <limits> | 9 #include <limits> |
10 #include <vector> | 10 #include <vector> |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 if (height != line_height_) { | 130 if (height != line_height_) { |
131 line_height_ = height; | 131 line_height_ = height; |
132 ResetCachedSize(); | 132 ResetCachedSize(); |
133 PreferredSizeChanged(); | 133 PreferredSizeChanged(); |
134 SchedulePaint(); | 134 SchedulePaint(); |
135 } | 135 } |
136 } | 136 } |
137 | 137 |
138 void Label::SetMultiLine(bool multi_line) { | 138 void Label::SetMultiLine(bool multi_line) { |
139 DCHECK(!multi_line || (elide_behavior_ == gfx::ELIDE_TAIL || | 139 DCHECK(!multi_line || (elide_behavior_ == gfx::ELIDE_TAIL || |
140 elide_behavior_ == gfx::TRUNCATE)); | 140 elide_behavior_ == gfx::NO_ELIDE)); |
141 if (multi_line != is_multi_line_) { | 141 if (multi_line != is_multi_line_) { |
142 is_multi_line_ = multi_line; | 142 is_multi_line_ = multi_line; |
143 ResetCachedSize(); | 143 ResetCachedSize(); |
144 PreferredSizeChanged(); | 144 PreferredSizeChanged(); |
145 SchedulePaint(); | 145 SchedulePaint(); |
146 } | 146 } |
147 } | 147 } |
148 | 148 |
149 void Label::SetObscured(bool obscured) { | 149 void Label::SetObscured(bool obscured) { |
150 if (obscured != is_obscured_) { | 150 if (obscured != is_obscured_) { |
151 is_obscured_ = obscured; | 151 is_obscured_ = obscured; |
152 SetTextInternal(text_); | 152 SetTextInternal(text_); |
153 } | 153 } |
154 } | 154 } |
155 | 155 |
156 void Label::SetAllowCharacterBreak(bool allow_character_break) { | 156 void Label::SetAllowCharacterBreak(bool allow_character_break) { |
157 if (allow_character_break != allow_character_break_) { | 157 if (allow_character_break != allow_character_break_) { |
158 allow_character_break_ = allow_character_break; | 158 allow_character_break_ = allow_character_break; |
159 ResetCachedSize(); | 159 ResetCachedSize(); |
160 PreferredSizeChanged(); | 160 PreferredSizeChanged(); |
161 SchedulePaint(); | 161 SchedulePaint(); |
162 } | 162 } |
163 } | 163 } |
164 | 164 |
165 void Label::SetElideBehavior(gfx::ElideBehavior elide_behavior) { | 165 void Label::SetElideBehavior(gfx::ElideBehavior elide_behavior) { |
166 DCHECK(!is_multi_line_ || (elide_behavior_ == gfx::ELIDE_TAIL || | 166 DCHECK(!is_multi_line_ || (elide_behavior_ == gfx::ELIDE_TAIL || |
167 elide_behavior_ == gfx::TRUNCATE)); | 167 elide_behavior_ == gfx::NO_ELIDE)); |
168 if (elide_behavior != elide_behavior_) { | 168 if (elide_behavior != elide_behavior_) { |
169 elide_behavior_ = elide_behavior; | 169 elide_behavior_ = elide_behavior; |
170 ResetCachedSize(); | 170 ResetCachedSize(); |
171 PreferredSizeChanged(); | 171 PreferredSizeChanged(); |
172 SchedulePaint(); | 172 SchedulePaint(); |
173 } | 173 } |
174 } | 174 } |
175 | 175 |
176 void Label::SetTooltipText(const base::string16& tooltip_text) { | 176 void Label::SetTooltipText(const base::string16& tooltip_text) { |
177 tooltip_text_ = tooltip_text; | 177 tooltip_text_ = tooltip_text; |
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
489 gfx::Rect bounds(size()); | 489 gfx::Rect bounds(size()); |
490 bounds.Inset(GetInsets()); | 490 bounds.Inset(GetInsets()); |
491 return bounds; | 491 return bounds; |
492 } | 492 } |
493 | 493 |
494 void Label::CalculateDrawStringParams(base::string16* paint_text, | 494 void Label::CalculateDrawStringParams(base::string16* paint_text, |
495 gfx::Rect* text_bounds, | 495 gfx::Rect* text_bounds, |
496 int* flags) const { | 496 int* flags) const { |
497 DCHECK(paint_text && text_bounds && flags); | 497 DCHECK(paint_text && text_bounds && flags); |
498 | 498 |
499 const bool forbid_ellipsis = elide_behavior_ == gfx::TRUNCATE || | 499 const bool forbid_ellipsis = elide_behavior_ == gfx::NO_ELIDE || |
500 elide_behavior_ == gfx::FADE_TAIL; | 500 elide_behavior_ == gfx::FADE_TAIL; |
501 if (is_multi_line_ || forbid_ellipsis) { | 501 if (is_multi_line_ || forbid_ellipsis) { |
502 *paint_text = layout_text(); | 502 *paint_text = layout_text(); |
503 } else { | 503 } else { |
504 *paint_text = gfx::ElideText(layout_text(), font_list_, | 504 *paint_text = gfx::ElideText(layout_text(), font_list_, |
505 GetAvailableRect().width(), elide_behavior_); | 505 GetAvailableRect().width(), elide_behavior_); |
506 } | 506 } |
507 | 507 |
508 *text_bounds = GetTextBounds(); | 508 *text_bounds = GetTextBounds(); |
509 *flags = ComputeDrawStringFlags(); | 509 *flags = ComputeDrawStringFlags(); |
(...skipping 25 matching lines...) Expand all Loading... |
535 cached_heights_[i] = gfx::Size(); | 535 cached_heights_[i] = gfx::Size(); |
536 } | 536 } |
537 | 537 |
538 bool Label::ShouldShowDefaultTooltip() const { | 538 bool Label::ShouldShowDefaultTooltip() const { |
539 return !is_multi_line_ && !is_obscured_ && | 539 return !is_multi_line_ && !is_obscured_ && |
540 gfx::GetStringWidth(layout_text(), font_list_) > | 540 gfx::GetStringWidth(layout_text(), font_list_) > |
541 GetAvailableRect().width(); | 541 GetAvailableRect().width(); |
542 } | 542 } |
543 | 543 |
544 } // namespace views | 544 } // namespace views |
OLD | NEW |