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

Side by Side Diff: printing/printing_utils.cc

Issue 1212883003: Include user email into document title before spooling (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Tue Jul 7 10:19:02 PDT 2015 Created 5 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
« no previous file with comments | « printing/printing_utils.h ('k') | printing/printing_utils_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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "printing/printing_utils.h" 5 #include "printing/printing_utils.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/logging.h"
10
11 #include "base/strings/utf_string_conversions.h"
9 #include "third_party/icu/source/common/unicode/uchar.h" 12 #include "third_party/icu/source/common/unicode/uchar.h"
10 #include "ui/gfx/text_elider.h" 13 #include "ui/gfx/text_elider.h"
11 14
12 namespace {
13 const int kMaxDocumentTitleLength = 50;
14 }
15
16 namespace printing { 15 namespace printing {
17 16
18 base::string16 SimplifyDocumentTitle(const base::string16& title) { 17 namespace {
18
19 const size_t kMaxDocumentTitleLength = 80;
20
21 } // namespace
22
23 base::string16 SimplifyDocumentTitleWithLength(const base::string16& title,
24 size_t length) {
19 base::string16 no_controls(title); 25 base::string16 no_controls(title);
20 no_controls.erase( 26 no_controls.erase(
21 std::remove_if(no_controls.begin(), no_controls.end(), &u_iscntrl), 27 std::remove_if(no_controls.begin(), no_controls.end(), &u_iscntrl),
22 no_controls.end()); 28 no_controls.end());
23 base::string16 result; 29 base::string16 result;
24 gfx::ElideString(no_controls, kMaxDocumentTitleLength, &result); 30 gfx::ElideString(no_controls, static_cast<int>(length), &result);
25 return result; 31 return result;
26 } 32 }
27 33
34 base::string16 FormatDocumentTitleWithOwnerAndLength(
35 const base::string16& owner,
36 const base::string16& title,
37 size_t length) {
38 const base::string16 separator = base::ASCIIToUTF16(": ");
39 DCHECK(separator.size() < length);
40
41 base::string16 short_title =
42 SimplifyDocumentTitleWithLength(owner, length - separator.size());
43 short_title += separator;
44 if (short_title.size() < length) {
45 short_title +=
46 SimplifyDocumentTitleWithLength(title, length - short_title.size());
47 }
48
49 return short_title;
50 }
51
52 base::string16 SimplifyDocumentTitle(const base::string16& title) {
53 return SimplifyDocumentTitleWithLength(title, kMaxDocumentTitleLength);
54 }
55
56 base::string16 FormatDocumentTitleWithOwner(const base::string16& owner,
57 const base::string16& title) {
58 return FormatDocumentTitleWithOwnerAndLength(owner, title,
59 kMaxDocumentTitleLength);
60 }
61
28 } // namespace printing 62 } // namespace printing
OLDNEW
« no previous file with comments | « printing/printing_utils.h ('k') | printing/printing_utils_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698