Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 #ifndef UI_BASE_TEXT_TEXT_ELIDER_H_ | 5 #ifndef UI_BASE_TEXT_TEXT_ELIDER_H_ |
| 6 #define UI_BASE_TEXT_TEXT_ELIDER_H_ | 6 #define UI_BASE_TEXT_TEXT_ELIDER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <unicode/coll.h> | 9 #include <unicode/coll.h> |
| 10 #include <unicode/uchar.h> | 10 #include <unicode/uchar.h> |
| 11 | 11 |
| 12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/string16.h" | 13 #include "base/string16.h" |
| 14 #include "ui/gfx/font.h" | 14 #include "ui/gfx/font.h" |
| 15 #include "third_party/skia/include/core/SkPaint.h" | |
| 16 #include "third_party/skia/include/core/SkScalar.h" | |
| 15 | 17 |
| 16 class FilePath; | 18 class FilePath; |
| 17 class GURL; | 19 class GURL; |
| 18 | 20 |
| 19 namespace ui { | 21 namespace ui { |
| 20 | 22 |
| 21 extern const char kEllipsis[]; | 23 extern const char kEllipsis[]; |
| 22 | 24 |
| 25 // Specifies what type of object is passed into the Elide functions. | |
| 26 // These are used to measure the width of the text string. | |
| 27 enum ObjectType { | |
| 28 Skia_Paint, // SkPaint object. | |
| 29 GFX_Font // gfx::Font object. | |
| 30 }; | |
| 31 | |
| 23 // This function takes a GURL object and elides it. It returns a string | 32 // This function takes a GURL object and elides it. It returns a string |
| 24 // which composed of parts from subdomain, domain, path, filename and query. | 33 // which composed of parts from subdomain, domain, path, filename and query. |
| 25 // A "..." is added automatically at the end if the elided string is bigger | 34 // A "..." is added automatically at the end if the elided string is bigger |
| 26 // than the available pixel width. For available pixel width = 0, empty | 35 // than the available pixel width. For available pixel width = 0, empty |
| 27 // string is returned. |languages| is a comma separted list of ISO 639 | 36 // string is returned. |languages| is a comma separted list of ISO 639 |
| 28 // language codes and is used to determine what characters are understood | 37 // language codes and is used to determine what characters are understood |
| 29 // by a user. It should come from |prefs::kAcceptLanguages|. | 38 // by a user. It should come from |prefs::kAcceptLanguages|. |
| 30 // | 39 // |
| 31 // Note: in RTL locales, if the URL returned by this function is going to be | 40 // Note: in RTL locales, if the URL returned by this function is going to be |
| 32 // displayed in the UI, then it is likely that the string needs to be marked | 41 // displayed in the UI, then it is likely that the string needs to be marked |
| 33 // as an LTR string (using base::i18n::WrapStringWithLTRFormatting()) so that it | 42 // as an LTR string (using base::i18n::WrapStringWithLTRFormatting()) so that it |
| 34 // is displayed properly in an RTL context. Please refer to | 43 // is displayed properly in an RTL context. Please refer to |
| 35 // http://crbug.com/6487 for more information. | 44 // http://crbug.com/6487 for more information. |
| 36 string16 ElideUrl(const GURL& url, | 45 string16 ElideUrl(const GURL& url, |
| 37 const gfx::Font& font, | 46 const gfx::Font& font, |
| 38 int available_pixel_width, | 47 int available_pixel_width, |
| 39 const std::string& languages); | 48 const std::string& languages); |
| 40 | 49 |
| 50 // Overloaded function. | |
| 51 // Takes a SkPaint object to determine the width of the text on the screen. | |
| 52 string16 ElideUrl(const GURL& url, | |
| 53 const SkPaint paint, | |
| 54 SkScalar available_point_width, | |
| 55 const std::string& languages); | |
| 56 | |
| 57 // Overloaded function. | |
| 58 // The |font_or_paint| argument is a pointer to either a Font or Paint object | |
| 59 // and that is specified in the |object_type| parameter. | |
| 60 // Depending on what type of object is passed, the appropriate function is | |
| 61 // called to measure the width of the text. | |
| 62 string16 ElideUrl(const GURL& url, | |
|
Lei Zhang
2011/07/12 22:04:50
You shouldn't expose the internal implementation.
Aayush Kumar
2011/07/13 21:52:16
Done.
| |
| 63 void* font_or_paint, | |
| 64 int available_pixel_width, | |
| 65 const std::string& languages, | |
| 66 ObjectType object_type); | |
| 67 | |
| 41 // Elides |text| to fit in |available_pixel_width|. If |elide_in_middle| is | 68 // Elides |text| to fit in |available_pixel_width|. If |elide_in_middle| is |
| 42 // set the ellipsis is placed in the middle of the string; otherwise it is | 69 // set the ellipsis is placed in the middle of the string; otherwise it is |
| 43 // placed at the end. | 70 // placed at the end. |
| 44 string16 ElideText(const string16& text, | 71 string16 ElideText(const string16& text, |
| 45 const gfx::Font& font, | 72 const gfx::Font& font, |
| 46 int available_pixel_width, | 73 int available_pixel_width, |
| 47 bool elide_in_middle); | 74 bool elide_in_middle); |
| 48 | 75 |
| 76 // Overloaded function. | |
| 77 // Takes a SkPaint object to determine the width of the text on the screen. | |
| 78 string16 ElideText(const string16& text, | |
| 79 const SkPaint paint, | |
| 80 SkScalar available_point_width, | |
| 81 bool elide_in_middle); | |
| 82 | |
| 83 // Overloaded function. | |
| 84 // The |font_or_paint| argument is a pointer to either a Font or Paint object | |
| 85 // and that is specified in the |object_type| parameter. | |
| 86 // Depending on what type of object is passed, the appropriate function is | |
| 87 // called to measure the width of the text. | |
| 88 string16 ElideText(const string16& text, | |
| 89 void* font_or_paint, | |
| 90 SkScalar available_pixel_width, | |
| 91 bool elide_in_middle, | |
| 92 ObjectType object_type); | |
| 93 | |
| 49 // Elide a filename to fit a given pixel width, with an emphasis on not hiding | 94 // Elide a filename to fit a given pixel width, with an emphasis on not hiding |
| 50 // the extension unless we have to. If filename contains a path, the path will | 95 // the extension unless we have to. If filename contains a path, the path will |
| 51 // be removed if filename doesn't fit into available_pixel_width. The elided | 96 // be removed if filename doesn't fit into available_pixel_width. The elided |
| 52 // filename is forced to have LTR directionality, which means that in RTL UI | 97 // filename is forced to have LTR directionality, which means that in RTL UI |
| 53 // the elided filename is wrapped with LRE (Left-To-Right Embedding) mark and | 98 // the elided filename is wrapped with LRE (Left-To-Right Embedding) mark and |
| 54 // PDF (Pop Directional Formatting) mark. | 99 // PDF (Pop Directional Formatting) mark. |
| 55 string16 ElideFilename(const FilePath& filename, | 100 string16 ElideFilename(const FilePath& filename, |
| 56 const gfx::Font& font, | 101 const gfx::Font& font, |
| 57 int available_pixel_width); | 102 int available_pixel_width); |
| 58 | 103 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 113 // intra-word (respecting UTF-16 surrogate pairs) as necssary. Truncation | 158 // intra-word (respecting UTF-16 surrogate pairs) as necssary. Truncation |
| 114 // (indicated by an added 3 dots) occurs if the result is still too long. | 159 // (indicated by an added 3 dots) occurs if the result is still too long. |
| 115 // Returns true if the input had to be truncated (and not just reformatted). | 160 // Returns true if the input had to be truncated (and not just reformatted). |
| 116 bool ElideRectangleString(const string16& input, size_t max_rows, | 161 bool ElideRectangleString(const string16& input, size_t max_rows, |
| 117 size_t max_cols, bool strict, string16* output); | 162 size_t max_cols, bool strict, string16* output); |
| 118 | 163 |
| 119 | 164 |
| 120 } // namespace ui | 165 } // namespace ui |
| 121 | 166 |
| 122 #endif // UI_BASE_TEXT_TEXT_ELIDER_H_ | 167 #endif // UI_BASE_TEXT_TEXT_ELIDER_H_ |
| OLD | NEW |