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

Side by Side Diff: ui/message_center/views/bounded_label.cc

Issue 23731010: Move text_elider to gfx. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Update3 Created 7 years, 3 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 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 "ui/message_center/views/bounded_label.h" 5 #include "ui/message_center/views/bounded_label.h"
6 6
7 #include <limits> 7 #include <limits>
8 8
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
11 #include "ui/base/text/text_elider.h"
12 #include "ui/gfx/canvas.h" 11 #include "ui/gfx/canvas.h"
12 #include "ui/gfx/text_elider.h"
13 #include "ui/views/controls/label.h" 13 #include "ui/views/controls/label.h"
14 14
15 namespace { 15 namespace {
16 16
17 const size_t kPreferredLinesCacheSize = 10; 17 const size_t kPreferredLinesCacheSize = 10;
18 const size_t kPreferredSizeCacheSize = 10; 18 const size_t kPreferredSizeCacheSize = 10;
19 19
20 } // namespace 20 } // namespace
21 21
22 namespace message_center { 22 namespace message_center {
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 height = (lines + 1) * line_height; 136 height = (lines + 1) * line_height;
137 } 137 }
138 138
139 // Try to ensure that the width is no smaller than the width of the text's 139 // Try to ensure that the width is no smaller than the width of the text's
140 // characters to avoid the http://crbug.com/237700 infinite loop. 140 // characters to avoid the http://crbug.com/237700 infinite loop.
141 // TODO(dharcourt): Remove when http://crbug.com/237700 is fixed. 141 // TODO(dharcourt): Remove when http://crbug.com/237700 is fixed.
142 width = std::max(width, 2 * font().GetStringWidth(UTF8ToUTF16("W"))); 142 width = std::max(width, 2 * font().GetStringWidth(UTF8ToUTF16("W")));
143 143
144 // Wrap, using INT_MAX for -1 widths that indicate no wrapping. 144 // Wrap, using INT_MAX for -1 widths that indicate no wrapping.
145 std::vector<string16> wrapped; 145 std::vector<string16> wrapped;
146 ui::ElideRectangleText(text(), font(), 146 gfx::ElideRectangleText(text(), font(),
147 (width < 0) ? std::numeric_limits<int>::max() : width, 147 (width < 0) ? std::numeric_limits<int>::max() : width,
148 height, ui::WRAP_LONG_WORDS, &wrapped); 148 height, gfx::WRAP_LONG_WORDS, &wrapped);
149 149
150 // Elide if necessary. 150 // Elide if necessary.
151 if (lines > 0 && wrapped.size() > static_cast<unsigned int>(lines)) { 151 if (lines > 0 && wrapped.size() > static_cast<unsigned int>(lines)) {
152 // Add an ellipsis to the last line. If this ellipsis makes the last line 152 // Add an ellipsis to the last line. If this ellipsis makes the last line
153 // too wide, that line will be further elided by the ui::ElideText below, 153 // too wide, that line will be further elided by the gfx::ElideText below,
154 // so for example "ABC" could become "ABC..." and then "AB...". 154 // so for example "ABC" could become "ABC..." and then "AB...".
155 string16 last = wrapped[lines - 1] + UTF8ToUTF16(ui::kEllipsis); 155 string16 last = wrapped[lines - 1] + UTF8ToUTF16(gfx::kEllipsis);
156 if (width > 0 && font().GetStringWidth(last) > width) 156 if (width > 0 && font().GetStringWidth(last) > width)
157 last = ui::ElideText(last, font(), width, ui::ELIDE_AT_END); 157 last = gfx::ElideText(last, font(), width, gfx::ELIDE_AT_END);
158 wrapped.resize(lines - 1); 158 wrapped.resize(lines - 1);
159 wrapped.push_back(last); 159 wrapped.push_back(last);
160 } 160 }
161 161
162 return wrapped; 162 return wrapped;
163 } 163 }
164 164
165 void InnerBoundedLabel::OnBoundsChanged(const gfx::Rect& previous_bounds) { 165 void InnerBoundedLabel::OnBoundsChanged(const gfx::Rect& previous_bounds) {
166 ClearCaches(); 166 ClearCaches();
167 views::Label::OnBoundsChanged(previous_bounds); 167 views::Label::OnBoundsChanged(previous_bounds);
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 338
339 void BoundedLabel::OnNativeThemeChanged(const ui::NativeTheme* theme) { 339 void BoundedLabel::OnNativeThemeChanged(const ui::NativeTheme* theme) {
340 label_->SetNativeTheme(theme); 340 label_->SetNativeTheme(theme);
341 } 341 }
342 342
343 string16 BoundedLabel::GetWrappedTextForTest(int width, int lines) { 343 string16 BoundedLabel::GetWrappedTextForTest(int width, int lines) {
344 return JoinString(label_->GetWrappedText(width, lines), '\n'); 344 return JoinString(label_->GetWrappedText(width, lines), '\n');
345 } 345 }
346 346
347 } // namespace message_center 347 } // namespace message_center
OLDNEW
« no previous file with comments | « ui/message_center/cocoa/notification_controller.mm ('k') | ui/message_center/views/notification_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698