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

Side by Side Diff: ui/views/widget/tooltip_manager.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, 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/widget/tooltip_manager.h" 5 #include "ui/views/widget/tooltip_manager.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/strings/string_split.h" 10 #include "base/strings/string_split.h"
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "ui/gfx/text_elider.h" 12 #include "ui/gfx/text_elider.h"
13 #include "ui/gfx/text_utils.h" 13 #include "ui/gfx/text_utils.h"
14 14
15 // Maximum number of characters we allow in a tooltip. 15 // Maximum number of characters we allow in a tooltip.
16 const size_t kMaxTooltipLength = 1024; 16 const size_t kMaxTooltipLength = 1024;
17 17
18 // Maximum number of lines we allow in the tooltip. 18 // Maximum number of lines we allow in the tooltip.
19 const size_t kMaxLines = 6; 19 const size_t kMaxLines = 6;
20 20
21
msw 2013/10/01 02:42:48 nit: remove this blank line
jianli 2013/10/01 18:56:50 Done.
21 namespace views { 22 namespace views {
22 23
23 // static 24 // static
24 void TooltipManager::TrimTooltipToFit(string16* text, 25 void TooltipManager::TrimTooltipToFit(string16* text,
25 int* max_width, 26 int* max_width,
26 int* line_count, 27 int* line_count,
27 int x, 28 int x,
28 int y, 29 int y,
29 gfx::NativeView context) { 30 gfx::NativeView context) {
30 *max_width = 0; 31 *max_width = 0;
(...skipping 14 matching lines...) Expand all
45 lines.resize(kMaxLines); 46 lines.resize(kMaxLines);
46 *line_count = static_cast<int>(lines.size()); 47 *line_count = static_cast<int>(lines.size());
47 48
48 // Format each line to fit. 49 // Format each line to fit.
49 const gfx::FontList& font_list = GetDefaultFontList(); 50 const gfx::FontList& font_list = GetDefaultFontList();
50 string16 result; 51 string16 result;
51 for (std::vector<string16>::iterator i = lines.begin(); i != lines.end(); 52 for (std::vector<string16>::iterator i = lines.begin(); i != lines.end();
52 ++i) { 53 ++i) {
53 string16 elided_text = 54 string16 elided_text =
54 gfx::ElideText(*i, font_list, available_width, gfx::ELIDE_AT_END); 55 gfx::ElideText(*i, font_list, available_width, gfx::ELIDE_AT_END);
55 *max_width = std::max(*max_width, 56 *max_width = std::max<int>(
56 gfx::GetStringWidth(elided_text, font_list)); 57 *max_width, gfx::GetStringWidth(elided_text, font_list));
57 if (!result.empty()) 58 if (!result.empty())
58 result.push_back('\n'); 59 result.push_back('\n');
59 result.append(elided_text); 60 result.append(elided_text);
60 } 61 }
61 *text = result; 62 *text = result;
62 } 63 }
63 64
64 } // namespace views 65 } // namespace views
OLDNEW
« ui/gfx/text_elider.cc ('K') | « ui/views/corewm/tooltip_controller_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698