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

Unified Diff: ui/views/controls/label.cc

Issue 24883002: Uses and returns the fractional width in text eliding (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix win bots Created 7 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: ui/views/controls/label.cc
diff --git a/ui/views/controls/label.cc b/ui/views/controls/label.cc
index 7d4bc7e84703c03dfcbb50ed1f231e991e3b7590..f6e86499910b4027af62f808f85aeb00fb56702a 100644
--- a/ui/views/controls/label.cc
+++ b/ui/views/controls/label.cc
@@ -189,7 +189,8 @@ void Label::SizeToFit(int max_width) {
int label_width = 0;
for (std::vector<string16>::const_iterator iter = lines.begin();
iter != lines.end(); ++iter) {
- label_width = std::max(label_width, gfx::GetStringWidth(*iter, font_list_));
+ label_width = std::max<int>(
+ label_width, gfx::GetStringWidth(*iter, font_list_));
}
label_width += GetInsets().width();
@@ -249,12 +250,11 @@ int Label::GetHeightForWidth(int w) {
return s.height() + GetInsets().height();
}
- int cache_width = w;
-
- int h = font_list_.GetHeight();
+ float fw = w;
+ float h = font_list_.GetHeight();
const int flags = ComputeDrawStringFlags();
- gfx::Canvas::SizeStringInt(text_, font_list_, &w, &h, line_height_, flags);
- cached_heights_[cached_heights_cursor_] = gfx::Size(cache_width, h);
+ gfx::Canvas::SizeStringToFit(text_, font_list_, &fw, &h, line_height_, flags);
+ cached_heights_[cached_heights_cursor_] = gfx::Size(w, h);
cached_heights_cursor_ = (cached_heights_cursor_ + 1) % kCachedSizeLimit;
return h + GetInsets().height();
}
@@ -329,17 +329,18 @@ gfx::Size Label::GetTextSize() const {
if (!text_size_valid_) {
// For single-line strings, we supply the largest possible width, because
// while adding NO_ELLIPSIS to the flags works on Windows for forcing
- // SizeStringInt() to calculate the desired width, it doesn't seem to work
+ // SizeStringToFit() to calculate the desired width, it doesn't seem to work
// on Linux.
- int w = is_multi_line_ ?
+ float w = is_multi_line_ ?
GetAvailableRect().width() : std::numeric_limits<int>::max();
- int h = font_list_.GetHeight();
+ float h = font_list_.GetHeight();
// For single-line strings, ignore the available width and calculate how
// wide the text wants to be.
int flags = ComputeDrawStringFlags();
if (!is_multi_line_)
flags |= gfx::Canvas::NO_ELLIPSIS;
- gfx::Canvas::SizeStringInt(text_, font_list_, &w, &h, line_height_, flags);
+ gfx::Canvas::SizeStringToFit(
+ text_, font_list_, &w, &h, line_height_, flags);
text_size_.SetSize(w, h);
text_size_valid_ = true;
}

Powered by Google App Engine
This is Rietveld 408576698