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

Side by Side Diff: views/view_text_utils.cc

Issue 2811032: Revert 50784 - Canvas refactoring part 3.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 10 years, 6 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 | « views/view.cc ('k') | views/view_unittest.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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "views/view_text_utils.h" 5 #include "views/view_text_utils.h"
6 6
7 #include "app/bidi_line_iterator.h" 7 #include "app/bidi_line_iterator.h"
8 #include "base/i18n/rtl.h" 8 #include "base/i18n/rtl.h"
9 #include "base/i18n/word_iterator.h" 9 #include "base/i18n/word_iterator.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/utf_string_conversions.h" 11 #include "base/utf_string_conversions.h"
12 #include "gfx/canvas_skia.h" 12 #include "gfx/canvas.h"
13 #include "gfx/color_utils.h" 13 #include "gfx/color_utils.h"
14 #include "gfx/size.h" 14 #include "gfx/size.h"
15 #include "views/controls/label.h" 15 #include "views/controls/label.h"
16 #include "views/controls/link.h" 16 #include "views/controls/link.h"
17 17
18 namespace view_text_utils { 18 namespace view_text_utils {
19 19
20 void DrawTextAndPositionUrl(gfx::Canvas* canvas, 20 void DrawTextAndPositionUrl(gfx::Canvas* canvas,
21 views::Label* label, 21 views::Label* label,
22 const std::wstring& text, 22 const std::wstring& text,
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 // iterate to the next line breaking opportunity. 111 // iterate to the next line breaking opportunity.
112 while (iter.Advance()) { 112 while (iter.Advance()) {
113 // Get the word and figure out the dimensions. 113 // Get the word and figure out the dimensions.
114 std::wstring word; 114 std::wstring word;
115 if (!ltr_within_rtl) 115 if (!ltr_within_rtl)
116 word = UTF16ToWide(iter.GetWord()); // Get the next word. 116 word = UTF16ToWide(iter.GetWord()); // Get the next word.
117 else 117 else
118 word = text; // Draw the whole text at once. 118 word = text; // Draw the whole text at once.
119 119
120 int w = font.GetStringWidth(word), h = font.height(); 120 int w = font.GetStringWidth(word), h = font.height();
121 gfx::CanvasSkia::SizeStringInt(word, font, &w, &h, flags); 121 canvas->SizeStringInt(word, font, &w, &h, flags);
122 122
123 // If we exceed the boundaries, we need to wrap. 123 // If we exceed the boundaries, we need to wrap.
124 WrapIfWordDoesntFit(w, font.height(), position, bounds); 124 WrapIfWordDoesntFit(w, font.height(), position, bounds);
125 125
126 int x = label->MirroredXCoordinateInsideView(position->width()) + 126 int x = label->MirroredXCoordinateInsideView(position->width()) +
127 bounds.x(); 127 bounds.x();
128 if (text_direction_is_rtl) { 128 if (text_direction_is_rtl) {
129 x -= w; 129 x -= w;
130 // When drawing LTR strings inside RTL text we need to make sure we 130 // When drawing LTR strings inside RTL text we need to make sure we
131 // draw the trailing space (if one exists after the LTR text) to the 131 // draw the trailing space (if one exists after the LTR text) to the
132 // left of the LTR string. 132 // left of the LTR string.
133 if (ltr_within_rtl && word[word.size() - 1] == L' ') { 133 if (ltr_within_rtl && word[word.size() - 1] == L' ') {
134 int space_w = font.GetStringWidth(L" "), space_h = font.height(); 134 int space_w = font.GetStringWidth(L" "), space_h = font.height();
135 gfx::CanvasSkia::SizeStringInt(L" ", font, &space_w, &space_h, flags); 135 canvas->SizeStringInt(L" ", font, &space_w, &space_h, flags);
136 x += space_w; 136 x += space_w;
137 } 137 }
138 } 138 }
139 int y = position->height() + bounds.y(); 139 int y = position->height() + bounds.y();
140 140
141 // Draw the text on the screen (mirrored, if RTL run). 141 // Draw the text on the screen (mirrored, if RTL run).
142 canvas->DrawStringInt(word, font, text_color, x, y, w, font.height(), 142 canvas->DrawStringInt(word, font, text_color, x, y, w, font.height(),
143 flags); 143 flags);
144 144
145 if (word.size() > 0 && word[word.size() - 1] == L'\x0a') { 145 if (word.size() > 0 && word[word.size() - 1] == L'\x0a') {
(...skipping 14 matching lines...) Expand all
160 int font_height, 160 int font_height,
161 gfx::Size* position, 161 gfx::Size* position,
162 const gfx::Rect& bounds) { 162 const gfx::Rect& bounds) {
163 if (position->width() + word_width > bounds.right()) { 163 if (position->width() + word_width > bounds.right()) {
164 position->set_width(0); 164 position->set_width(0);
165 position->Enlarge(0, font_height); 165 position->Enlarge(0, font_height);
166 } 166 }
167 } 167 }
168 168
169 } // namespace view_text_utils 169 } // namespace view_text_utils
OLDNEW
« no previous file with comments | « views/view.cc ('k') | views/view_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698