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 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 render_text->ApplyStyle(UNDERLINE, true, Range(2, 5)); | 345 render_text->ApplyStyle(UNDERLINE, true, Range(2, 5)); |
346 std::vector<std::pair<size_t, bool> > expected_underline; | 346 std::vector<std::pair<size_t, bool> > expected_underline; |
347 expected_underline.push_back(std::pair<size_t, bool>(0, false)); | 347 expected_underline.push_back(std::pair<size_t, bool>(0, false)); |
348 expected_underline.push_back(std::pair<size_t, bool>(1, true)); | 348 expected_underline.push_back(std::pair<size_t, bool>(1, true)); |
349 expected_underline.push_back(std::pair<size_t, bool>(6, false)); | 349 expected_underline.push_back(std::pair<size_t, bool>(6, false)); |
350 EXPECT_TRUE(render_text->styles()[UNDERLINE].EqualsForTesting( | 350 EXPECT_TRUE(render_text->styles()[UNDERLINE].EqualsForTesting( |
351 expected_underline)); | 351 expected_underline)); |
352 #endif // OS_MACOSX | 352 #endif // OS_MACOSX |
353 } | 353 } |
354 | 354 |
| 355 TEST_F(RenderTextTest, AppendTextKeepsStyles) { |
| 356 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); |
| 357 // Setup basic functionality. |
| 358 render_text->SetText(ASCIIToUTF16("abc")); |
| 359 render_text->ApplyColor(SK_ColorRED, Range(0, 1)); |
| 360 render_text->ApplyBaselineStyle(SUPERSCRIPT, Range(1, 2)); |
| 361 render_text->ApplyStyle(UNDERLINE, true, Range(2, 3)); |
| 362 // Verify basic functionality. |
| 363 std::vector<std::pair<size_t, SkColor>> expected_color; |
| 364 expected_color.push_back(std::pair<size_t, SkColor>(0, SK_ColorRED)); |
| 365 expected_color.push_back(std::pair<size_t, SkColor>(1, SK_ColorBLACK)); |
| 366 EXPECT_TRUE(render_text->colors().EqualsForTesting(expected_color)); |
| 367 std::vector<std::pair<size_t, BaselineStyle>> expected_baseline; |
| 368 expected_baseline.push_back( |
| 369 std::pair<size_t, BaselineStyle>(0, NORMAL_BASELINE)); |
| 370 expected_baseline.push_back(std::pair<size_t, BaselineStyle>(1, SUPERSCRIPT)); |
| 371 expected_baseline.push_back( |
| 372 std::pair<size_t, BaselineStyle>(2, NORMAL_BASELINE)); |
| 373 EXPECT_TRUE(render_text->baselines().EqualsForTesting(expected_baseline)); |
| 374 std::vector<std::pair<size_t, bool>> expected_style; |
| 375 expected_style.push_back(std::pair<size_t, bool>(0, false)); |
| 376 expected_style.push_back(std::pair<size_t, bool>(2, true)); |
| 377 EXPECT_TRUE( |
| 378 render_text->styles()[UNDERLINE].EqualsForTesting(expected_style)); |
| 379 // Ensure AppendText maintains current text styles. |
| 380 render_text->AppendText(ASCIIToUTF16("def")); |
| 381 EXPECT_EQ(render_text->GetDisplayText(), ASCIIToUTF16("abcdef")); |
| 382 EXPECT_TRUE(render_text->colors().EqualsForTesting(expected_color)); |
| 383 EXPECT_TRUE(render_text->baselines().EqualsForTesting(expected_baseline)); |
| 384 EXPECT_TRUE( |
| 385 render_text->styles()[UNDERLINE].EqualsForTesting(expected_style)); |
| 386 } |
| 387 |
355 // TODO(asvitkine): Cursor movements tests disabled on Mac because RenderTextMac | 388 // TODO(asvitkine): Cursor movements tests disabled on Mac because RenderTextMac |
356 // does not implement this yet. http://crbug.com/131618 | 389 // does not implement this yet. http://crbug.com/131618 |
357 #if !defined(OS_MACOSX) | 390 #if !defined(OS_MACOSX) |
358 void TestVisualCursorMotionInObscuredField(RenderText* render_text, | 391 void TestVisualCursorMotionInObscuredField(RenderText* render_text, |
359 const base::string16& text, | 392 const base::string16& text, |
360 bool select) { | 393 bool select) { |
361 ASSERT_TRUE(render_text->obscured()); | 394 ASSERT_TRUE(render_text->obscured()); |
362 render_text->SetText(text); | 395 render_text->SetText(text); |
363 int len = text.length(); | 396 int len = text.length(); |
364 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, select); | 397 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, select); |
(...skipping 2457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2822 string_size.set_width(string_size.width() / 2); | 2855 string_size.set_width(string_size.width() / 2); |
2823 render_text.SetDisplayRect(gfx::Rect(string_size)); | 2856 render_text.SetDisplayRect(gfx::Rect(string_size)); |
2824 render_text.EnsureLayout(); | 2857 render_text.EnsureLayout(); |
2825 CFIndex glyph_count = CTLineGetGlyphCount(render_text.line_); | 2858 CFIndex glyph_count = CTLineGetGlyphCount(render_text.line_); |
2826 EXPECT_GT(text.size(), static_cast<size_t>(glyph_count)); | 2859 EXPECT_GT(text.size(), static_cast<size_t>(glyph_count)); |
2827 EXPECT_NE(0, glyph_count); | 2860 EXPECT_NE(0, glyph_count); |
2828 } | 2861 } |
2829 #endif | 2862 #endif |
2830 | 2863 |
2831 } // namespace gfx | 2864 } // namespace gfx |
OLD | NEW |