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/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
394 EXPECT_EQ(valid_expect_0_and_1, render_text->GetLayoutText()); | 394 EXPECT_EQ(valid_expect_0_and_1, render_text->GetLayoutText()); |
395 render_text->RenderText::SetObscuredRevealIndex(2); | 395 render_text->RenderText::SetObscuredRevealIndex(2); |
396 EXPECT_EQ(ASCIIToUTF16("*h***"), render_text->GetLayoutText()); | 396 EXPECT_EQ(ASCIIToUTF16("*h***"), render_text->GetLayoutText()); |
397 render_text->RenderText::SetObscuredRevealIndex(5); | 397 render_text->RenderText::SetObscuredRevealIndex(5); |
398 const char16 valid_expect_5_and_6[] = {'*', '*', '*', '*', 0xD800, 0xDC00, 0}; | 398 const char16 valid_expect_5_and_6[] = {'*', '*', '*', '*', 0xD800, 0xDC00, 0}; |
399 EXPECT_EQ(valid_expect_5_and_6, render_text->GetLayoutText()); | 399 EXPECT_EQ(valid_expect_5_and_6, render_text->GetLayoutText()); |
400 render_text->RenderText::SetObscuredRevealIndex(6); | 400 render_text->RenderText::SetObscuredRevealIndex(6); |
401 EXPECT_EQ(valid_expect_5_and_6, render_text->GetLayoutText()); | 401 EXPECT_EQ(valid_expect_5_and_6, render_text->GetLayoutText()); |
402 } | 402 } |
403 | 403 |
404 TEST_F(RenderTextTest, ElidedText) { | |
405 // TODO(skanuj) : Add more test cases for following | |
406 // - RenderText styles. | |
407 // - Cross interaction of truncate, elide and obscure. | |
408 // - ElideText tests from text_elider.cc. | |
409 struct { | |
410 const wchar_t* text; | |
411 const wchar_t* layout_text; | |
412 } cases[] = { | |
413 // Strings shorter than the elision width should be laid out in full. | |
414 { L"" , L"" }, | |
415 { kWeak , kWeak }, | |
416 { kLtr , kLtr }, | |
417 { kLtrRtl , kLtrRtl }, | |
418 { kLtrRtlLtr , kLtrRtlLtr }, | |
419 { kRtl , kRtl }, | |
420 { kRtlLtr , kRtlLtr }, | |
421 { kRtlLtrRtl , kRtlLtrRtl }, | |
422 // Strings as long as the elision width should be laid out in full. | |
423 { L"012ab", L"012ab" }, | |
424 // Long strings should be elided with an ellipsis appended at the end. | |
425 { L"012" L"abc" , L"012a\x2026" }, | |
426 { L"012" L"ab" L"\x5d0\x5d1" , L"012a\x2026" }, | |
427 { L"012" L"a" L"\x5d1" L"b" , L"012a\x2026" }, | |
428 // No RLM marker added as digits (012) have weak directionality. | |
429 { L"01" L"\x5d0\x5d1\x5d2" L"ab" , L"01\x5d0\x5d1\x2026" }, | |
430 // RLM marker added as "ab" have string LTR directionality. | |
msw
2013/12/14 03:11:41
nice, good comments!
Anuj
2013/12/14 03:35:03
Fixed spelling of "strong" :)
| |
431 { L"ab" L"\x5d0\x5d1\x5d2" L"ab" , L"ab\x5d0\x5d1\x2026\x200f" }, | |
432 // Complex script is not handled. In this example, the "\x0915\x093f" is a | |
433 // compound glyph, but only half of it is elided. | |
434 { L"0123\x0915\x093f" L"abcd" , L"0123\x0915\x2026" }, | |
435 // Surrogate pairs should be elided reasonably enough. | |
436 { L"0\x05e9\x05bc\x05c1\x05b8" , L"0\x05e9\x05bc\x05c1\x05b8" }, | |
437 { L"0\x05e9\x05bc\x05c1\x05b8" L"ab" , L"0\x05e9\x05bc\x2026" }, | |
438 { L"01\x05e9\x05bc\x05c1\x05b8" L"ab" , L"01\x05e9\x2026" }, | |
439 { L"012\x05e9\x05bc\x05c1\x05b8" L"ab" , L"012\x2026" }, | |
440 { L"012\xF0\x9D\x84\x9E" , L"012\xF0\x2026" }, | |
441 }; | |
442 | |
443 scoped_ptr<RenderText> expected_render_text(RenderText::CreateInstance()); | |
444 expected_render_text->SetFontList(FontList("serif, Sans serif, 12px")); | |
445 expected_render_text->SetDisplayRect(gfx::Rect(0, 0, 9999, 100)); | |
446 | |
447 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); | |
448 render_text->SetFontList(FontList("serif, Sans serif, 12px")); | |
449 render_text->SetElideBehavior(gfx::ELIDE_AT_END); | |
450 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) { | |
451 expected_render_text->SetText(WideToUTF16(cases[i].layout_text)); | |
452 int expected_width = expected_render_text->GetContentWidth(); | |
453 render_text->SetText(WideToUTF16(cases[i].text)); | |
454 #if defined(OS_WIN) | |
455 int original_width = render_text->GetContentWidth(); | |
msw
2013/12/14 03:11:41
optional nit: you can inline this in the check bel
Anuj
2013/12/14 03:35:03
I will let this be.
| |
456 if ((base::win::GetVersion() < base::win::VERSION_VISTA) && | |
457 (expected_width >= original_width)) | |
msw
2013/12/14 03:11:41
Ha! Was this the issue? the ellipsis character was
Anuj
2013/12/14 03:35:03
I am guessing so. Added the TODO.
| |
458 continue; | |
459 #endif | |
460 render_text->SetDisplayRect(gfx::Rect(0, 0, expected_width, 100)); | |
461 EXPECT_EQ(WideToUTF16(cases[i].text), render_text->text()); | |
462 EXPECT_EQ(WideToUTF16(cases[i].layout_text), render_text->GetLayoutText()) | |
463 << "->For case " << i << ": " << cases[i].text << "\n"; | |
464 expected_render_text->SetText(base::string16()); | |
465 } | |
466 } | |
467 | |
468 TEST_F(RenderTextTest, ElidedObscuredText) { | |
469 scoped_ptr<RenderText> expected_render_text(RenderText::CreateInstance()); | |
470 expected_render_text->SetFontList(FontList("serif, Sans serif, 12px")); | |
471 expected_render_text->SetDisplayRect(gfx::Rect(0, 0, 9999, 100)); | |
472 expected_render_text->SetText(WideToUTF16(L"**\x2026")); | |
473 | |
474 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); | |
475 render_text->SetFontList(FontList("serif, Sans serif, 12px")); | |
476 render_text->SetElideBehavior(gfx::ELIDE_AT_END); | |
477 render_text->SetDisplayRect( | |
478 gfx::Rect(0, 0, expected_render_text->GetContentWidth(), 100)); | |
479 render_text->SetObscured(true); | |
480 render_text->SetText(WideToUTF16(L"abcdef")); | |
481 EXPECT_EQ(WideToUTF16(L"abcdef"), render_text->text()); | |
482 EXPECT_EQ(WideToUTF16(L"**\x2026"), render_text->GetLayoutText()); | |
483 } | |
484 | |
404 TEST_F(RenderTextTest, TruncatedText) { | 485 TEST_F(RenderTextTest, TruncatedText) { |
405 struct { | 486 struct { |
406 const wchar_t* text; | 487 const wchar_t* text; |
407 const wchar_t* layout_text; | 488 const wchar_t* layout_text; |
408 } cases[] = { | 489 } cases[] = { |
409 // Strings shorter than the truncation length should be laid out in full. | 490 // Strings shorter than the truncation length should be laid out in full. |
410 { L"", L"" }, | 491 { L"", L"" }, |
411 { kWeak, kWeak }, | 492 { kWeak, kWeak }, |
412 { kLtr, kLtr }, | 493 { kLtr, kLtr }, |
413 { kLtrRtl, kLtrRtl }, | 494 { kLtrRtl, kLtrRtl }, |
(...skipping 1384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1798 render_text->SetText(WideToUTF16(L"x \x25B6 y")); | 1879 render_text->SetText(WideToUTF16(L"x \x25B6 y")); |
1799 render_text->EnsureLayout(); | 1880 render_text->EnsureLayout(); |
1800 ASSERT_EQ(3U, render_text->runs_.size()); | 1881 ASSERT_EQ(3U, render_text->runs_.size()); |
1801 EXPECT_EQ(Range(0, 2), render_text->runs_[0]->range); | 1882 EXPECT_EQ(Range(0, 2), render_text->runs_[0]->range); |
1802 EXPECT_EQ(Range(2, 3), render_text->runs_[1]->range); | 1883 EXPECT_EQ(Range(2, 3), render_text->runs_[1]->range); |
1803 EXPECT_EQ(Range(3, 5), render_text->runs_[2]->range); | 1884 EXPECT_EQ(Range(3, 5), render_text->runs_[2]->range); |
1804 } | 1885 } |
1805 #endif // defined(OS_WIN) | 1886 #endif // defined(OS_WIN) |
1806 | 1887 |
1807 } // namespace gfx | 1888 } // namespace gfx |
OLD | NEW |