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

Side by Side Diff: ui/gfx/text_elider.cc

Issue 916203002: Reduce the number of text reshaping in RenderText (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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 | « ui/gfx/render_text_unittest.cc ('k') | ui/views/controls/textfield/textfield.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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 // This file implements utility functions for eliding and formatting UI text. 5 // This file implements utility functions for eliding and formatting UI text.
6 // 6 //
7 // Note that several of the functions declared in text_elider.h are implemented 7 // Note that several of the functions declared in text_elider.h are implemented
8 // in this file using helper classes in an unnamed namespace. 8 // in this file using helper classes in an unnamed namespace.
9 9
10 #include "ui/gfx/text_elider.h" 10 #include "ui/gfx/text_elider.h"
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 render_text->SetCursorEnabled(false); 214 render_text->SetCursorEnabled(false);
215 // Do not bother accurately sizing strings over 5000 characters here, for 215 // Do not bother accurately sizing strings over 5000 characters here, for
216 // performance purposes. This matches the behavior of Canvas::SizeStringFloat. 216 // performance purposes. This matches the behavior of Canvas::SizeStringFloat.
217 render_text->set_truncate_length(5000); 217 render_text->set_truncate_length(5000);
218 render_text->SetFontList(font_list); 218 render_text->SetFontList(font_list);
219 available_pixel_width = std::ceil(available_pixel_width); 219 available_pixel_width = std::ceil(available_pixel_width);
220 render_text->SetDisplayRect( 220 render_text->SetDisplayRect(
221 gfx::ToEnclosingRect(gfx::RectF(gfx::SizeF(available_pixel_width, 1)))); 221 gfx::ToEnclosingRect(gfx::RectF(gfx::SizeF(available_pixel_width, 1))));
222 render_text->SetElideBehavior(behavior); 222 render_text->SetElideBehavior(behavior);
223 render_text->SetText(text); 223 render_text->SetText(text);
224 return render_text->layout_text(); 224 return render_text->GetDisplayText();
225 #else 225 #else
226 DCHECK_NE(behavior, FADE_TAIL); 226 DCHECK_NE(behavior, FADE_TAIL);
227 if (text.empty() || behavior == FADE_TAIL || behavior == NO_ELIDE || 227 if (text.empty() || behavior == FADE_TAIL || behavior == NO_ELIDE ||
228 GetStringWidthF(text, font_list) <= available_pixel_width) { 228 GetStringWidthF(text, font_list) <= available_pixel_width) {
229 return text; 229 return text;
230 } 230 }
231 if (behavior == ELIDE_EMAIL) 231 if (behavior == ELIDE_EMAIL)
232 return ElideEmail(text, font_list, available_pixel_width); 232 return ElideEmail(text, font_list, available_pixel_width);
233 233
234 const bool elide_in_middle = (behavior == ELIDE_MIDDLE); 234 const bool elide_in_middle = (behavior == ELIDE_MIDDLE);
(...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after
822 index = char_iterator.getIndex(); 822 index = char_iterator.getIndex();
823 } else { 823 } else {
824 // String has leading whitespace, return the elide string. 824 // String has leading whitespace, return the elide string.
825 return kElideString; 825 return kElideString;
826 } 826 }
827 827
828 return string.substr(0, index) + kElideString; 828 return string.substr(0, index) + kElideString;
829 } 829 }
830 830
831 } // namespace gfx 831 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/render_text_unittest.cc ('k') | ui/views/controls/textfield/textfield.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698