OLD | NEW |
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/format_macros.h" | 9 #include "base/format_macros.h" |
10 #include "base/i18n/break_iterator.h" | 10 #include "base/i18n/break_iterator.h" |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 render_text->ApplyStyle(ITALIC, true, Range(3, 6)); | 164 render_text->ApplyStyle(ITALIC, true, Range(3, 6)); |
165 render_text->ApplyStyle(ITALIC, true, Range(7, text_length)); | 165 render_text->ApplyStyle(ITALIC, true, Range(7, text_length)); |
166 std::vector<std::pair<size_t, bool> > expected_italic; | 166 std::vector<std::pair<size_t, bool> > expected_italic; |
167 expected_italic.push_back(std::pair<size_t, bool>(0, true)); | 167 expected_italic.push_back(std::pair<size_t, bool>(0, true)); |
168 expected_italic.push_back(std::pair<size_t, bool>(2, false)); | 168 expected_italic.push_back(std::pair<size_t, bool>(2, false)); |
169 expected_italic.push_back(std::pair<size_t, bool>(3, true)); | 169 expected_italic.push_back(std::pair<size_t, bool>(3, true)); |
170 expected_italic.push_back(std::pair<size_t, bool>(6, false)); | 170 expected_italic.push_back(std::pair<size_t, bool>(6, false)); |
171 expected_italic.push_back(std::pair<size_t, bool>(7, true)); | 171 expected_italic.push_back(std::pair<size_t, bool>(7, true)); |
172 EXPECT_TRUE(render_text->styles()[ITALIC].EqualsForTesting(expected_italic)); | 172 EXPECT_TRUE(render_text->styles()[ITALIC].EqualsForTesting(expected_italic)); |
173 | 173 |
174 // Truncating the text should trim any corresponding breaks. | 174 // Changing the text should clear any breaks except for the first one. |
175 render_text->SetText(ASCIIToUTF16("0123456")); | 175 render_text->SetText(ASCIIToUTF16("0123456")); |
176 expected_italic.resize(4); | 176 expected_italic.resize(1); |
177 EXPECT_TRUE(render_text->styles()[ITALIC].EqualsForTesting(expected_italic)); | 177 EXPECT_TRUE(render_text->styles()[ITALIC].EqualsForTesting(expected_italic)); |
178 render_text->SetText(ASCIIToUTF16("01234")); | 178 render_text->ApplyStyle(ITALIC, false, Range(2, 4)); |
179 expected_italic.resize(3); | 179 render_text->SetText(ASCIIToUTF16("012345678")); |
| 180 EXPECT_TRUE(render_text->styles()[ITALIC].EqualsForTesting(expected_italic)); |
| 181 render_text->ApplyStyle(ITALIC, false, Range(0, 1)); |
| 182 render_text->SetText(ASCIIToUTF16("0123456")); |
| 183 expected_italic.begin()->second = false; |
| 184 EXPECT_TRUE(render_text->styles()[ITALIC].EqualsForTesting(expected_italic)); |
| 185 render_text->ApplyStyle(ITALIC, true, Range(2, 4)); |
| 186 render_text->SetText(ASCIIToUTF16("012345678")); |
180 EXPECT_TRUE(render_text->styles()[ITALIC].EqualsForTesting(expected_italic)); | 187 EXPECT_TRUE(render_text->styles()[ITALIC].EqualsForTesting(expected_italic)); |
181 | 188 |
182 // Appending text should extend the terminal styles without changing breaks. | 189 // TODO(tmoniuszko): Enable when RenderTextMac::IsValidCursorIndex is |
183 render_text->SetText(ASCIIToUTF16("012345678")); | 190 // implemented. |
184 EXPECT_TRUE(render_text->styles()[ITALIC].EqualsForTesting(expected_italic)); | 191 #if !defined(OS_MACOSX) |
| 192 // Styles shouldn't be changed mid-grapheme. |
| 193 render_text->SetText(WideToUTF16( |
| 194 L"0" L"\x0915\x093f" L"1" L"\x0915\x093f" L"2")); |
| 195 render_text->ApplyStyle(UNDERLINE, true, Range(2, 5)); |
| 196 std::vector<std::pair<size_t, bool> > expected_underline; |
| 197 expected_underline.push_back(std::pair<size_t, bool>(0, false)); |
| 198 expected_underline.push_back(std::pair<size_t, bool>(1, true)); |
| 199 expected_underline.push_back(std::pair<size_t, bool>(6, false)); |
| 200 EXPECT_TRUE(render_text->styles()[UNDERLINE].EqualsForTesting( |
| 201 expected_underline)); |
| 202 #endif // OS_MACOSX |
185 } | 203 } |
186 | 204 |
187 #if defined(OS_LINUX) && !defined(USE_OZONE) | 205 #if defined(OS_LINUX) && !defined(USE_OZONE) |
188 TEST_F(RenderTextTest, PangoAttributes) { | 206 TEST_F(RenderTextTest, PangoAttributes) { |
189 scoped_ptr<RenderText> render_text(RenderText::CreateNativeInstance()); | 207 scoped_ptr<RenderText> render_text(RenderText::CreateNativeInstance()); |
190 render_text->SetText(ASCIIToUTF16("012345678")); | 208 render_text->SetText(ASCIIToUTF16("012345678")); |
191 | 209 |
192 // Apply ranged BOLD/ITALIC styles and check the resulting Pango attributes. | 210 // Apply ranged BOLD/ITALIC styles and check the resulting Pango attributes. |
193 render_text->ApplyStyle(BOLD, true, Range(2, 4)); | 211 render_text->ApplyStyle(BOLD, true, Range(2, 4)); |
194 render_text->ApplyStyle(ITALIC, true, Range(1, 3)); | 212 render_text->ApplyStyle(ITALIC, true, Range(1, 3)); |
(...skipping 2090 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2285 EXPECT_EQ(Range(0, 0), run.CharRangeToGlyphRange(Range(4, 5))); | 2303 EXPECT_EQ(Range(0, 0), run.CharRangeToGlyphRange(Range(4, 5))); |
2286 EXPECT_EQ(Range(0, 0), run.GetGraphemeBounds(iter.get(), 4)); | 2304 EXPECT_EQ(Range(0, 0), run.GetGraphemeBounds(iter.get(), 4)); |
2287 Range chars; | 2305 Range chars; |
2288 Range glyphs; | 2306 Range glyphs; |
2289 run.GetClusterAt(4, &chars, &glyphs); | 2307 run.GetClusterAt(4, &chars, &glyphs); |
2290 EXPECT_EQ(Range(3, 8), chars); | 2308 EXPECT_EQ(Range(3, 8), chars); |
2291 EXPECT_EQ(Range(0, 0), glyphs); | 2309 EXPECT_EQ(Range(0, 0), glyphs); |
2292 } | 2310 } |
2293 | 2311 |
2294 } // namespace gfx | 2312 } // namespace gfx |
OLD | NEW |