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

Side by Side Diff: ui/gfx/canvas_skia.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/base/text/text_elider_unittest.cc ('k') | ui/gfx/render_text.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 #include "ui/gfx/canvas.h" 5 #include "ui/gfx/canvas.h"
6 6
7 #include "base/i18n/rtl.h" 7 #include "base/i18n/rtl.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "ui/base/text/text_elider.h"
11 #include "ui/gfx/font_list.h" 10 #include "ui/gfx/font_list.h"
12 #include "ui/gfx/insets.h" 11 #include "ui/gfx/insets.h"
13 #include "ui/gfx/range/range.h" 12 #include "ui/gfx/range/range.h"
14 #include "ui/gfx/rect.h" 13 #include "ui/gfx/rect.h"
15 #include "ui/gfx/render_text.h" 14 #include "ui/gfx/render_text.h"
16 #include "ui/gfx/shadow_value.h" 15 #include "ui/gfx/shadow_value.h"
16 #include "ui/gfx/text_elider.h"
17 #include "ui/gfx/text_utils.h" 17 #include "ui/gfx/text_utils.h"
18 18
19 namespace gfx { 19 namespace gfx {
20 20
21 namespace { 21 namespace {
22 22
23 // If necessary, wraps |text| with RTL/LTR directionality characters based on 23 // If necessary, wraps |text| with RTL/LTR directionality characters based on
24 // |flags| and |text| content. 24 // |flags| and |text| content.
25 // Returns true if the text will be rendered right-to-left. 25 // Returns true if the text will be rendered right-to-left.
26 // TODO(msw): Nix this, now that RenderTextWin supports directionality directly. 26 // TODO(msw): Nix this, now that RenderTextWin supports directionality directly.
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 } 96 }
97 97
98 // Elides |text| and adjusts |range| appropriately. If eliding causes |range| 98 // Elides |text| and adjusts |range| appropriately. If eliding causes |range|
99 // to no longer point to the same character in |text|, |range| is made invalid. 99 // to no longer point to the same character in |text|, |range| is made invalid.
100 void ElideTextAndAdjustRange(const FontList& font_list, 100 void ElideTextAndAdjustRange(const FontList& font_list,
101 int width, 101 int width,
102 base::string16* text, 102 base::string16* text,
103 gfx::Range* range) { 103 gfx::Range* range) {
104 const base::char16 start_char = 104 const base::char16 start_char =
105 (range->IsValid() ? text->at(range->start()) : 0); 105 (range->IsValid() ? text->at(range->start()) : 0);
106 *text = ui::ElideText(*text, font_list, width, ui::ELIDE_AT_END); 106 *text = gfx::ElideText(*text, font_list, width, gfx::ELIDE_AT_END);
107 if (!range->IsValid()) 107 if (!range->IsValid())
108 return; 108 return;
109 if (range->start() >= text->length() || 109 if (range->start() >= text->length() ||
110 text->at(range->start()) != start_char) { 110 text->at(range->start()) != start_char) {
111 *range = gfx::Range::InvalidRange(); 111 *range = gfx::Range::InvalidRange();
112 } 112 }
113 } 113 }
114 114
115 // Updates |render_text| from the specified parameters. 115 // Updates |render_text| from the specified parameters.
116 void UpdateRenderText(const Rect& rect, 116 void UpdateRenderText(const Rect& rect,
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 DCHECK_GE(*height, 0); 176 DCHECK_GE(*height, 0);
177 177
178 flags = AdjustPlatformSpecificFlags(text, flags); 178 flags = AdjustPlatformSpecificFlags(text, flags);
179 179
180 base::string16 adjusted_text = text; 180 base::string16 adjusted_text = text;
181 #if defined(OS_WIN) 181 #if defined(OS_WIN)
182 AdjustStringDirection(flags, &adjusted_text); 182 AdjustStringDirection(flags, &adjusted_text);
183 #endif 183 #endif
184 184
185 if ((flags & MULTI_LINE) && *width != 0) { 185 if ((flags & MULTI_LINE) && *width != 0) {
186 ui::WordWrapBehavior wrap_behavior = ui::TRUNCATE_LONG_WORDS; 186 gfx::WordWrapBehavior wrap_behavior = gfx::TRUNCATE_LONG_WORDS;
187 if (flags & CHARACTER_BREAK) 187 if (flags & CHARACTER_BREAK)
188 wrap_behavior = ui::WRAP_LONG_WORDS; 188 wrap_behavior = gfx::WRAP_LONG_WORDS;
189 else if (!(flags & NO_ELLIPSIS)) 189 else if (!(flags & NO_ELLIPSIS))
190 wrap_behavior = ui::ELIDE_LONG_WORDS; 190 wrap_behavior = gfx::ELIDE_LONG_WORDS;
191 191
192 Rect rect(*width, INT_MAX); 192 Rect rect(*width, INT_MAX);
193 std::vector<base::string16> strings; 193 std::vector<base::string16> strings;
194 ui::ElideRectangleText(adjusted_text, font_list, 194 gfx::ElideRectangleText(adjusted_text, font_list,
195 rect.width(), rect.height(), 195 rect.width(), rect.height(),
196 wrap_behavior, &strings); 196 wrap_behavior, &strings);
197 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); 197 scoped_ptr<RenderText> render_text(RenderText::CreateInstance());
198 UpdateRenderText(rect, base::string16(), font_list, flags, 0, 198 UpdateRenderText(rect, base::string16(), font_list, flags, 0,
199 render_text.get()); 199 render_text.get());
200 200
201 int h = 0; 201 int h = 0;
202 int w = 0; 202 int w = 0;
203 for (size_t i = 0; i < strings.size(); ++i) { 203 for (size_t i = 0; i < strings.size(); ++i) {
204 StripAcceleratorChars(flags, &strings[i]); 204 StripAcceleratorChars(flags, &strings[i]);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 base::string16 adjusted_text = text; 251 base::string16 adjusted_text = text;
252 252
253 #if defined(OS_WIN) 253 #if defined(OS_WIN)
254 AdjustStringDirection(flags, &adjusted_text); 254 AdjustStringDirection(flags, &adjusted_text);
255 #endif 255 #endif
256 256
257 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); 257 scoped_ptr<RenderText> render_text(RenderText::CreateInstance());
258 render_text->SetTextShadows(shadows); 258 render_text->SetTextShadows(shadows);
259 259
260 if (flags & MULTI_LINE) { 260 if (flags & MULTI_LINE) {
261 ui::WordWrapBehavior wrap_behavior = ui::IGNORE_LONG_WORDS; 261 gfx::WordWrapBehavior wrap_behavior = gfx::IGNORE_LONG_WORDS;
262 if (flags & CHARACTER_BREAK) 262 if (flags & CHARACTER_BREAK)
263 wrap_behavior = ui::WRAP_LONG_WORDS; 263 wrap_behavior = gfx::WRAP_LONG_WORDS;
264 else if (!(flags & NO_ELLIPSIS)) 264 else if (!(flags & NO_ELLIPSIS))
265 wrap_behavior = ui::ELIDE_LONG_WORDS; 265 wrap_behavior = gfx::ELIDE_LONG_WORDS;
266 266
267 std::vector<base::string16> strings; 267 std::vector<base::string16> strings;
268 ui::ElideRectangleText(adjusted_text, 268 gfx::ElideRectangleText(adjusted_text,
269 font_list, 269 font_list,
270 text_bounds.width(), text_bounds.height(), 270 text_bounds.width(), text_bounds.height(),
271 wrap_behavior, 271 wrap_behavior,
272 &strings); 272 &strings);
273 273
274 for (size_t i = 0; i < strings.size(); i++) { 274 for (size_t i = 0; i < strings.size(); i++) {
275 gfx::Range range = StripAcceleratorChars(flags, &strings[i]); 275 gfx::Range range = StripAcceleratorChars(flags, &strings[i]);
276 UpdateRenderText(rect, strings[i], font_list, flags, color, 276 UpdateRenderText(rect, strings[i], font_list, flags, color,
277 render_text.get()); 277 render_text.get());
278 int line_padding = 0; 278 int line_padding = 0;
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 size_t desired_characters_to_truncate_from_head, 463 size_t desired_characters_to_truncate_from_head,
464 const Font& font, 464 const Font& font,
465 SkColor color, 465 SkColor color,
466 const Rect& display_rect) { 466 const Rect& display_rect) {
467 DrawFadeTruncatingStringRect(text, truncate_mode, 467 DrawFadeTruncatingStringRect(text, truncate_mode,
468 desired_characters_to_truncate_from_head, 468 desired_characters_to_truncate_from_head,
469 FontList(font), color, display_rect); 469 FontList(font), color, display_rect);
470 } 470 }
471 471
472 } // namespace gfx 472 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/base/text/text_elider_unittest.cc ('k') | ui/gfx/render_text.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698