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

Side by Side 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: fixed lint Created 8 years, 9 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 // This file defines utility functions for eliding and formatting UI text. 5 // This file defines utility functions for eliding and formatting UI text.
6 6
7 #ifndef UI_BASE_TEXT_TEXT_ELIDER_H_ 7 #ifndef UI_BASE_TEXT_TEXT_ELIDER_H_
8 #define UI_BASE_TEXT_TEXT_ELIDER_H_ 8 #define UI_BASE_TEXT_TEXT_ELIDER_H_
9 #pragma once 9 #pragma once
10 10
11 #include <string> 11 #include <string>
12 #include <vector> 12 #include <vector>
13 13
14 #include "base/basictypes.h" 14 #include "base/basictypes.h"
15 #include "base/string16.h" 15 #include "base/string16.h"
16 #include "ui/base/ui_export.h" 16 #include "ui/base/ui_export.h"
17 #include "ui/gfx/font.h" 17 #include "ui/gfx/font.h"
18 #include "unicode/coll.h" 18 #include "unicode/coll.h"
19 #include "unicode/uchar.h" 19 #include "unicode/uchar.h"
20 20
21 class FilePath; 21 class FilePath;
22 class GURL; 22 class GURL;
23 23
24 namespace ui { 24 namespace ui {
25 25
26 UI_EXPORT extern const char kEllipsis[]; 26 UI_EXPORT extern const char kEllipsis[];
27 UI_EXPORT extern const size_t kMaxProfileUsernameLength;
Alexei Svitkine (slow) 2012/02/28 15:46:22 This is the wrong place for such a constant. ui/ba
gab 2012/02/28 19:20:11 Right, I didn't know where to put this as the reve
27 28
28 // This function takes a GURL object and elides it. It returns a string 29 // This function takes a GURL object and elides it. It returns a string
29 // which composed of parts from subdomain, domain, path, filename and query. 30 // which composed of parts from subdomain, domain, path, filename and query.
30 // A "..." is added automatically at the end if the elided string is bigger 31 // A "..." is added automatically at the end if the elided string is bigger
31 // than the available pixel width. For available pixel width = 0, empty 32 // than the available pixel width. For available pixel width = 0, empty
32 // string is returned. |languages| is a comma separted list of ISO 639 33 // string is returned. |languages| is a comma separted list of ISO 639
33 // language codes and is used to determine what characters are understood 34 // language codes and is used to determine what characters are understood
34 // by a user. It should come from |prefs::kAcceptLanguages|. 35 // by a user. It should come from |prefs::kAcceptLanguages|.
35 // 36 //
36 // Note: in RTL locales, if the URL returned by this function is going to be 37 // Note: in RTL locales, if the URL returned by this function is going to be
37 // displayed in the UI, then it is likely that the string needs to be marked 38 // displayed in the UI, then it is likely that the string needs to be marked
38 // as an LTR string (using base::i18n::WrapStringWithLTRFormatting()) so that it 39 // as an LTR string (using base::i18n::WrapStringWithLTRFormatting()) so that it
39 // is displayed properly in an RTL context. Please refer to 40 // is displayed properly in an RTL context. Please refer to
40 // http://crbug.com/6487 for more information. 41 // http://crbug.com/6487 for more information.
41 UI_EXPORT string16 ElideUrl(const GURL& url, 42 UI_EXPORT string16 ElideUrl(const GURL& url,
42 const gfx::Font& font, 43 const gfx::Font& font,
43 int available_pixel_width, 44 int available_pixel_width,
44 const std::string& languages); 45 const std::string& languages);
45 46
47 // Elides only the username portion of the email, if possible, so that the
48 // overall email is at most max_email_length characters (e.g.
Alexei Svitkine (slow) 2012/02/28 15:46:22 Please variables parameter names in comments with
49 // longusername@host.com --> longuser...@host.com for max_email_length == 20).
50 // If the domain name by itself already has more characters than available,
51 // we elide the domain name in the middle so that only max_email_length / 2
Alexei Svitkine (slow) 2012/02/28 15:46:22 Nit: Please rephrase in a way that avoids using "w
52 // characters remain. We then proceed with the regular eliding described above.
53 // In any scenario: the string returned will never be longer than
54 // max_email_length including the inserted ellipses; and the elided strings
55 // will have at least one character remaining on either side of the '@'(other
56 // than the ellipsis-es).
57 // This function assumes max_email_length is >= 5.
58 UI_EXPORT string16 ElideEmail(const string16& email,
59 size_t max_email_length);
sail 2012/02/28 18:37:20 Eliding using character length is incorrect. Elidi
60
46 enum ElideBehavior { 61 enum ElideBehavior {
47 // Add ellipsis at the end of the string. 62 // Add ellipsis at the end of the string.
48 ELIDE_AT_END, 63 ELIDE_AT_END,
49 // Add ellipsis in the middle of the string. 64 // Add ellipsis in the middle of the string.
50 ELIDE_IN_MIDDLE, 65 ELIDE_IN_MIDDLE,
51 // Truncate the end of the string. 66 // Truncate the end of the string.
52 TRUNCATE_AT_END 67 TRUNCATE_AT_END
53 }; 68 };
54 69
55 // Elides |text| to fit in |available_pixel_width| according to the specified 70 // Elides |text| to fit in |available_pixel_width| according to the specified
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 // Truncates the string to length characters. This breaks the string at 184 // Truncates the string to length characters. This breaks the string at
170 // the first word break before length, adding the horizontal ellipsis 185 // the first word break before length, adding the horizontal ellipsis
171 // character (unicode character 0x2026) to render ... 186 // character (unicode character 0x2026) to render ...
172 // The supplied string is returned if the string has length characters or 187 // The supplied string is returned if the string has length characters or
173 // less. 188 // less.
174 UI_EXPORT string16 TruncateString(const string16& string, size_t length); 189 UI_EXPORT string16 TruncateString(const string16& string, size_t length);
175 190
176 } // namespace ui 191 } // namespace ui
177 192
178 #endif // UI_BASE_TEXT_TEXT_ELIDER_H_ 193 #endif // UI_BASE_TEXT_TEXT_ELIDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698