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

Side by Side Diff: ui/gfx/render_text.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/gfx/canvas_skia.cc ('k') | ui/gfx/text_elider.h » ('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/render_text.h" 5 #include "ui/gfx/render_text.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/i18n/break_iterator.h" 9 #include "base/i18n/break_iterator.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/stl_util.h" 11 #include "base/stl_util.h"
12 #include "third_party/icu/source/common/unicode/rbbi.h" 12 #include "third_party/icu/source/common/unicode/rbbi.h"
13 #include "third_party/icu/source/common/unicode/utf16.h" 13 #include "third_party/icu/source/common/unicode/utf16.h"
14 #include "third_party/skia/include/core/SkTypeface.h" 14 #include "third_party/skia/include/core/SkTypeface.h"
15 #include "third_party/skia/include/effects/SkGradientShader.h" 15 #include "third_party/skia/include/effects/SkGradientShader.h"
16 #include "ui/base/text/text_elider.h"
17 #include "ui/base/text/utf16_indexing.h" 16 #include "ui/base/text/utf16_indexing.h"
18 #include "ui/gfx/canvas.h" 17 #include "ui/gfx/canvas.h"
19 #include "ui/gfx/insets.h" 18 #include "ui/gfx/insets.h"
20 #include "ui/gfx/skia_util.h" 19 #include "ui/gfx/skia_util.h"
21 #include "ui/gfx/text_constants.h" 20 #include "ui/gfx/text_constants.h"
21 #include "ui/gfx/text_elider.h"
22 22
23 namespace gfx { 23 namespace gfx {
24 24
25 namespace { 25 namespace {
26 26
27 // All chars are replaced by this char when the password style is set. 27 // All chars are replaced by this char when the password style is set.
28 // TODO(benrg): GTK uses the first of U+25CF, U+2022, U+2731, U+273A, '*' 28 // TODO(benrg): GTK uses the first of U+25CF, U+2022, U+2731, U+273A, '*'
29 // that's available in the font (find_invisible_char() in gtkentry.c). 29 // that's available in the font (find_invisible_char() in gtkentry.c).
30 const char16 kPasswordReplacementChar = '*'; 30 const char16 kPasswordReplacementChar = '*';
31 31
(...skipping 938 matching lines...) Expand 10 before | Expand all | Expand 10 after
970 if (layout_text_.length() > cp_start) 970 if (layout_text_.length() > cp_start)
971 layout_text_.replace(cp_start, 1, text_.substr(start, end - start)); 971 layout_text_.replace(cp_start, 1, text_.substr(start, end - start));
972 } 972 }
973 } 973 }
974 974
975 const base::string16& text = obscured_ ? layout_text_ : text_; 975 const base::string16& text = obscured_ ? layout_text_ : text_;
976 if (truncate_length_ > 0 && truncate_length_ < text.length()) { 976 if (truncate_length_ > 0 && truncate_length_ < text.length()) {
977 // Truncate the text at a valid character break and append an ellipsis. 977 // Truncate the text at a valid character break and append an ellipsis.
978 icu::StringCharacterIterator iter(text.c_str()); 978 icu::StringCharacterIterator iter(text.c_str());
979 iter.setIndex32(truncate_length_ - 1); 979 iter.setIndex32(truncate_length_ - 1);
980 layout_text_.assign(text.substr(0, iter.getIndex()) + ui::kEllipsisUTF16); 980 layout_text_.assign(text.substr(0, iter.getIndex()) + gfx::kEllipsisUTF16);
981 } 981 }
982 } 982 }
983 983
984 void RenderText::UpdateCachedBoundsAndOffset() { 984 void RenderText::UpdateCachedBoundsAndOffset() {
985 if (cached_bounds_and_offset_valid_) 985 if (cached_bounds_and_offset_valid_)
986 return; 986 return;
987 987
988 // First, set the valid flag true to calculate the current cursor bounds using 988 // First, set the valid flag true to calculate the current cursor bounds using
989 // the stale |display_offset_|. Applying |delta_offset| at the end of this 989 // the stale |display_offset_|. Applying |delta_offset| at the end of this
990 // function will set |cursor_bounds_| and |display_offset_| to correct values. 990 // function will set |cursor_bounds_| and |display_offset_| to correct values.
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1028 cursor_bounds_ += delta_offset; 1028 cursor_bounds_ += delta_offset;
1029 } 1029 }
1030 1030
1031 void RenderText::DrawSelection(Canvas* canvas) { 1031 void RenderText::DrawSelection(Canvas* canvas) {
1032 const std::vector<Rect> sel = GetSubstringBounds(selection()); 1032 const std::vector<Rect> sel = GetSubstringBounds(selection());
1033 for (std::vector<Rect>::const_iterator i = sel.begin(); i < sel.end(); ++i) 1033 for (std::vector<Rect>::const_iterator i = sel.begin(); i < sel.end(); ++i)
1034 canvas->FillRect(*i, selection_background_focused_color_); 1034 canvas->FillRect(*i, selection_background_focused_color_);
1035 } 1035 }
1036 1036
1037 } // namespace gfx 1037 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/canvas_skia.cc ('k') | ui/gfx/text_elider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698