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

Unified Diff: ui/base/text/text_elider.h

Issue 9489011: Elide long emails in the wrench and profile menus. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: lint - fix comment spacing Created 8 years, 10 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
« no previous file with comments | « no previous file | ui/base/text/text_elider.cc » ('j') | ui/base/text/text_elider.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/base/text/text_elider.h
diff --git a/ui/base/text/text_elider.h b/ui/base/text/text_elider.h
index caac9d82f7385b5c75c2ac16fbe4dd7bc010f5d3..ea8f379b02227a6ce7eb01d8d665674d56375729 100644
--- a/ui/base/text/text_elider.h
+++ b/ui/base/text/text_elider.h
@@ -25,13 +25,27 @@ namespace ui {
UI_EXPORT extern const char kEllipsis[];
+// Elides only the username portion of the |email|, if possible, so that the
+// returned email is at most |available_pixel_width| wide under |font|.
asvitkine_google 2012/03/01 20:13:29 I would suggest having the first sentence describe
+// If the domain name by itself is already wider than the width available: it is
+// elided in the middle so that it splits the available width equally with
+// the elided username (should the username be short enough that it doesn't
+// require half the available width: the domain will take that extra width).
+// This function guarantees that the string returned will contain at least one
+// character, other than the ellipsis-es, on either side of the '@'. If it is
+// impossible to achieve these requirements: only an ellipsis will be returned.
+UI_EXPORT string16 ElideEmail(const string16& email,
+ const gfx::Font& font,
+ int available_pixel_width);
+
// This function takes a GURL object and elides it. It returns a string
// which composed of parts from subdomain, domain, path, filename and query.
// A "..." is added automatically at the end if the elided string is bigger
-// than the available pixel width. For available pixel width = 0, empty
-// string is returned. |languages| is a comma separated list of ISO 639
-// language codes and is used to determine what characters are understood
-// by a user. It should come from |prefs::kAcceptLanguages|.
+// than the |available_pixel_width|. For |available_pixel_width| == 0, a
+// formatted, but un-elided, string is returned. |languages| is a comma
+// separated list of ISO 639 language codes and is used to determine what
+// characters are understood by a user. It should come from
+// |prefs::kAcceptLanguages|.
//
// Note: in RTL locales, if the URL returned by this function is going to be
// displayed in the UI, then it is likely that the string needs to be marked
@@ -52,8 +66,10 @@ enum ElideBehavior {
TRUNCATE_AT_END
};
-// Elides |text| to fit in |available_pixel_width| according to the specified
-// |elide_behavior|.
+// This function, if the |text| does not fit the |available_pixel_width|, cuts
+// |text| and adds an ellipsis where specified by |elide_behavior|.
asvitkine_google 2012/03/01 20:13:29 I like the previous wording better. If you want, y
gab 2012/03/01 21:48:18 Right, one of the versions of the code I tried yes
+// If we must elide, but the ellipsis itself doesn't even fit in
+// |available_pixel_width|, this returns an empty string.
UI_EXPORT string16 ElideText(const string16& text,
const gfx::Font& font,
int available_pixel_width,
« no previous file with comments | « no previous file | ui/base/text/text_elider.cc » ('j') | ui/base/text/text_elider.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698