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

Unified Diff: ash/system/user/tray_user.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 round-down problems Created 7 years, 2 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: ash/system/user/tray_user.cc
diff --git a/ash/system/user/tray_user.cc b/ash/system/user/tray_user.cc
index c11890ab88042ca02a04f0dafb7edf4d1957256c..abc765ee5ec8226ad28e7e90753b4652a3d070e7 100644
--- a/ash/system/user/tray_user.cc
+++ b/ash/system/user/tray_user.cc
@@ -540,10 +540,10 @@ void PublicAccountUserDetails::CalculatePreferredSize(SystemTrayItem* owner,
const gfx::Insets insets = GetInsets();
views::TrayBubbleView* bubble_view =
owner->system_tray()->GetSystemBubble()->bubble_view();
- int min_width = std::max(
+ float min_width = std::max(
link_size.width(),
bubble_view->GetPreferredSize().width() - (used_width + insets.width()));
- int max_width = std::min(
+ float max_width = std::min<float>(
font.GetStringWidth(text_) + space_width + link_size.width(),
bubble_view->GetMaximumSize().width() - (used_width + insets.width()));
// Do a binary search for the minimum width that ensures no more than three
@@ -554,9 +554,9 @@ void PublicAccountUserDetails::CalculatePreferredSize(SystemTrayItem* owner,
std::vector<base::string16> lines;
while (min_width < max_width) {
lines.clear();
- const int width = (min_width + max_width) / 2;
+ const float width = (min_width + max_width) / 2;
const bool too_narrow = gfx::ElideRectangleText(
- text_, font, width, INT_MAX, gfx::TRUNCATE_LONG_WORDS, &lines) != 0;
+ text_, font, width, FLT_MAX, gfx::TRUNCATE_LONG_WORDS, &lines) != 0;
int line_count = lines.size();
if (!too_narrow && line_count == 3 &&
width - font.GetStringWidth(lines.back()) <=
@@ -572,7 +572,7 @@ void PublicAccountUserDetails::CalculatePreferredSize(SystemTrayItem* owner,
// Calculate the corresponding height and set the preferred size.
lines.clear();
gfx::ElideRectangleText(
- text_, font, min_width, INT_MAX, gfx::TRUNCATE_LONG_WORDS, &lines);
+ text_, font, min_width, FLT_MAX, gfx::TRUNCATE_LONG_WORDS, &lines);
int line_count = lines.size();
if (min_width - font.GetStringWidth(lines.back()) <=
space_width + link_size.width()) {
@@ -582,7 +582,7 @@ void PublicAccountUserDetails::CalculatePreferredSize(SystemTrayItem* owner,
const int link_extra_height = std::max(
link_size.height() - learn_more_->GetInsets().top() - line_height, 0);
preferred_size_ = gfx::Size(
- min_width + insets.width(),
+ std::ceil(min_width + insets.width()),
line_count * line_height + link_extra_height + insets.height());
bubble_view->SetWidth(preferred_size_.width() + used_width);

Powered by Google App Engine
This is Rietveld 408576698