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

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: Patch 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..264a7e967fb474a635fb648eaa3028704ae0b3f7 100644
--- a/ui/views/controls/label.cc
+++ b/ui/views/controls/label.cc
@@ -189,7 +189,9 @@ 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(
+ label_width,
+ static_cast<int>(gfx::GetStringWidth(*iter, font_list_)));
msw 2013/09/27 21:54:48 Shouldn't this retain the floating point value? Ei
jianli 2013/10/01 00:32:58 I do not think fractional width will be needed for
}
label_width += GetInsets().width();
@@ -249,12 +251,11 @@ int Label::GetHeightForWidth(int w) {
return s.height() + GetInsets().height();
}
- int cache_width = w;
-
- int h = font_list_.GetHeight();
+ float fw = w;
msw 2013/09/27 21:54:48 |fw| isn't really used after its value is updated
jianli 2013/10/01 00:32:58 Though |fw| is not used after its value is update
msw 2013/10/01 02:42:48 Ah, now I understand; this code was already cachin
+ 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::SizeStringInt(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();
}
@@ -331,9 +332,9 @@ gfx::Size Label::GetTextSize() const {
// while adding NO_ELLIPSIS to the flags works on Windows for forcing
// SizeStringInt() 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();

Powered by Google App Engine
This is Rietveld 408576698