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

Side by Side Diff: ui/base/text/text_elider.h

Issue 7328011: Introduce ui.dll / libui.so for the component build. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 5 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 #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 "ui/ui_api.h"
15 16
16 class FilePath; 17 class FilePath;
17 class GURL; 18 class GURL;
18 19
19 namespace ui { 20 namespace ui {
20 21
21 extern const char kEllipsis[]; 22 UI_API extern const char kEllipsis[];
22 23
23 // This function takes a GURL object and elides it. It returns a string 24 // 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. 25 // 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 26 // 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 27 // than the available pixel width. For available pixel width = 0, empty
27 // string is returned. |languages| is a comma separted list of ISO 639 28 // string is returned. |languages| is a comma separted list of ISO 639
28 // language codes and is used to determine what characters are understood 29 // language codes and is used to determine what characters are understood
29 // by a user. It should come from |prefs::kAcceptLanguages|. 30 // by a user. It should come from |prefs::kAcceptLanguages|.
30 // 31 //
31 // Note: in RTL locales, if the URL returned by this function is going to be 32 // 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 33 // 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 34 // as an LTR string (using base::i18n::WrapStringWithLTRFormatting()) so that it
34 // is displayed properly in an RTL context. Please refer to 35 // is displayed properly in an RTL context. Please refer to
35 // http://crbug.com/6487 for more information. 36 // http://crbug.com/6487 for more information.
36 string16 ElideUrl(const GURL& url, 37 UI_API string16 ElideUrl(const GURL& url,
37 const gfx::Font& font, 38 const gfx::Font& font,
38 int available_pixel_width, 39 int available_pixel_width,
39 const std::string& languages); 40 const std::string& languages);
40 41
41 // Elides |text| to fit in |available_pixel_width|. If |elide_in_middle| is 42 // 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 43 // set the ellipsis is placed in the middle of the string; otherwise it is
43 // placed at the end. 44 // placed at the end.
44 string16 ElideText(const string16& text, 45 UI_API string16 ElideText(const string16& text,
45 const gfx::Font& font, 46 const gfx::Font& font,
46 int available_pixel_width, 47 int available_pixel_width,
47 bool elide_in_middle); 48 bool elide_in_middle);
48 49
49 // Elide a filename to fit a given pixel width, with an emphasis on not hiding 50 // 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 51 // 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 52 // 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 53 // 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 54 // the elided filename is wrapped with LRE (Left-To-Right Embedding) mark and
54 // PDF (Pop Directional Formatting) mark. 55 // PDF (Pop Directional Formatting) mark.
55 string16 ElideFilename(const FilePath& filename, 56 UI_API string16 ElideFilename(const FilePath& filename,
56 const gfx::Font& font, 57 const gfx::Font& font,
57 int available_pixel_width); 58 int available_pixel_width);
58 59
59 // SortedDisplayURL maintains a string from a URL suitable for display to the 60 // SortedDisplayURL maintains a string from a URL suitable for display to the
60 // use. SortedDisplayURL also provides a function used for comparing two 61 // use. SortedDisplayURL also provides a function used for comparing two
61 // SortedDisplayURLs for use in visually ordering the SortedDisplayURLs. 62 // SortedDisplayURLs for use in visually ordering the SortedDisplayURLs.
62 // 63 //
63 // SortedDisplayURL is relatively cheap and supports value semantics. 64 // SortedDisplayURL is relatively cheap and supports value semantics.
64 class SortedDisplayURL { 65 class UI_API SortedDisplayURL {
65 public: 66 public:
66 SortedDisplayURL(const GURL& url, const std::string& languages); 67 SortedDisplayURL(const GURL& url, const std::string& languages);
67 SortedDisplayURL(); 68 SortedDisplayURL();
68 ~SortedDisplayURL(); 69 ~SortedDisplayURL();
69 70
70 // Compares this SortedDisplayURL to |url| using |collator|. Returns a value 71 // Compares this SortedDisplayURL to |url| using |collator|. Returns a value
71 // < 0, = 1 or > 0 as to whether this url is less then, equal to or greater 72 // < 0, = 1 or > 0 as to whether this url is less then, equal to or greater
72 // than the supplied url. 73 // than the supplied url.
73 int Compare(const SortedDisplayURL& other, icu::Collator* collator) const; 74 int Compare(const SortedDisplayURL& other, icu::Collator* collator) const;
74 75
(...skipping 20 matching lines...) Expand all
95 // not pixels. 96 // not pixels.
96 97
97 // If the size of |input| is more than |max_len|, this function returns 98 // If the size of |input| is more than |max_len|, this function returns
98 // true and |input| is shortened into |output| by removing chars in the 99 // true and |input| is shortened into |output| by removing chars in the
99 // middle (they are replaced with up to 3 dots, as size permits). 100 // middle (they are replaced with up to 3 dots, as size permits).
100 // Ex: ElideString(ASCIIToUTF16("Hello"), 10, &str) puts Hello in str and 101 // Ex: ElideString(ASCIIToUTF16("Hello"), 10, &str) puts Hello in str and
101 // returns false. ElideString(ASCIIToUTF16("Hello my name is Tom"), 10, &str) 102 // returns false. ElideString(ASCIIToUTF16("Hello my name is Tom"), 10, &str)
102 // puts "Hell...Tom" in str and returns true. 103 // puts "Hell...Tom" in str and returns true.
103 // TODO(tsepez): Doesn't handle UTF-16 surrogate pairs properly. 104 // TODO(tsepez): Doesn't handle UTF-16 surrogate pairs properly.
104 // TODO(tsepez): Doesn't handle bidi properly. 105 // TODO(tsepez): Doesn't handle bidi properly.
105 bool ElideString(const string16& input, int max_len, string16* output); 106 UI_API bool ElideString(const string16& input, int max_len,
107 string16* output);
106 108
107 // Reformat |input| into |output| so that it fits into a |max_rows| by 109 // Reformat |input| into |output| so that it fits into a |max_rows| by
108 // |max_cols| rectangle of characters. Input newlines are respected, but 110 // |max_cols| rectangle of characters. Input newlines are respected, but
109 // lines that are too long are broken into pieces. If |strict| is true, 111 // lines that are too long are broken into pieces. If |strict| is true,
110 // we break first at naturally occuring whitespace boundaries, otherwise 112 // we break first at naturally occuring whitespace boundaries, otherwise
111 // we assume some other mechanism will do this in approximately the same 113 // we assume some other mechanism will do this in approximately the same
112 // spot after the fact. If the word itself is too long, we always break 114 // spot after the fact. If the word itself is too long, we always break
113 // intra-word (respecting UTF-16 surrogate pairs) as necssary. Truncation 115 // 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. 116 // (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). 117 // Returns true if the input had to be truncated (and not just reformatted).
116 bool ElideRectangleString(const string16& input, size_t max_rows, 118 UI_API bool ElideRectangleString(const string16& input, size_t max_rows,
117 size_t max_cols, bool strict, string16* output); 119 size_t max_cols, bool strict,
120 string16* output);
118 121
119 122
120 } // namespace ui 123 } // namespace ui
121 124
122 #endif // UI_BASE_TEXT_TEXT_ELIDER_H_ 125 #endif // UI_BASE_TEXT_TEXT_ELIDER_H_
OLDNEW
« no previous file with comments | « ui/base/text/bytes_formatting.h ('k') | ui/base/theme_provider.h » ('j') | ui/ui.gyp » ('J')

Powered by Google App Engine
This is Rietveld 408576698