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

Side by Side Diff: ui/views/controls/styled_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
« no previous file with comments | « ui/views/controls/label.cc ('k') | ui/views/corewm/tooltip_controller.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 "ui/views/controls/styled_label.h" 5 #include "ui/views/controls/styled_label.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "ui/base/text/text_elider.h" 10 #include "ui/gfx/text_elider.h"
11 #include "ui/native_theme/native_theme.h" 11 #include "ui/native_theme/native_theme.h"
12 #include "ui/views/controls/label.h" 12 #include "ui/views/controls/label.h"
13 #include "ui/views/controls/link.h" 13 #include "ui/views/controls/link.h"
14 #include "ui/views/controls/styled_label_listener.h" 14 #include "ui/views/controls/styled_label_listener.h"
15 15
16 namespace views { 16 namespace views {
17 17
18 namespace { 18 namespace {
19 19
20 // Calculates the height of a line of text. Currently returns the height of 20 // Calculates the height of a line of text. Currently returns the height of
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 const gfx::Rect chunk_bounds(x, 0, width - x, 2 * line_height); 181 const gfx::Rect chunk_bounds(x, 0, width - x, 2 * line_height);
182 std::vector<string16> substrings; 182 std::vector<string16> substrings;
183 gfx::Font text_font; 183 gfx::Font text_font;
184 // If the start of the remaining text is inside a styled range, the font 184 // If the start of the remaining text is inside a styled range, the font
185 // style may differ from the base font. The font specified by the range 185 // style may differ from the base font. The font specified by the range
186 // should be used when eliding text. 186 // should be used when eliding text.
187 if (position >= range.start()) { 187 if (position >= range.start()) {
188 text_font = 188 text_font =
189 text_font.DeriveFont(0, style_ranges.top().style_info.font_style); 189 text_font.DeriveFont(0, style_ranges.top().style_info.font_style);
190 } 190 }
191 ui::ElideRectangleText(remaining_string, 191 gfx::ElideRectangleText(remaining_string,
192 text_font, 192 text_font,
193 chunk_bounds.width(), 193 chunk_bounds.width(),
194 chunk_bounds.height(), 194 chunk_bounds.height(),
195 ui::IGNORE_LONG_WORDS, 195 gfx::IGNORE_LONG_WORDS,
196 &substrings); 196 &substrings);
197 197
198 DCHECK(!substrings.empty()); 198 DCHECK(!substrings.empty());
199 string16 chunk = substrings[0]; 199 string16 chunk = substrings[0];
200 if (chunk.empty()) { 200 if (chunk.empty()) {
201 // Nothing fits on this line. Start a new line. 201 // Nothing fits on this line. Start a new line.
202 // If x is 0, first line may have leading whitespace that doesn't fit in a 202 // If x is 0, first line may have leading whitespace that doesn't fit in a
203 // single line, so try trimming those. Otherwise there is no room for 203 // single line, so try trimming those. Otherwise there is no room for
204 // anything; abort. 204 // anything; abort.
205 if (x == 0) { 205 if (x == 0) {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 } 261 }
262 x += view_size.width() - 2 * overlap; 262 x += view_size.width() - 2 * overlap;
263 263
264 remaining_string = remaining_string.substr(chunk.size()); 264 remaining_string = remaining_string.substr(chunk.size());
265 } 265 }
266 266
267 return (line + 1) * line_height + GetInsets().height(); 267 return (line + 1) * line_height + GetInsets().height();
268 } 268 }
269 269
270 } // namespace views 270 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/label.cc ('k') | ui/views/corewm/tooltip_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698