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

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

Issue 23769011: Move a bunch of windows stuff from ui/base/win to ui/gfx/win (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Moar bustage. 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/platform_font_win.cc ('k') | ui/gfx/render_text_linux.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/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/utf16_indexing.h"
17 #include "ui/gfx/canvas.h" 16 #include "ui/gfx/canvas.h"
18 #include "ui/gfx/insets.h" 17 #include "ui/gfx/insets.h"
19 #include "ui/gfx/skia_util.h" 18 #include "ui/gfx/skia_util.h"
20 #include "ui/gfx/text_constants.h" 19 #include "ui/gfx/text_constants.h"
21 #include "ui/gfx/text_elider.h" 20 #include "ui/gfx/text_elider.h"
21 #include "ui/gfx/utf16_indexing.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 913 matching lines...) Expand 10 before | Expand all | Expand 10 after
945 SetSelectionModel(SelectionModel( 945 SetSelectionModel(SelectionModel(
946 gfx::Range(select ? selection().start() : cursor, cursor), 946 gfx::Range(select ? selection().start() : cursor, cursor),
947 (cursor == 0) ? CURSOR_FORWARD : CURSOR_BACKWARD)); 947 (cursor == 0) ? CURSOR_FORWARD : CURSOR_BACKWARD));
948 } 948 }
949 949
950 void RenderText::UpdateLayoutText() { 950 void RenderText::UpdateLayoutText() {
951 layout_text_.clear(); 951 layout_text_.clear();
952 952
953 if (obscured_) { 953 if (obscured_) {
954 size_t obscured_text_length = 954 size_t obscured_text_length =
955 static_cast<size_t>(ui::UTF16IndexToOffset(text_, 0, text_.length())); 955 static_cast<size_t>(gfx::UTF16IndexToOffset(text_, 0, text_.length()));
956 layout_text_.assign(obscured_text_length, kPasswordReplacementChar); 956 layout_text_.assign(obscured_text_length, kPasswordReplacementChar);
957 957
958 if (obscured_reveal_index_ >= 0 && 958 if (obscured_reveal_index_ >= 0 &&
959 obscured_reveal_index_ < static_cast<int>(text_.length())) { 959 obscured_reveal_index_ < static_cast<int>(text_.length())) {
960 // Gets the index range in |text_| to be revealed. 960 // Gets the index range in |text_| to be revealed.
961 size_t start = obscured_reveal_index_; 961 size_t start = obscured_reveal_index_;
962 U16_SET_CP_START(text_.data(), 0, start); 962 U16_SET_CP_START(text_.data(), 0, start);
963 size_t end = start; 963 size_t end = start;
964 UChar32 unused_char; 964 UChar32 unused_char;
965 U16_NEXT(text_.data(), end, text_.length(), unused_char); 965 U16_NEXT(text_.data(), end, text_.length(), unused_char);
966 966
967 // Gets the index in |layout_text_| to be replaced. 967 // Gets the index in |layout_text_| to be replaced.
968 const size_t cp_start = 968 const size_t cp_start =
969 static_cast<size_t>(ui::UTF16IndexToOffset(text_, 0, start)); 969 static_cast<size_t>(gfx::UTF16IndexToOffset(text_, 0, start));
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);
(...skipping 48 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/platform_font_win.cc ('k') | ui/gfx/render_text_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698