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

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

Issue 6257006: Move a bunch of random other files to src/ui/base... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 11 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
« no previous file with comments | « ui/base/text/text_elider.h ('k') | ui/base/text/text_elider_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 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 #include <vector> 5 #include <vector>
6 6
7 #include "app/text_elider.h" 7 #include "ui/base/text/text_elider.h"
8
8 #include "base/file_path.h" 9 #include "base/file_path.h"
9 #include "base/i18n/break_iterator.h" 10 #include "base/i18n/break_iterator.h"
10 #include "base/i18n/char_iterator.h" 11 #include "base/i18n/char_iterator.h"
11 #include "base/i18n/rtl.h" 12 #include "base/i18n/rtl.h"
12 #include "base/string_split.h" 13 #include "base/string_split.h"
13 #include "base/string_util.h" 14 #include "base/string_util.h"
14 #include "base/sys_string_conversions.h" 15 #include "base/sys_string_conversions.h"
15 #include "base/utf_string_conversions.h" 16 #include "base/utf_string_conversions.h"
16 #include "gfx/font.h" 17 #include "gfx/font.h"
17 #include "googleurl/src/gurl.h" 18 #include "googleurl/src/gurl.h"
18 #include "net/base/escape.h" 19 #include "net/base/escape.h"
19 #include "net/base/net_util.h" 20 #include "net/base/net_util.h"
20 #include "net/base/registry_controlled_domain.h" 21 #include "net/base/registry_controlled_domain.h"
21 22
23 namespace ui {
22 24
23 namespace { 25 namespace {
24 26
25 const char* kEllipsis = "\xE2\x80\xA6"; 27 const char* kEllipsis = "\xE2\x80\xA6";
26 28
27 // Cuts |text| to be |length| characters long. If |cut_in_middle| is true, the 29 // Cuts |text| to be |length| characters long. If |cut_in_middle| is true, the
28 // middle of the string is removed to leave equal-length pieces from the 30 // middle of the string is removed to leave equal-length pieces from the
29 // beginning and end of the string; otherwise, the end of the string is removed 31 // beginning and end of the string; otherwise, the end of the string is removed
30 // and only the beginning remains. If |insert_ellipsis| is true, then an 32 // and only the beginning remains. If |insert_ellipsis| is true, then an
31 // ellipsis character will by inserted at the cut point. 33 // ellipsis character will by inserted at the cut point.
32 string16 CutString(const string16& text, 34 string16 CutString(const string16& text,
33 size_t length, 35 size_t length,
34 bool cut_in_middle, 36 bool cut_in_middle,
35 bool insert_ellipsis) { 37 bool insert_ellipsis) {
36 // TODO(tony): This is wrong, it might split the string in the middle of a 38 // TODO(tony): This is wrong, it might split the string in the middle of a
37 // surrogate pair. 39 // surrogate pair.
38 const string16 kInsert = insert_ellipsis ? UTF8ToUTF16(kEllipsis) : 40 const string16 kInsert = insert_ellipsis ? UTF8ToUTF16(kEllipsis) :
39 ASCIIToUTF16(""); 41 ASCIIToUTF16("");
40 if (!cut_in_middle) 42 if (!cut_in_middle)
41 return text.substr(0, length) + kInsert; 43 return text.substr(0, length) + kInsert;
42 // We put the extra character, if any, before the cut. 44 // We put the extra character, if any, before the cut.
43 const size_t half_length = length / 2; 45 const size_t half_length = length / 2;
44 return text.substr(0, length - half_length) + kInsert + 46 return text.substr(0, length - half_length) + kInsert +
45 text.substr(text.length() - half_length, half_length); 47 text.substr(text.length() - half_length, half_length);
46 } 48 }
47 49
48 } // namespace 50 } // namespace
49 51
50 namespace gfx {
51
52 // This function takes a GURL object and elides it. It returns a string 52 // This function takes a GURL object and elides it. It returns a string
53 // which composed of parts from subdomain, domain, path, filename and query. 53 // which composed of parts from subdomain, domain, path, filename and query.
54 // A "..." is added automatically at the end if the elided string is bigger 54 // A "..." is added automatically at the end if the elided string is bigger
55 // than the available pixel width. For available pixel width = 0, a formatted, 55 // than the available pixel width. For available pixel width = 0, a formatted,
56 // but un-elided, string is returned. 56 // but un-elided, string is returned.
57 // 57 //
58 // TODO(pkasting): http://b/119635 This whole function gets 58 // TODO(pkasting): http://b/119635 This whole function gets
59 // kerning/ligatures/etc. issues potentially wrong by assuming that the width of 59 // kerning/ligatures/etc. issues potentially wrong by assuming that the width of
60 // a rendered string is always the sum of the widths of its substrings. Also I 60 // a rendered string is always the sum of the widths of its substrings. Also I
61 // suspect it could be made simpler. 61 // suspect it could be made simpler.
(...skipping 593 matching lines...) Expand 10 before | Expand all | Expand 10 after
655 namespace gfx { 655 namespace gfx {
656 656
657 bool ElideRectangleString(const string16& input, size_t max_rows, 657 bool ElideRectangleString(const string16& input, size_t max_rows,
658 size_t max_cols, string16* output) { 658 size_t max_cols, string16* output) {
659 RectangleString rect(max_rows, max_cols, output); 659 RectangleString rect(max_rows, max_cols, output);
660 rect.Init(); 660 rect.Init();
661 rect.AddString(input); 661 rect.AddString(input);
662 return rect.Finalize(); 662 return rect.Finalize();
663 } 663 }
664 664
665 } // namespace gfx 665 } // namespace ui
666
OLDNEW
« no previous file with comments | « ui/base/text/text_elider.h ('k') | ui/base/text/text_elider_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698