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

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

Issue 7348010: Added Header and Footer support using Skia (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Custom length strings being printed 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 "third_party/skia/include/core/SkPaint.h"
15 #include "third_party/skia/include/core/SkScalar.h"
14 #include "ui/gfx/font.h" 16 #include "ui/gfx/font.h"
15 #include "ui/ui_api.h" 17 #include "ui/ui_api.h"
16 18
17 class FilePath; 19 class FilePath;
18 class GURL; 20 class GURL;
19 21
20 namespace ui { 22 namespace ui {
21 23
22 UI_API extern const char kEllipsis[]; 24 UI_API extern const char kEllipsis[];
23 25
26 // Specifies what type of object is passed into the Elide functions.
27 // These are used to measure the width of the text string.
28 enum ObjectType {
29 Skia_Paint, // SkPaint object.
30 GFX_Font // gfx::Font object.
31 };
32
24 // This function takes a GURL object and elides it. It returns a string 33 // This function takes a GURL object and elides it. It returns a string
25 // which composed of parts from subdomain, domain, path, filename and query. 34 // which composed of parts from subdomain, domain, path, filename and query.
26 // A "..." is added automatically at the end if the elided string is bigger 35 // A "..." is added automatically at the end if the elided string is bigger
27 // than the available pixel width. For available pixel width = 0, empty 36 // than the available pixel width. For available pixel width = 0, empty
28 // string is returned. |languages| is a comma separted list of ISO 639 37 // string is returned. |languages| is a comma separted list of ISO 639
29 // language codes and is used to determine what characters are understood 38 // language codes and is used to determine what characters are understood
30 // by a user. It should come from |prefs::kAcceptLanguages|. 39 // by a user. It should come from |prefs::kAcceptLanguages|.
31 // 40 //
32 // Note: in RTL locales, if the URL returned by this function is going to be 41 // Note: in RTL locales, if the URL returned by this function is going to be
33 // displayed in the UI, then it is likely that the string needs to be marked 42 // displayed in the UI, then it is likely that the string needs to be marked
34 // as an LTR string (using base::i18n::WrapStringWithLTRFormatting()) so that it 43 // as an LTR string (using base::i18n::WrapStringWithLTRFormatting()) so that it
35 // is displayed properly in an RTL context. Please refer to 44 // is displayed properly in an RTL context. Please refer to
36 // http://crbug.com/6487 for more information. 45 // http://crbug.com/6487 for more information.
37 UI_API string16 ElideUrl(const GURL& url, 46 UI_API string16 ElideUrl(const GURL& url,
38 const gfx::Font& font, 47 const gfx::Font& font,
39 int available_pixel_width, 48 int available_pixel_width,
40 const std::string& languages); 49 const std::string& languages);
41 50
51 // Overloaded function.
dpapad 2011/07/19 20:34:01 I do not think that this comment is needed. Also c
vandebo (ex-Chrome) 2011/07/19 21:31:20 Yea, this doesn't look like a valid overload.
Aayush Kumar 2011/07/21 21:58:53 Restored changes. On 2011/07/19 21:31:20, vandebo
52 // Takes a SkPaint object to determine the width of the text on the screen.
53 string16 ElideUrl(const GURL& url,
54 const SkPaint paint,
55 SkScalar available_point_width,
56 const std::string& languages);
57
42 // Elides |text| to fit in |available_pixel_width|. If |elide_in_middle| is 58 // Elides |text| to fit in |available_pixel_width|. If |elide_in_middle| is
43 // set the ellipsis is placed in the middle of the string; otherwise it is 59 // set the ellipsis is placed in the middle of the string; otherwise it is
44 // placed at the end. 60 // placed at the end.
45 UI_API string16 ElideText(const string16& text, 61 UI_API string16 ElideText(const string16& text,
46 const gfx::Font& font, 62 const gfx::Font& font,
47 int available_pixel_width, 63 int available_pixel_width,
48 bool elide_in_middle); 64 bool elide_in_middle);
49 65
66 // Overloaded function.
67 // Takes a SkPaint object to determine the width of the text on the screen.
68 string16 ElideText(const string16& text,
69 const SkPaint paint,
70 SkScalar available_point_width,
71 bool elide_in_middle);
72
50 // Elide a filename to fit a given pixel width, with an emphasis on not hiding 73 // Elide a filename to fit a given pixel width, with an emphasis on not hiding
51 // the extension unless we have to. If filename contains a path, the path will 74 // the extension unless we have to. If filename contains a path, the path will
52 // be removed if filename doesn't fit into available_pixel_width. The elided 75 // be removed if filename doesn't fit into available_pixel_width. The elided
53 // filename is forced to have LTR directionality, which means that in RTL UI 76 // filename is forced to have LTR directionality, which means that in RTL UI
54 // the elided filename is wrapped with LRE (Left-To-Right Embedding) mark and 77 // the elided filename is wrapped with LRE (Left-To-Right Embedding) mark and
55 // PDF (Pop Directional Formatting) mark. 78 // PDF (Pop Directional Formatting) mark.
56 UI_API string16 ElideFilename(const FilePath& filename, 79 UI_API string16 ElideFilename(const FilePath& filename,
57 const gfx::Font& font, 80 const gfx::Font& font,
58 int available_pixel_width); 81 int available_pixel_width);
59 82
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 // (indicated by an added 3 dots) occurs if the result is still too long. 139 // (indicated by an added 3 dots) occurs if the result is still too long.
117 // Returns true if the input had to be truncated (and not just reformatted). 140 // Returns true if the input had to be truncated (and not just reformatted).
118 UI_API bool ElideRectangleString(const string16& input, size_t max_rows, 141 UI_API bool ElideRectangleString(const string16& input, size_t max_rows,
119 size_t max_cols, bool strict, 142 size_t max_cols, bool strict,
120 string16* output); 143 string16* output);
121 144
122 145
123 } // namespace ui 146 } // namespace ui
124 147
125 #endif // UI_BASE_TEXT_TEXT_ELIDER_H_ 148 #endif // UI_BASE_TEXT_TEXT_ELIDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698