OLD | NEW |
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/word_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" |
11 #include "gfx/canvas_skia.h" | 11 #include "gfx/canvas_skia.h" |
12 #include "gfx/color_utils.h" | 12 #include "gfx/color_utils.h" |
13 #include "gfx/size.h" | 13 #include "gfx/size.h" |
14 #include "views/controls/label.h" | 14 #include "views/controls/label.h" |
15 #include "views/controls/link.h" | 15 #include "views/controls/link.h" |
16 | 16 |
17 namespace view_text_utils { | 17 namespace view_text_utils { |
18 | 18 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 #if defined(OS_WIN) | 91 #if defined(OS_WIN) |
92 const SkColor text_color = color_utils::GetSysSkColor(COLOR_WINDOWTEXT); | 92 const SkColor text_color = color_utils::GetSysSkColor(COLOR_WINDOWTEXT); |
93 #else | 93 #else |
94 // TODO(beng): source from theme provider. | 94 // TODO(beng): source from theme provider. |
95 const SkColor text_color = SK_ColorBLACK; | 95 const SkColor text_color = SK_ColorBLACK; |
96 #endif | 96 #endif |
97 | 97 |
98 // Iterate through line breaking opportunities (which in English would be | 98 // Iterate through line breaking opportunities (which in English would be |
99 // spaces and such). This tells us where to wrap. | 99 // spaces and such). This tells us where to wrap. |
100 string16 text16(WideToUTF16(text)); | 100 string16 text16(WideToUTF16(text)); |
101 WordIterator iter(&text16, WordIterator::BREAK_LINE); | 101 base::BreakIterator iter(&text16, base::BreakIterator::BREAK_SPACE); |
102 if (!iter.Init()) | 102 if (!iter.Init()) |
103 return; | 103 return; |
104 | 104 |
105 int flags = (text_direction_is_rtl ? gfx::Canvas::TEXT_ALIGN_RIGHT : | 105 int flags = (text_direction_is_rtl ? gfx::Canvas::TEXT_ALIGN_RIGHT : |
106 gfx::Canvas::TEXT_ALIGN_LEFT); | 106 gfx::Canvas::TEXT_ALIGN_LEFT); |
107 flags |= gfx::Canvas::MULTI_LINE | gfx::Canvas::HIDE_PREFIX; | 107 flags |= gfx::Canvas::MULTI_LINE | gfx::Canvas::HIDE_PREFIX; |
108 | 108 |
109 // Iterate over each word in the text, or put in a more locale-neutral way: | 109 // Iterate over each word in the text, or put in a more locale-neutral way: |
110 // iterate to the next line breaking opportunity. | 110 // iterate to the next line breaking opportunity. |
111 while (iter.Advance()) { | 111 while (iter.Advance()) { |
112 // Get the word and figure out the dimensions. | 112 // Get the word and figure out the dimensions. |
113 std::wstring word; | 113 std::wstring word; |
114 if (!ltr_within_rtl) | 114 if (!ltr_within_rtl) |
115 word = UTF16ToWide(iter.GetWord()); // Get the next word. | 115 word = UTF16ToWide(iter.GetString()); // Get the next word. |
116 else | 116 else |
117 word = text; // Draw the whole text at once. | 117 word = text; // 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(WideToUTF16Hack(word), font, &w, &h, flags); | 120 gfx::CanvasSkia::SizeStringInt(WideToUTF16Hack(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->MirroredXCoordinateInsideView(position->width()) + |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 |
OLD | NEW |