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, AppendText) { | |
msw
2015/03/24 22:20:59
nit: name AppendTextKeepsStyles
dschuyler
2015/03/24 22:38:12
Done.
| |
356 // Ensure AppendText maintains current text styles. | |
msw
2015/03/24 22:20:59
nit: move this comment down to replace the comment
dschuyler
2015/03/24 22:38:12
Done.
| |
357 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); | |
358 // Setup basic functionality. | |
359 render_text->SetText(ASCIIToUTF16("abc")); | |
360 const SkColor color = SK_ColorRED; | |
msw
2015/03/24 22:20:59
nit: just inline SK_ColorRED here and line 367.
dschuyler
2015/03/24 22:38:12
Done.
| |
361 render_text->ApplyColor(color, Range(1, 2)); | |
msw
2015/03/24 22:20:59
nit: make the text red over range 0-1 (for more co
dschuyler
2015/03/24 22:38:12
Done.
| |
362 render_text->ApplyBaselineStyle(SUPERSCRIPT, Range(1, 2)); | |
363 render_text->ApplyStyle(UNDERLINE, true, Range(1, 2)); | |
msw
2015/03/24 22:20:59
nit: apply underline over range 2-3 (for more cove
dschuyler
2015/03/24 22:38:12
Done.
| |
364 // Verify basic functionality. | |
365 std::vector<std::pair<size_t, SkColor>> expected_color; | |
366 expected_color.push_back(std::pair<size_t, SkColor>(0, SK_ColorBLACK)); | |
367 expected_color.push_back(std::pair<size_t, SkColor>(1, color)); | |
368 expected_color.push_back(std::pair<size_t, SkColor>(2, SK_ColorBLACK)); | |
369 EXPECT_TRUE(render_text->colors().EqualsForTesting(expected_color)); | |
370 std::vector<std::pair<size_t, BaselineStyle>> expected_baseline; | |
371 expected_baseline.push_back( | |
372 std::pair<size_t, BaselineStyle>(0, NORMAL_BASELINE)); | |
373 expected_baseline.push_back(std::pair<size_t, BaselineStyle>(1, SUPERSCRIPT)); | |
374 expected_baseline.push_back( | |
375 std::pair<size_t, BaselineStyle>(2, NORMAL_BASELINE)); | |
376 EXPECT_TRUE(render_text->baselines().EqualsForTesting(expected_baseline)); | |
377 std::vector<std::pair<size_t, bool>> expected_style; | |
378 expected_style.push_back(std::pair<size_t, bool>(0, false)); | |
379 expected_style.push_back(std::pair<size_t, bool>(1, true)); | |
380 expected_style.push_back(std::pair<size_t, bool>(2, false)); | |
381 EXPECT_TRUE( | |
382 render_text->styles()[UNDERLINE].EqualsForTesting(expected_style)); | |
383 // Do the specific test (the core of this test). | |
384 render_text->AppendText(ASCIIToUTF16("def")); | |
385 EXPECT_EQ(render_text->GetDisplayText(), ASCIIToUTF16("abcdef")); | |
386 EXPECT_TRUE(render_text->colors().EqualsForTesting(expected_color)); | |
387 EXPECT_TRUE(render_text->baselines().EqualsForTesting(expected_baseline)); | |
388 EXPECT_TRUE( | |
389 render_text->styles()[UNDERLINE].EqualsForTesting(expected_style)); | |
390 } | |
391 | |
355 // TODO(asvitkine): Cursor movements tests disabled on Mac because RenderTextMac | 392 // TODO(asvitkine): Cursor movements tests disabled on Mac because RenderTextMac |
356 // does not implement this yet. http://crbug.com/131618 | 393 // does not implement this yet. http://crbug.com/131618 |
357 #if !defined(OS_MACOSX) | 394 #if !defined(OS_MACOSX) |
358 void TestVisualCursorMotionInObscuredField(RenderText* render_text, | 395 void TestVisualCursorMotionInObscuredField(RenderText* render_text, |
359 const base::string16& text, | 396 const base::string16& text, |
360 bool select) { | 397 bool select) { |
361 ASSERT_TRUE(render_text->obscured()); | 398 ASSERT_TRUE(render_text->obscured()); |
362 render_text->SetText(text); | 399 render_text->SetText(text); |
363 int len = text.length(); | 400 int len = text.length(); |
364 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, select); | 401 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); | 2859 string_size.set_width(string_size.width() / 2); |
2823 render_text.SetDisplayRect(gfx::Rect(string_size)); | 2860 render_text.SetDisplayRect(gfx::Rect(string_size)); |
2824 render_text.EnsureLayout(); | 2861 render_text.EnsureLayout(); |
2825 CFIndex glyph_count = CTLineGetGlyphCount(render_text.line_); | 2862 CFIndex glyph_count = CTLineGetGlyphCount(render_text.line_); |
2826 EXPECT_GT(text.size(), static_cast<size_t>(glyph_count)); | 2863 EXPECT_GT(text.size(), static_cast<size_t>(glyph_count)); |
2827 EXPECT_NE(0, glyph_count); | 2864 EXPECT_NE(0, glyph_count); |
2828 } | 2865 } |
2829 #endif | 2866 #endif |
2830 | 2867 |
2831 } // namespace gfx | 2868 } // namespace gfx |
OLD | NEW |