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

Unified Diff: ui/views/corewm/tooltip_controller.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: ui/views/corewm/tooltip_controller.cc
diff --git a/ui/views/corewm/tooltip_controller.cc b/ui/views/corewm/tooltip_controller.cc
index 54b4f7ae04a2826ea7abecf04c7208dd3795c01a..8b2f271090d3ed60acad3c79ce79767af2fd995d 100644
--- a/ui/views/corewm/tooltip_controller.cc
+++ b/ui/views/corewm/tooltip_controller.cc
@@ -38,7 +38,7 @@ const int kTooltipHorizontalPadding = 3;
// Max visual tooltip width. If a tooltip is greater than this width, it will
// be wrapped.
-const int kTooltipMaxWidthPixels = 400;
+const float kTooltipMaxWidthPixels = 400;
// Maximum number of lines we allow in the tooltip.
const size_t kMaxLines = 10;
@@ -109,14 +109,15 @@ class TooltipController::Tooltip : public views::WidgetObserver {
void SetText(aura::Window* window,
const string16& tooltip_text,
const gfx::Point& location) {
- int max_width, line_count;
+ float max_width;
+ int line_count;
string16 trimmed_text(tooltip_text);
controller_->TrimTooltipToFit(
controller_->GetMaxWidth(location), &trimmed_text, &max_width,
&line_count);
label_.SetText(trimmed_text);
- int width = max_width + 2 * kTooltipHorizontalPadding;
+ float width = max_width + 2 * kTooltipHorizontalPadding;
int height = label_.GetHeightForWidth(max_width) +
2 * kTooltipVerticalPadding;
if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoDropShadows)) {
@@ -367,9 +368,9 @@ gfx::Rect TooltipController::GetBoundsForTooltip(
}
// static
-void TooltipController::TrimTooltipToFit(int max_width,
+void TooltipController::TrimTooltipToFit(float max_width,
string16* text,
- int* width,
+ float* width,
int* line_count) {
*width = 0;
*line_count = 0;
@@ -380,7 +381,7 @@ void TooltipController::TrimTooltipToFit(int max_width,
*text = text->substr(0, kMaxTooltipLength);
// Determine the available width for the tooltip.
- int available_width = std::min(kTooltipMaxWidthPixels, max_width);
+ float available_width = std::min(kTooltipMaxWidthPixels, max_width);
std::vector<string16> lines;
base::SplitString(*text, '\n', &lines);
@@ -395,14 +396,14 @@ void TooltipController::TrimTooltipToFit(int max_width,
// to a new line.
std::vector<string16> words;
base::SplitStringDontTrim(*l, ' ', &words);
- int current_width = 0;
+ float current_width = 0;
string16 line;
for (std::vector<string16>::iterator w = words.begin(); w != words.end();
++w) {
string16 word = *w;
if (w + 1 != words.end())
word.push_back(' ');
- int word_width = font.GetStringWidth(word);
+ float word_width = font.GetStringWidth(word);
if (current_width + word_width > available_width) {
// Current width will exceed the available width. Must start a new line.
if (!line.empty())
@@ -431,7 +432,7 @@ void TooltipController::TrimTooltipToFit(int max_width,
l != result_lines.end(); ++l) {
if (!result.empty())
result.push_back('\n');
- int line_width = font.GetStringWidth(*l);
+ float line_width = font.GetStringWidth(*l);
// Since we only break at word boundaries, it could happen that due to some
// very long word, line_width is greater than the available_width. In such
// case, we simply truncate at available_width and add ellipses at the end.

Powered by Google App Engine
This is Rietveld 408576698