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

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

Issue 354963003: Move gfx::ElideText functionality to RenderText. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sync and rebase. Created 6 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « ui/gfx/text_elider_unittest.cc ('k') | ui/views/examples/label_example.cc » ('j') | 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 <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
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
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
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
OLDNEW
« no previous file with comments | « ui/gfx/text_elider_unittest.cc ('k') | ui/views/examples/label_example.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698