| OLD | NEW |
| 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_GFX_TEXT_ELIDER_H_ | 7 #ifndef UI_GFX_TEXT_ELIDER_H_ |
| 8 #define UI_GFX_TEXT_ELIDER_H_ | 8 #define UI_GFX_TEXT_ELIDER_H_ |
| 9 | 9 |
| 10 #include <string> | 10 #include <string> |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 // This function guarantees that the string returned will contain at least one | 34 // This function guarantees that the string returned will contain at least one |
| 35 // character, other than the ellipses, on either side of the '@'. If it is | 35 // character, other than the ellipses, on either side of the '@'. If it is |
| 36 // impossible to achieve these requirements: only an ellipsis will be returned. | 36 // impossible to achieve these requirements: only an ellipsis will be returned. |
| 37 // If possible: this elides only the username portion of the |email|. Otherwise, | 37 // If possible: this elides only the username portion of the |email|. Otherwise, |
| 38 // the domain is elided in the middle so that it splits the available width | 38 // the domain is elided in the middle so that it splits the available width |
| 39 // equally with the elided username (should the username be short enough that it | 39 // equally with the elided username (should the username be short enough that it |
| 40 // doesn't need half the available width: the elided domain will occupy that | 40 // doesn't need half the available width: the elided domain will occupy that |
| 41 // extra width). | 41 // extra width). |
| 42 GFX_EXPORT string16 ElideEmail(const string16& email, | 42 GFX_EXPORT string16 ElideEmail(const string16& email, |
| 43 const gfx::FontList& font_list, | 43 const gfx::FontList& font_list, |
| 44 int available_pixel_width); | 44 float available_pixel_width); |
| 45 // Obsolete version. Use the above version which takes gfx::FontList. | 45 // Obsolete version. Use the above version which takes gfx::FontList. |
| 46 GFX_EXPORT string16 ElideEmail(const string16& email, | 46 GFX_EXPORT string16 ElideEmail(const string16& email, |
| 47 const gfx::Font& font, | 47 const gfx::Font& font, |
| 48 int available_pixel_width); | 48 float available_pixel_width); |
| 49 | 49 |
| 50 // This function takes a GURL object and elides it. It returns a string | 50 // This function takes a GURL object and elides it. It returns a string |
| 51 // which composed of parts from subdomain, domain, path, filename and query. | 51 // which composed of parts from subdomain, domain, path, filename and query. |
| 52 // A "..." is added automatically at the end if the elided string is bigger | 52 // A "..." is added automatically at the end if the elided string is bigger |
| 53 // than the |available_pixel_width|. For |available_pixel_width| == 0, a | 53 // than the |available_pixel_width|. For |available_pixel_width| == 0, a |
| 54 // formatted, but un-elided, string is returned. |languages| is a comma | 54 // formatted, but un-elided, string is returned. |languages| is a comma |
| 55 // separated list of ISO 639 language codes and is used to determine what | 55 // separated list of ISO 639 language codes and is used to determine what |
| 56 // characters are understood by a user. It should come from | 56 // characters are understood by a user. It should come from |
| 57 // |prefs::kAcceptLanguages|. | 57 // |prefs::kAcceptLanguages|. |
| 58 // | 58 // |
| 59 // Note: in RTL locales, if the URL returned by this function is going to be | 59 // Note: in RTL locales, if the URL returned by this function is going to be |
| 60 // displayed in the UI, then it is likely that the string needs to be marked | 60 // displayed in the UI, then it is likely that the string needs to be marked |
| 61 // as an LTR string (using base::i18n::WrapStringWithLTRFormatting()) so that it | 61 // as an LTR string (using base::i18n::WrapStringWithLTRFormatting()) so that it |
| 62 // is displayed properly in an RTL context. Please refer to | 62 // is displayed properly in an RTL context. Please refer to |
| 63 // http://crbug.com/6487 for more information. | 63 // http://crbug.com/6487 for more information. |
| 64 GFX_EXPORT string16 ElideUrl(const GURL& url, | 64 GFX_EXPORT string16 ElideUrl(const GURL& url, |
| 65 const gfx::FontList& font_list, | 65 const gfx::FontList& font_list, |
| 66 int available_pixel_width, | 66 float available_pixel_width, |
| 67 const std::string& languages); | 67 const std::string& languages); |
| 68 // Obsolete version. Use the above version which takes gfx::FontList. | 68 // Obsolete version. Use the above version which takes gfx::FontList. |
| 69 GFX_EXPORT string16 ElideUrl(const GURL& url, | 69 GFX_EXPORT string16 ElideUrl(const GURL& url, |
| 70 const gfx::Font& font, | 70 const gfx::Font& font, |
| 71 int available_pixel_width, | 71 float available_pixel_width, |
| 72 const std::string& languages); | 72 const std::string& languages); |
| 73 | 73 |
| 74 enum ElideBehavior { | 74 enum ElideBehavior { |
| 75 // Add ellipsis at the end of the string. | 75 // Add ellipsis at the end of the string. |
| 76 ELIDE_AT_END, | 76 ELIDE_AT_END, |
| 77 // Add ellipsis in the middle of the string. | 77 // Add ellipsis in the middle of the string. |
| 78 ELIDE_IN_MIDDLE, | 78 ELIDE_IN_MIDDLE, |
| 79 // Truncate the end of the string. | 79 // Truncate the end of the string. |
| 80 TRUNCATE_AT_END | 80 TRUNCATE_AT_END |
| 81 }; | 81 }; |
| 82 | 82 |
| 83 // Elides |text| to fit in |available_pixel_width| according to the specified | 83 // Elides |text| to fit in |available_pixel_width| according to the specified |
| 84 // |elide_behavior|. | 84 // |elide_behavior|. |
| 85 GFX_EXPORT string16 ElideText(const string16& text, | 85 GFX_EXPORT string16 ElideText(const string16& text, |
| 86 const gfx::FontList& font_list, | 86 const gfx::FontList& font_list, |
| 87 int available_pixel_width, | 87 float available_pixel_width, |
| 88 ElideBehavior elide_behavior); | 88 ElideBehavior elide_behavior); |
| 89 // Obsolete version. Use the above version which takes gfx::FontList. | 89 // Obsolete version. Use the above version which takes gfx::FontList. |
| 90 GFX_EXPORT string16 ElideText(const string16& text, | 90 GFX_EXPORT string16 ElideText(const string16& text, |
| 91 const gfx::Font& font, | 91 const gfx::Font& font, |
| 92 int available_pixel_width, | 92 float available_pixel_width, |
| 93 ElideBehavior elide_behavior); | 93 ElideBehavior elide_behavior); |
| 94 | 94 |
| 95 // Elide a filename to fit a given pixel width, with an emphasis on not hiding | 95 // Elide a filename to fit a given pixel width, with an emphasis on not hiding |
| 96 // the extension unless we have to. If filename contains a path, the path will | 96 // the extension unless we have to. If filename contains a path, the path will |
| 97 // be removed if filename doesn't fit into available_pixel_width. The elided | 97 // be removed if filename doesn't fit into available_pixel_width. The elided |
| 98 // filename is forced to have LTR directionality, which means that in RTL UI | 98 // filename is forced to have LTR directionality, which means that in RTL UI |
| 99 // the elided filename is wrapped with LRE (Left-To-Right Embedding) mark and | 99 // the elided filename is wrapped with LRE (Left-To-Right Embedding) mark and |
| 100 // PDF (Pop Directional Formatting) mark. | 100 // PDF (Pop Directional Formatting) mark. |
| 101 GFX_EXPORT string16 ElideFilename(const base::FilePath& filename, | 101 GFX_EXPORT string16 ElideFilename(const base::FilePath& filename, |
| 102 const gfx::FontList& font_list, | 102 const gfx::FontList& font_list, |
| 103 int available_pixel_width); | 103 float available_pixel_width); |
| 104 // Obsolete version. Use the above version which takes gfx::FontList. | 104 // Obsolete version. Use the above version which takes gfx::FontList. |
| 105 GFX_EXPORT string16 ElideFilename(const base::FilePath& filename, | 105 GFX_EXPORT string16 ElideFilename(const base::FilePath& filename, |
| 106 const gfx::Font& font, | 106 const gfx::Font& font, |
| 107 int available_pixel_width); | 107 float available_pixel_width); |
| 108 | 108 |
| 109 // SortedDisplayURL maintains a string from a URL suitable for display to the | 109 // SortedDisplayURL maintains a string from a URL suitable for display to the |
| 110 // use. SortedDisplayURL also provides a function used for comparing two | 110 // use. SortedDisplayURL also provides a function used for comparing two |
| 111 // SortedDisplayURLs for use in visually ordering the SortedDisplayURLs. | 111 // SortedDisplayURLs for use in visually ordering the SortedDisplayURLs. |
| 112 // | 112 // |
| 113 // SortedDisplayURL is relatively cheap and supports value semantics. | 113 // SortedDisplayURL is relatively cheap and supports value semantics. |
| 114 class GFX_EXPORT SortedDisplayURL { | 114 class GFX_EXPORT SortedDisplayURL { |
| 115 public: | 115 public: |
| 116 SortedDisplayURL(const GURL& url, const std::string& languages); | 116 SortedDisplayURL(const GURL& url, const std::string& languages); |
| 117 SortedDisplayURL(); | 117 SortedDisplayURL(); |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 // Reformats |text| into output vector |lines| so that the resulting text fits | 201 // Reformats |text| into output vector |lines| so that the resulting text fits |
| 202 // into an |available_pixel_width| by |available_pixel_height| rectangle with | 202 // into an |available_pixel_width| by |available_pixel_height| rectangle with |
| 203 // the specified |font_list|. Input newlines are respected, but lines that are | 203 // the specified |font_list|. Input newlines are respected, but lines that are |
| 204 // too long are broken into pieces. For words that are too wide to fit on a | 204 // too long are broken into pieces. For words that are too wide to fit on a |
| 205 // single line, the wrapping behavior can be specified with the |wrap_behavior| | 205 // single line, the wrapping behavior can be specified with the |wrap_behavior| |
| 206 // param. Returns a combination of |ReformattingResultFlags| that indicate | 206 // param. Returns a combination of |ReformattingResultFlags| that indicate |
| 207 // whether the given rectangle had insufficient space to accommodate |texŧ|, | 207 // whether the given rectangle had insufficient space to accommodate |texŧ|, |
| 208 // leading to elision or truncation (and not just reformatting). | 208 // leading to elision or truncation (and not just reformatting). |
| 209 GFX_EXPORT int ElideRectangleText(const string16& text, | 209 GFX_EXPORT int ElideRectangleText(const string16& text, |
| 210 const gfx::FontList& font_list, | 210 const gfx::FontList& font_list, |
| 211 int available_pixel_width, | 211 float available_pixel_width, |
| 212 int available_pixel_height, | 212 float available_pixel_height, |
| 213 WordWrapBehavior wrap_behavior, | 213 WordWrapBehavior wrap_behavior, |
| 214 std::vector<string16>* lines); | 214 std::vector<string16>* lines); |
| 215 // Obsolete version. Use the above version which takes gfx::FontList. | 215 // Obsolete version. Use the above version which takes gfx::FontList. |
| 216 GFX_EXPORT int ElideRectangleText(const string16& text, | 216 GFX_EXPORT int ElideRectangleText(const string16& text, |
| 217 const gfx::Font& font, | 217 const gfx::Font& font, |
| 218 int available_pixel_width, | 218 float available_pixel_width, |
| 219 int available_pixel_height, | 219 float available_pixel_height, |
| 220 WordWrapBehavior wrap_behavior, | 220 WordWrapBehavior wrap_behavior, |
| 221 std::vector<string16>* lines); | 221 std::vector<string16>* lines); |
| 222 | 222 |
| 223 // Truncates the string to length characters. This breaks the string at | 223 // Truncates the string to length characters. This breaks the string at |
| 224 // the first word break before length, adding the horizontal ellipsis | 224 // the first word break before length, adding the horizontal ellipsis |
| 225 // character (unicode character 0x2026) to render ... | 225 // character (unicode character 0x2026) to render ... |
| 226 // The supplied string is returned if the string has length characters or | 226 // The supplied string is returned if the string has length characters or |
| 227 // less. | 227 // less. |
| 228 GFX_EXPORT string16 TruncateString(const string16& string, size_t length); | 228 GFX_EXPORT string16 TruncateString(const string16& string, size_t length); |
| 229 | 229 |
| 230 } // namespace gfx | 230 } // namespace gfx |
| 231 | 231 |
| 232 #endif // UI_GFX_TEXT_ELIDER_H_ | 232 #endif // UI_GFX_TEXT_ELIDER_H_ |
| OLD | NEW |