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

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

Issue 374253002: Strip carriage return from find text; show newline symbols. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Restore char16 arrays for cross platform support. Created 6 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/find_bar/find_tab_helper.cc ('k') | no next file » | 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/render_text.h" 5 #include "ui/gfx/render_text.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <climits> 8 #include <climits>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/i18n/break_iterator.h" 11 #include "base/i18n/break_iterator.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/stl_util.h" 13 #include "base/stl_util.h"
14 #include "base/strings/string_util.h"
14 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
15 #include "third_party/icu/source/common/unicode/rbbi.h" 16 #include "third_party/icu/source/common/unicode/rbbi.h"
16 #include "third_party/icu/source/common/unicode/utf16.h" 17 #include "third_party/icu/source/common/unicode/utf16.h"
17 #include "third_party/skia/include/core/SkTypeface.h" 18 #include "third_party/skia/include/core/SkTypeface.h"
18 #include "third_party/skia/include/effects/SkGradientShader.h" 19 #include "third_party/skia/include/effects/SkGradientShader.h"
19 #include "ui/gfx/canvas.h" 20 #include "ui/gfx/canvas.h"
20 #include "ui/gfx/insets.h" 21 #include "ui/gfx/insets.h"
21 #include "ui/gfx/render_text_harfbuzz.h" 22 #include "ui/gfx/render_text_harfbuzz.h"
22 #include "ui/gfx/scoped_canvas.h" 23 #include "ui/gfx/scoped_canvas.h"
23 #include "ui/gfx/skia_util.h" 24 #include "ui/gfx/skia_util.h"
(...skipping 1140 matching lines...) Expand 10 before | Expand all | Expand 10 after
1164 } 1165 }
1165 1166
1166 if (elide_behavior_ != TRUNCATE && elide_behavior_ != FADE_TAIL && 1167 if (elide_behavior_ != TRUNCATE && elide_behavior_ != FADE_TAIL &&
1167 display_rect_.width() > 0 && !layout_text_.empty() && 1168 display_rect_.width() > 0 && !layout_text_.empty() &&
1168 GetContentWidth() > display_rect_.width()) { 1169 GetContentWidth() > display_rect_.width()) {
1169 // This doesn't trim styles so ellipsis may get rendered as a different 1170 // This doesn't trim styles so ellipsis may get rendered as a different
1170 // style than the preceding text. See crbug.com/327850. 1171 // style than the preceding text. See crbug.com/327850.
1171 layout_text_.assign(ElideText(layout_text_)); 1172 layout_text_.assign(ElideText(layout_text_));
1172 } 1173 }
1173 1174
1175 // Replace the newline character with a newline symbol in single line mode.
1176 static const base::char16 kNewline[] = { '\n', 0 };
1177 static const base::char16 kNewlineSymbol[] = { 0x2424, 0 };
1178 if (!multiline_)
1179 base::ReplaceChars(layout_text_, kNewline, kNewlineSymbol, &layout_text_);
1180
1174 ResetLayout(); 1181 ResetLayout();
1175 } 1182 }
1176 1183
1177 // TODO(skanuj): Fix code duplication with ElideText in ui/gfx/text_elider.cc 1184 // TODO(skanuj): Fix code duplication with ElideText in ui/gfx/text_elider.cc
1178 // See crbug.com/327846 1185 // See crbug.com/327846
1179 base::string16 RenderText::ElideText(const base::string16& text) { 1186 base::string16 RenderText::ElideText(const base::string16& text) {
1180 const bool insert_ellipsis = (elide_behavior_ != TRUNCATE); 1187 const bool insert_ellipsis = (elide_behavior_ != TRUNCATE);
1181 // Create a RenderText copy with attributes that affect the rendering width. 1188 // Create a RenderText copy with attributes that affect the rendering width.
1182 scoped_ptr<RenderText> render_text(CreateInstance()); 1189 scoped_ptr<RenderText> render_text(CreateInstance());
1183 render_text->SetFontList(font_list_); 1190 render_text->SetFontList(font_list_);
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
1315 cursor_bounds_ += delta_offset; 1322 cursor_bounds_ += delta_offset;
1316 } 1323 }
1317 1324
1318 void RenderText::DrawSelection(Canvas* canvas) { 1325 void RenderText::DrawSelection(Canvas* canvas) {
1319 const std::vector<Rect> sel = GetSubstringBounds(selection()); 1326 const std::vector<Rect> sel = GetSubstringBounds(selection());
1320 for (std::vector<Rect>::const_iterator i = sel.begin(); i < sel.end(); ++i) 1327 for (std::vector<Rect>::const_iterator i = sel.begin(); i < sel.end(); ++i)
1321 canvas->FillRect(*i, selection_background_focused_color_); 1328 canvas->FillRect(*i, selection_background_focused_color_);
1322 } 1329 }
1323 1330
1324 } // namespace gfx 1331 } // namespace gfx
OLDNEW
« no previous file with comments | « chrome/browser/ui/find_bar/find_tab_helper.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698