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) { | |
356 // Ensure AppendText maintains current text styles. | |
357 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); | |
358 const SkColor color = SK_ColorRED; | |
359 render_text->SetColor(color); | |
360 render_text->SetBaselineStyle(SUPERSCRIPT); | |
361 render_text->SetStyle(BOLD, true); | |
362 render_text->SetStyle(UNDERLINE, false); | |
363 const wchar_t* const cases[] = {L"Hello", L"", L" ", L"world"}; | |
364 size_t total_length = 0; | |
365 for (size_t i = 0; i < arraysize(cases); ++i) { | |
366 EXPECT_TRUE(render_text->colors().EqualsValueForTesting(color)); | |
367 EXPECT_TRUE(render_text->baselines().EqualsValueForTesting(SUPERSCRIPT)); | |
368 EXPECT_TRUE(render_text->styles()[BOLD].EqualsValueForTesting(true)); | |
369 EXPECT_TRUE(render_text->styles()[UNDERLINE].EqualsValueForTesting(false)); | |
370 EXPECT_EQ(total_length, render_text->GetDisplayText().length()); | |
371 base::string16 str = WideToUTF16(cases[i]); | |
372 render_text->AppendText(str); | |
373 total_length += str.length(); | |
374 EXPECT_EQ(total_length, render_text->GetDisplayText().length()); | |
375 std::vector<std::pair<size_t, SkColor>> expected_color; | |
376 expected_color.push_back(std::pair<size_t, SkColor>(0, color)); | |
msw
2015/03/24 20:06:03
None of this makes sense... Call ApplyStyle / Appl
dschuyler
2015/03/24 20:54:08
Done.
| |
377 EXPECT_TRUE(render_text->colors().EqualsForTesting(expected_color)); | |
378 std::vector<std::pair<size_t, bool>> expected_bold; | |
379 expected_bold.push_back(std::pair<size_t, bool>(0, true)); | |
380 EXPECT_TRUE(render_text->styles()[BOLD].EqualsForTesting(expected_bold)); | |
381 std::vector<std::pair<size_t, BaselineStyle>> expected_baseline; | |
382 expected_baseline.push_back( | |
383 std::pair<size_t, BaselineStyle>(0, SUPERSCRIPT)); | |
384 EXPECT_TRUE(render_text->baselines().EqualsForTesting(expected_baseline)); | |
385 } | |
386 const base::string16 result_string = ASCIIToUTF16("Hello world"); | |
387 EXPECT_EQ(render_text->GetDisplayText(), result_string); | |
388 } | |
389 | |
355 // TODO(asvitkine): Cursor movements tests disabled on Mac because RenderTextMac | 390 // TODO(asvitkine): Cursor movements tests disabled on Mac because RenderTextMac |
356 // does not implement this yet. http://crbug.com/131618 | 391 // does not implement this yet. http://crbug.com/131618 |
357 #if !defined(OS_MACOSX) | 392 #if !defined(OS_MACOSX) |
358 void TestVisualCursorMotionInObscuredField(RenderText* render_text, | 393 void TestVisualCursorMotionInObscuredField(RenderText* render_text, |
359 const base::string16& text, | 394 const base::string16& text, |
360 bool select) { | 395 bool select) { |
361 ASSERT_TRUE(render_text->obscured()); | 396 ASSERT_TRUE(render_text->obscured()); |
362 render_text->SetText(text); | 397 render_text->SetText(text); |
363 int len = text.length(); | 398 int len = text.length(); |
364 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, select); | 399 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); | 2857 string_size.set_width(string_size.width() / 2); |
2823 render_text.SetDisplayRect(gfx::Rect(string_size)); | 2858 render_text.SetDisplayRect(gfx::Rect(string_size)); |
2824 render_text.EnsureLayout(); | 2859 render_text.EnsureLayout(); |
2825 CFIndex glyph_count = CTLineGetGlyphCount(render_text.line_); | 2860 CFIndex glyph_count = CTLineGetGlyphCount(render_text.line_); |
2826 EXPECT_GT(text.size(), static_cast<size_t>(glyph_count)); | 2861 EXPECT_GT(text.size(), static_cast<size_t>(glyph_count)); |
2827 EXPECT_NE(0, glyph_count); | 2862 EXPECT_NE(0, glyph_count); |
2828 } | 2863 } |
2829 #endif | 2864 #endif |
2830 | 2865 |
2831 } // namespace gfx | 2866 } // namespace gfx |
OLD | NEW |