OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/i18n/bidi_line_iterator.h" | 7 #include "base/i18n/bidi_line_iterator.h" |
8 #include "base/i18n/break_iterator.h" | 8 #include "base/i18n/break_iterator.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 word = iter.GetString(); // Get the next word. | 115 word = iter.GetString(); // Get the next word. |
116 else | 116 else |
117 word = text16; // Draw the whole text at once. | 117 word = text16; // Draw the whole text at once. |
118 | 118 |
119 int w = font.GetStringWidth(word), h = font.GetHeight(); | 119 int w = font.GetStringWidth(word), h = font.GetHeight(); |
120 gfx::CanvasSkia::SizeStringInt(word, font, &w, &h, flags); | 120 gfx::CanvasSkia::SizeStringInt(word, font, &w, &h, flags); |
121 | 121 |
122 // If we exceed the boundaries, we need to wrap. | 122 // If we exceed the boundaries, we need to wrap. |
123 WrapIfWordDoesntFit(w, font.GetHeight(), position, bounds); | 123 WrapIfWordDoesntFit(w, font.GetHeight(), position, bounds); |
124 | 124 |
125 int x = label->MirroredXCoordinateInsideView(position->width()) + | 125 int x = label->GetMirroredXInView(position->width()) + bounds.x(); |
126 bounds.x(); | |
127 if (text_direction_is_rtl) { | 126 if (text_direction_is_rtl) { |
128 x -= w; | 127 x -= w; |
129 // When drawing LTR strings inside RTL text we need to make sure we | 128 // When drawing LTR strings inside RTL text we need to make sure we |
130 // draw the trailing space (if one exists after the LTR text) to the | 129 // draw the trailing space (if one exists after the LTR text) to the |
131 // left of the LTR string. | 130 // left of the LTR string. |
132 if (ltr_within_rtl && word[word.size() - 1] == ' ') { | 131 if (ltr_within_rtl && word[word.size() - 1] == ' ') { |
133 int space_w = font.GetStringWidth(ASCIIToUTF16(" ")); | 132 int space_w = font.GetStringWidth(ASCIIToUTF16(" ")); |
134 int space_h = font.GetHeight(); | 133 int space_h = font.GetHeight(); |
135 gfx::CanvasSkia::SizeStringInt(ASCIIToUTF16(" "), font, &space_w, | 134 gfx::CanvasSkia::SizeStringInt(ASCIIToUTF16(" "), font, &space_w, |
136 &space_h, flags); | 135 &space_h, flags); |
(...skipping 24 matching lines...) Expand all Loading... |
161 int font_height, | 160 int font_height, |
162 gfx::Size* position, | 161 gfx::Size* position, |
163 const gfx::Rect& bounds) { | 162 const gfx::Rect& bounds) { |
164 if (position->width() + word_width > bounds.right()) { | 163 if (position->width() + word_width > bounds.right()) { |
165 position->set_width(0); | 164 position->set_width(0); |
166 position->Enlarge(0, font_height); | 165 position->Enlarge(0, font_height); |
167 } | 166 } |
168 } | 167 } |
169 | 168 |
170 } // namespace view_text_utils | 169 } // namespace view_text_utils |
OLD | NEW |